From 7ef32096af6017607f70a0b5aa2fbc03925c72d1 Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Fri, 8 Jul 2022 08:43:44 -0400 Subject: [PATCH] Basic room disco info --- telegram/utils.go | 13 ++++++++----- xmpp/handlers.go | 33 +++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/telegram/utils.go b/telegram/utils.go index 7747acb..5244803 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -1075,11 +1075,8 @@ func (c *Client) GetGroupChats() []*client.Chat { if err == nil { for _, id := range chats.ChatIds { chat, _, _ := c.GetContactByID(id, nil) - if chat != nil { - typ := chat.Type.ChatTypeType() - if typ == client.TypeChatTypeBasicGroup { - groupChats = append(groupChats, chat) - } + if chat != nil && c.IsGroup(chat) { + groupChats = append(groupChats, chat) } } } else { @@ -1089,6 +1086,12 @@ func (c *Client) GetGroupChats() []*client.Chat { return groupChats } +// IsGroup determines if a chat is eligible to be represented as MUC +func (c *Client) IsGroup(chat *client.Chat) bool { + typ := chat.Type.ChatTypeType() + return typ == client.TypeChatTypeBasicGroup +} + // subscribe to a Telegram ID func (c *Client) subscribeToID(id int64, chat *client.Chat) { var args []args.V diff --git a/xmpp/handlers.go b/xmpp/handlers.go index 3b688f5..6531983 100644 --- a/xmpp/handlers.go +++ b/xmpp/handlers.go @@ -339,18 +339,35 @@ func handleGetDisco(dt discoType, s xmpp.Sender, iq *stanza.IQ) { if dt == discoTypeInfo { disco := answer.DiscoInfo() - _, ok := toToID(iq.To) - if ok { + toID, toOk := toToID(iq.To) + if toOk { disco.AddIdentity("", "account", "registered") } else { disco.AddIdentity("Telegram Gateway", "gateway", "telegram") } - bare, _, ok := splitFrom(iq.From) - if ok { - session, ok := sessions[bare] - if ok && session.Session.MUC { - disco.AddFeatures(stanza.NSDiscoItems) - disco.AddIdentity("Telegram group chats", "conference", "text") + bare, _, fromOk := splitFrom(iq.From) + if fromOk { + session, sessionOk := sessions[bare] + if sessionOk && session.Session.MUC { + if toOk { + chat, _, err := session.GetContactByID(toID, nil) + if err == nil && session.IsGroup(chat) { + disco.AddIdentity(chat.Title, "conference", "text") + } + + disco.AddFeatures( + "http://jabber.org/protocol/muc", + "muc_persistent", + "muc_hidden", + "muc_membersonly", + "muc_unmoderated", + "muc_nonanonymous", + "muc_unsecured", + ) + } else { + disco.AddFeatures(stanza.NSDiscoItems) + disco.AddIdentity("Telegram group chats", "conference", "text") + } } } answer.Payload = disco