Fix nil pointer on chatstats notification.

This commit is contained in:
Chteufleur 2016-11-13 20:03:26 +01:00
parent cb49e1fbe9
commit 5268350afb
1 changed files with 20 additions and 12 deletions

View File

@ -284,24 +284,30 @@ func (g *GatewayInfo) chatstatesNotification() {
switch chatstate { switch chatstate {
case "stop": case "stop":
if okInactive { if okInactive {
if !timerInactive.Stop() { if timerInactive != nil {
<-timerInactive.C if !timerInactive.Stop() {
<-timerInactive.C
}
delete(inactiveTimers, jid)
} }
delete(inactiveTimers, jid)
} }
if okPaused { if okPaused {
if !timerPaused.Stop() { if timerPaused != nil {
<-timerPaused.C if !timerPaused.Stop() {
<-timerPaused.C
}
delete(pausedTimers, jid)
} }
delete(pausedTimers, jid)
} }
case "paused": case "paused":
if okInactive { if okInactive {
if !timerPaused.Stop() { if timerPaused != nil {
<-timerPaused.C if !timerPaused.Stop() {
<-timerPaused.C
}
timerPaused.Reset(20 * time.Second)
} }
timerPaused.Reset(20 * time.Second)
} else { } else {
timerPaused = time.AfterFunc(20*time.Second, func() { timerPaused = time.AfterFunc(20*time.Second, func() {
g.sendXmppMessage(jid, "", "", &xmpp.Paused{}) g.sendXmppMessage(jid, "", "", &xmpp.Paused{})
@ -312,10 +318,12 @@ func (g *GatewayInfo) chatstatesNotification() {
case "inactive": case "inactive":
if okInactive { if okInactive {
if !timerInactive.Stop() { if timerInactive != nil {
<-timerInactive.C if !timerInactive.Stop() {
<-timerInactive.C
}
timerInactive.Reset(120 * time.Second)
} }
timerInactive.Reset(120 * time.Second)
} else { } else {
timerInactive = time.AfterFunc(120*time.Second, func() { timerInactive = time.AfterFunc(120*time.Second, func() {
g.sendXmppMessage(jid, "", "", &xmpp.Inactive{}) g.sendXmppMessage(jid, "", "", &xmpp.Inactive{})