Skip to content

Commit

Permalink
Dedupe attachments by file name, but allow any number of pasted images.
Browse files Browse the repository at this point in the history
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 oxen-io#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;
```
  • Loading branch information
ianmacd committed Feb 17, 2023
1 parent 2710ea9 commit 34a8c1a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ts/state/ducks/stagedAttachments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 34a8c1a

Please sign in to comment.