Repository navigation
feat(chat): send failed photos again once back online - #375
Conversation
0248044 to
175d86d
Compare
7826552 to
80a8a02
Compare
175d86d to
8a0de89
Compare
80a8a02 to
fcfbf15
Compare
8a0de89 to
c7ea7da
Compare
fcfbf15 to
8dc8b89
Compare
c7ea7da to
ce99050
Compare
8dc8b89 to
4da5dda
Compare
ce99050 to
84dbbb6
Compare
4da5dda to
80b94fa
Compare
84dbbb6 to
8528b37
Compare
80b94fa to
d7826a4
Compare
8528b37 to
2311956
Compare
e42c83b to
baf3af7
Compare
baf3af7 to
cfe3238
Compare
Julkzein
left a comment
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
I see, thanks for checking, the KDoc makes it clear now.
cfe3238 to
16dbb7f
Compare
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>
16dbb7f to
e8bdbf4
Compare
|
Julkzein
left a comment
There was a problem hiding this comment.
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.



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
ConversationViewModeltakes the app'sConnectivityRepository(feat(connectivity): know whether the device is online in the listing form #388), the same instance the listing forms use, and watchesisOnline.ConversationViewModel: each time the device goes from offline to online, every photo that failed with a network error is sent again with its same message id. Other failures, like a refusal, would fail again, so they wait for the user's Retry.sendPhotofrom feat(chat): send and load photo messages #352, so if the first try timed out with its message still queued on the phone, the resend waits for that message instead of writing it twice, then uploads the photo and marks it uploaded.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 checkpass locally after rebasing ontomain: 1739 unit tests, 0 failures.ConversationViewModeltests: 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.