Skip to content

feat(chat): send photos from the conversation screen - #373

Merged
Mamel0uk merged 21 commits into
mainfrom
feature/photo-send
Nov 18, 2026
Merged

Mamel0uk merged 21 commits into
mainfrom
feature/photo-send

Conversation

@Mamel0uk

@Mamel0uk Mamel0uk commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part of #281. You can now attach a photo in a conversation (camera or gallery), add a caption and send it, with an uploading state and Retry when it fails.

It's the first of 3 PRs for #281: #374 shows the photos in the thread, and #375 sends failed photos again once back online.

What

  • A camera button left of the message field opens Take photo / Choose from gallery. It reuses PhotoCamera (and its permission dialog) and the photo picker from the listing form.
  • The photo shows as a thumbnail with ✕ above the field. The draft becomes its caption ("Add a caption…") and Send sends both. One photo at a time, and only once the conversation exists.
  • While it uploads, the photo shows as my own bubble, faded with a spinner and "Sending…". If it fails, the bubble says why (offline, refused, …) with Retry and Remove. Retry reuses the same message id, since the rules refuse an overwrite. With feat(chat): send and load photo messages #352's pending stage, a send that failed midway can leave its message on the server with photoPending: true, so the other person sees a photo still uploading until Retry finishes it. Remove deletes that message too (new rule: only its sender can delete a message whose photo is still pending), so it doesn't stay pending for the other person. Leaving the screen with a failed photo does the same, since nothing can retry it after that. The retry itself (waiting for a message still queued on the phone, uploading only if needed, marking the photo uploaded) is all in sendPhoto, so nothing here had to change.
  • An upload keeps running if you leave the conversation, so its message doesn't stay pending for the other person. If it fails after you left, its message is deleted like with Remove. If Android kills the app meanwhile, that's for the background outbox (Send chat photos in the background when back online #372).
  • Camera photos live in their own chat folder and are deleted once sent, removed or cancelled, or when you leave the screen (an upload under way deletes its photo when it ends). Gallery photos are never deleted. The photo being taken is kept in the SavedStateHandle, so it's still attached if Android kills the app while the camera is open.
  • Figma: attach menu, attached photo, sending.
stateDiagram-v2
    [*] --> Attached: camera / gallery
    Attached --> [*]: ✕
    Attached --> Uploading: Send
    Uploading --> Sent
    Uploading --> Failed: offline / refused
    Failed --> Uploading: Retry (same id)
    Failed --> [*]: Remove (deletes its message)
    Sent --> [*]
Loading

On its own, a sent photo shows as a bubble with only its caption and time: the photo itself is shown by #374, so the two should be merged together.

Why

#36: show details of an item in the chat by sending a photo.

Update (Nov 18): rebased onto #352 after its review fixes (the photoPending stage and the retry fixes), and onto the latest main with it. Main's #351 now observes the listing instead of reloading it, so a failed photo send no longer reloads the listing: a pause or deletion reaches the screen through that observation (b9ba7e9). The two tests that checked the reload were adjusted.

Update (Nov 18, later): #352 is merged, so this is rebased onto main without its commits. No code change. ./gradlew ktfmtCheck check passes on the whole stack: 1560 unit tests, 0 failures.

Update (Nov 18, after review): fixed the review points in 5 commits:

  • a photo can't be sent while a text is still being sent (it would send the text again as its caption);
  • a photo picked or taken while the conversation is still loading is kept, with Send enabled once it's loaded;
  • the photo being taken survives Android killing the app (SavedStateHandle, like the listing form);
  • leaving the screen no longer cancels an upload, and the camera photos are cleaned up;
  • Remove deletes the message on the server. firestore.rules changed, so it has to be published.

Update (Nov 18, 2nd review): leaving the screen with a failed photo, or an upload failing after you left, now deletes its message too, like Remove (71c6e19). Before, it stayed pending for the other person forever.

Known limits of Remove:

  • The other person's inbox keeps the "Photo" preview and the unread dot until the next message, since the rules only let the preview change with a new message.
  • If the photo was uploaded but marking it uploaded failed, Remove deletes the message but the file stays in Storage. Only the two participants can read it, and it's the photo being sent anyway. Deleting it would mean opening deletes in storage.rules, before the message, and a Storage delete isn't queued offline.

#374 and #375 are rebased on top.

Validation

  • ./gradlew ktfmtCheck check pass locally: 1549 unit tests, 0 failures. Rules tests (rules-tests, emulators): 212 pass, with 6 new ones for deleting a pending photo message.
  • 69 new tests: ViewModel (attach, camera cancel, send, failure, retry, remove, file cleanup, loading, process death, leaving during an upload or with a failed photo), repository (delete) and Robolectric (button and menu, attached photo, uploading and failed bubbles).
Capture d’écran 2026-11-18 à 04 24 55 Capture d’écran 2026-11-18 à 04 25 53 Capture d’écran 2026-11-18 à 04 32 05 Capture d’écran 2026-11-18 à 04 32 35

AI use

Claude Code (Claude Opus 5.5) did the Figma frames, the implementation and the tests step by step, with each commit approved by me. It also reviewed the branch and split it into these 3 PRs. I checked every diff.

@Mamel0uk

Copy link
Copy Markdown
Contributor Author

I split #281 into three PRs because one PR was too big to review well: about 2,400 lines, roughly 1,000 of app code and 1,300 of tests. It also mixed several separate things. Nobody can review that properly in one go, and a big PR is more likely to get a quick "LGTM" than a real review.

It also ended up much bigger than planned. The scope got redefined a few times along the way, because things behaved in ways we didn't expect. The biggest one: after the fix in #352, a photo's message is written before the photo is uploaded. So the other person could see a message whose photo wasn't there yet, and the sender saw their photo twice while it uploaded. Handling that cleanly took extra work: removing the old write callback, waiting a bit for a photo that's still uploading, and a fix so a photo only shows once. On top of that, testing offline showed that people would have to tap Retry themselves once back online, so I added an automatic resend. Each change made sense on its own, but together they made the PR a lot bigger than the issue suggested.

So I cut it by behaviour, so each PR can be read and checked on its own:

Each PR builds and passes check on its own, and each one comes with its own tests. They're stacked on #352, so the review order is #352 → #373 → #374 → #375. I'll rebase them onto main as each one merges.

@Mamel0uk
Mamel0uk force-pushed the feature/photo-send branch 2 times, most recently from 7f6740f to ed2f50e Compare November 18, 2026 14:00
@Mamel0uk
Mamel0uk force-pushed the feature/photo-messages branch from 144e8a8 to f9b1749 Compare November 18, 2026 15:16
Base automatically changed from feature/photo-messages to main November 18, 2026 16:25
Mamel0uk and others added 15 commits November 18, 2026 17:26
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sendPhoto now waits for the server and throws every failure, so the
ViewModel no longer needs a callback for a late rejection: a photo
leaves the pending list once sendPhoto returns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Its message is written before the photo is uploaded, so it showed next to
the pending bubble. Messages with a pending photo are now left out until
the photo is sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Mamel0uk
Mamel0uk marked this pull request as ready for review November 18, 2026 16:30
@peng-0110
peng-0110 self-requested a review November 18, 2026 17:05

@peng-0110 peng-0110 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.

Good work, found a couple isues below that needs to be addressed. Otherwise looks good.

Blocking

  1. Sent photos can't be seen (ConversationScreen.kt:620). Message bubbles only show message.text. Nothing draws imagePath or photoPending. Once an upload succeeds, a photo without a caption becomes an empty bubble with just a timestamp, on both sides. If showing photos is planned for a later PR, this one still adds a send button whose result nobody can see. Either add display here, or hold the button back until it exists.

Bugs
2. Camera photos leak (ConversationViewModel.kt:376). If any upload is still running when the user leaves the screen, onCleared returns early. Attached and failed camera photos then stay in files/listing_photos/chat forever. Unlike the listing forms, chat never calls deleteAllExcept to sweep old files.
3. A camera photo is lost if Android kills the app (:164). photoBeingTaken isn't kept in a SavedStateHandle the way ListingFormViewModel keeps it. If the app is killed while the camera is open, the photo is silently dropped and its file leaks. The code comment saying it survives recreation is only true for rotation and similar changes.
4. A picked photo is dropped right after the app restarts (:193). Until the conversation reloads, canAttachPhoto is false, so a gallery or camera result arriving in that window is ignored.
5. The same text can be sent twice (:245). The sendInFlight check now runs after the photo branch. If the user sends text, then attaches a photo and taps Send before the first send finishes, the text goes out again as the photo's caption.
6. "Remove" doesn't remove a message already on the server (:356). If the message was saved but the upload failed, tapping Remove only clears the phone's own state. The pending message stays on the server for good, and both people see it.
7. Leaving the screen strands an upload (:372). Pressing Back during an upload cancels it after the message is saved. The other person sees a photo that never arrives, and there's no Retry when the conversation is reopened. This is the in-app version of the problem left open in #352.

Mamel0uk and others added 3 commits November 18, 2026 18:29
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mamel0uk and others added 2 commits November 18, 2026 18:36
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Mamel0uk

Copy link
Copy Markdown
Contributor Author

Thanks for the review! 1: the photos are displayed in #374, which is stacked on this one. I split #281 to keep it reviewable, so I'd merge them together. 2 to 7 are fixed in the new commits. Uploads now keep running when you leave the screen (that also fixes the leaking files), the photo being taken is kept in the SavedStateHandle, a photo coming back while the screen is still loading is kept, you can't send a photo while a text is still being sent, and Remove now deletes the message on the server (new rule: only the sender can delete a message whose photo is still pending). The inbox preview keeps showing "Photo" until the next message. If Android kills the app during an upload, that's still for #372.

@Mamel0uk
Mamel0uk requested a review from peng-0110 November 18, 2026 17:50

@peng-0110 peng-0110 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.

Thank you for making the fixes, here are some follow up issues.

Must fix

Leaving the screen with a failed photo leaves its message stuck as pending, and nothing can fix it afterwards.

  • Where: ConversationViewModel.onCleared() and the catch block in upload() (the if (cleared) branch).
  • What's wrong: both of these only delete the local camera file. Neither calls chatRepository.deletePhotoMessage.
  • How it fails:
    a. You send a photo on a bad connection. The message is written with photoPending: true, then the upload or the "photo uploaded" step times out. The bubble shows "Not sent" with Retry and Remove.
    b. You press back instead of Remove.
    c. The camera file is deleted, so Retry is impossible. The pending bubble state is gone too.
    d. When you reopen the conversation, the message shows as a plain empty bubble with no Retry or Remove.
    e. The other person sees a photo that is still uploading, forever.
  • The same happens when an upload that is still running after you leave ends in failure.
  • Proof: I added two probe tests in a throwaway worktree. One closes the ViewModel after a failed send. The other lets an upload fail after closing. Both print deletedMessages=[], and in both the file is deleted.
  • Why it's must-fix: the PR's whole argument for Remove and for photoUploadScope is "so it doesn't stay pending for the other person". Pressing back is the most common way out, and it breaks that promise. #372 can't rescue it either, because the file is already gone. #375 only retries while the screen is open.

Should fix (raise in review, not blocking)

  • Remove can't take back a photo that was already uploaded. If the upload succeeded but marking it uploaded failed, Remove deletes the message but the Storage file stays. storage.rules refuse deletes, and any participant can still get it at a predictable path. Either document this or make Remove's wording not promise a full takeback.
  • The other person still sees the removed message in their inbox. The unread dot and the "photo" preview stay until they open the conversation. The PR already mentions the preview, so this is a known limitation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Mamel0uk

Copy link
Copy Markdown
Contributor Author

Thanks, good catch! Fixed: leaving the screen now does what Remove does for a failed photo, so its message is deleted and doesn't stay pending. That covers both a photo that already failed and an upload that fails after you've left. For the Storage file: it's only readable by the two participants and it's the photo they were sending anyway, so I documented it instead of opening deletes in storage.rules. The inbox preview/unread dot is the known limitation from before, since the rules only let the preview change with a new message.

@Mamel0uk
Mamel0uk requested a review from peng-0110 November 18, 2026 18:32
@sonarqubecloud

Copy link
Copy Markdown

@peng-0110 peng-0110 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.

LGTM, Good Work!

@Mamel0uk
Mamel0uk merged commit f41be5f into main Nov 18, 2026
4 checks passed
@Mamel0uk
Mamel0uk deleted the feature/photo-send branch November 18, 2026 19:28
@Mamel0uk Mamel0uk self-assigned this Nov 19, 2026
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.

2 participants