aboutsummaryrefslogtreecommitdiff
path: root/telegram
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-12-08 18:35:27 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-12-08 18:35:27 +0300
commit2d3e8ebbb663a95e750206bc66f309427c6750b9 (patch)
tree8f5dd8af30c16a2e2c4e8fe83b9c7668376f36e7 /telegram
parent4df1643312dc21139895c9f4c6daba6c4cb5b855 (diff)
Add /delete command
Diffstat (limited to 'telegram')
-rw-r--r--telegram/commands.go43
1 files changed, 24 insertions, 19 deletions
diff --git a/telegram/commands.go b/telegram/commands.go
index 6b1ccda..8718955 100644
--- a/telegram/commands.go
+++ b/telegram/commands.go
@@ -48,7 +48,7 @@ var chatCommands = map[string]command{
"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"},
- //"delete": command{"", "delete current chat from chat list"},
+ "delete": command{"", "delete current chat from chat list"},
//"members": command{"[query]", "search members [by optional query] in current chat (requires admin rights)"},
}
@@ -113,6 +113,15 @@ func parseCommand(cmdline string) (string, []string) {
return bodyFields[0][1:], bodyFields[1:]
}
+func (c *Client) unsubscribe(chatID int64) {
+ gateway.SendPresence(
+ c.xmpp,
+ c.jid,
+ gateway.SPFrom(strconv.FormatInt(chatID, 10)),
+ gateway.SPType("unsubscribed"),
+ )
+}
+
func (c *Client) usernameOrIdToId(username string) (int32, error) {
userID, err := strconv.ParseInt(username, 10, 32)
// couldn't parse the id, try to lookup as a username
@@ -170,12 +179,7 @@ func (c *Client) ProcessTransportCommand(cmdline string) string {
}
for id := range c.cache.chats {
- gateway.SendPresence(
- c.xmpp,
- c.jid,
- gateway.SPFrom(strconv.FormatInt(id, 10)),
- gateway.SPType("unsubscribed"),
- )
+ c.unsubscribe(id)
}
c.Session.Login = ""
@@ -553,12 +557,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
return err.Error(), true
}
- gateway.SendPresence(
- c.xmpp,
- c.jid,
- gateway.SPFrom(strconv.FormatInt(chatID, 10)),
- gateway.SPType("unsubscribed"),
- )
+ c.unsubscribe(chatID)
}
// close secret chat
case "close":
@@ -577,13 +576,19 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
return err.Error(), true
}
- gateway.SendPresence(
- c.xmpp,
- c.jid,
- gateway.SPFrom(strconv.FormatInt(chatID, 10)),
- gateway.SPType("unsubscribed"),
- )
+ c.unsubscribe(chatID)
}
+ // delete current chat
+ case "delete":
+ _, err := c.client.DeleteChatHistory(&client.DeleteChatHistoryRequest{
+ ChatId: chatID,
+ RemoveFromChatList: true,
+ })
+ if err != nil {
+ return err.Error(), true
+ }
+
+ c.unsubscribe(chatID)
case "help":
return helpString(helpTypeChat), true
default: