refactor: change the room interface

This commit is contained in:
AlexAlexandre 2021-12-14 20:44:49 -03:00
parent 5635fbbebb
commit d649eb5f4e
2 changed files with 32 additions and 25 deletions

View File

@ -1,3 +1,6 @@
import { Observable } from 'rxjs';
import Model from '@nozbe/watermelondb/Model';
import { IRocketChatRecord } from './IRocketChatRecord';
export enum RoomType {
@ -23,7 +26,7 @@ export interface IRoom extends IRocketChatRecord {
visitor?: boolean;
autoTranslateLanguage?: boolean;
autoTranslate?: boolean;
observe?: Function;
observe?(): Observable<Model>;
usedCannedResponse?: string;
bannerClosed?: boolean;
lastOpen?: Date;

View File

@ -4,7 +4,7 @@ import { connect } from 'react-redux';
import parse from 'url-parse';
import moment from 'moment';
import * as Haptics from 'expo-haptics';
import { Model, Q } from '@nozbe/watermelondb';
import { Q } from '@nozbe/watermelondb';
import { dequal } from 'dequal';
import { withSafeAreaInsets } from 'react-native-safe-area-context';
import { StackNavigationProp } from '@react-navigation/stack';
@ -199,13 +199,15 @@ class RoomView extends React.Component<IRoomViewProps, any> {
const name = props.route.params?.name;
const fname = props.route.params?.fname;
const prid = props.route.params?.prid;
const room: any = props.route.params?.room ?? {
rid: this.rid,
t: this.t,
name,
fname,
prid
};
const room =
props.route.params?.room ??
({
rid: this.rid,
t: this.t,
name,
fname,
prid
} as IRoom);
this.jumpToMessageId = props.route.params?.jumpToMessageId;
this.jumpToThreadId = props.route.params?.jumpToThreadId;
const roomUserId = props.route.params?.roomUserId ?? RocketChat.getUidDirectMessage(room);
@ -629,22 +631,24 @@ class RoomView extends React.Component<IRoomViewProps, any> {
delete this.sub;
};
observeRoom = (room: Model) => {
const observable = room.observe();
this.subSubscription = observable.subscribe((changes: any) => {
const roomUpdate = roomAttrsUpdate.reduce((ret: any, attr: any) => {
ret[attr] = changes[attr];
return ret;
}, {});
if (this.mounted) {
this.internalSetState({ room: changes, roomUpdate });
} else {
// @ts-ignore
this.state.room = changes;
// @ts-ignore
this.state.roomUpdate = roomUpdate;
}
});
observeRoom = (room: IRoom) => {
if (room.observe) {
const observable = room.observe();
this.subSubscription = observable.subscribe((changes: any) => {
const roomUpdate = roomAttrsUpdate.reduce((ret: any, attr: any) => {
ret[attr] = changes[attr];
return ret;
}, {});
if (this.mounted) {
this.internalSetState({ room: changes, roomUpdate });
} else {
// @ts-ignore
this.state.room = changes;
// @ts-ignore
this.state.roomUpdate = roomUpdate;
}
});
}
};
errorActionsShow = (message: string) => {