From 17cd831319fb7053044213150286da4fc1f9d491 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Thu, 18 Jun 2020 03:38:00 -0400 Subject: [PATCH] fix #1144 --- irc/client.go | 20 ++++++++++++++++++-- irc/getters.go | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/irc/client.go b/irc/client.go index d733ee23..4a36e926 100644 --- a/irc/client.go +++ b/irc/client.go @@ -728,7 +728,7 @@ func (client *Client) Touch(active bool, session *Session) { client.lastActive = now session.lastActive = now } - if client.accountSettings.AutoreplayMissed { + if client.accountSettings.AutoreplayMissed || session.deviceID != "" { client.setLastSeen(now, session.deviceID) if now.Sub(client.lastSeenLastWrite) > lastSeenWriteInterval { markDirty = true @@ -1228,8 +1228,10 @@ func (client *Client) Quit(message string, session *Session) { func (client *Client) destroy(session *Session) { config := client.server.Config() var sessionsToDestroy []*Session + var saveLastSeen bool client.stateMutex.Lock() + details := client.detailsNoMutex() brbState := client.brbTimer.state brbAt := client.brbTimer.brbAt @@ -1237,7 +1239,7 @@ func (client *Client) destroy(session *Session) { sessionRemoved := false registered := client.registered alwaysOn := client.alwaysOn - saveLastSeen := alwaysOn && client.accountSettings.AutoreplayMissed + var remainingSessions int if session == nil { sessionsToDestroy = client.sessions @@ -1250,6 +1252,20 @@ func (client *Client) destroy(session *Session) { } } + // save last seen if applicable: + if alwaysOn { + if client.accountSettings.AutoreplayMissed { + saveLastSeen = true + } else { + for _, session := range sessionsToDestroy { + if session.deviceID != "" { + saveLastSeen = true + break + } + } + } + } + // should we destroy the whole client this time? // BRB is not respected if this is a destroy of the whole client (i.e., session == nil) brbEligible := session != nil && brbState == BrbEnabled diff --git a/irc/getters.go b/irc/getters.go index 1d2038f3..b27af59e 100644 --- a/irc/getters.go +++ b/irc/getters.go @@ -104,7 +104,7 @@ func (client *Client) AddSession(session *Session) (success bool, numSessions in newSessions := make([]*Session, len(client.sessions)+1) copy(newSessions, client.sessions) newSessions[len(newSessions)-1] = session - if client.accountSettings.AutoreplayMissed { + if client.accountSettings.AutoreplayMissed || session.deviceID != "" { lastSeen = client.lastSeen[session.deviceID] } client.sessions = newSessions