From 51f44653b7c90c70f11499a341baa4e2db8226fb Mon Sep 17 00:00:00 2001 From: Amir Ghezelbash Date: Wed, 31 May 2023 17:52:57 +0330 Subject: [PATCH 1/2] feat: Display message failed to send for MLS (FS-2030) --- package.json | 2 +- .../PartialFailureToSend.tsx | 33 ++++++++++++++++--- src/script/entity/message/ContentMessage.ts | 5 +-- src/script/storage/record/EventRecord.ts | 2 +- yarn.lock | 20 +++++------ 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 24bbdd6ded9..fa6d21b034f 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "@emotion/react": "11.11.0", "@types/eslint": "8.37.0", "@wireapp/avs": "9.2.13", - "@wireapp/core": "40.3.0", + "@wireapp/core": "40.3.1", "@wireapp/lru-cache": "3.8.1", "@wireapp/react-ui-kit": "9.7.2", "@wireapp/store-engine-dexie": "2.1.1", diff --git a/src/script/components/MessagesList/Message/ContentMessage/Warnings/PartialFailureToSend/PartialFailureToSend.tsx b/src/script/components/MessagesList/Message/ContentMessage/Warnings/PartialFailureToSend/PartialFailureToSend.tsx index 1510e26b91b..e8f74904de2 100644 --- a/src/script/components/MessagesList/Message/ContentMessage/Warnings/PartialFailureToSend/PartialFailureToSend.tsx +++ b/src/script/components/MessagesList/Message/ContentMessage/Warnings/PartialFailureToSend/PartialFailureToSend.tsx @@ -32,14 +32,36 @@ import {warning} from '../Warnings.styles'; export type User = {qualifiedId: QualifiedId; name: () => string}; type Props = { - failedToSend: {queued?: QualifiedUserClients; failed?: QualifiedId[]}; + failedToSend: { + queued?: QualifiedUserClients | QualifiedId[]; + failed?: QualifiedId[]; + }; knownUsers: User[]; }; type ParsedUsers = {namedUsers: User[]; unknownUsers: QualifiedId[]}; -function generateNamedUsers(users: User[], userClients: QualifiedUserClients): ParsedUsers { - return Object.entries(userClients).reduce( +function generateNamedUsers( + users: User[], + userClientsOrQualifiedIds: QualifiedUserClients | QualifiedId[], +): ParsedUsers { + if (Array.isArray(userClientsOrQualifiedIds)) { + return userClientsOrQualifiedIds.reduce( + (parsedUsers, currentQulifiedId) => { + const user = users.find(user => + matchQualifiedIds(user.qualifiedId, {id: currentQulifiedId.id, domain: currentQulifiedId.domain}), + ); + if (user && user.name()) { + parsedUsers.namedUsers.push(user); + } else { + parsedUsers.unknownUsers.push({id: currentQulifiedId.id, domain: currentQulifiedId.domain}); + } + return parsedUsers; + }, + {namedUsers: [], unknownUsers: []}, + ); + } + return Object.entries(userClientsOrQualifiedIds).reduce( (namedUsers, [domain, domainUsers]) => { const domainNamedUsers = Object.keys(domainUsers).reduce( (domainNamedUsers, userId) => { @@ -76,8 +98,9 @@ export const PartialFailureToSendWarning = ({failedToSend, knownUsers}: Props) = const [isOpen, setIsOpen] = useState(false); const {queued = {}, failed = []} = failedToSend; - const userCount = - Object.entries(queued).reduce((count, [_domain, users]) => count + Object.keys(users).length, 0) + failed.length; + const userCount = Array.isArray(queued) + ? queued.length + : Object.entries(queued).reduce((count, [_domain, users]) => count + Object.keys(users).length, 0) + failed.length; const showToggle = userCount > 1; diff --git a/src/script/entity/message/ContentMessage.ts b/src/script/entity/message/ContentMessage.ts index ba5ac31d1cd..816af6d5008 100644 --- a/src/script/entity/message/ContentMessage.ts +++ b/src/script/entity/message/ContentMessage.ts @@ -49,8 +49,9 @@ export class ContentMessage extends Message { public readonly is_liked: ko.PureComputed; public readonly like_caption: ko.PureComputed; public readonly other_likes: ko.PureComputed; - public readonly failedToSend: ko.Observable<{queued?: QualifiedUserClients; failed?: QualifiedId[]} | undefined> = - ko.observable(); + public readonly failedToSend: ko.Observable< + {queued?: QualifiedUserClients | QualifiedId[]; failed?: QualifiedId[]} | undefined + > = ko.observable(); // raw content of a file that was supposed to be sent but failed. Is undefined if the message has been successfully sent public readonly fileData: ko.Observable = ko.observable(); public readonly quote: ko.Observable; diff --git a/src/script/storage/record/EventRecord.ts b/src/script/storage/record/EventRecord.ts index 0ba1c107cbc..1582638842b 100644 --- a/src/script/storage/record/EventRecord.ts +++ b/src/script/storage/record/EventRecord.ts @@ -51,7 +51,7 @@ type SentEvent = { /** raw content of a file that was supposed to be sent but failed. Is undefined if the message has been successfully sent */ fileData?: Blob; failedToSend?: { - queue?: QualifiedUserClients; + queue?: QualifiedUserClients | QualifiedId[]; failed?: QualifiedId[]; }; }; diff --git a/yarn.lock b/yarn.lock index b912286179d..b7d4edfcc75 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5747,9 +5747,9 @@ __metadata: languageName: node linkType: hard -"@wireapp/api-client@npm:^24.15.0": - version: 24.15.0 - resolution: "@wireapp/api-client@npm:24.15.0" +"@wireapp/api-client@npm:^24.15.1": + version: 24.15.1 + resolution: "@wireapp/api-client@npm:24.15.1" dependencies: "@wireapp/commons": ^5.1.0 "@wireapp/priority-queue": ^2.1.1 @@ -5762,7 +5762,7 @@ __metadata: spark-md5: 3.0.2 tough-cookie: 4.1.2 ws: 8.11.0 - checksum: 5a2a6dad73b56110690f6e62bd7f45bb7ed1ccdaaa748f8207fb7da987150dd7e2c8cf8cfd68a7c3c951e9ac69afd49dd2335157156dff277c3f72efc3695273 + checksum: a0b0d3bc398ddb5dec12642c61efb46306228ff2f2875abb4d62406612ce2e7e31b6f21433b8597b90adcc9e83bc744f070b2664a54d872401b216c72b7d3162 languageName: node linkType: hard @@ -5815,11 +5815,11 @@ __metadata: languageName: node linkType: hard -"@wireapp/core@npm:40.3.0": - version: 40.3.0 - resolution: "@wireapp/core@npm:40.3.0" +"@wireapp/core@npm:40.3.1": + version: 40.3.1 + resolution: "@wireapp/core@npm:40.3.1" dependencies: - "@wireapp/api-client": ^24.15.0 + "@wireapp/api-client": ^24.15.1 "@wireapp/commons": ^5.1.0 "@wireapp/core-crypto": 0.8.2 "@wireapp/cryptobox": 12.8.0 @@ -5836,7 +5836,7 @@ __metadata: logdown: 3.3.1 long: ^5.2.0 uuidjs: 4.2.13 - checksum: 975932a904843790651cf7f28b0a0df5e83cdd3d3a631caef5ded9e08b91e316e128310427e75fd91650083dcaace8cecd2df46b321b52ac9b4cfbd4313803f4 + checksum: 16c5d181043300a7e77a4a9012ef5faf828488a49c62db923663dadc96cfde93a84568f8f92e92750eabb42b87b7db5d5bd3fd5832d759302e3331864262721e languageName: node linkType: hard @@ -18625,7 +18625,7 @@ dexie@latest: "@typescript-eslint/parser": ^5.59.7 "@wireapp/avs": 9.2.13 "@wireapp/copy-config": 2.1.0 - "@wireapp/core": 40.3.0 + "@wireapp/core": 40.3.1 "@wireapp/eslint-config": 2.2.1 "@wireapp/lru-cache": 3.8.1 "@wireapp/prettier-config": 0.6.0 From eb0be37fcbba7f44bfa7975899c4668aa5562461 Mon Sep 17 00:00:00 2001 From: Amir Ghezelbash Date: Wed, 31 May 2023 18:04:03 +0330 Subject: [PATCH 2/2] simply use currentQulifiedId --- .../Warnings/PartialFailureToSend/PartialFailureToSend.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/script/components/MessagesList/Message/ContentMessage/Warnings/PartialFailureToSend/PartialFailureToSend.tsx b/src/script/components/MessagesList/Message/ContentMessage/Warnings/PartialFailureToSend/PartialFailureToSend.tsx index 9b3e408d42a..def73343d4a 100644 --- a/src/script/components/MessagesList/Message/ContentMessage/Warnings/PartialFailureToSend/PartialFailureToSend.tsx +++ b/src/script/components/MessagesList/Message/ContentMessage/Warnings/PartialFailureToSend/PartialFailureToSend.tsx @@ -53,13 +53,11 @@ function generateNamedUsers( if (Array.isArray(userClientsOrQualifiedIds)) { return userClientsOrQualifiedIds.reduce( (parsedUsers, currentQulifiedId) => { - const user = users.find(user => - matchQualifiedIds(user.qualifiedId, {id: currentQulifiedId.id, domain: currentQulifiedId.domain}), - ); + const user = users.find(user => matchQualifiedIds(user.qualifiedId, currentQulifiedId)); if (user && user.name()) { parsedUsers.namedUsers.push(user); } else { - parsedUsers.unknownUsers.push({id: currentQulifiedId.id, domain: currentQulifiedId.domain}); + parsedUsers.unknownUsers.push(currentQulifiedId); } return parsedUsers; },