From 293d56f4a285ed6f84aa6b0ba80d970dcb54b34d Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Wed, 5 Apr 2023 13:16:34 +0600 Subject: [PATCH] Write email fix (#2890) Signed-off-by: Denis Bykhov --- .../src/components/NewMessages.svelte | 19 +++++++++++++++---- plugins/gmail-resources/src/utils.ts | 18 +++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/plugins/gmail-resources/src/components/NewMessages.svelte b/plugins/gmail-resources/src/components/NewMessages.svelte index 70406f7937..6af812be1a 100644 --- a/plugins/gmail-resources/src/components/NewMessages.svelte +++ b/plugins/gmail-resources/src/components/NewMessages.svelte @@ -52,7 +52,13 @@ attachedTo: { $in: contacts.map((p) => p._id) } }, (res) => { - channels = res + const map = new Map() + for (const channel of res) { + if (!map.has(channel.attachedTo)) { + map.set(channel.attachedTo, channel) + } + } + channels = Array.from(map.values()) } ) let channels: Channel[] = [] @@ -258,15 +264,15 @@
@@ -341,6 +347,11 @@ } } + .targets { + max-height: 10rem; + overflow-x: auto; + } + .input { overflow: auto; padding: 1rem; diff --git a/plugins/gmail-resources/src/utils.ts b/plugins/gmail-resources/src/utils.ts index 0e57cf7bd1..060a83ce1c 100644 --- a/plugins/gmail-resources/src/utils.ts +++ b/plugins/gmail-resources/src/utils.ts @@ -42,9 +42,17 @@ export async function checkHasEmail (doc: Doc | Doc[] | undefined): Promise p._id) : [doc._id] - const res = await client.findAll(contact.class.Channel, { - provider: contact.channelProvider.Email, - attachedTo: { $in: arr } - }) - return res.length === arr.length + const res = await client.findAll( + contact.class.Channel, + { + provider: contact.channelProvider.Email, + attachedTo: { $in: arr } + }, + { projection: { _id: 1, attachedTo: 1 } } + ) + const set = new Set(res.map((p) => p.attachedTo)) + for (const val of arr) { + if (!set.has(val)) return false + } + return true }