|
|
@ -24,6 +24,12 @@ const ( |
|
|
|
) |
|
|
|
const NodeVCard4 string = "urn:xmpp:vcard4" |
|
|
|
|
|
|
|
type discoType int |
|
|
|
const ( |
|
|
|
discoTypeInfo discoType = iota |
|
|
|
discoTypeItems |
|
|
|
) |
|
|
|
|
|
|
|
func logPacketType(p stanza.Packet) { |
|
|
|
log.Warnf("Ignoring packet: %T\n", p) |
|
|
|
} |
|
|
@ -52,7 +58,12 @@ func HandleIq(s xmpp.Sender, p stanza.Packet) { |
|
|
|
} |
|
|
|
_, ok = iq.Payload.(*stanza.DiscoInfo) |
|
|
|
if ok { |
|
|
|
go handleGetDiscoInfo(s, iq) |
|
|
|
go handleGetDisco(discoTypeInfo, s, iq) |
|
|
|
return |
|
|
|
} |
|
|
|
_, ok = iq.Payload.(*stanza.DiscoItems) |
|
|
|
if ok { |
|
|
|
go handleGetDisco(discoTypeItems, s, iq) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -313,7 +324,7 @@ func handleGetVcardIq(s xmpp.Sender, iq *stanza.IQ, typ byte) { |
|
|
|
_ = gateway.ResumableSend(component, &answer) |
|
|
|
} |
|
|
|
|
|
|
|
func handleGetDiscoInfo(s xmpp.Sender, iq *stanza.IQ) { |
|
|
|
func handleGetDisco(dt discoType, s xmpp.Sender, iq *stanza.IQ) { |
|
|
|
answer, err := stanza.NewIQ(stanza.Attrs{ |
|
|
|
Type: stanza.IQTypeResult, |
|
|
|
From: iq.To, |
|
|
@ -326,14 +337,85 @@ func handleGetDiscoInfo(s xmpp.Sender, iq *stanza.IQ) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
disco := answer.DiscoInfo() |
|
|
|
_, ok := toToID(iq.To) |
|
|
|
if ok { |
|
|
|
disco.AddIdentity("", "account", "registered") |
|
|
|
} else { |
|
|
|
disco.AddIdentity("Telegram Gateway", "gateway", "telegram") |
|
|
|
if dt == discoTypeInfo { |
|
|
|
disco := answer.DiscoInfo() |
|
|
|
toID, toOk := toToID(iq.To) |
|
|
|
if !toOk { |
|
|
|
disco.AddIdentity("Telegram Gateway", "gateway", "telegram") |
|
|
|
} |
|
|
|
|
|
|
|
var isMuc bool |
|
|
|
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) { |
|
|
|
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", |
|
|
|
) |
|
|
|
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 && !isMuc { |
|
|
|
disco.AddIdentity("", "account", "registered") |
|
|
|
} |
|
|
|
answer.Payload = disco |
|
|
|
} else if dt == discoTypeItems { |
|
|
|
disco := answer.DiscoItems() |
|
|
|
|
|
|
|
_, ok := toToID(iq.To) |
|
|
|
if !ok { |
|
|
|
bare, _, ok := splitFrom(iq.From) |
|
|
|
if ok { |
|
|
|
// raw access, no need to create a new instance if not connected
|
|
|
|
session, ok := sessions[bare] |
|
|
|
if ok && session.Session.MUC { |
|
|
|
bareJid := gateway.Jid.Bare() |
|
|
|
disco.AddItem(bareJid, "", "Telegram group chats") |
|
|
|
for _, chat := range session.GetGroupChats() { |
|
|
|
jid := strconv.FormatInt(chat.Id, 10) + "@" + bareJid |
|
|
|
disco.AddItem(jid, "", chat.Title) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
answer.Payload = disco |
|
|
|
} |
|
|
|
answer.Payload = disco |
|
|
|
|
|
|
|
log.Debugf("%#v", answer) |
|
|
|
|
|
|
|