diff --git a/src/api/initialDataTypes.js b/src/api/initialDataTypes.js index 3f0c3963b50..68538cc6827 100644 --- a/src/api/initialDataTypes.js +++ b/src/api/initialDataTypes.js @@ -511,12 +511,9 @@ export type InitialDataUserStatus = $ReadOnly<{| */ // TODO(server-1.9.1): Make required. user_status?: $ReadOnly<{| - // TODO(flow): The key here is really UserId, not just any number; but - // this Flow bug: - // https://github.com/facebook/flow/issues/5407 - // means that doesn't work right, and the best workaround is to - // leave it as `number`. - [userId: number]: $ReadOnly<{| + // Keys are UserId encoded as strings (just because JS objects are + // string-keyed). + [userId: string]: $ReadOnly<{| // TODO: add status emoji properties // TODO: Comment on what these mean (if doc not fixed): // https://chat.zulip.org/#narrow/stream/412-api-documentation/topic/Emoji.20statuses.20in.20zulip.2Eyaml/near/1322329 diff --git a/src/user-status/userStatusReducer.js b/src/user-status/userStatusReducer.js index 4a3a9dc9bc1..9048de185e4 100644 --- a/src/user-status/userStatusReducer.js +++ b/src/user-status/userStatusReducer.js @@ -1,4 +1,8 @@ /* @flow strict-local */ + +import { objectFromEntries } from '../jsBackport'; +import { makeUserId } from '../api/idTypes'; +import objectEntries from '../utils/objectEntries'; import type { UserStatusState, PerAccountApplicableAction } from '../types'; import { LOGOUT, @@ -22,7 +26,18 @@ export default ( return initialState; case REGISTER_COMPLETE: - return action.data.user_status || initialState; + return objectFromEntries( + objectEntries(action.data.user_status ?? {}).map(([id, status]) => [ + // Converting from string keys to numeric ones here doesn't + // actually make a difference to how the state is represented + // at runtime. But it will when we start using + // Immutable.Map soon, and it satisfies + // Flow. + // TODO: Use Immutable.Map + makeUserId(Number.parseInt(id, 10)), + status, + ]), + ); case EVENT_USER_STATUS_UPDATE: { const newUserStatus = { ...state[action.user_id] };