diff --git a/src/api/initialDataTypes.js b/src/api/initialDataTypes.js index 944ef0f5a55..e8d5ee1afb0 100644 --- a/src/api/initialDataTypes.js +++ b/src/api/initialDataTypes.js @@ -504,12 +504,7 @@ 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<{| + [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..f1946aba755 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,20 @@ export default ( return initialState; case REGISTER_COMPLETE: - return action.data.user_status || initialState; + return action.data.user_status + ? 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, + ]), + ) + : initialState; case EVENT_USER_STATUS_UPDATE: { const newUserStatus = { ...state[action.user_id] };