Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Migrate REST API - saveNotificationSettings to Typescript #3865

Merged
merged 2 commits into from
Mar 9, 2022
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
12 changes: 11 additions & 1 deletion app/definitions/IRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IMessage } from './IMessage';
import { IRocketChatRecord } from './IRocketChatRecord';
import { IServedBy } from './IServedBy';
import { IVisitor, SubscriptionType } from './ISubscription';
import { IUser } from './IUser';
import { IUser, TNotifications } from './IUser';

interface IRequestTranscript {
email: string;
Expand Down Expand Up @@ -202,3 +202,13 @@ export interface IServerRoom extends IRocketChatRecord {
livechatData?: any;
tags?: string[];
}

export interface IRoomNotifications {
disableNotifications?: boolean;
muteGroupMentions?: boolean;
hideUnreadStatus?: boolean;
audioNotificationsValue?: string;
desktopNotifications?: TNotifications;
mobilePushNotifications?: TNotifications;
emailNotifications?: TNotifications;
}
2 changes: 1 addition & 1 deletion app/definitions/IUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export interface IUserSettings {
[key: string]: any;
};
}
type TNotifications = 'default' | 'all' | 'mentions' | 'nothing';
export type TNotifications = 'default' | 'all' | 'mentions' | 'nothing';

export interface INotificationPreferences {
id: string;
Expand Down
5 changes: 4 additions & 1 deletion app/definitions/rest/v1/rooms.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IMessage } from '../../IMessage';
import type { IServerRoom } from '../../IRoom';
import type { IRoomNotifications, IServerRoom } from '../../IRoom';
import type { IUser } from '../../IUser';

export type RoomsEndpoints = {
Expand Down Expand Up @@ -41,4 +41,7 @@ export type RoomsEndpoints = {
'rooms.favorite': {
POST: (params: { roomId: string; favorite: boolean }) => {};
};
'rooms.saveNotification': {
POST: (params: { roomId: string; notifications: IRoomNotifications }) => {};
};
};
6 changes: 2 additions & 4 deletions app/lib/rocketchat/services/restApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sdk from './sdk';
import { TEAM_TYPE } from '../../../definitions/ITeam';
import roomTypeToApiType, { RoomTypes } from '../methods/roomTypeToApiType';
import { SubscriptionType, INotificationPreferences } from '../../../definitions';
import { SubscriptionType, INotificationPreferences, IRoomNotifications } from '../../../definitions';
import { ISpotlight } from '../../../definitions/ISpotlight';

export const createChannel = ({
Expand Down Expand Up @@ -557,10 +557,8 @@ export const saveUserPreferences = (data: any): any =>
// @ts-ignore
sdk.post('users.setPreferences', { data });

export const saveNotificationSettings = (roomId: string, notifications: any): any =>
export const saveNotificationSettings = (roomId: string, notifications: IRoomNotifications) =>
// RC 0.63.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('rooms.saveNotification', { roomId, notifications });

export const getSingleMessage = (msgId: string) =>
Expand Down
3 changes: 2 additions & 1 deletion app/views/NotificationPreferencesView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import log, { events, logEvent } from '../../utils/log';
import sharedStyles from '../Styles';
import { OPTIONS } from './options';
import { ChatsStackParamList } from '../../stacks/types';
import { IRoomNotifications } from '../../definitions';

const styles = StyleSheet.create({
pickerText: {
Expand Down Expand Up @@ -73,7 +74,7 @@ class NotificationPreferencesView extends React.Component<INotificationPreferenc
}
}

saveNotificationSettings = async (key: string, value: string | boolean, params: any) => {
saveNotificationSettings = async (key: string, value: string | boolean, params: IRoomNotifications) => {
// @ts-ignore
logEvent(events[`NP_${key.toUpperCase()}`]);
const { room } = this.state;
Expand Down