Dedupe attachments by file name, but allow any number of pasted images.

Previously, the code simply deduped attachments on file name, using the
internal name `image.png` for any pasted image. This effectively made it
possible to paste only a single image into a message.

Now, we ignore files called `image.png` when deduping.

Deduping on file name is flawed anyway, because:

1. It's trivial to post multiple identical attachments, so long as each
   of them has a different file name.

2. It's **not** possible to post different attachments if they happen to
   have the same base file name (i.e. after the directory component is
   removed).

So, we're actually getting both false positives and false negatives
here.

Fixes #2345, but introduces a new problem:

When deleting a pasted attachment from a list of such attachments prior
to sending, **all** pasted attachments are removed, presumably due to
their all having the same internal file name.

It may be better not to dedupe attachments at all, rather than use the
crude mechanism of the file name. In that case, the following code would
suffice:

```
-    const uniqAttachments = _.uniqBy(allAttachments, m => m.fileName);

-    state.stagedAttachments[conversationKey] = uniqAttachments;
+    state.stagedAttachments[conversationKey] = allAttachments;
```
pull/2681/head
Ian Macdonald 2 years ago
parent 2710ea9134
commit 34a8c1a8a5
No known key found for this signature in database
GPG Key ID: AE4C20556BA626FA

@ -37,9 +37,12 @@ const stagedAttachmentsSlice = createSlice({
}
const allAttachments = _.concat(currentStagedAttachments, newAttachments);
const uniqAttachments = _.uniqBy(allAttachments, m => m.fileName);
const pastedAttachments = allAttachments.filter(m => m.fileName === 'image.png');
const allAttachmentsExceptPasted = allAttachments.filter(m => m.fileName !== 'image.png');
const uniqAttachments = _.uniqBy(allAttachmentsExceptPasted, m => m.fileName);
const finalAttachments = _.concat(uniqAttachments, pastedAttachments);
state.stagedAttachments[conversationKey] = uniqAttachments;
state.stagedAttachments[conversationKey] = finalAttachments;
return state;
},
removeAllStagedAttachmentsInConversation(

Loading…
Cancel
Save