Skip to content

Commit 26b1ce7

Browse files
committed
initial data types: Give UserSettings a jsdoc and align definition
To prepare this type to be reused for a new PATCH /settings binding, coming next. This makes one functional change to the types: since `available_notification_sounds` and `emojiset_choices` no longer appear in `UserSettings`, the `UserSettingsUpdateEvent` type gets narrower by excluding those too. That's correct; we don't expect an event that updates those two rogue "user settings".
1 parent 89397f0 commit 26b1ce7

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/api/initialDataTypes.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,13 @@ export type InitialDataUpdateMessageFlags = $ReadOnly<{|
598598
|}>,
599599
|}>;
600600

601+
/**
602+
* The user settings, stored on the server.
603+
*
604+
* See:
605+
* - PATCH /settings doc: https://zulip.com/api/update-settings
606+
* - POST /register doc: https://zulip.com/api/register-queue
607+
*/
601608
// Assumes FL 89+, because servers added user_settings to the /register
602609
// response in FL 89.
603610
//
@@ -654,8 +661,6 @@ export type UserSettings = {|
654661
+desktop_icon_count_display: 1 | 2 | 3,
655662
+realm_name_in_notifications: boolean,
656663
+presence_enabled: boolean,
657-
+available_notification_sounds: $ReadOnlyArray<string>,
658-
+emojiset_choices: $ReadOnlyArray<{| +key: string, +text: string |}>,
659664

660665
// TODO(server-5.0): New in FL 105.
661666
+send_private_typing_notifications?: boolean,
@@ -680,7 +685,15 @@ export type UserSettings = {|
680685
// TODO(server-5.0): Remove FL 89+ comment.
681686
export type InitialDataUserSettings = {|
682687
// TODO(server-5.0): New in FL 89, for requesting clients, so assumes 89.
683-
+user_settings?: UserSettings,
688+
+user_settings?: {|
689+
...UserSettings,
690+
691+
// These appear here even though they aren't really user settings at
692+
// all. We're hoping to drop them from here because of that:
693+
// https://chat.zulip.org/#narrow/stream/378-api-design/topic/User.20settings.20discrepancies/near/1456533
694+
+available_notification_sounds: $ReadOnlyArray<string>,
695+
+emojiset_choices: $ReadOnlyArray<{| +key: string, +text: string |}>,
696+
|},
684697
|};
685698

686699
/**

src/realm/__tests__/realmReducer-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ describe('realmReducer', () => {
310310
initialState[statePropertyName] = initialStateValue;
311311

312312
const expectedState = { ...initialState };
313-
// $FlowFixMe[prop-missing]
314313
/* $FlowFixMe[incompatible-type]: Trust that the caller passed the
315314
right kind of value for its chosen key. */
316315
expectedState[statePropertyName] = eventValue;

src/settings/__tests__/settingsReducer-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS,
88
EVENT,
99
} from '../../actionConstants';
10-
import type { UserSettings } from '../../api/initialDataTypes';
10+
import type { InitialData, UserSettings } from '../../api/initialDataTypes';
1111
import { EventTypes } from '../../api/eventTypes';
1212
import settingsReducer from '../settingsReducer';
1313
import * as eg from '../../__tests__/lib/exampleData';
@@ -54,7 +54,9 @@ describe('settingsReducer', () => {
5454
user_settings: {
5555
/* $FlowIgnore[incompatible-cast] - testing modern servers, which
5656
send user_settings. */
57-
...(eg.action.register_complete.data.user_settings: UserSettings),
57+
...(eg.action.register_complete.data.user_settings: $NonMaybeType<
58+
InitialData['user_settings'],
59+
>),
5860
enable_offline_push_notifications: true,
5961
enable_online_push_notifications: true,
6062
enable_stream_push_notifications: true,

0 commit comments

Comments
 (0)