Skip to content

Commit 1b57bdc

Browse files
committed
fix: trigger chat fetches after cash link sends and refresh controller when fetching chats
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 69cda83 commit 1b57bdc

2 files changed

Lines changed: 28 additions & 32 deletions

File tree

api/src/main/java/com/getcode/network/HistoryController.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class HistoryController @Inject constructor(
7676
private fun owner(): KeyPair? = SessionManager.getKeyPair()
7777

7878
suspend fun fetchChats() {
79+
pagerMap.clear()
80+
chatFlows.clear()
81+
7982
val containers = fetchChatsWithoutMessages()
8083
Timber.d("chats fetched = ${containers.count()}")
8184
_chats.value = containers
@@ -93,8 +96,6 @@ class HistoryController @Inject constructor(
9396
}
9497

9598
_chats.value = updatedWithMessages.sortedByDescending { it.lastMessageMillis }
96-
97-
pagerMap.clear()
9899
}
99100

100101
suspend fun advanceReadPointer(chatId: ID) {

app/src/main/java/com/getcode/view/main/home/HomeViewModel.kt

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,8 @@ class HomeViewModel @Inject constructor(
343343
)
344344
}
345345
.subscribe({
346-
viewModelScope.launch {
347-
cancelSend(PresentationStyle.Pop)
348-
vibrator.vibrate()
349-
historyController.fetchChats()
350-
}
346+
cancelSend(PresentationStyle.Pop)
347+
vibrator.vibrate()
351348
}, {
352349
ErrorUtils.handleError(it)
353350
cancelSend(style = PresentationStyle.Slide)
@@ -426,43 +423,41 @@ class HomeViewModel @Inject constructor(
426423
sendTransactionDisposable?.dispose()
427424
BottomBarManager.clearByType(BottomBarManager.BottomBarMessageType.REMOTE_SEND)
428425

429-
val shown = showToastIfNeeded(style)
430426

431-
uiFlow.update {
432-
it.copy(
433-
presentationStyle = style,
434-
billState = it.billState.copy(
435-
bill = null,
427+
viewModelScope.launch {
428+
historyController.fetchChats()
429+
430+
val shown = showToastIfNeeded(style)
431+
432+
uiFlow.update {
433+
it.copy(
434+
presentationStyle = style,
435+
billState = it.billState.copy(
436+
bill = null,
437+
)
436438
)
437-
)
438-
}
439+
}
439440

440-
viewModelScope.launch {
441441
if (shown) {
442442
delay(300)
443443
}
444-
withContext(Dispatchers.Main) {
445-
uiFlow.update {
446-
it.copy(
447-
billState = it.billState.copy(
448-
valuation = null,
449-
hideBillButtons = false
450-
)
444+
445+
uiFlow.update {
446+
it.copy(
447+
billState = it.billState.copy(
448+
valuation = null,
449+
hideBillButtons = false
451450
)
452-
}
451+
)
453452
}
454-
}
455453

456-
viewModelScope.launch {
457454
if (shown) {
458455
delay(5.seconds.inWholeMilliseconds)
459456
}
460-
withContext(Dispatchers.Main) {
461-
uiFlow.update {
462-
it.copy(
463-
billState = it.billState.copy(showToast = false)
464-
)
465-
}
457+
uiFlow.update {
458+
it.copy(
459+
billState = it.billState.copy(showToast = false)
460+
)
466461
}
467462
}
468463
}

0 commit comments

Comments
 (0)