Skip to content

Commit

Permalink
Fixes #3633 (#3643)
Browse files Browse the repository at this point in the history
  • Loading branch information
hkirat authored Apr 7, 2023
1 parent dc3a6fd commit 5158183
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 13 additions & 9 deletions packages/db/src/api/friendships.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ export const refreshFriendships = async (uuid: string, jwt?: string) => {
return;
}
const existingChats = await db.inbox.toArray();
existingChats.forEach((existingChat) => {
for (const existingChat of existingChats) {
if (!chats.find((x) => x.remoteUserId === existingChat.remoteUserId)) {
db.inbox.delete(existingChat.remoteUserId);
await db.inbox.delete(existingChat.remoteUserId);
}
});
}
if (chats) {
chats?.forEach((chat) => {
db.inbox.put(chat);
});
await Promise.all(
chats?.map(async (chat) => {
await db.inbox.put(chat);
}) || []
);
}
} catch (e) {
console.error(e);
Expand All @@ -49,9 +51,11 @@ export const refreshGroups = async (uuid: string, jwt?: string) => {

const res = await response.json();
const collections: CollectionChatData[] = res.collections;
collections?.forEach((collection) => {
createOrUpdateCollection(uuid, collection);
});
await Promise.all(
collections?.map(async (collection) => {
await createOrUpdateCollection(uuid, collection);
}) || []
);
} catch (e) {
console.error(e);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/db/src/db/chats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export const createOrUpdateCollection = async (
) => {
const db = getDb(uuid);
if (await db.collections.get(data.collectionId)) {
db.collections.update(data.collectionId, data);
return db.collections.update(data.collectionId, data);
} else {
db.collections.put(data);
return db.collections.put(data);
}
};

1 comment on commit 5158183

@vercel
Copy link

@vercel vercel bot commented on 5158183 Apr 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.