From 45951db11e7888cf7d42b1753de95806f669e860 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Mon, 6 Nov 2023 16:58:29 -0800 Subject: [PATCH] typing status: Lengthen the hardcoded expiry period to 45s --- src/typing/typingActions.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/typing/typingActions.js b/src/typing/typingActions.js index 27d4842ffe7..391065316ab 100644 --- a/src/typing/typingActions.js +++ b/src/typing/typingActions.js @@ -4,6 +4,33 @@ import type { PerAccountAction, ThunkAction } from '../types'; import { sleep } from '../utils/async'; import { getTyping } from '../directSelectors'; +/** + * The value to use for `server_typing_started_expiry_period_milliseconds`. + * + * The corresponding old server setting was `TYPING_STARTED_EXPIRY_PERIOD`. + * + * The specified behavior is that we should be taking this value from server + * data. See docs: + * https://chat.zulip.org/api/set-typing-status + * + * But in this legacy codebase, the most expedient thing is to hardcode it + * to a large value. We'll get proper user-facing behavior as long as this + * value exceeds by at least a network round-trip the effective value of + * `server_typing_started_wait_period_milliseconds` in the behavior of other + * clients. Discussion: + * https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/typing.20notifications.20constants/near/1665193 + */ +const typingStartedExpiryPeriodMs = 45000; + +/** + * The period at which to poll for expired typing notifications. + * + * Really no polling should be needed here -- a timer would be better. + * But that's how this code has always worked, and for this legacy codebase + * that'll do. + */ +const typingPollPeriodMs = 3000; + export const clearTyping = (outdatedNotifications: $ReadOnlyArray): PerAccountAction => ({ type: 'CLEAR_TYPING', outdatedNotifications, @@ -12,7 +39,7 @@ export const clearTyping = (outdatedNotifications: $ReadOnlyArray): PerA const typingStatusExpiryLoop = () => async (dispatch, getState) => { // loop to auto dismiss typing notifications after typingNotificationTimeout while (true) { - await sleep(15000); + await sleep(typingPollPeriodMs); const currentTime = new Date().getTime(); const typing = getTyping(getState()); if (Object.keys(typing).length === 0) { @@ -20,7 +47,7 @@ const typingStatusExpiryLoop = () => async (dispatch, getState) => { } const outdatedNotifications = []; Object.keys(typing).forEach(recipients => { - if (currentTime - typing[recipients].time >= 15000) { + if (currentTime - typing[recipients].time >= typingStartedExpiryPeriodMs) { outdatedNotifications.push(recipients); } });