diff --git a/app/definitions/IUser.ts b/app/definitions/IUser.ts index e1746554d7..7a82aa64ec 100644 --- a/app/definitions/IUser.ts +++ b/app/definitions/IUser.ts @@ -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 { _id: string; diff --git a/app/definitions/rest/v1/user.ts b/app/definitions/rest/v1/user.ts index b8c37cc174..737ed9a583 100644 --- a/app/definitions/rest/v1/user.ts +++ b/app/definitions/rest/v1/user.ts @@ -1,4 +1,4 @@ -import { IUser, IUserRegistered } from '../../IUser'; +import { INotificationPreferences, IUser, IUserPreferences, IUserRegistered } from '../../IUser'; export type UserEndpoints = { 'users.info': { @@ -11,6 +11,12 @@ export type UserEndpoints = { success: boolean; }; }; + 'users.setPreferences': { + POST: (params: { userId: IUser['_id']; data: Partial }) => { + user: IUserPreferences; + success: boolean; + }; + }; 'users.register': { POST: (params: { name: string; email: string; username: string; pass: string }) => { user: IUserRegistered }; }; diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/rocketchat/services/restApi.ts index 5b27f610b5..dbf1a8de68 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/rocketchat/services/restApi.ts @@ -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, @@ -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) => // 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 => diff --git a/app/views/UserNotificationPreferencesView/index.tsx b/app/views/UserNotificationPreferencesView/index.tsx index 8961cb38f7..79a6817323 100644 --- a/app/views/UserNotificationPreferencesView/index.tsx +++ b/app/views/UserNotificationPreferencesView/index.tsx @@ -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() {