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

feat: add image attachment support to chat #2149

Closed
wants to merge 22 commits into from

Conversation

nakajima
Copy link
Contributor

This PR adds support for sending E2E encrypted images in messages.

It uses the newly introduced Attachment and RemoteAttachment content types which you can read more about here: https://xmtp.org/blog/attachments-and-remote-attachments.

Screen.Recording.2023-03-22.at.3.56.04.PM.mov

I had to change some of the hardcoded height values that were in the messages area before to accommodate the composer growing when you're about to send an image. I also added a slight background color to the composer because it looked confusing to have a bunch of white space when you had an attachment preview in there. Feel free to change any of that if it doesn't work for you.

Type of change

  • New feature (non-breaking change which adds functionality)
  • Enhancement (non-breaking small changes to existing functionality)

How should this be tested?

You should be able to add an image by clicking the photo button in the chat view.

@nakajima nakajima requested a review from bigint as a code owner March 22, 2023 23:07
@vercel
Copy link

vercel bot commented Mar 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
prerender ✅ Ready (Inspect) Visit Preview Apr 11, 2023 4:12pm
ui ❌ Failed (Inspect) Apr 11, 2023 4:12pm
web ❌ Failed (Inspect) Apr 11, 2023 4:12pm

@vercel vercel bot temporarily deployed to Preview – web March 22, 2023 23:12 Inactive
@vercel vercel bot temporarily deployed to Preview – prerender March 22, 2023 23:14 Inactive
@bigint
Copy link
Member

bigint commented Mar 24, 2023

Can we make like a regular chat attachment to upload and load seamlessly? 🙇🏼

We don't want to show attachment name, load button etc

Also is it possible to send text along with attachments?

@bigint bigint changed the title Add image attachment support to chat feat: add image attachment support to chat Mar 24, 2023
@nakajima
Copy link
Contributor Author

Can we make like a regular chat attachment to upload and load seamlessly? 🙇🏼

So we don't recommend attachments get autoloaded by default, since it presents somewhat of a security risk. What do you think of adding the ability to automatically load attachments for "Following" conversations that are under a certain size, maybe 100MB?

Also is it possible to send text along with attachments?

Not yet, but we can add this soon.

@bigint
Copy link
Member

bigint commented Mar 24, 2023

So we don't recommend attachments get autoloaded by default, since it presents somewhat of a security risk. What do you think of adding the ability to automatically load attachments for "Following" conversations that are under a certain size, maybe 100MB?

yea good idea to add only for following users and we can button in requested profiles

Also we can explain something like this for users like twitter does instead just showing load button

image

@nakajima
Copy link
Contributor Author

Cool, I'll get goin on that.

@bigint
Copy link
Member

bigint commented Mar 24, 2023

Amazing you are great @nakajima 💪👏

@nakajima
Copy link
Contributor Author

Ok, just pushed 528db21. This makes it so that we auto load attachments for convos where you're following the other profile (unless the attachment is greater than 100mb).

I also introduced a new cache using indexed db to prevent loading the same attachments multiple times, since it can be a bit expensive.

Some screenshots:

not following too big loader
Screenshot 2023-03-24 at 1 28 37 PM Screenshot 2023-03-24 at 1 29 29 PM Screenshot 2023-03-24 at 1 29 39 PM

@vercel vercel bot temporarily deployed to Preview – web March 24, 2023 20:44 Inactive
@vercel vercel bot temporarily deployed to Preview – prerender March 24, 2023 20:44 Inactive
nakajima and others added 2 commits March 24, 2023 13:52
Co-authored-by: Strek <ssharishkumar@gmail.com>
@vercel vercel bot temporarily deployed to Preview – web March 24, 2023 20:53 Inactive
@vercel vercel bot temporarily deployed to Preview – prerender March 24, 2023 20:54 Inactive
@vercel vercel bot temporarily deployed to Preview – web March 24, 2023 20:58 Inactive
@vercel vercel bot temporarily deployed to Preview – prerender March 24, 2023 20:58 Inactive
@bigint
Copy link
Member

bigint commented Mar 25, 2023

@nakajima Loader state will cause CLS, can we keep the same width as warn state for loading card 🙇🏼 ?

@bigint
Copy link
Member

bigint commented Mar 25, 2023

