Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions app/lib/methods/updateMessages.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
import { Q } from '@nozbe/watermelondb';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';

import { MESSAGE_TYPE_ANY_LOAD } from '../../constants/messageTypeLoad';
import { IMessage, TMessageModel, TSubscriptionModel, TThreadMessageModel, TThreadModel } from '../../definitions';
import database from '../database';
import { getSubscriptionByRoomId } from '../database/services/Subscription';
import { Encryption } from '../encryption';
import { MESSAGE_TYPE_ANY_LOAD } from '../../constants/messageTypeLoad';
import { generateLoadMoreId } from '../utils';
import protectedFunction from './helpers/protectedFunction';
import buildMessage from './helpers/buildMessage';
import { IMessage, TMessageModel, TThreadMessageModel, TThreadModel } from '../../definitions';
import { getSubscriptionByRoomId } from '../database/services/Subscription';
import protectedFunction from './helpers/protectedFunction';

interface IUpdateMessages {
rid: string;
Expand All @@ -27,9 +27,11 @@ export default async function updateMessages({
return Promise.resolve(0);
}

const sub = await getSubscriptionByRoomId(rid);
let sub = (await getSubscriptionByRoomId(rid)) as TSubscriptionModel;
if (!sub) {
throw new Error('updateMessages: subscription not found');
sub = { id: rid } as any;
// TODO: If I didn't join the room I obviously don't have a subscription, this error catch is imperfect. Think of a way to handle the error when I actually try to open a room without subscription.
console.log('updateMessages: subscription not found');
}

const db = database.active;
Expand Down