Skip to content

Commit 11849c1

Browse files
gnpricechrisbobbe
authored andcommitted
presence: Add userLastActive method
1 parent 0d83579 commit 11849c1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/model/presence.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,31 @@ class Presence extends HasRealmStore with ChangeNotifier {
143143
}
144144
}
145145

146+
/// The timestamp when the given user was "last active", if any.
147+
///
148+
/// This is meaningful only when [presenceStatusForUser] is null.
149+
/// When that method returns active or idle, the user should be displayed
150+
/// with a description like "Active now" or "Idle" rather than
151+
/// one like "Last active $duration ago" that uses this timestamp.
152+
int? userLastActive(int userId) {
153+
// The corresponding implementation on web is complicated;
154+
// but the actual behavior seems to be this simple.
155+
//
156+
// In web, see buddy_data.user_last_seen_time_status; the last-active time
157+
// is used only when the status is offline (vs active or idle).
158+
// The timestamp comes via presence.last_active_date from the data structure
159+
// fed by presence.status_from_raw.
160+
//
161+
// That status_from_raw function sometimes uses idle_timestamp;
162+
// but only when status idle, where the timestamp will be ignored anyway.
163+
// It also consults the equivalent of [User.dateJoined] as a fallback,
164+
// for when processing a user who has "never logged in"... but it's
165+
// not clear that function ever gets called in such a case.
166+
// Those wrinkles aside, it always uses active_timestamp.
167+
168+
return _map[userId]?.activeTimestamp;
169+
}
170+
146171
void handlePresenceEvent(PresenceEvent event) {
147172
// TODO(#1618)
148173
}

0 commit comments

Comments
 (0)