Skip to content

Commit 47a8b3f

Browse files
committed
presence: Get tuning parameters from server, and store them
Toward #5669. This doesn't yet actually use the new tuning parameters; we'll do that in the next few commits.
1 parent 2ea1239 commit 47a8b3f

File tree

6 files changed

+27
-2
lines changed

6 files changed

+27
-2
lines changed

src/api/initialDataTypes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ export type RawInitialDataBase = $ReadOnly<{|
6161
* `zulip_feature_level`, above.
6262
*/
6363
zulip_version: string,
64+
65+
/** New in FL 164; use 60 when absent. */
66+
// TODO(server-7.0): simplify to always-present
67+
server_presence_ping_interval_seconds?: number,
68+
69+
/** New in FL 164; use 140 when absent. */
70+
// TODO(server-7.0): simplify to always-present
71+
server_presence_offline_threshold_seconds?: number,
6472
|}>;
6573

6674
/**

src/presence/PresenceHeartbeat.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default function PresenceHeartbeat(props: Props): React.Node {
2626
// TODO(#5005): should ensure this gets the intended account
2727
dispatch(reportPresence(true));
2828
};
29+
// TODO(#5669): get heartbeat interval from PresenceState
2930
const heartbeat = new Heartbeat(onHeartbeat, 1000 * 60);
3031

3132
// React to any state change.

src/presence/__tests__/presence-testlib.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@ import { reducer } from '../presenceModel';
55
import * as eg from '../../__tests__/lib/exampleData';
66
import { objectFromEntries } from '../../jsBackport';
77

8-
export function makePresenceState(data: $ReadOnlyArray<[User, UserPresence]>): PresenceState {
8+
export function makePresenceState(
9+
data: $ReadOnlyArray<[User, UserPresence]>,
10+
args?: {|
11+
+offlineThresholdSeconds?: number,
12+
+pingIntervalSeconds?: number,
13+
|},
14+
): PresenceState {
15+
const { offlineThresholdSeconds, pingIntervalSeconds } = args ?? {};
916
return reducer(
1017
undefined,
1118
eg.mkActionRegisterComplete({
1219
presences: objectFromEntries(data.map(([user, presence]) => [user.email, presence])),
20+
server_presence_offline_threshold_seconds: offlineThresholdSeconds ?? 140,
21+
server_presence_ping_interval_seconds: pingIntervalSeconds ?? 60,
1322
}),
1423
);
1524
}

src/presence/presenceModel.js

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

57+
// TODO(#5669): get OFFLINE_THRESHOLD_SECS from PresenceState
5758
const OFFLINE_THRESHOLD_SECS = 140;
5859

5960
/**
@@ -198,6 +199,8 @@ export const getPresenceStatusForUserId = (
198199
//
199200

200201
const initialState: PresenceState = {
202+
pingIntervalSeconds: 60,
203+
offlineThresholdSeconds: 140,
201204
byEmail: Immutable.Map(),
202205
};
203206

@@ -211,6 +214,8 @@ export function reducer(
211214

212215
case REGISTER_COMPLETE:
213216
return {
217+
pingIntervalSeconds: action.data.server_presence_ping_interval_seconds ?? 60,
218+
offlineThresholdSeconds: action.data.server_presence_offline_threshold_seconds ?? 140,
214219
byEmail: Immutable.Map(action.data.presences),
215220
};
216221

src/reduxTypes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ export type OutboxState = $ReadOnlyArray<Outbox>;
218218
* presence status.
219219
*/
220220
export type PresenceState = $ReadOnly<{|
221+
pingIntervalSeconds: number,
222+
offlineThresholdSeconds: number,
221223
byEmail: Immutable.Map<string, UserPresence>,
222224
|}>;
223225

src/storage/migrations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ const migrationsInner: {| [string]: (LessPartialState) => LessPartialState |} =
512512
// Change `state.mute` data structure: was a plain JS Map.
513513
'59': dropCache,
514514

515-
// Changed `state.presence`, but no migration because that's in `discardKeys`.
515+
// Changed `state.presence` (twice), but no migration because that's in `discardKeys`.
516516

517517
// TIP: When adding a migration, consider just using `dropCache`.
518518
// (See its jsdoc for guidance on when that's the right answer.)

0 commit comments

Comments
 (0)