Also build failed 🙇🏼

image

@vercel vercel bot temporarily deployed to Preview – prerender March 28, 2023 15:54 Inactive
@vercel vercel bot temporarily deployed to Preview – web March 28, 2023 15:55 Inactive
@vercel vercel bot temporarily deployed to Preview – prerender March 30, 2023 05:07 Inactive
@vercel vercel bot temporarily deployed to Preview – web March 30, 2023 05:10 Inactive
@vercel vercel bot temporarily deployed to Preview – web March 30, 2023 05:39 Inactive
@vercel vercel bot temporarily deployed to Preview – prerender March 30, 2023 05:39 Inactive
@bigint
Copy link
Member

bigint commented Mar 31, 2023

@nakajima It would be great if you fix the conflicts, I'll merge after that 🚀 🙇🏼

Copy link
Member

@bigint bigint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit:

Rad LGTM

@bigint bigint enabled auto-merge (squash) March 31, 2023 17:23
auto-merge was automatically disabled April 11, 2023 16:06

Head branch was pushed to by a user without write access

@socket-security
Copy link

New dependency changes detected. Learn more about Socket for GitHub ↗︎


🚨 Potential security issues found in this pull request. To accept the risk, merge this PR and you will not be notified again.

Bot Commands

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore foo@1.0.0 bar@* or ignore all packages with @SocketSecurity ignore-all

  • @SocketSecurity ignore secp256k1@3.7.1
  • @SocketSecurity ignore eccrypto@1.1.6
📜 Install scripts

Install scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.

Packages should not be running non-essential scripts during install and there are often solutions to problems people solve with install scripts that can be run at publish time instead.

Package Script field Source
secp256k1@3.7.1 (added) install package.json via xmtp-content-type-remote-attachment@1.0.6, apps/web/package.json via xmtp-content-type-remote-attachment@1.0.6
🫣 Native code

Contains native code which could be a vector to obscure malicious code, and generally decrease the likelihood of reproducible or reliable installs.

Ensure that native code bindings are expected. Consumers may consider pure JS and functionally similar alternatives to avoid the challenges and risks associated with native code bindings.

Package Location Source
eccrypto@1.1.6 (added) binding.gyp package.json via xmtp-content-type-remote-attachment@1.0.6, apps/web/package.json via xmtp-content-type-remote-attachment@1.0.6
Pull request alert summary
Issue Status
Install scripts ⚠️ 1 issue
Native code ⚠️ 1 issue
Bin script shell injection ✅ 0 issues
Unresolved require ✅ 0 issues
Invalid package.json ✅ 0 issues
HTTP dependency ✅ 0 issues
Git dependency ✅ 0 issues
Potential typo squat ✅ 0 issues
Known Malware ✅ 0 issues
Telemetry ✅ 0 issues
Protestware/Troll package ✅ 0 issues

📊 Modified Dependency Overview:

➕ Added Package Capability Access +/- Transitive Count Publisher
xmtp-content-type-remote-attachment@1.0.6 network +32 xmtp-eng-robot
idb-keyval@6.2.0 None +2 jaffathecake

@vercel vercel bot temporarily deployed to Preview – prerender April 11, 2023 16:10 Inactive
@vercel vercel bot temporarily deployed to Preview – ui April 11, 2023 16:10 Inactive
@vercel vercel bot temporarily deployed to Preview – web April 11, 2023 16:12 Inactive
Copy link
Member

@saagu335 saagu335 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nakajima Please fix the conflicts and @ me I'll merge this ASAP 🙇

PS: we migrated to pnpm from yarn

@bigint
Copy link
Member

bigint commented Apr 23, 2023

Gonna close this for now!

We need to fix the speed issue first, later we can ship more features 🙇🏼

RN it takes 40s to load my inbox 😢

@bigint bigint closed this Apr 23, 2023
@bigint bigint reopened this May 4, 2023
@bigint
Copy link
Member

bigint commented May 10, 2023

@nakajima It would be great if you resolve the conflicts 🙇🏼

@daria-github
Copy link
Contributor

@bigint conflicts should be resolved in this PR: #2845

@bigint
Copy link
Member

bigint commented May 12, 2023

Closing this and continued here #2845

@bigint bigint closed this May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants