Skip to content

Commit b5ceffc

Browse files
committed
Drop cache registrations on pause
1 parent 17e371d commit b5ceffc

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

.idea/deploymentTargetSelector.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composeApp/src/commonMain/kotlin/com/hypergonial/chat/model/Cache.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,13 @@ class Cache(private val cachedChannelsCount: Int = 10) : SynchronizedObject() {
9898
_members.clear()
9999
_typingIndicators.clear()
100100
_readStates.clear()
101-
_msgcaches.forEach { it.reset() }
101+
_msgcaches.clear()
102102
_ownUser = null
103103
}
104104
}
105105

106106
fun clearMessageCache() {
107-
// It's important to not delete the cache objects as that will
108-
// invalidate registrations and potentially break app logic
109-
// Caches will be pushed out as new ones come in anyway
110-
synchronized(this) { _msgcaches.forEach { it.reset() } }
107+
synchronized(this) { _msgcaches.clear() }
111108
}
112109

113110
/**

composeApp/src/commonMain/kotlin/com/hypergonial/chat/view/components/ChannelComponent.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ class DefaultChannelComponent(
236236
init {
237237
client.cache.registerMessageCacheFor(channelId)
238238
client.eventManager.apply {
239+
subscribeWithLifeCycle(ctx.lifecycle, ::onResume)
239240
subscribeWithLifeCycle(ctx.lifecycle, ::onTypingStart)
240241
subscribeWithLifeCycle(ctx.lifecycle, ::onTypingEnd)
241242
subscribeWithLifeCycle(ctx.lifecycle, ::onMessageCreate)
@@ -250,6 +251,10 @@ class DefaultChannelComponent(
250251
onReadMessages(channelId)
251252
}
252253

254+
private fun onResume(event: LifecycleResumedEvent) {
255+
client.cache.registerMessageCacheFor(channelId)
256+
}
257+
253258
override fun onLogoutClicked() = onLogout()
254259

255260
/** The number of messages currently visible in the UI. This is used to determine when to page out messages. */

0 commit comments

Comments
 (0)