Write email fix ()

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-04-05 13:16:34 +06:00 committed by GitHub
parent eb25bd2d3c
commit 293d56f4a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 9 deletions
plugins/gmail-resources/src

View File

@ -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 @@
<div class="buttons-group">
<div class="flex-grow flex-col">
<Label label={plugin.string.NewMessage} />
<span class="content-accent-color">
<div class="content-accent-color targets">
<b>
{#each channels as channel, i}
<div>
{getName(channel)}
</div>
{/each}
</b></span
>
</b>
</div>
</div>
</div>
<div class="buttons-group small-gap">
@ -341,6 +347,11 @@
}
}
.targets {
max-height: 10rem;
overflow-x: auto;
}
.input {
overflow: auto;
padding: 1rem;

View File

@ -42,9 +42,17 @@ export async function checkHasEmail (doc: Doc | Doc[] | undefined): Promise<bool
if (doc === undefined) return false
const client = getClient()
const arr = Array.isArray(doc) ? doc.map((p) => 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
}