Skip to content

Commit b0a3983

Browse files
committed
presence: Use server's offline threshold in getPresenceOnlyStatusForUser
Fixes: #5669
1 parent 15cde0f commit b0a3983

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/presence/__tests__/presenceModel-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,22 @@ describe('getPresenceOnlyStatusForUser', () => {
243243
).toBe('idle');
244244
});
245245

246+
test('Use specified offline threshold', () => {
247+
const userPresence = {
248+
aggregated: {
249+
client: 'website',
250+
status: 'idle',
251+
timestamp: Math.trunc(Date.now() / 1000 - 60), // 1 minute
252+
},
253+
};
254+
expect(
255+
getPresenceOnlyStatusForUser(
256+
makePresenceState([[eg.otherUser, userPresence]], { offlineThresholdSeconds: 40 }),
257+
eg.otherUser,
258+
),
259+
).toBe('offline');
260+
});
261+
246262
test('if status is not "offline" and last activity was less than 5min ago result is "active"', () => {
247263
const userPresence = {
248264
aggregated: {

src/presence/presenceModel.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ const presenceStatusGeq = (a: PresenceStatus, b: PresenceStatus): boolean => {
5454
}
5555
};
5656

57-
// TODO(#5669): get OFFLINE_THRESHOLD_SECS from PresenceState
58-
const OFFLINE_THRESHOLD_SECS = 140;
59-
6057
/**
6158
* Aggregate our information on a user's presence across their clients.
6259
*
@@ -165,7 +162,7 @@ export function getPresenceOnlyStatusForUser(
165162
const timestampDate = new Date(timestamp * 1000);
166163
const diffToNowInSeconds = differenceInSeconds(Date.now(), timestampDate);
167164

168-
if (diffToNowInSeconds > OFFLINE_THRESHOLD_SECS) {
165+
if (diffToNowInSeconds > state.offlineThresholdSeconds) {
169166
return 'offline';
170167
}
171168

0 commit comments

Comments
 (0)