Skip to content

Commit

Permalink
Add invite and list
Browse files Browse the repository at this point in the history
  • Loading branch information
larynjahor committed Sep 8, 2022
1 parent 9eeee98 commit ae5b2d6
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/cc.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ var ccCmd = &cobra.Command{

func init() {
ccCmd.AddCommand(cc.ChatsCmd)
ccCmd.AddCommand(cc.MessagesCmd)
rootCmd.AddCommand(ccCmd)
}
1 change: 1 addition & 0 deletions cmd/cc/chats.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ func init() {
ChatsCmd.AddCommand(chats.DeleteCmd)
ChatsCmd.AddCommand(chats.UpdateCmd)
ChatsCmd.AddCommand(chats.GetCmd)
ChatsCmd.AddCommand(chats.InviteCmd)
}
2 changes: 1 addition & 1 deletion cmd/cc/chats/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var CreateCmd = &cobra.Command{
return err
}
if !ok {
fmt.Printf("Successfuly created chat %s.\n", title)
fmt.Printf("Successfuly created chat %s.\n", chat.GetUuid())
}

return err
Expand Down
69 changes: 69 additions & 0 deletions cmd/cc/chats/invite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package chats

import (
"errors"
"fmt"

"github.com/slntopp/nocloud-cc/pkg/chats/proto"
"github.com/slntopp/nocloud-cli/cmd/cc/helpers"
"github.com/slntopp/nocloud-cli/pkg/tools"
"github.com/spf13/cobra"
)

// InviteCmd represents the invite command
var InviteCmd = &cobra.Command{
Use: "invite [flags]",
Short: "Invite to chat",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, _ []string) (err error) {
ctx, client := helpers.MakeChatsServiceClientOrFail()
var account string
if account, err = cmd.Flags().GetString("account"); err != nil || account == "" {
return errors.New("empty account uui")
}
var chat string
if chat, err = cmd.Flags().GetString("chat"); err != nil || chat == "" {
return errors.New("empty chat uuid")
}

_, err = client.Invite(ctx, &proto.InviteChatRequest{
ChatUuid: chat,
UserUuid: account,
})

if err != nil {
fmt.Printf("Error while inviting to chat %s. Reason: %v.\n", chat, err)
return err
}

ok, err := tools.PrintJsonDataQ(cmd, chat)
if err != nil {
return err
}
if !ok {
fmt.Printf("Successfuly invited account %s to chat %s.\n", account, chat)
}

return err
},
}

func init() {
InviteCmd.Flags().StringP("account", "a", "", "Account uuid")
InviteCmd.Flags().StringP("chat", "c", "", "Chat uuid")
}
2 changes: 1 addition & 1 deletion cmd/cc/messages/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var GetCmd = &cobra.Command{
})

if err != nil {
fmt.Printf("Error while deleting message %s. Reason: %v.\n", uuid, err)
fmt.Printf("Error while fetching message %s. Reason: %v.\n", uuid, err)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/cc/messages/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var ListCmd = &cobra.Command{
return err
}
if !ok {
fmt.Printf("Successfuly fetched messages %v.\n", resp)
fmt.Printf("Successfuly fetched messages %v.\n", resp.Messages)
}

return err
Expand Down
1 change: 1 addition & 0 deletions cmd/cc/messages/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var UpdateCmd = &cobra.Command{
}

resp, err := client.UpdateChatMessage(ctx, &proto.ChatMessage{
Uuid: uuid,
Message: messageText,
})

Expand Down

0 comments on commit ae5b2d6

Please sign in to comment.