From 4f55a6e53a15dd366ec2f6cfc4c877a19fe58372 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Fri, 13 Dec 2024 15:07:41 +0000 Subject: [PATCH 1/3] Fix to avoid local blob urls being stored in the cache --- .../src/services/community/community.client.ts | 11 +++++------ .../openchat-agent/src/services/group/group.client.ts | 11 +++++------ .../openchat-agent/src/services/user/user.client.ts | 8 +++++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/frontend/openchat-agent/src/services/community/community.client.ts b/frontend/openchat-agent/src/services/community/community.client.ts index f3284a79f3..fe71bffde8 100644 --- a/frontend/openchat-agent/src/services/community/community.client.ts +++ b/frontend/openchat-agent/src/services/community/community.client.ts @@ -1179,10 +1179,12 @@ export class CommunityClient extends CandidService { : dataClient.uploadData(event.event.content, [chatId.communityId]); return uploadContentPromise.then((content) => { - const newContent = content ?? event.event.content; + if (content !== undefined) { + event.event.content = content; + } const args = { channel_id: BigInt(chatId.channelId), - content: apiMessageContent(newContent), + content: apiMessageContent(event.event.content), message_id: event.event.messageId, sender_name: senderName, sender_display_name: senderDisplayName, @@ -1207,10 +1209,7 @@ export class CommunityClient extends CandidService { onRequestAccepted, ) .then((resp) => { - const retVal: [SendMessageResponse, Message] = [ - resp, - { ...event.event, content: newContent }, - ]; + const retVal: [SendMessageResponse, Message] = [resp, event.event]; setCachedMessageFromSendResponse( this.db, chatId, diff --git a/frontend/openchat-agent/src/services/group/group.client.ts b/frontend/openchat-agent/src/services/group/group.client.ts index 2ee7e8ef9d..8aba7e2cef 100644 --- a/frontend/openchat-agent/src/services/group/group.client.ts +++ b/frontend/openchat-agent/src/services/group/group.client.ts @@ -596,9 +596,11 @@ export class GroupClient extends CandidService { : dataClient.uploadData(event.event.content, [this.chatId.groupId]); return uploadContentPromise.then((content) => { - const newContent = content ?? event.event.content; + if (content !== undefined) { + event.event.content = content; + } const args = { - content: apiMessageContent(newContent), + content: apiMessageContent(event.event.content), message_id: event.event.messageId, sender_name: senderName, sender_display_name: senderDisplayName, @@ -624,10 +626,7 @@ export class GroupClient extends CandidService { onRequestAccepted, ) .then((resp) => { - const retVal: [SendMessageResponse, Message] = [ - resp, - { ...event.event, content: newContent }, - ]; + const retVal: [SendMessageResponse, Message] = [resp, event.event]; setCachedMessageFromSendResponse( this.db, this.chatId, diff --git a/frontend/openchat-agent/src/services/user/user.client.ts b/frontend/openchat-agent/src/services/user/user.client.ts index 8e91ab2d62..4356f68061 100644 --- a/frontend/openchat-agent/src/services/user/user.client.ts +++ b/frontend/openchat-agent/src/services/user/user.client.ts @@ -767,9 +767,11 @@ export class UserClient extends CandidService { : dataClient.uploadData(event.event.content, [this.userId, chatId.userId]); return uploadContentPromise.then((content) => { - const newContent = content ?? event.event.content; + if (content !== undefined) { + event.event.content = content; + } const req = { - content: apiMessageContent(newContent), + content: apiMessageContent(event.event.content), recipient: principalStringToBytes(chatId.userId), message_id: event.event.messageId, replies_to: mapOptional(event.event.repliesTo, (replyContext) => @@ -789,7 +791,7 @@ export class UserClient extends CandidService { UserSendMessageArgs, UserSendMessageResponse, onRequestAccepted, - ).then((resp) => [resp, { ...event.event, content: newContent }]); + ).then((resp) => [resp, event]); }); } From 694c537322076fde4d766ceb7f95df9a25754d0a Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Fri, 13 Dec 2024 15:12:07 +0000 Subject: [PATCH 2/3] Bump cache version --- frontend/openchat-agent/src/utils/caching.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/openchat-agent/src/utils/caching.ts b/frontend/openchat-agent/src/utils/caching.ts index 588600bfa3..cc584d564d 100644 --- a/frontend/openchat-agent/src/utils/caching.ts +++ b/frontend/openchat-agent/src/utils/caching.ts @@ -54,7 +54,7 @@ import type { CryptocurrencyContent } from "openchat-shared"; import type { PrizeContent } from "openchat-shared"; import type { P2PSwapContent } from "openchat-shared"; -const CACHE_VERSION = 120; +const CACHE_VERSION = 121; const EARLIEST_SUPPORTED_MIGRATION = 115; const MAX_INDEX = 9999999999; @@ -208,6 +208,14 @@ async function clearEverything( nuke(db); } +async function clearEvents( + _db: IDBPDatabase, + _principal: Principal, + tx: IDBPTransaction[], "versionchange">, +) { + await tx.objectStore("chat_events").clear(); +} + async function clearChatAndGroups( _db: IDBPDatabase, _principal: Principal, @@ -247,6 +255,7 @@ const migrations: Record> = { createBotsStore(db, principal, tx), ]); }, + 121: clearEvents, }; async function migrate( From b5e18910ea600a729b4890eabe1be25d1ab630e9 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Fri, 13 Dec 2024 15:22:15 +0000 Subject: [PATCH 3/3] Fix --- frontend/openchat-agent/src/services/user/user.client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/openchat-agent/src/services/user/user.client.ts b/frontend/openchat-agent/src/services/user/user.client.ts index 4356f68061..de1ea27227 100644 --- a/frontend/openchat-agent/src/services/user/user.client.ts +++ b/frontend/openchat-agent/src/services/user/user.client.ts @@ -791,7 +791,7 @@ export class UserClient extends CandidService { UserSendMessageArgs, UserSendMessageResponse, onRequestAccepted, - ).then((resp) => [resp, event]); + ).then((resp) => [resp, event.event]); }); }