XMPP: autorejoin MUCs when reconnecting
This commit is contained in:
parent
473336f0eb
commit
1d54a50c31
1 changed files with 26 additions and 7 deletions
|
@ -35,7 +35,8 @@ type XMPP struct {
|
|||
|
||||
conn *gxmpp.Client
|
||||
|
||||
isMUC map[string]bool
|
||||
isMUC map[string]bool
|
||||
joinedMUC map[string]bool
|
||||
}
|
||||
|
||||
func (xm *XMPP) SetHandler(h Handler) {
|
||||
|
@ -86,6 +87,7 @@ func (xm *XMPP) Configure(c Configuration) error {
|
|||
if xm.isMUC == nil {
|
||||
xm.isMUC = make(map[string]bool)
|
||||
}
|
||||
xm.joinedMUC = make(map[string]bool)
|
||||
|
||||
xm.connectorLoopNum += 1
|
||||
go xm.connectLoop(xm.connectorLoopNum)
|
||||
|
@ -106,7 +108,7 @@ func (xm *XMPP) connectLoop(num int) {
|
|||
return
|
||||
}
|
||||
tc := &tls.Config{
|
||||
ServerName: strings.Split(xm.jid, "@")[1],
|
||||
ServerName: xm.server,
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
options := gxmpp.Options{
|
||||
|
@ -132,12 +134,23 @@ func (xm *XMPP) connectLoop(num int) {
|
|||
} else {
|
||||
xm.connected = true
|
||||
xm.timeout = 10
|
||||
err = xm.handleXMPP()
|
||||
if err != nil {
|
||||
xm.connected = false
|
||||
log.Debugf("XMPP disconnected: %s\n", err)
|
||||
log.Debugf("Reconnecting.\n")
|
||||
|
||||
for muc, joined := range xm.joinedMUC {
|
||||
if joined {
|
||||
_, err := xm.conn.JoinMUCNoHistory(muc, xm.nickname)
|
||||
if err != nil {
|
||||
log.Warnf("Could not rejoin MUC %s after reconnection: %s", muc, err)
|
||||
xm.handler.Left(RoomID(muc))
|
||||
delete(xm.joinedMUC, muc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = xm.handleXMPP()
|
||||
|
||||
xm.connected = false
|
||||
log.Debugf("XMPP disconnected: %s\n", err)
|
||||
log.Debugf("Reconnecting.\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -289,6 +302,11 @@ func (xm *XMPP) Join(roomId RoomID) error {
|
|||
|
||||
log.Tracef("Join %s with nick %s\n", roomId, xm.nickname)
|
||||
_, err := xm.conn.JoinMUCNoHistory(string(roomId), xm.nickname)
|
||||
|
||||
if err == nil {
|
||||
xm.joinedMUC[string(roomId)] = true
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -304,6 +322,7 @@ func (xm *XMPP) Invite(userId UserID, roomId RoomID) error {
|
|||
|
||||
func (xm *XMPP) Leave(roomId RoomID) {
|
||||
xm.conn.LeaveMUC(string(roomId))
|
||||
delete(xm.joinedMUC, string(roomId))
|
||||
}
|
||||
|
||||
func (xm *XMPP) SearchForUsers(query string) ([]UserSearchResult, error) {
|
||||
|
|
Loading…
Reference in a new issue