Add /delete command

This commit is contained in:
bodqhrohro 2019-12-08 17:35:27 +02:00
parent 4df1643312
commit 2d3e8ebbb6

View file

@ -48,7 +48,7 @@ var chatCommands = map[string]command{
"ban": command{"id or @username [hours]", "restrict @username from current chat for [hours] or forever"}, "ban": command{"id or @username [hours]", "restrict @username from current chat for [hours] or forever"},
"leave": command{"", "leave current chat"}, "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"}, "delete": command{"", "delete current chat from chat list"},
//"members": command{"[query]", "search members [by optional query] in current chat (requires admin rights)"}, //"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:] 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) { func (c *Client) usernameOrIdToId(username string) (int32, error) {
userID, err := strconv.ParseInt(username, 10, 32) userID, err := strconv.ParseInt(username, 10, 32)
// couldn't parse the id, try to lookup as a username // 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 { for id := range c.cache.chats {
gateway.SendPresence( c.unsubscribe(id)
c.xmpp,
c.jid,
gateway.SPFrom(strconv.FormatInt(id, 10)),
gateway.SPType("unsubscribed"),
)
} }
c.Session.Login = "" c.Session.Login = ""
@ -553,12 +557,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
return err.Error(), true return err.Error(), true
} }
gateway.SendPresence( c.unsubscribe(chatID)
c.xmpp,
c.jid,
gateway.SPFrom(strconv.FormatInt(chatID, 10)),
gateway.SPType("unsubscribed"),
)
} }
// close secret chat // close secret chat
case "close": case "close":
@ -577,13 +576,19 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
return err.Error(), true return err.Error(), true
} }
gateway.SendPresence( c.unsubscribe(chatID)
c.xmpp,
c.jid,
gateway.SPFrom(strconv.FormatInt(chatID, 10)),
gateway.SPType("unsubscribed"),
)
} }
// 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": case "help":
return helpString(helpTypeChat), true return helpString(helpTypeChat), true
default: default: