Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot paste more than one image into a new posting. #2345

Open
ianmacd opened this issue May 24, 2022 · 3 comments · May be fixed by #2681
Open

Cannot paste more than one image into a new posting. #2345

ianmacd opened this issue May 24, 2022 · 3 comments · May be fixed by #2681
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ianmacd
Copy link

ianmacd commented May 24, 2022

Describe the bug

The composition window allows a single image to be pasted directly into it, but not multiple images. The first image may be pasted or selected from a file, but subsequent images can only selected from files.

When making N screenshots to attach to a posting, it's a hindrance to have to save N-1 of them to files, and then select them for attachment.

To Reproduce

  1. Copy an image to the clipboard.
  2. Paste it into the composition box.
  3. Copy a second image to the clipboard.
  4. Attempt to paste it into the composition box. Nothing happens.
  • Session Version: 1.8.6.
@KeeJef KeeJef added enhancement New feature or request good first issue Good for newcomers labels Aug 11, 2022
@Bilb
Copy link
Collaborator

Bilb commented Feb 14, 2023

this happens because we filter attachments by name. Because a pasted image as no name, it gets filtered out.
We could do some fancy things like computing a hash of the data to avoid inserting a few times the same picture, or just not care about it (I think signal does that)

Should be easy to allow duplicate empty filename (check addStagedAttachmentsInConversation)

@ianmacd
Copy link
Author

ianmacd commented Feb 15, 2023

this happens because we filter attachments by name. Because a pasted image as no name, it gets filtered out.

Actually, it would appear that a pasted image is given the internal name image.png, even though it doesn't exist on a file-system.

We could do some fancy things like computing a hash of the data to avoid inserting a few times the same picture, or just not care about it (I think signal does that)

Should be easy to allow duplicate empty filename (check addStagedAttachmentsInConversation)

Thanks for this pointer. I can see how to fix the problem now.

The easiest way is obviously not to check for duplicate names at all. That seemed lazy, though, so I instead chose to keep the check for duplicate names, but to ignore any named image.png.

That worked, but revealed the full extent of this bug, which is that the deduping function really only considers the file's name, not its content. This means that:

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

  2. It's impossible to post different attachments if they have the same base file-name (i.e. minus its directory path).

So, we're actually getting both false positives and false negatives here, which seems as if it's doing more harm than good and inclines me to go back to my original solution of skipping the deduping altogether.

ianmacd added a commit to ianmacd/session-desktop that referenced this issue Feb 15, 2023
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.

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;
```
ianmacd added a commit to ianmacd/session-desktop that referenced this issue Feb 15, 2023
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;
```
@ianmacd
Copy link
Author

ianmacd commented Feb 16, 2023

@Bilb Do you have any idea where the name image.png is being assigned to image data pasted into the message composition window?

I just cannot find the place in the code where this assignment takes place. Obviously it's not a trivial string assignment or I would have located it immediately.

ianmacd added a commit to ianmacd/session-desktop that referenced this issue Feb 17, 2023
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;
```
ianmacd added a commit to ianmacd/session-desktop that referenced this issue Feb 17, 2023
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;
```
ianmacd added a commit to ianmacd/session-desktop that referenced this issue Feb 17, 2023
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;
```
@ianmacd ianmacd linked a pull request Feb 17, 2023 that will close this issue
4 tasks
ianmacd added a commit to ianmacd/session-desktop that referenced this issue Feb 21, 2023
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;
```
ianmacd added a commit to ianmacd/session-desktop that referenced this issue Mar 31, 2023
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;
```
ianmacd added a commit to ianmacd/session-desktop that referenced this issue Apr 6, 2023
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;
```
ianmacd added a commit to ianmacd/session-desktop that referenced this issue Jun 21, 2023
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;
```
ianmacd added a commit to ianmacd/session-desktop that referenced this issue Jun 28, 2023
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;
```
ianmacd added a commit to ianmacd/session-desktop that referenced this issue Jul 17, 2023
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;
```
ianmacd added a commit to ianmacd/session-desktop that referenced this issue Jul 18, 2023
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;
```
ianmacd added a commit to ianmacd/session-desktop that referenced this issue Jul 18, 2023
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;
```
ianmacd added a commit to ianmacd/session-desktop that referenced this issue Jul 18, 2023
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;
```
ianmacd added a commit to ianmacd/session-desktop that referenced this issue Aug 9, 2023
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;
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants