Skip to content

Commit 15cde0f

Browse files
committed
presence: Use server's offline threshold in last-active string
1 parent 6327f64 commit 15cde0f

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/presence/__tests__/presenceModel-test.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,17 @@ describe('getUserLastActiveAsRelativeTimeString', () => {
140140
userPresence: UserPresence,
141141
userStatus: UserStatus,
142142
zulipFeatureLevel?: number,
143+
offlineThresholdSeconds?: number,
143144
}): string | null {
144-
const { userPresence, userStatus, zulipFeatureLevel = eg.recentZulipFeatureLevel } = args;
145+
const {
146+
userPresence,
147+
userStatus,
148+
zulipFeatureLevel = eg.recentZulipFeatureLevel,
149+
offlineThresholdSeconds, // eslint-disable-line no-shadow
150+
} = args;
145151
return getUserLastActiveAsRelativeTimeString(
146152
eg.reduxStatePlus({
147-
presence: makePresenceState([[eg.otherUser, userPresence]]),
153+
presence: makePresenceState([[eg.otherUser, userPresence]], { offlineThresholdSeconds }),
148154
userStatuses: Immutable.Map([[eg.otherUser.user_id, userStatus]]),
149155
accounts: [{ ...eg.plusReduxState.accounts[0], zulipFeatureLevel }],
150156
}),
@@ -169,6 +175,16 @@ describe('getUserLastActiveAsRelativeTimeString', () => {
169175
expect(lastActiveString({ userPresence, userStatus })).toBe('now');
170176
});
171177

178+
test('Use specified offline threshold', () => {
179+
const userPresence = {
180+
aggregated: { client: 'website', status: 'active', timestamp: currentTimestamp - 100 },
181+
};
182+
const userStatus = { away: false, status_text: null, status_emoji: null };
183+
expect(lastActiveString({ userPresence, userStatus, offlineThresholdSeconds: 80 })).toBe(
184+
'2 minutes ago',
185+
);
186+
});
187+
172188
// TODO(server-6.0): Remove
173189
test('Pre-FL 148: if less than a day and user is "away", use imprecise "today"', () => {
174190
const userPresence = {

src/presence/presenceModel.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ export function getUserLastActiveAsRelativeTimeString(
120120
user: UserOrBot,
121121
dateNow: number,
122122
): string | null {
123-
const presence = getUserPresenceByEmail(getPresence(state), user.email);
123+
const presenceState = getPresence(state);
124+
const presence = getUserPresenceByEmail(presenceState, user.email);
124125
if (!presence) {
125126
return null;
126127
}
@@ -142,7 +143,7 @@ export function getUserLastActiveAsRelativeTimeString(
142143
return 'today';
143144
}
144145

145-
return differenceInSeconds(dateNow, lastTimeActive) < OFFLINE_THRESHOLD_SECS
146+
return differenceInSeconds(dateNow, lastTimeActive) < presenceState.offlineThresholdSeconds
146147
? 'now'
147148
: `${formatDistanceToNow(lastTimeActive)} ago`;
148149
}

0 commit comments

Comments
 (0)