creating ISubscriptions

This commit is contained in:
AlexAlexandre 2021-12-15 00:48:03 -03:00
parent 667f26e7cd
commit 09a8254813
2 changed files with 16 additions and 2 deletions

View File

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

View File

@ -69,6 +69,7 @@ import { ChatsStackParamList } from '../../stacks/types';
import { IRoom, IRoomModel, RoomType } from '../../definitions/IRoom';
import { IAttachment } from '../../definitions/IAttachment';
import { IThread } from '../../definitions/IThread';
import { ISubscriptions } from '../../definitions/ISubscriptions';
const stateAttrsUpdate = [
'joined',
@ -764,9 +765,9 @@ class RoomView extends React.Component<IRoomViewProps, any> {
.query(Q.where('archived', false), Q.where('open', true), Q.where('rid', Q.notEq(this.rid)))
.observeWithColumns(['unread']);
this.queryUnreads = observable.subscribe((data: any) => {
this.queryUnreads = observable.subscribe((data: ISubscriptions[]) => {
const { unreadsCount } = this.state;
const newUnreadsCount = data.filter((s: any) => s.unread > 0).reduce((a: any, b: any) => a + (b.unread || 0), 0);
const newUnreadsCount = data.filter(s => s.unread > 0).reduce((a, b) => a + (b.unread || 0), 0);
if (unreadsCount !== newUnreadsCount) {
this.setState({ unreadsCount: newUnreadsCount }, () => this.setHeader());
}