fix(regression/cs2): issue in which ui callbacks fire multiply
Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
parent
7fca8e503c
commit
d119f7b47f
|
|
@ -170,7 +170,7 @@ fun ChannelScreen(
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
viewModel.startListening()
|
viewModel.startListening(createUiCallbackListener = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load/switch channel
|
// Load/switch channel
|
||||||
|
|
|
||||||
|
|
@ -444,7 +444,7 @@ class ChannelScreenViewModel @Inject constructor(
|
||||||
ackChannel(channel?.id ?: return, messageId)
|
ackChannel(channel?.id ?: return, messageId)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun startListening() {
|
suspend fun startListening(createUiCallbackListener: Boolean = true) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
withContext(RevoltAPI.realtimeContext) {
|
withContext(RevoltAPI.realtimeContext) {
|
||||||
flow {
|
flow {
|
||||||
|
|
@ -633,7 +633,7 @@ class ChannelScreenViewModel @Inject constructor(
|
||||||
is RealtimeSocketFrames.Reconnected -> {
|
is RealtimeSocketFrames.Reconnected -> {
|
||||||
Log.d("ChannelScreen", "Reconnected to WS.")
|
Log.d("ChannelScreen", "Reconnected to WS.")
|
||||||
loadMessages(50, ignoreExisting = true)
|
loadMessages(50, ignoreExisting = true)
|
||||||
startListening()
|
startListening(createUiCallbackListener = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.catch {
|
}.catch {
|
||||||
|
|
@ -641,6 +641,8 @@ class ChannelScreenViewModel @Inject constructor(
|
||||||
}.launchIn(this)
|
}.launchIn(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (createUiCallbackListener) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
UiCallbacks.uiCallbackFlow.onEach {
|
UiCallbacks.uiCallbackFlow.onEach {
|
||||||
|
|
@ -654,7 +656,10 @@ class ChannelScreenViewModel @Inject constructor(
|
||||||
|
|
||||||
val shouldMention = kvStorage.getBoolean("mentionOnReply") ?: false
|
val shouldMention = kvStorage.getBoolean("mentionOnReply") ?: false
|
||||||
draftReplyTo.add(
|
draftReplyTo.add(
|
||||||
SendMessageReply(message.message.id ?: return@onEach, shouldMention)
|
SendMessageReply(
|
||||||
|
message.message.id ?: return@onEach,
|
||||||
|
shouldMention
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -675,6 +680,7 @@ class ChannelScreenViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun updateItems(newItems: List<ChannelScreenItem>) {
|
private suspend fun updateItems(newItems: List<ChannelScreenItem>) {
|
||||||
// Spec https://wiki.rvlt.gg/index.php/Text_Channel_(UI)#Message_Grouping_Algorithm
|
// Spec https://wiki.rvlt.gg/index.php/Text_Channel_(UI)#Message_Grouping_Algorithm
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue