From 2b5bb43bdd664715fff776a1b92d23db59c7cbec Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Tue, 1 Jul 2025 16:01:43 -0400 Subject: [PATCH] Send an invite to MUC on /add wherever applicable --- telegram/commands.go | 2 +- telegram/handlers.go | 6 +++--- telegram/utils.go | 7 ++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/telegram/commands.go b/telegram/commands.go index d78cd20..d4d8d37 100644 --- a/telegram/commands.go +++ b/telegram/commands.go @@ -1126,7 +1126,7 @@ func (c *Client) cmdAdd(args []string) (string, bool) { return "No error, but chat is nil", false } - c.subscribeToID(chat.Id, chat) + c.subscribeToID(chat.Id, chat, true) return "", true } diff --git a/telegram/handlers.go b/telegram/handlers.go index 7bc3afc..dfbc8f0 100644 --- a/telegram/handlers.go +++ b/telegram/handlers.go @@ -180,7 +180,7 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) { c.cache.SetChat(update.Chat.Id, update.Chat) if update.Chat.Positions != nil && len(update.Chat.Positions) > 0 { - c.subscribeToID(update.Chat.Id, update.Chat) + c.subscribeToID(update.Chat.Id, update.Chat, false) } if update.Chat.Id < 0 { @@ -192,14 +192,14 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) { // chat position is updated func (c *Client) updateChatPosition(update *client.UpdateChatPosition) { if update.Position != nil && update.Position.Order != 0 { - go c.subscribeToID(update.ChatId, nil) + go c.subscribeToID(update.ChatId, nil, false) } } // chat last message is updated func (c *Client) updateChatLastMessage(update *client.UpdateChatLastMessage) { if update.Positions != nil && len(update.Positions) > 0 { - go c.subscribeToID(update.ChatId, nil) + go c.subscribeToID(update.ChatId, nil, false) } } diff --git a/telegram/utils.go b/telegram/utils.go index 8ec51c4..30f95c4 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -2401,7 +2401,7 @@ func (c *Client) IsGroup(chat *client.Chat) bool { } // subscribe to a Telegram ID -func (c *Client) subscribeToID(id int64, chat *client.Chat) { +func (c *Client) subscribeToID(id int64, chat *client.Chat, firstTime bool) { args := gateway.SimplePresence(id, "subscribe") if chat == nil { @@ -2409,6 +2409,11 @@ func (c *Client) subscribeToID(id int64, chat *client.Chat) { } if chat != nil { if c.Session.MUC && c.IsGroup(chat) { + if firstTime { + for resource := range c.resourcesRange() { + gateway.InviteToMUC(id, c.jid+"/"+resource, c.xmpp) + } + } return }