Skip to content

Commit

Permalink
Chore: Server API types - user.setPreferences (#3781)
Browse files Browse the repository at this point in the history
* chore: implementing type for test api - user.setPreferences

* chore: minor tweak
  • Loading branch information
AlexAlexandre authored Mar 3, 2022
1 parent 4ba7f16 commit 7de686b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
16 changes: 16 additions & 0 deletions app/definitions/IUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ export interface IUserSettings {
[key: string]: any;
};
}
type TNotifications = 'default' | 'all' | 'mentions' | 'nothing';

export interface INotificationPreferences {
id: string;
enableMessageParserEarlyAdoption: boolean;
desktopNotifications: TNotifications;
pushNotifications: TNotifications;
emailNotificationMode?: 'mentions' | 'nothing';
}

export interface IUserPreferences {
user: { _id: string };
settings: {
preferences: INotificationPreferences;
};
}

export interface IUser extends IRocketChatRecord, Omit<ILoggedUser, 'username' | 'name' | 'status'> {
_id: string;
Expand Down
8 changes: 7 additions & 1 deletion app/definitions/rest/v1/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IUser, IUserRegistered } from '../../IUser';
import { INotificationPreferences, IUser, IUserPreferences, IUserRegistered } from '../../IUser';

export type UserEndpoints = {
'users.info': {
Expand All @@ -11,6 +11,12 @@ export type UserEndpoints = {
success: boolean;
};
};
'users.setPreferences': {
POST: (params: { userId: IUser['_id']; data: Partial<INotificationPreferences> }) => {
user: IUserPreferences;
success: boolean;
};
};
'users.register': {
POST: (params: { name: string; email: string; username: string; pass: string }) => { user: IUserRegistered };
};
Expand Down
8 changes: 3 additions & 5 deletions app/lib/rocketchat/services/restApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SubscriptionType } from '../../../definitions';
import sdk from './sdk';
import { TEAM_TYPE } from '../../../definitions/ITeam';
import roomTypeToApiType, { RoomTypes } from '../methods/roomTypeToApiType';
import sdk from './sdk';
import { SubscriptionType, INotificationPreferences } from '../../../definitions';

export const createChannel = ({
name,
Expand Down Expand Up @@ -283,10 +283,8 @@ export const reportMessage = (messageId: string): any =>
// @ts-ignore
sdk.post('chat.reportMessage', { messageId, description: 'Message reported by user' });

export const setUserPreferences = (userId: string, data: any): any =>
export const setUserPreferences = (userId: string, data: Partial<INotificationPreferences>) =>
// RC 0.62.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('users.setPreferences', { userId, data });

export const setUserStatus = (status?: string, message?: string): any =>
Expand Down
10 changes: 6 additions & 4 deletions app/views/UserNotificationPreferencesView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ class UserNotificationPreferencesView extends React.Component<
const { user } = this.props;
const { id } = user;
const result = await RocketChat.setUserPreferences(id, params);
const {
user: { settings }
} = result;
this.setState({ preferences: settings.preferences });
if (result.success) {
const {
user: { settings }
} = result;
this.setState({ preferences: settings.preferences });
}
};

render() {
Expand Down

0 comments on commit 7de686b

Please sign in to comment.