Merge pull request #1145 from slingamn/autoreplay_again

fix #1144
This commit is contained in:
Shivaram Lingamneni 2020-06-18 01:22:15 -07:00 committed by GitHub
commit 3662698f87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -728,7 +728,7 @@ func (client *Client) Touch(active bool, session *Session) {
client.lastActive = now client.lastActive = now
session.lastActive = now session.lastActive = now
} }
if client.accountSettings.AutoreplayMissed { if client.accountSettings.AutoreplayMissed || session.deviceID != "" {
client.setLastSeen(now, session.deviceID) client.setLastSeen(now, session.deviceID)
if now.Sub(client.lastSeenLastWrite) > lastSeenWriteInterval { if now.Sub(client.lastSeenLastWrite) > lastSeenWriteInterval {
markDirty = true markDirty = true
@ -1228,8 +1228,10 @@ func (client *Client) Quit(message string, session *Session) {
func (client *Client) destroy(session *Session) { func (client *Client) destroy(session *Session) {
config := client.server.Config() config := client.server.Config()
var sessionsToDestroy []*Session var sessionsToDestroy []*Session
var saveLastSeen bool
client.stateMutex.Lock() client.stateMutex.Lock()
details := client.detailsNoMutex() details := client.detailsNoMutex()
brbState := client.brbTimer.state brbState := client.brbTimer.state
brbAt := client.brbTimer.brbAt brbAt := client.brbTimer.brbAt
@ -1237,7 +1239,7 @@ func (client *Client) destroy(session *Session) {
sessionRemoved := false sessionRemoved := false
registered := client.registered registered := client.registered
alwaysOn := client.alwaysOn alwaysOn := client.alwaysOn
saveLastSeen := alwaysOn && client.accountSettings.AutoreplayMissed
var remainingSessions int var remainingSessions int
if session == nil { if session == nil {
sessionsToDestroy = client.sessions 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? // 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) // BRB is not respected if this is a destroy of the whole client (i.e., session == nil)
brbEligible := session != nil && brbState == BrbEnabled brbEligible := session != nil && brbState == BrbEnabled

View File

@ -104,7 +104,7 @@ func (client *Client) AddSession(session *Session) (success bool, numSessions in
newSessions := make([]*Session, len(client.sessions)+1) newSessions := make([]*Session, len(client.sessions)+1)
copy(newSessions, client.sessions) copy(newSessions, client.sessions)
newSessions[len(newSessions)-1] = session newSessions[len(newSessions)-1] = session
if client.accountSettings.AutoreplayMissed { if client.accountSettings.AutoreplayMissed || session.deviceID != "" {
lastSeen = client.lastSeen[session.deviceID] lastSeen = client.lastSeen[session.deviceID]
} }
client.sessions = newSessions client.sessions = newSessions