Skip to content

Commit

Permalink
typing status: Lengthen the hardcoded expiry period to 45s
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed Nov 7, 2023
1 parent aee850c commit 6d26d1c
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/typing/typingActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>): PerAccountAction => ({
type: 'CLEAR_TYPING',
outdatedNotifications,
Expand All @@ -12,15 +39,15 @@ export const clearTyping = (outdatedNotifications: $ReadOnlyArray<string>): 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) {
break; // break if no typing notifications
}
const outdatedNotifications = [];
Object.keys(typing).forEach(recipients => {
if (currentTime - typing[recipients].time >= 15000) {
if (currentTime - typing[recipients].time >= typingStartedExpiryPeriodMs) {
outdatedNotifications.push(recipients);
}
});
Expand Down

0 comments on commit 6d26d1c

Please sign in to comment.