-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9eeee98
commit ae5b2d6
Showing
7 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters