Add leave! command to leave group as owner

This commit is contained in:
Bohdan Horbeshko 2022-02-03 14:29:16 -05:00
parent 6701335302
commit fe5ca09c7c

View file

@ -74,6 +74,7 @@ var chatCommands = map[string]command{
"unban": command{"id or @username", "unbans @username in current chat (and devotes from admins)"},
"promote": command{"id or @username [title]", "promote user to admin in current chat"},
"leave": command{"", "leave current chat"},
"leave!": command{"", "leave current chat (for owners)"},
"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)"},
@ -159,8 +160,8 @@ func rawCmdArguments(cmdline string, start uint8) (string) {
return ""
}
func (c *Client) unsubscribe(chatID int64) {
gateway.SendPresence(
func (c *Client) unsubscribe(chatID int64) error {
return gateway.SendPresence(
c.xmpp,
c.jid,
gateway.SPFrom(strconv.FormatInt(chatID, 10)),
@ -728,7 +729,23 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
return err.Error(), true
}
c.unsubscribe(chatID)
err = c.unsubscribe(chatID)
if err != nil {
return err.Error(), true
}
// leave current chat (for owners)
case "leave!":
_, err := c.client.DeleteChat(&client.DeleteChatRequest{
ChatId: chatID,
})
if err != nil {
return err.Error(), true
}
err = c.unsubscribe(chatID)
if err != nil {
return err.Error(), true
}
// close secret chat
case "close":
chat, _, err := c.GetContactByID(chatID, nil)
@ -746,7 +763,10 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
return err.Error(), true
}
c.unsubscribe(chatID)
err = c.unsubscribe(chatID)
if err != nil {
return err.Error(), true
}
}
// delete current chat
case "delete":
@ -759,7 +779,10 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
return err.Error(), true
}
c.unsubscribe(chatID)
err = c.unsubscribe(chatID)
if err != nil {
return err.Error(), true
}
// message search
case "search":
var limit int32 = 100