Skip to content

Commit

Permalink
Fix a few database issues found on Bugsnag on ThreadMessagesView
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolmello authored and dnlsilva committed Feb 9, 2022
1 parent 0a05e06 commit 78f6d83
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions app/views/ThreadMessagesView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ class ThreadMessagesView extends React.Component<IThreadMessagesViewProps, IThre
let threadsToUpdate: any[] = [];
let threadsToDelete: any[] = [];

if (remove && remove.length) {
threadsToDelete = allThreadsRecords.filter((i1: { id: string }) => remove.find(i2 => i1.id === i2._id));
threadsToDelete = threadsToDelete.map(t => t.prepareDestroyPermanently());
}

if (update && update.length) {
update = update.map(m => buildMessage(m));
// filter threads
Expand All @@ -297,19 +302,18 @@ class ThreadMessagesView extends React.Component<IThreadMessagesViewProps, IThre
);
threadsToUpdate = threadsToUpdate.map(thread => {
const newThread = update.find(t => t._id === thread.id);
return thread.prepareUpdate(
protectedFunction((t: any) => {
Object.assign(t, newThread);
})
);
try {
return thread.prepareUpdate(
protectedFunction((t: any) => {
Object.assign(t, newThread);
})
);
} catch {
return null;
}
});
}

if (remove && remove.length) {
threadsToDelete = allThreadsRecords.filter((i1: { id: string }) => remove.find(i2 => i1.id === i2._id));
threadsToDelete = threadsToDelete.map(t => t.prepareDestroyPermanently());
}

await db.write(async () => {
await db.batch(
...threadsToCreate,
Expand Down

0 comments on commit 78f6d83

Please sign in to comment.