From: Bernhard Tittelbach Date: Wed, 28 Aug 2013 02:39:23 +0000 (+0000) Subject: presence subscription both ways X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=a1f29138492d8dad21a41ad6c06fa36c6e324e69;p=svn42.git presence subscription both ways --- diff --git a/r3-netstatus/r3xmppbot/r3xmppbot.go b/r3-netstatus/r3xmppbot/r3xmppbot.go index 1a2d9f0..6017c3a 100644 --- a/r3-netstatus/r3xmppbot/r3xmppbot.go +++ b/r3-netstatus/r3xmppbot/r3xmppbot.go @@ -313,11 +313,21 @@ func (botdata *XmppBot) handleIncomingXMPPStanzas(xmppin <- chan xmpp.Stanza, xm if stanza.GetHeader() == nil { continue } - if stanza.GetHeader().Type == "subscribe" { - xmppout <- botdata.makeXMPPPresence(stanza.GetHeader().From, "subscribed") + switch stanza.GetHeader().Type { + case "subscribe": + xmppout <- botdata.makeXMPPPresence(stanza.GetHeader().From, "subscribed") + jabber_events <- JabberEvent{stanza.GetHeader().From, true, R3NoChange, false} + xmppout <- botdata.makeXMPPPresence(stanza.GetHeader().From, "subscribe") + case "unsubscribe", "unsubscribed": + jabber_events <- JabberEvent{stanza.GetHeader().From, false, R3NoInfo, false} + botdata.jid_lastauthtime_[stanza.GetHeader().From] = 0 //logout + xmppout <- botdata.makeXMPPPresence(stanza.GetHeader().From, "unsubscribe") + case "unavailable": + jabber_events <- JabberEvent{stanza.GetHeader().From, false, R3NoChange, false} + botdata.jid_lastauthtime_[stanza.GetHeader().From] = 0 //logout + default: + jabber_events <- JabberEvent{stanza.GetHeader().From, true, R3NoChange, false} } - jabber_events <- JabberEvent{stanza.GetHeader().From, stanza.GetHeader().Type != "unavailable", R3NoChange, false} - if stanza.GetHeader().Type == "unavailable" { botdata.jid_lastauthtime_[stanza.GetHeader().From] = 0} //logout if offline case *xmpp.Iq: if stanza.GetHeader() == nil { continue @@ -358,12 +368,22 @@ func NewStartedBot(loginjid, loginpwd, password, state_save_dir string, insecure return nil, nil, err } - err = botdata.xmppclient_.StartSession(false, &xmpp.Presence{}) + err = botdata.xmppclient_.StartSession(true, &xmpp.Presence{}) if err != nil { log.Println("'Error StartSession:", err) return nil, nil, err } + roster := xmpp.Roster(botdata.xmppclient_) + for _, entry := range roster { + if entry.Subscription == "from" { + botdata.xmppclient_.Out <- botdata.makeXMPPPresence(entry.Jid, "subscribe") + } + if entry.Subscription == "none" { + delete(botdata.realraum_jids_, entry.Jid) + } + } + presence_events := make(chan interface{},1) jabber_events := make(chan JabberEvent,1)