diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2019-12-08 18:25:29 +0300 |
---|---|---|
committer | bodqhrohro <bodqhrohro@gmail.com> | 2019-12-08 18:25:29 +0300 |
commit | 4df1643312dc21139895c9f4c6daba6c4cb5b855 (patch) | |
tree | b804b24122b30dd3c1f1026a5ac3ae02df07c443 | |
parent | 49423147e3a2ecb4affede4ece5af659b096f87f (diff) |
Add /close command
-rw-r--r-- | telegram/commands.go | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/telegram/commands.go b/telegram/commands.go index ad82cb6..6b1ccda 100644 --- a/telegram/commands.go +++ b/telegram/commands.go @@ -47,7 +47,7 @@ var chatCommands = map[string]command{ "kick": command{"id or @username", "remove user to current chat"}, "ban": command{"id or @username [hours]", "restrict @username from current chat for [hours] or forever"}, "leave": command{"", "leave current chat"}, - //"close": command{"", "close current secret chat"}, + "close": command{"", "close current secret chat"}, //"delete": command{"", "delete current chat from chat list"}, //"members": command{"[query]", "search members [by optional query] in current chat (requires admin rights)"}, } @@ -560,6 +560,30 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) gateway.SPType("unsubscribed"), ) } + // close secret chat + case "close": + chat, _, err := c.GetContactByID(chatID, nil) + if err != nil { + return err.Error(), true + } + + chatType := chat.Type.ChatTypeType() + if chatType == client.TypeChatTypeSecret { + chatTypeSecret, _ := chat.Type.(*client.ChatTypeSecret) + _, err = c.client.CloseSecretChat(&client.CloseSecretChatRequest{ + SecretChatId: chatTypeSecret.SecretChatId, + }) + if err != nil { + return err.Error(), true + } + + gateway.SendPresence( + c.xmpp, + c.jid, + gateway.SPFrom(strconv.FormatInt(chatID, 10)), + gateway.SPType("unsubscribed"), + ) + } case "help": return helpString(helpTypeChat), true default: |