-
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.
Merge pull request #19 from slntopp/dev-chat-cmd
Dev chat cmd
- Loading branch information
Showing
17 changed files
with
855 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
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 cmd | ||
|
||
import ( | ||
"github.com/slntopp/nocloud-cli/cmd/cc" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// ccCmd represents Core Chat module cmd | ||
var ccCmd = &cobra.Command{ | ||
Use: "cc", | ||
Aliases: []string{}, | ||
Short: "Core Chat nocloud-cli module", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
ccCmd.AddCommand(cc.ChatsCmd) | ||
ccCmd.AddCommand(cc.MessagesCmd) | ||
rootCmd.AddCommand(ccCmd) | ||
} |
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,37 @@ | ||
/* | ||
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 cc | ||
|
||
import ( | ||
"github.com/slntopp/nocloud-cli/cmd/cc/chats" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// chatsCmd represents the chats command | ||
var ChatsCmd = &cobra.Command{ | ||
Use: "chat", | ||
Aliases: []string{"cht", "ch", "chats"}, | ||
Short: "Manage nocloud-cc chats", | ||
} | ||
|
||
func init() { | ||
ChatsCmd.AddCommand(chats.CreateCmd) | ||
ChatsCmd.AddCommand(chats.GetCmd) | ||
ChatsCmd.AddCommand(chats.DeleteCmd) | ||
ChatsCmd.AddCommand(chats.UpdateCmd) | ||
ChatsCmd.AddCommand(chats.GetCmd) | ||
ChatsCmd.AddCommand(chats.InviteCmd) | ||
} |
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,65 @@ | ||
/* | ||
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" | ||
) | ||
|
||
// createCmd represents the create command | ||
var CreateCmd = &cobra.Command{ | ||
Use: "create [flags]", | ||
Short: "Create chat", | ||
Args: cobra.ExactArgs(0), | ||
RunE: func(cmd *cobra.Command, _ []string) (err error) { | ||
ctx, client := helpers.MakeChatsServiceClientOrFail() | ||
var title string | ||
if title, err = cmd.Flags().GetString("title"); err != nil || title == "" { | ||
return errors.New("empty uuid") | ||
} | ||
|
||
chat, err := client.CreateChat(ctx, &proto.CreateChatRequest{ | ||
Chat: &proto.Chat{ | ||
Title: title, | ||
}, | ||
}) | ||
|
||
if err != nil { | ||
fmt.Printf("Error while creating chat %s. Reason: %v.\n", title, err) | ||
return err | ||
} | ||
|
||
ok, err := tools.PrintJsonDataQ(cmd, chat) | ||
if err != nil { | ||
return err | ||
} | ||
if !ok { | ||
fmt.Printf("Successfuly created chat %s.\n", chat.GetUuid()) | ||
} | ||
|
||
return err | ||
}, | ||
} | ||
|
||
func init() { | ||
CreateCmd.Flags().StringP("title", "t", "", "Chat title") | ||
} |
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,63 @@ | ||
/* | ||
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" | ||
) | ||
|
||
// deleteCmd represents the delete command | ||
var DeleteCmd = &cobra.Command{ | ||
Use: "delete [flags]", | ||
Short: "Delete chat", | ||
Args: cobra.ExactArgs(0), | ||
RunE: func(cmd *cobra.Command, _ []string) (err error) { | ||
ctx, client := helpers.MakeChatsServiceClientOrFail() | ||
|
||
var uuid string | ||
if uuid, err = cmd.Flags().GetString("uuid"); err != nil || uuid == "" { | ||
return errors.New("empty uuid") | ||
} | ||
chat, err := client.DeleteChat(ctx, &proto.DeleteChatRequest{ | ||
Uuid: uuid, | ||
}) | ||
|
||
if err != nil { | ||
fmt.Printf("Error while deleting chat %s. Reason: %v.\n", uuid, err) | ||
return err | ||
} | ||
|
||
ok, err := tools.PrintJsonDataQ(cmd, chat) | ||
if err != nil { | ||
return err | ||
} | ||
if !ok { | ||
fmt.Printf("Successfuly deleted chat %s.\n", uuid) | ||
} | ||
|
||
return err | ||
}, | ||
} | ||
|
||
func init() { | ||
DeleteCmd.Flags().StringP("uuid", "u", "", "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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
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" | ||
) | ||
|
||
// deleteCmd represents the delete command | ||
var GetCmd = &cobra.Command{ | ||
Use: "get [flags]", | ||
Short: "Get chat", | ||
Args: cobra.ExactArgs(0), | ||
RunE: func(cmd *cobra.Command, _ []string) (err error) { | ||
ctx, client := helpers.MakeChatsServiceClientOrFail() | ||
|
||
var uuid string | ||
if uuid, err = cmd.Flags().GetString("uuid"); err != nil || uuid == "" { | ||
return errors.New("empty uuid") | ||
} | ||
chat, err := client.GetChat(ctx, &proto.GetChatRequest{ | ||
Uuid: uuid, | ||
}) | ||
|
||
if err != nil { | ||
fmt.Printf("Error while fetching chat %s. Reason: %v.\n", uuid, err) | ||
return err | ||
} | ||
|
||
ok, err := tools.PrintJsonDataQ(cmd, chat) | ||
if err != nil { | ||
return err | ||
} | ||
if !ok { | ||
fmt.Printf("Successfuly fetched chat %v.\n", chat) | ||
} | ||
|
||
return err | ||
}, | ||
} | ||
|
||
func init() { | ||
GetCmd.Flags().StringP("uuid", "u", "", "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
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") | ||
} |
Oops, something went wrong.