Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/definitions/IUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,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 } from '../../IUser';
import { INotificationPreferences, IUser, IUserPreferences } from '../../IUser';

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

export const createChannel = ({
name,
Expand Down Expand Up @@ -301,10 +302,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