|
|
@ -55,6 +55,11 @@ func HandleIq(s xmpp.Sender, p stanza.Packet) { |
|
|
|
go handleGetDiscoInfo(s, iq) |
|
|
|
return |
|
|
|
} |
|
|
|
_, ok = iq.Payload.(*stanza.DiscoItems) |
|
|
|
if ok { |
|
|
|
go handleGetDiscoItems(s, iq) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -333,6 +338,59 @@ func handleGetDiscoInfo(s xmpp.Sender, iq *stanza.IQ) { |
|
|
|
} 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") |
|
|
|
} |
|
|
|
} |
|
|
|
answer.Payload = disco |
|
|
|
|
|
|
|
log.Debugf("%#v", answer) |
|
|
|
|
|
|
|
component, ok := s.(*xmpp.Component) |
|
|
|
if !ok { |
|
|
|
log.Error("Not a component") |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
_ = gateway.ResumableSend(component, answer) |
|
|
|
} |
|
|
|
|
|
|
|
func handleGetDiscoItems(s xmpp.Sender, iq *stanza.IQ) { |
|
|
|
answer, err := stanza.NewIQ(stanza.Attrs{ |
|
|
|
Type: stanza.IQTypeResult, |
|
|
|
From: iq.To, |
|
|
|
To: iq.From, |
|
|
|
Id: iq.Id, |
|
|
|
Lang: "en", |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
log.Errorf("Failed to create answer IQ: %v", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
log.Debugf("%#v", answer) |
|
|
|