Skip to content

Commit 88d8be6

Browse files
committed
chore(chats): badge chat tab with unread count
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent ad0ca5b commit 88d8be6

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ class ChatHistoryController @Inject constructor(
123123
.map { it.filter { c -> !c.isMuted && c.isSubscribed } }
124124
.map { it.sumOf { c -> c.unreadCount } }
125125

126+
val chatUnreadCount = chats
127+
.filterNotNull()
128+
// Ignore muted chats and unsubscribed chats
129+
.map { it.filter { c -> !c.isMuted && c.isSubscribed } }
130+
.map { it.sumOf { c -> c.unreadCount } }
131+
126132
private fun owner(): KeyPair? = SessionManager.getKeyPair()
127133

128134
suspend fun fetchChats(update: Boolean = false) {

app/src/main/java/com/getcode/SessionController.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ data class SessionState(
157157
val isRemoteSendLoading: Boolean = false,
158158
val splatTipCard: Boolean = false,
159159
val notificationUnreadCount: Int = 0,
160+
val chatUnreadCount: Int = 0,
160161
val buyModule: Feature = BuyModuleFeature(),
161162
val requestKin: Feature = RequestKinFeature(),
162163
val cameraGestures: Feature = CameraGesturesFeature(),
@@ -401,6 +402,13 @@ class SessionController @Inject constructor(
401402
state.update { it.copy(notificationUnreadCount = count) }
402403
}.launchIn(scope)
403404

405+
historyController.chatUnreadCount
406+
.distinctUntilChanged()
407+
.map { it }
408+
.onEach { count ->
409+
state.update { it.copy(chatUnreadCount = count) }
410+
}.launchIn(scope)
411+
404412
prefRepository.observeOrDefault(PrefsBool.LOG_SCAN_TIMES, false)
405413
.flowOn(Dispatchers.IO)
406414
.onEach { log ->

app/src/main/java/com/getcode/view/main/scanner/components/BottomBar.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ internal fun HomeBottom(
9797
modifier = Modifier.weight(1f),
9898
label = stringResource(R.string.action_chat),
9999
painter = painterResource(R.drawable.ic_chat),
100-
badgeCount = 0,
100+
badgeCount = state.chatUnreadCount,
101101
onClick = { onPress(action) },
102102
)
103103
}

0 commit comments

Comments
 (0)