From 1625b448928038689addf2c559a80cc89a21c12c Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 4 Dec 2023 09:24:10 +0100 Subject: [PATCH] lib/model: Improve LastSeen handling (#9256) LastSeen for a device was only updated when they connected. This now updates it when they disconnect, so that we remember the last time we actually saw them. When asking the API for current stats, currently connected devices get a last seen value of the current time. --- lib/model/model.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/model/model.go b/lib/model/model.go index 64475468d..4cc94238c 100644 --- a/lib/model/model.go +++ b/lib/model/model.go @@ -817,6 +817,11 @@ func (m *model) DeviceStatistics() (map[protocol.DeviceID]stats.DeviceStatistics if err != nil { return nil, err } + if len(m.deviceConnIDs[id]) > 0 { + // If a device is currently connected, we can see them right + // now. + stats.LastSeen = time.Now().Truncate(time.Second) + } res[id] = stats } return res, nil @@ -2483,6 +2488,7 @@ func (m *model) deviceWasSeen(deviceID protocol.DeviceID) { func (m *model) deviceDidCloseFRLocked(deviceID protocol.DeviceID, duration time.Duration) { if sr, ok := m.deviceStatRefs[deviceID]; ok { _ = sr.LastConnectionDuration(duration) + _ = sr.WasSeen() } }