Skip to content

feat(chat): send failed photos again once back online - #375

Merged
Mamel0uk merged 5 commits into
mainfrom
feature/photo-resend-online
Nov 19, 2026
Merged

Mamel0uk merged 5 commits into
mainfrom
feature/photo-resend-online

Conversation

@Mamel0uk

@Mamel0uk Mamel0uk commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #281. Closes #36. A photo that failed because the device was offline is sent again by itself when the connection comes back, as long as the conversation is open.

Last of 3 PRs for #281. #373 and #374 are merged; this one is now on main.

What

Why

After a "Not sent" bubble caused by a bad connection, users shouldn't have to notice that they're back online and tap Retry themselves.

Validation

  • ./gradlew ktfmtCheck assemble lint check pass locally after rebasing onto main: 1739 unit tests, 0 failures.
  • 5 ConversationViewModel tests: a network failure is sent again with the same id, a refusal is left alone, nothing happens while still offline, a second reconnection retries again, and a photo still sending is left alone.

AI use

Claude Code (Claude Opus 5.5) wrote the code and tests with me approving each commit, and split the original branch into these PRs. I checked every diff.

@Mamel0uk
Mamel0uk force-pushed the feature/photo-receive branch from 0248044 to 175d86d Compare November 18, 2026 13:01
@Mamel0uk
Mamel0uk force-pushed the feature/photo-resend-online branch from 7826552 to 80a8a02 Compare November 18, 2026 13:01
@Mamel0uk
Mamel0uk force-pushed the feature/photo-receive branch from 175d86d to 8a0de89 Compare November 18, 2026 14:00
@Mamel0uk
Mamel0uk force-pushed the feature/photo-resend-online branch from 80a8a02 to fcfbf15 Compare November 18, 2026 14:00
@Mamel0uk
Mamel0uk force-pushed the feature/photo-receive branch from 8a0de89 to c7ea7da Compare November 18, 2026 16:11
@Mamel0uk
Mamel0uk force-pushed the feature/photo-resend-online branch from fcfbf15 to 8dc8b89 Compare November 18, 2026 16:11
@Mamel0uk
Mamel0uk force-pushed the feature/photo-receive branch from c7ea7da to ce99050 Compare November 18, 2026 16:29
@Mamel0uk
Mamel0uk force-pushed the feature/photo-resend-online branch from 8dc8b89 to 4da5dda Compare November 18, 2026 16:29
@Mamel0uk
Mamel0uk force-pushed the feature/photo-receive branch from ce99050 to 84dbbb6 Compare November 18, 2026 17:49
@Mamel0uk
Mamel0uk force-pushed the feature/photo-resend-online branch from 4da5dda to 80b94fa Compare November 18, 2026 17:49
@Mamel0uk
Mamel0uk force-pushed the feature/photo-receive branch from 84dbbb6 to 8528b37 Compare November 18, 2026 18:31
@Mamel0uk
Mamel0uk force-pushed the feature/photo-resend-online branch from 80b94fa to d7826a4 Compare November 18, 2026 18:31
@Mamel0uk
Mamel0uk force-pushed the feature/photo-receive branch from 8528b37 to 2311956 Compare November 18, 2026 19:30
@Mamel0uk
Mamel0uk force-pushed the feature/photo-resend-online branch 3 times, most recently from e42c83b to baf3af7 Compare November 18, 2026 21:08
Base automatically changed from feature/photo-receive to main November 18, 2026 21:17
@Mamel0uk
Mamel0uk force-pushed the feature/photo-resend-online branch from baf3af7 to cfe3238 Compare November 18, 2026 21:19
@Mamel0uk
Mamel0uk marked this pull request as ready for review November 18, 2026 21:21
@Mamel0uk Mamel0uk self-assigned this Nov 19, 2026

@Julkzein Julkzein 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.

Nice, focused last step for #281: only network failures are resent, a refusal waits for the user, a photo still sending is left alone, and reusing sendPhoto from #352 means a resend after a timeout waits for the queued message instead of writing it twice. The tests cover the right cases, including a second reconnection.

Two things before approving. The branch is 10 commits behind main and merging it conflicts in AppNavHost.kt, where main now passes connectivityRepository and locationRepository (#388, #369), so I couldn't run the checks merged with main. And main already has a connectivity abstraction, which I think this PR should reuse (inline).

import kotlinx.coroutines.flow.distinctUntilChanged

/** Tells whether the device can reach the internet, so work that needs it can wait for it. */
fun interface ConnectivityObserver {

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.

Important: Main already has ConnectivityRepository (connectivity/model, from #388) with an isOnline: StateFlow<Boolean>, one instance for the whole app, which AppNavHost already receives as connectivityRepository. This adds a second definition of "online" and a second network callback per conversation. It also misses a case #388 handles: during a Wi-Fi/mobile handoff Android can report the old network lost after the new one became the default, and onLost here (l.37) then sends false while the device is online. Could ConversationViewModel take the ConnectivityRepository and collect isOnline instead, and drop ConnectivityObserver and its fake? There's already a FakeConnectivityRepository in sharedTest.

@Mamel0uk Mamel0uk Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 110475c: ConversationViewModel now takes the ConnectivityRepository from #388 and collects isOnline, and AppNavHost passes in the one it already gets. ConnectivityObserver, its fake and its test are gone, and the tests use FakeConnectivityRepository. I also dropped distinctUntilChanged and catch since a StateFlow already does both. Also rebased onto main, so the AppNavHost conflict is gone.

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.

Perfect, much simpler now: one connectivity source for the app, and the handoff case comes for free from #388. Good call dropping distinctUntilChanged and catch too, a StateFlow already does both. lgtm

connectivity
.observeOnline()
.distinctUntilChanged()
.filter { online -> online }

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.

Nitpick: The KDoc says "each time the device comes back online", but the flow's first value also passes this filter, so opening the screen while online resends the photos that failed with a network error right away. That seems useful (for example photos restored after the app was killed), but could the comment say so, so it doesn't look accidental?

@Mamel0uk Mamel0uk Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Pending photos aren't restored after the app is killed, they're only in the ViewModel and start empty, so that first value never resends anything. I put that in the KDoc (e8bdbf4).

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.

I see, thanks for checking, the KDoc makes it clear now.

@Mamel0uk
Mamel0uk force-pushed the feature/photo-resend-online branch from cfe3238 to 16dbb7f Compare November 19, 2026 17:54
@Mamel0uk
Mamel0uk requested a review from Julkzein November 19, 2026 17:54
Mamel0uk and others added 5 commits November 19, 2026 19:01
While the conversation is open, a photo that failed for want of a
connection is sent again with the same message ID as soon as the device
is online. Other failures still wait for Retry. The ViewModel gets the
connection through a new ConnectivityObserver interface.

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>
@Mamel0uk
Mamel0uk force-pushed the feature/photo-resend-online branch from 16dbb7f to e8bdbf4 Compare November 19, 2026 18:04
@sonarqubecloud

Copy link
Copy Markdown

@Julkzein Julkzein 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.

After the back and forth this looks good to me: the resend now follows the app's single ConnectivityRepository from #388, so the Wi-Fi/mobile handoff is handled, and the branch is up to date with main. The diff is down to +108/−1. lgtm.

@Mamel0uk
Mamel0uk merged commit bce8899 into main Nov 19, 2026
3 checks passed
@Mamel0uk
Mamel0uk deleted the feature/photo-resend-online branch November 19, 2026 18:20
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.

Send photos from the conversation screen As a user, I want to send photos in a conversation, so that I can show details.

2 participants