fix: broadcast offline presence as soon as the last session drops

Logout left contacts seeing the user online until the me topic idle timeout
fired presUsersOfInterest(off), and even that frame was silently dropped
for p2p routes by handlePresence's xoriginal check. MarkUserOffline now
returns the remaining session count and cleanUp notifies users of interest
immediately once it hits zero; p2p presence is delivered straight to the
contact's me topic, mirroring presSingleUserOffline. Zentao #22.
This commit is contained in:
Austin
2026-09-18 17:42:18 +08:00
parent f4cedc7d75
commit 753a04ed12
4 changed files with 53 additions and 11 deletions
+11 -1
View File
@@ -465,9 +465,19 @@ func (s *Session) cleanUp(expired bool) {
if err := store.SecurityAudit.CloseLogin(s.tenantID, s.sid, time.Now().UTC().Round(time.Millisecond)); err != nil {
logs.Warn.Println("s.cleanUp: failed to close login audit", s.uid, err, s.sid)
}
if err := store.MarkUserOffline(s.tenantID, s.uid, s.sid, currentNodeID()); err != nil {
remaining, err := store.MarkUserOffline(s.tenantID, s.uid, s.sid, currentNodeID())
if err != nil {
logs.Warn.Println("s.cleanUp: failed to mark user offline", s.uid, err, s.sid)
}
// 最后一个会话已断开(如主动登出、断网):立即通知关注者该用户离线,
// 不再等待 me topic 闲置超时后的 presUsersOfInterest("off")。
if err == nil && remaining == 0 && globals.hub != nil {
if uoi, uerr := store.Users.GetSubs(s.tenantID, s.uid); uerr == nil {
presUsersOfInterestOffline(s.tenantID, s.uid, uoi, "off")
} else {
logs.Warn.Println("s.cleanUp: failed to notify users of interest", s.uid, uerr, s.sid)
}
}
}
s.purgeChannels()
s.inflightReqs.Wait()