Skip to content

fix: P2P chat messages with images block rendering until download completes#526

Merged
grunch merged 1 commit into
mainfrom
p2p-chat-rendering-block
Mar 13, 2026
Merged

fix: P2P chat messages with images block rendering until download completes#526
grunch merged 1 commit into
mainfrom
p2p-chat-rendering-block

Conversation

@Catrya

@Catrya Catrya commented Mar 10, 2026

Copy link
Copy Markdown
Member

fix #517

  • Fix blocking await in ChatRoomNotifier._onChatEvent() that prevented P2P chat messages with encrypted images
    from appearing until download completed
  • Extract EncryptedImageUploadService and EncryptedFileUploadService to static fields in both ChatRoomNotifier and DisputeChatNotifier for consistency with ChatFileUploadHelper pattern

How to test it

P2P chat image rendering (main fix)

  • Open a P2P chat with a counterpart
  • Have the counterpart send an encrypted image
  • Expected: Message appears immediately in the chat with a loading spinner ("Decrypting image...")
  • Expected: Once download completes, the spinner is replaced by the actual image
  • Previously: Message was invisible until the image fully downloaded and decrypted

Slow connection test

  • Enable network throttling or use a slow connection
  • Receive an encrypted image in P2P chat
  • Expected: Message bubble visible within ~1 second, image loads progressively in background
  • Previously: Chat appeared frozen for several seconds with no feedback

Regression checks

  • Send and receive text-only P2P messages — should work as before
  • Send and receive encrypted images in dispute chat — should work as before (dispute chat already used
    unawaited())
  • Verify images are cached after first load (scrolling away and back should show image instantly)
  • App restart: historical messages with images should load correctly

Summary by CodeRabbit

  • Refactor
    • Reorganized image and file upload service management across chat and dispute messaging features for consistency.
    • Updated message processing flow in the chat module.

@coderabbitai

coderabbitai Bot commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3972d84e-549d-437e-ac8d-79dd7b438b5b

📥 Commits

Reviewing files that changed from the base of the PR and between 902a650 and 25c9f8a.

📒 Files selected for processing (2)
  • lib/features/chat/notifiers/chat_room_notifier.dart
  • lib/features/disputes/notifiers/dispute_chat_notifier.dart

Walkthrough

Two chat notifiers refactored to reuse static service instances for image and file uploads instead of creating new ones per call. ChatRoomNotifier additionally switches message content processing from awaited to fire-and-forget execution.

Changes

Cohort / File(s) Summary
ChatRoomNotifier service consolidation
lib/features/chat/notifiers/chat_room_notifier.dart
Added static _imageUploadService and _fileUploadService fields, replaced per-call instantiations with static field usage. Changed message content processing from await _processMessageContent() to unawaited(_processMessageContent()) for non-blocking execution.
DisputeChatNotifier service consolidation
lib/features/disputes/notifiers/dispute_chat_notifier.dart
Added static _imageUploadService and _fileUploadService fields. Replaced per-call instantiations in _processEncryptedImageMessage and _processEncryptedFileMessage with static field usage.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • Issue #517: Addresses the same refactoring in ChatRoomNotifier and DisputeChatNotifier to use shared static service instances and implements the fire-and-forget message processing pattern.

Possibly related PRs

  • PR #514: Implements the multimedia download/decrypt flow that these service consolidation changes now optimize and reuse.
  • PR #367: Introduced the encrypted image and file upload services that are now being centralized as static instances across chat notifiers.

Suggested reviewers

  • grunch
  • AndreaDiazCorreia
  • arkanoider

Poem

🐰 Static services now dance in harmony,
No more instances born with each decree,
Fire-and-forget messages take their flight,
The notifiers work leaner, oh what a sight! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: removing a blocking await that prevented P2P chat messages with images from rendering until download completes, which aligns with the code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch p2p-chat-rendering-block

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@BraCR10 BraCR10 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Images load properly without blocking the UI. No issues detected related to this PR.

Note: Some decrypt errors appeared in logs during testing, but I think these are unrelated to the image rendering changes.

I/flutter ( 583): �[38;5;196m┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────�[0m I/flutter ( 583): �[38;5;196m│ Exception: Failed to decrypt NIP-59 event: Exception: Decryption failed: Exception: Invalid payload size�[0m I/flutter ( 583): �[38;5;196m├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄�[0m I/flutter ( 583): �[38;5;196m│ #0 MostroService._onData (package:mostro_mobile/services/mostro_service.dart:151:14)�[0m I/flutter ( 583): �[38;5;196m│ #1 <asynchronous suspension>�[0m I/flutter ( 583): �[38;5;196m├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄�[0m I/flutter ( 583): �[38;5;196m│ 22:28:19.632 (+0:01:53.703835)�[0m I/flutter ( 583): �[38;5;196m├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄�[0m I/flutter ( 583): �[38;5;196m│ ⛔ Error processing event�[0m I/flutter ( 583): �[38;5;196m└──────────────

@mostronatorcoder mostronatorcoder Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Strict review completed.

I inspected both modified notifiers and the execution path change is correct:

  • message insertion into state now happens before media prefetch in P2P chat,
  • media prefetch is intentionally fire-and-forget (unawaited) to avoid blocking UI rendering,
  • service reuse via notifier-level singletons reduces per-message object churn without changing behavior.

I did not find functional regressions in the changed scope.

Note: local Flutter validation is currently blocked by an existing dependency resolution issue in this branch (riverpod_generator vs flutter_test/test/matcher), which is pre-existing and unrelated to this diff.

@grunch grunch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@grunch grunch merged commit 4a0f2bf into main Mar 13, 2026
2 checks passed
@grunch grunch deleted the p2p-chat-rendering-block branch May 22, 2026 14:30
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.

P2P chat messages with images block rendering until download completes

3 participants