Add MUC-to-legacy migrator

This commit is contained in:
Bohdan Horbeshko 2025-07-03 13:48:37 -04:00
parent 65cc9b1551
commit d6582a888f
3 changed files with 30 additions and 4 deletions

View file

@ -458,8 +458,13 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) (strin
if err != nil {
return err.Error(), false
}
if args[0] == "muc" && args[1] == "true" {
if args[0] == "muc" {
switch args[1] {
case "true":
go c.MigrateToMUCs()
case "false":
go c.MigrateFromMUCs()
}
}
gateway.DirtySessions = true

View file

@ -2817,6 +2817,22 @@ func (c *Client) MigrateToMUCs() {
}
}
// MigrateFromMUCs kicks from MUCs and subscribes back to legacy group chats
func (c *Client) MigrateFromMUCs() {
var chatIDs []int64
for _, chat := range c.GetGroupChats() {
chatIDs = append(chatIDs, chat.Id)
}
c.locks.mucCacheLock.Lock()
for _, chatID := range chatIDs {
c.kickMeFromMUC(chatID, []uint16{110, 332}, false, nil)
delete(c.mucCache, chatID)
c.subscribeToID(chatID, nil, false)
}
c.locks.mucCacheLock.Unlock()
}
// SetChatMemberStatus is a handy wrapper for the following TDLib method
func (c *Client) SetChatMemberStatus(chatID, userID int64, status ChatMemberStatus, numericPayload int64, stringPayload, nickname string) error {
var chatMemberStatus client.ChatMemberStatus

View file

@ -1478,8 +1478,13 @@ func handleSetQueryCommand(s xmpp.Sender, iq *stanza.IQ, command *stanza.Command
errString = fmt.Sprintf("Error for field %v: %v, aborting", field.Var, err.Error())
break
}
if field.Var == "muc" && fieldValue == "true" {
if field.Var == "muc" {
switch fieldValue {
case "true":
go session.MigrateToMUCs()
case "false":
go session.MigrateFromMUCs()
}
}
infoStrings = append(infoStrings, fmt.Sprintf("%s set to %s", field.Var, value))
gateway.DirtySessions = true