Extended room disco info
This commit is contained in:
parent
7ef32096af
commit
63521b8f90
2
go.mod
2
go.mod
|
@ -13,4 +13,4 @@ require (
|
|||
gosrc.io/xmpp v0.5.2-0.20211214110136-5f99e1cd06e1
|
||||
)
|
||||
|
||||
replace gosrc.io/xmpp => dev.narayana.im/narayana/go-xmpp v0.0.0-20220524203317-306b4ff58e8f
|
||||
replace gosrc.io/xmpp => dev.narayana.im/narayana/go-xmpp v0.0.0-20220708184440-35d9cd68e55f
|
||||
|
|
2
go.sum
2
go.sum
|
@ -2,6 +2,8 @@ dev.narayana.im/narayana/go-xmpp v0.0.0-20211218155535-e55463fc9829 h1:qe81G6+t1
|
|||
dev.narayana.im/narayana/go-xmpp v0.0.0-20211218155535-e55463fc9829/go.mod h1:L3NFMqYOxyLz3JGmgFyWf7r9htE91zVGiK40oW4RwdY=
|
||||
dev.narayana.im/narayana/go-xmpp v0.0.0-20220524203317-306b4ff58e8f h1:6249ajbMjgYz53Oq0IjTvjHXbxTfu29Mj1J/6swRHs4=
|
||||
dev.narayana.im/narayana/go-xmpp v0.0.0-20220524203317-306b4ff58e8f/go.mod h1:L3NFMqYOxyLz3JGmgFyWf7r9htE91zVGiK40oW4RwdY=
|
||||
dev.narayana.im/narayana/go-xmpp v0.0.0-20220708184440-35d9cd68e55f h1:aT50UsPH1dLje9CCAquRRhr7I9ZvL3kQU6WIWTe8PZ0=
|
||||
dev.narayana.im/narayana/go-xmpp v0.0.0-20220708184440-35d9cd68e55f/go.mod h1:L3NFMqYOxyLz3JGmgFyWf7r9htE91zVGiK40oW4RwdY=
|
||||
github.com/Arman92/go-tdlib v0.0.0-20191002071913-526f4e1d15f7 h1:GbV1Lv3lVHsSeKAqPTBem72OCsGjXntW4jfJdXciE+w=
|
||||
github.com/Arman92/go-tdlib v0.0.0-20191002071913-526f4e1d15f7/go.mod h1:ZzkRfuaFj8etIYMj/ECtXtgfz72RE6U+dos27b3XIwk=
|
||||
github.com/agnivade/wasmbrowsertest v0.3.1/go.mod h1:zQt6ZTdl338xxRaMW395qccVE2eQm0SjC/SDz0mPWQI=
|
||||
|
|
|
@ -1039,7 +1039,7 @@ func (c *Client) GetChatDescription(chat *client.Chat) string {
|
|||
return fullInfo.Description
|
||||
}
|
||||
} else {
|
||||
log.Warnf("Coudln't retrieve private chat info: %v", err.Error())
|
||||
log.Warnf("Couldn't retrieve private chat info: %v", err.Error())
|
||||
}
|
||||
} else if chatType == client.TypeChatTypeBasicGroup {
|
||||
basicGroupType, _ := chat.Type.(*client.ChatTypeBasicGroup)
|
||||
|
@ -1049,7 +1049,7 @@ func (c *Client) GetChatDescription(chat *client.Chat) string {
|
|||
if err == nil {
|
||||
return fullInfo.Description
|
||||
} else {
|
||||
log.Warnf("Coudln't retrieve basic group info: %v", err.Error())
|
||||
log.Warnf("Couldn't retrieve basic group info: %v", err.Error())
|
||||
}
|
||||
} else if chatType == client.TypeChatTypeSupergroup {
|
||||
supergroupType, _ := chat.Type.(*client.ChatTypeSupergroup)
|
||||
|
@ -1059,12 +1059,41 @@ func (c *Client) GetChatDescription(chat *client.Chat) string {
|
|||
if err == nil {
|
||||
return fullInfo.Description
|
||||
} else {
|
||||
log.Warnf("Coudln't retrieve supergroup info: %v", err.Error())
|
||||
log.Warnf("Couldn't retrieve supergroup info: %v", err.Error())
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetChatMemberCount obtains the member count depending on the chat type
|
||||
func (c *Client) GetChatMemberCount(chat *client.Chat) int32 {
|
||||
chatType := chat.Type.ChatTypeType()
|
||||
if chatType == client.TypeChatTypePrivate {
|
||||
return 2
|
||||
} else if chatType == client.TypeChatTypeBasicGroup {
|
||||
basicGroupType, _ := chat.Type.(*client.ChatTypeBasicGroup)
|
||||
basicGroup, err := c.client.GetBasicGroup(&client.GetBasicGroupRequest{
|
||||
BasicGroupId: basicGroupType.BasicGroupId,
|
||||
})
|
||||
if err == nil {
|
||||
return basicGroup.MemberCount
|
||||
} else {
|
||||
log.Warnf("Couldn't retrieve basic group: %v", err.Error())
|
||||
}
|
||||
} else if chatType == client.TypeChatTypeSupergroup {
|
||||
supergroupType, _ := chat.Type.(*client.ChatTypeSupergroup)
|
||||
supergroup, err := c.client.GetSupergroup(&client.GetSupergroupRequest{
|
||||
SupergroupId: supergroupType.SupergroupId,
|
||||
})
|
||||
if err == nil {
|
||||
return supergroup.MemberCount
|
||||
} else {
|
||||
log.Warnf("Couldn't retrieve supergroup: %v", err.Error())
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// GetGroupChats obtains all group chats
|
||||
func (c *Client) GetGroupChats() []*client.Chat {
|
||||
var groupChats []*client.Chat
|
||||
|
|
|
@ -340,11 +340,7 @@ func handleGetDisco(dt discoType, s xmpp.Sender, iq *stanza.IQ) {
|
|||
if dt == discoTypeInfo {
|
||||
disco := answer.DiscoInfo()
|
||||
toID, toOk := toToID(iq.To)
|
||||
if toOk {
|
||||
disco.AddIdentity("", "account", "registered")
|
||||
} else {
|
||||
disco.AddIdentity("Telegram Gateway", "gateway", "telegram")
|
||||
}
|
||||
var isMuc bool
|
||||
bare, _, fromOk := splitFrom(iq.From)
|
||||
if fromOk {
|
||||
session, sessionOk := sessions[bare]
|
||||
|
@ -352,24 +348,51 @@ func handleGetDisco(dt discoType, s xmpp.Sender, iq *stanza.IQ) {
|
|||
if toOk {
|
||||
chat, _, err := session.GetContactByID(toID, nil)
|
||||
if err == nil && session.IsGroup(chat) {
|
||||
isMuc = true
|
||||
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",
|
||||
)
|
||||
disco.AddFeatures(
|
||||
"http://jabber.org/protocol/muc",
|
||||
"muc_persistent",
|
||||
"muc_hidden",
|
||||
"muc_membersonly",
|
||||
"muc_unmoderated",
|
||||
"muc_nonanonymous",
|
||||
"muc_unsecured",
|
||||
)
|
||||
fields := []*stanza.Field{
|
||||
&stanza.Field{
|
||||
Var: "FORM_TYPE",
|
||||
Type: "hidden",
|
||||
ValuesList: []string{"http://jabber.org/protocol/muc#roominfo"},
|
||||
},
|
||||
&stanza.Field{
|
||||
Var: "muc#roominfo_description",
|
||||
Label: "Description",
|
||||
ValuesList: []string{session.GetChatDescription(chat)},
|
||||
},
|
||||
&stanza.Field{
|
||||
Var: "muc#roominfo_occupants",
|
||||
Label: "Number of occupants",
|
||||
ValuesList: []string{strconv.FormatInt(int64(session.GetChatMemberCount(chat)), 10)},
|
||||
},
|
||||
}
|
||||
|
||||
disco.Form = stanza.NewForm(fields, "result")
|
||||
}
|
||||
} else {
|
||||
disco.AddFeatures(stanza.NSDiscoItems)
|
||||
disco.AddIdentity("Telegram group chats", "conference", "text")
|
||||
}
|
||||
}
|
||||
}
|
||||
if toOk {
|
||||
if !isMuc {
|
||||
disco.AddIdentity("", "account", "registered")
|
||||
}
|
||||
} else {
|
||||
disco.AddIdentity("Telegram Gateway", "gateway", "telegram")
|
||||
}
|
||||
answer.Payload = disco
|
||||
} else if dt == discoTypeItems {
|
||||
disco := answer.DiscoItems()
|
||||
|
|
Loading…
Reference in a new issue