diff --git a/app/definitions/IRoom.ts b/app/definitions/IRoom.ts index 0fe2a7bbb..cb0106a59 100644 --- a/app/definitions/IRoom.ts +++ b/app/definitions/IRoom.ts @@ -213,6 +213,7 @@ export interface IServerRoom extends IRocketChatRecord { } export interface IRoomNotifications { + [key: string]: any; disableNotifications?: boolean; muteGroupMentions?: boolean; hideUnreadStatus?: boolean; @@ -221,3 +222,5 @@ export interface IRoomNotifications { mobilePushNotifications?: TNotifications; emailNotifications?: TNotifications; } + +export type TRoomNotificationsModel = IRoomNotifications & Model; diff --git a/app/stacks/types.ts b/app/stacks/types.ts index c1f391f10..31c85ad5e 100644 --- a/app/stacks/types.ts +++ b/app/stacks/types.ts @@ -1,6 +1,5 @@ import { NavigatorScreenParams } from '@react-navigation/core'; import { TextInputProps } from 'react-native'; -import Model from '@nozbe/watermelondb/Model'; import { IOptionsField } from '../views/NotificationPreferencesView/options'; import { IServer } from '../definitions/IServer'; @@ -101,7 +100,7 @@ export type ChatsStackParamList = { DirectoryView: undefined; NotificationPrefView: { rid: string; - room: Model; + room: TSubscriptionModel; }; ForwardLivechatView: { rid: string; diff --git a/app/views/NotificationPreferencesView/index.tsx b/app/views/NotificationPreferencesView/index.tsx index e0fbee7d3..75a263b6b 100644 --- a/app/views/NotificationPreferencesView/index.tsx +++ b/app/views/NotificationPreferencesView/index.tsx @@ -2,7 +2,6 @@ import React from 'react'; import { StyleSheet, Switch, Text } from 'react-native'; import { RouteProp } from '@react-navigation/core'; import { StackNavigationProp } from '@react-navigation/stack'; -import Model from '@nozbe/watermelondb/Model'; import { Observable, Subscription } from 'rxjs'; import database from '../../lib/database'; @@ -17,7 +16,7 @@ import log, { events, logEvent } from '../../utils/log'; import sharedStyles from '../Styles'; import { IOptionsField, OPTIONS } from './options'; import { ChatsStackParamList } from '../../stacks/types'; -import { IRoomNotifications } from '../../definitions'; +import { IRoomNotifications, TRoomNotificationsModel } from '../../definitions'; import { Services } from '../../lib/services'; const styles = StyleSheet.create({ @@ -27,23 +26,27 @@ const styles = StyleSheet.create({ } }); -interface INotificationPreferencesView { +interface INotificationPreferencesViewProps { navigation: StackNavigationProp; route: RouteProp; theme: TSupportedThemes; } -class NotificationPreferencesView extends React.Component { +interface INotificationPreferencesViewState { + room: TRoomNotificationsModel; +} + +class NotificationPreferencesView extends React.Component { static navigationOptions = () => ({ title: I18n.t('Notification_Preferences') }); private mounted: boolean; private rid: string; - private roomObservable?: Observable; + private roomObservable?: Observable; private subscription?: Subscription; - constructor(props: INotificationPreferencesView) { + constructor(props: INotificationPreferencesViewProps) { super(props); this.mounted = false; this.rid = props.route.params?.rid ?? ''; @@ -53,7 +56,7 @@ class NotificationPreferencesView extends React.Component { + this.subscription = this.roomObservable.subscribe(changes => { if (this.mounted) { this.setState({ room: changes }); } else { @@ -83,7 +86,7 @@ class NotificationPreferencesView extends React.Component { await room.update( - protectedFunction((r: any) => { + protectedFunction((r: IRoomNotifications) => { r[key] = value; }) ); @@ -100,7 +103,7 @@ class NotificationPreferencesView extends React.Component { await room.update( - protectedFunction((r: any) => { + protectedFunction((r: IRoomNotifications) => { r[key] = room[key]; }) );