Skip to content

P2P chat messages with images block rendering until download completes #517

Description

@Catrya

Description

In ChatRoomNotifier._onChatEvent() (line 156), _processMessageContent(chat) is called with await before the message is added to state (lines 159-164). This means that when a P2P chat message contains an encrypted image, the message doesn't appear in the UI until the image is fully downloaded and decrypted.

This same bug was identified and fixed in the dispute chat notifier during the #514 review , where await was replaced with unawaited() so the message appears immediately and the image loads in the background.

Expected behavior

Message appears in chat immediately with a loading spinner while the image downloads.

Current behavior

Message is invisible until the image download + decryption completes. On slow connections this can take several seconds, making it look like no message wasreceived.

Suggested fix

In lib/features/chat/notifiers/chat_room_notifier.dart, move _processMessageContent(chat) to after the message is added to state, and change await to unawaited():

// Current (blocking):                                    
final chat = await event.p2pUnwrap(session.sharedKey!);
await _processMessageContent(chat);  // blocks here
// ... then adds to state                                                                                           

// Fixed (fire-and-forget):                                                                                         
final chat = await event.p2pUnwrap(session.sharedKey!);   
// ... add to state first
unawaited(_processMessageContent(chat));  // downloads in background

Additional cleanup (same PR)

Both ChatRoomNotifier and DisputeChatNotifier create new EncryptedImageUploadService() and
EncryptedFileUploadService() instances on every method call in _processEncryptedImageMessage /
_processEncryptedFileMessage. These services are stateless and should be extracted to class-level or static fields
for consistency with ChatFileUploadHelper which already uses this pattern.

Context

  • Dispute chat already uses the correct pattern (unawaited) — see dispute_chat_notifier.dart:220
  • The _processMessageContent method itself could also be extracted to a shared utility to reduce duplication between
    P2P and dispute notifiers, but each calls different shared key methods internally (getSharedKey() vs
    getAdminSharedKey()), so extraction is optional

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions