From 5268350afbb3512867eb66cc0dad92f56265265b Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Sun, 13 Nov 2016 20:03:26 +0100 Subject: [PATCH] Fix nil pointer on chatstats notification. --- gateway/xmpp.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/gateway/xmpp.go b/gateway/xmpp.go index 2cbd27a..9864181 100644 --- a/gateway/xmpp.go +++ b/gateway/xmpp.go @@ -284,24 +284,30 @@ func (g *GatewayInfo) chatstatesNotification() { switch chatstate { case "stop": if okInactive { - if !timerInactive.Stop() { - <-timerInactive.C + if timerInactive != nil { + if !timerInactive.Stop() { + <-timerInactive.C + } + delete(inactiveTimers, jid) } - delete(inactiveTimers, jid) } if okPaused { - if !timerPaused.Stop() { - <-timerPaused.C + if timerPaused != nil { + if !timerPaused.Stop() { + <-timerPaused.C + } + delete(pausedTimers, jid) } - delete(pausedTimers, jid) } case "paused": if okInactive { - if !timerPaused.Stop() { - <-timerPaused.C + if timerPaused != nil { + if !timerPaused.Stop() { + <-timerPaused.C + } + timerPaused.Reset(20 * time.Second) } - timerPaused.Reset(20 * time.Second) } else { timerPaused = time.AfterFunc(20*time.Second, func() { g.sendXmppMessage(jid, "", "", &xmpp.Paused{}) @@ -312,10 +318,12 @@ func (g *GatewayInfo) chatstatesNotification() { case "inactive": if okInactive { - if !timerInactive.Stop() { - <-timerInactive.C + if timerInactive != nil { + if !timerInactive.Stop() { + <-timerInactive.C + } + timerInactive.Reset(120 * time.Second) } - timerInactive.Reset(120 * time.Second) } else { timerInactive = time.AfterFunc(120*time.Second, func() { g.sendXmppMessage(jid, "", "", &xmpp.Inactive{})