minor tweak and fix the ISubscriptions interface

This commit is contained in:
AlexAlexandre 2021-12-15 23:35:33 -03:00
parent f68a0ac145
commit 4b9ed36fa5
2 changed files with 10 additions and 8 deletions

View File

@ -1,13 +1,14 @@
import Model from '@nozbe/watermelondb/Model'; import Model from '@nozbe/watermelondb/Model';
import { IRoom } from './IRoom';
export interface ISubscriptions { export interface ISubscriptions {
_id: string; _id: string;
name: string; name: string;
fname: string; fname: string;
rid: string; rid: string;
unread: number; unread: number;
tunread: string;
tunreadUser: string;
tunreadGroup: string;
} }
export type ISubscriptionsModel = IRoom & Model; export type TSubscriptionsModel = ISubscriptions & Model;

View File

@ -2,7 +2,6 @@ import React, { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { dequal } from 'dequal'; import { dequal } from 'dequal';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import Model from '@nozbe/watermelondb/Model';
import { StackNavigationProp } from '@react-navigation/stack'; import { StackNavigationProp } from '@react-navigation/stack';
import * as HeaderButton from '../../containers/HeaderButton'; import * as HeaderButton from '../../containers/HeaderButton';
@ -12,6 +11,8 @@ import { events, logEvent } from '../../utils/log';
import { isTeamRoom } from '../../utils/room'; import { isTeamRoom } from '../../utils/room';
import { ChatsStackParamList } from '../../stacks/types'; import { ChatsStackParamList } from '../../stacks/types';
import { RoomType } from '../../definitions/IRoom'; import { RoomType } from '../../definitions/IRoom';
import { IThread, TThreadModel } from '../../definitions/IThread';
import { ISubscriptions, TSubscriptionsModel } from '../../definitions/ISubscriptions';
interface IRoomRightButtonsContainerProps { interface IRoomRightButtonsContainerProps {
userId: string; userId: string;
@ -93,26 +94,26 @@ class RightButtonsContainer extends Component<IRoomRightButtonsContainerProps, a
} }
} }
observeThread = (threadRecord: Model) => { observeThread = (threadRecord: TThreadModel) => {
const threadObservable = threadRecord.observe(); const threadObservable = threadRecord.observe();
this.threadSubscription = threadObservable.subscribe(thread => this.updateThread(thread)); this.threadSubscription = threadObservable.subscribe(thread => this.updateThread(thread));
}; };
updateThread = (thread: any) => { updateThread = (thread: IThread) => {
const { userId } = this.props; const { userId } = this.props;
this.setState({ this.setState({
isFollowingThread: thread.replies && !!thread.replies.find((t: string) => t === userId) isFollowingThread: thread.replies && !!thread.replies.find((t: string) => t === userId)
}); });
}; };
observeSubscription = (subRecord: Model) => { observeSubscription = (subRecord: TSubscriptionsModel) => {
const subObservable = subRecord.observe(); const subObservable = subRecord.observe();
this.subSubscription = subObservable.subscribe(sub => { this.subSubscription = subObservable.subscribe(sub => {
this.updateSubscription(sub); this.updateSubscription(sub);
}); });
}; };
updateSubscription = (sub: any) => { updateSubscription = (sub: ISubscriptions) => {
this.setState({ this.setState({
tunread: sub?.tunread, tunread: sub?.tunread,
tunreadUser: sub?.tunreadUser, tunreadUser: sub?.tunreadUser,