-
Couldn't load subscription status.
- Fork 1.4k
fix: e2ee attachment getting locked after interaction #6735
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
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughWhen updating messages, if an existing record is found and is type Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant Subscriptions as Subscriptions.updateMessage
participant DB as messageRecord (existing)
participant MessageOut as UpdatedMessage
Client->>Subscriptions: updateMessage(payload)
Subscriptions->>DB: find existing messageRecord
alt existing.type == "e2e"
Note right of Subscriptions: For each attachment\n- merge e2e metadata from DB\n- if DB.e2e == 'done' keep DB.title_link\n- else keep incoming title_link
Subscriptions->>MessageOut: transform attachments (merge e2e, set title_link)
else
Subscriptions->>MessageOut: keep attachments as-is
end
Subscriptions->>Client: return UpdatedMessage
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
app/lib/methods/subscriptions/room.ts (1)
266-272: Consider optimizing attachment matching for better performance.The current nested loop (mapping over new attachments while finding in existing attachments) has O(n*m) complexity. While acceptable for typical attachment counts, this could be optimized.
Consider creating a Map for O(1) lookups:
if (messageRecord.t === 'e2e' && message.attachments) { + // Create lookup map keyed by URL for efficient matching + const existingAttachmentMap = new Map( + messageRecord.attachments?.map(att => { + const key = att.image_url || att.video_url || att.audio_url || att.thumb_url; + return [key, att]; + }) ?? [] + ); + message.attachments = message.attachments?.map(att => { - const existing = messageRecord.attachments?.find( - a => - a.image_url === att.image_url || - a.video_url === att.video_url || - a.audio_url === att.audio_url || - a.thumb_url === att.thumb_url - ); + const key = att.image_url || att.video_url || att.audio_url || att.thumb_url; + const existing = existingAttachmentMap.get(key); return { ...att, e2e: existing?.e2e, title_link: existing?.e2e === 'done' ? existing?.title_link : att.title_link }; }); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
app/lib/methods/subscriptions/room.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: ESLint and Test / run-eslint-and-test
🔇 Additional comments (2)
app/lib/methods/subscriptions/room.ts (2)
277-277: Clarify the conditional title_link preservation logic.The
title_linkis preserved only whenexisting?.e2e === 'done', otherwise the newtitle_linkfrom the websocket payload is used. Please verify this is the intended behavior. Iftitle_linkcontains the local decrypted file path when E2EE decryption is complete, this logic makes sense—but it should be documented with a comment.Additionally, consider whether there are edge cases where
e2emight have other values (e.g., 'pending', 'error') that should also preserve thetitle_link.
264-280: The PR fix is complete and correct—no verification issues found.The code properly preserves all necessary E2EE metadata:
- The
e2eproperty is preserved from the existing attachment- The
title_link(which stores the local cached file path) is conditionally preserved whene2e === 'done'The
title_linkproperty confirmed as the local cache referenced in the PR description, used for offline access to downloaded media. The conditional preservation logic is sound—only preserve the cache when decryption is complete (e2e === 'done'), otherwise use the new URL from the websocket event.
Proposed changes
Whenever we or someone try to interact with an attachment in e2ee channel like reacting to that message or read receipt event happen, we receive websocket event which just overwrite the attachment payload provided from backend which removes the e2ee done and cache property from the local database (this thing is done in the app), so before updating the message, i am just trying to get the attachment from the local db and add the e2ee key and local cache path to each object.
Issue(s)
Closes: #5977
How to test or reproduce
It will show overlay component with key icon if we use the code from develop
Screenshots
Before
https://github.com/user-attachments/assets/8b5c1e5a-8d7c-4d77-a79d-2b6aa506b168
After
https://github.com/user-attachments/assets/5d496425-4a95-4be4-a526-651cd8746bde
Types of changes
Checklist
Further comments
Summary by CodeRabbit