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

View File

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