Skip to content

Commit 63861dc

Browse files
committed
api: Add updateUserSettings binding, for PATCH /settings
1 parent f551a53 commit 63861dc

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

src/api/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import tryGetFileTemporaryUrl from './tryGetFileTemporaryUrl';
5353
import getUsers from './users/getUsers';
5454
import createUser from './users/createUser';
5555
import getUserProfile from './users/getUserProfile';
56+
import updateUserSettings from './users/updateUserSettings';
5657
import updateUserStatus from './users/updateUserStatus';
5758
import getFileTemporaryUrl from './messages/getFileTemporaryUrl';
5859
import getReadReceipts from './messages/getReadReceipts';
@@ -103,6 +104,7 @@ export {
103104
getUsers,
104105
createUser,
105106
getUserProfile,
107+
updateUserSettings,
106108
updateUserStatus,
107109
getFileTemporaryUrl,
108110
getReadReceipts,

src/api/modelTypes.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,10 @@ export type RealmLinkifier = $ReadOnly<{|
166166
// response in FL 89.
167167
//
168168
// Current to FL 152; property ordering follows the /register doc. See the
169-
// "Current to" note on the InitialDataUserSettings type and update that as
170-
// needed too.
169+
// "Current to" notes in the two places we use this, and update them as
170+
// needed:
171+
// - InitialDataUserSettings (for POST /register response)
172+
// - api.updateUserSettings (for the PATCH /settings endpoint)
171173
//
172174
// TODO(server-5.0): Remove FL 89+ comment.
173175
export type UserSettings = {|

src/api/users/updateUserSettings.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* @flow strict-local */
2+
import invariant from 'invariant';
3+
4+
import type { UserSettings } from '../modelTypes';
5+
import type { ApiResponseSuccess, Auth } from '../transportTypes';
6+
import { apiPatch } from '../apiFetch';
7+
8+
// Assumes FL 89+ because the UserSettings type does; see note there.
9+
//
10+
// Current to FL 152. See the "Current to" note on the UserSettings type and
11+
// update that as needed too.
12+
//
13+
// TODO(server-5.0): Remove FL 89+ comment.
14+
type Args = {|
15+
...$Rest<UserSettings, { ... }>,
16+
17+
// These might move to a different endpoint in the future; see
18+
// https://chat.zulip.org/#narrow/stream/378-api-design/topic/User.20settings.20discrepancies/near/1457451
19+
+full_name?: string,
20+
+email?: string,
21+
+old_password?: string,
22+
+new_password?: string,
23+
|};
24+
25+
/**
26+
* https://zulip.com/api/update-settings
27+
*
28+
* NOTE: Only supports servers at feature level 89+ because UserSettings
29+
* assumes 89+; see there.
30+
*/
31+
// TODO(server-5.0): Simplify FL 89+ requirement
32+
export default (
33+
auth: Auth,
34+
args: Args,
35+
36+
// TODO(#4659): Don't get this from callers.
37+
zulipFeatureLevel: number,
38+
): Promise<ApiResponseSuccess> => {
39+
invariant(zulipFeatureLevel >= 89, 'api.updateUserSettings not supported with FL <89');
40+
41+
return apiPatch(auth, 'settings', args);
42+
};

0 commit comments

Comments
 (0)