refactor: trim message history orchestration

This commit is contained in:
Codex
2026-05-18 20:46:18 +03:00
parent c18a7963bf
commit 514b8859c7
5 changed files with 40 additions and 22 deletions
@@ -139,15 +139,7 @@ class MessagesHistoryViewModelImpl(
loaders.loadConvo()
loaders.loadMessagesHistory(currentOffset.value)
updatesReducer.newMessages.onEach(longPollEventHandler::onNewMessage).launchIn(viewModelScope)
updatesReducer.messageEdited.onEach(longPollEventHandler::onMessageEdited).launchIn(viewModelScope)
updatesReducer.messageIncomingRead.onEach(longPollEventHandler::onReadIncoming).launchIn(viewModelScope)
updatesReducer.messageOutgoingRead.onEach(longPollEventHandler::onReadOutgoing).launchIn(viewModelScope)
updatesReducer.messageDeleted.onEach(longPollEventHandler::onMessageDeleted).launchIn(viewModelScope)
updatesReducer.messageRestored.onEach(longPollEventHandler::onMessageRestored).launchIn(viewModelScope)
updatesReducer.messageMarkedAsImportant.onEach(longPollEventHandler::onMessageMarkedAsImportant).launchIn(viewModelScope)
updatesReducer.messageMarkedAsSpam.onEach(longPollEventHandler::onMessageMarkedAsSpam).launchIn(viewModelScope)
updatesReducer.messageMarkedAsNotSpam.onEach(longPollEventHandler::onMessageMarkedAsNotSpam).launchIn(viewModelScope)
observeLongPollUpdates()
}
override fun onNavigationConsumed() {
@@ -239,6 +231,18 @@ class MessagesHistoryViewModelImpl(
override fun onKeyboardShown() =
messageActions.onKeyboardShown()
private fun observeLongPollUpdates() {
updatesReducer.newMessages.onEach(longPollEventHandler::onNewMessage).launchIn(viewModelScope)
updatesReducer.messageEdited.onEach(longPollEventHandler::onMessageEdited).launchIn(viewModelScope)
updatesReducer.messageIncomingRead.onEach(longPollEventHandler::onReadIncoming).launchIn(viewModelScope)
updatesReducer.messageOutgoingRead.onEach(longPollEventHandler::onReadOutgoing).launchIn(viewModelScope)
updatesReducer.messageDeleted.onEach(longPollEventHandler::onMessageDeleted).launchIn(viewModelScope)
updatesReducer.messageRestored.onEach(longPollEventHandler::onMessageRestored).launchIn(viewModelScope)
updatesReducer.messageMarkedAsImportant.onEach(longPollEventHandler::onMessageMarkedAsImportant).launchIn(viewModelScope)
updatesReducer.messageMarkedAsSpam.onEach(longPollEventHandler::onMessageMarkedAsSpam).launchIn(viewModelScope)
updatesReducer.messageMarkedAsNotSpam.onEach(longPollEventHandler::onMessageMarkedAsNotSpam).launchIn(viewModelScope)
}
override suspend fun loadMessageReadPeers(peerId: Long, cmId: Long): Int =
readPeersLoader.loadMessageReadPeers(peerId = peerId, cmId = cmId)
@@ -182,7 +182,7 @@ fun MessagesList(
item = item,
onClick = {
if (item.actionCmId != null) {
onRequestScrollToCmId(item.actionCmId!!)
onRequestScrollToCmId(item.actionCmId)
}
}
)
@@ -301,7 +301,7 @@ fun MessagesList(
},
onReplyClick = {
if (item.replyCmId != null) {
onRequestScrollToCmId(item.replyCmId!!)
onRequestScrollToCmId(item.replyCmId)
}
},
offsetX = offsetAnimatable.value
@@ -328,7 +328,7 @@ fun MessagesList(
},
onReplyClick = {
if (item.replyCmId != null) {
onRequestScrollToCmId(item.replyCmId!!)
onRequestScrollToCmId(item.replyCmId)
}
},
offsetX = offsetAnimatable.value
@@ -214,10 +214,10 @@ fun Attachments(
}
}
fun VkAttachment.asUiPhoto(): UiPreview {
fun VkAttachment.asUiPhoto(): UiPreview? {
return when (this) {
is VkPhotoDomain -> {
val size = this.getDefault()!!
val size = this.getDefault() ?: return null
UiPreview(
id = this.id,
url = size.url,
@@ -247,7 +247,7 @@ fun VkAttachment.asUiPhoto(): UiPreview {
is VkFileDomain -> {
when {
this.preview?.video != null -> {
val video = this.preview?.video!!
val video = this.preview?.video ?: return null
UiPreview(
id = id,
@@ -259,7 +259,7 @@ fun VkAttachment.asUiPhoto(): UiPreview {
}
this.preview?.photo != null -> {
val photoSize = this.preview?.photo?.sizes?.first()!!
val photoSize = this.preview?.photo?.sizes?.firstOrNull() ?: return null
UiPreview(
id = id,
@@ -270,11 +270,11 @@ fun VkAttachment.asUiPhoto(): UiPreview {
)
}
else -> error("Unsupported type: $this")
else -> null
}
}
else -> error("Unsupported type: $this")
else -> null
}
}
@@ -108,8 +108,9 @@ fun Link(
Column(modifier = Modifier.weight(1f)) {
if (item.title != null) {
val title = item.title
Text(
text = item.title!!,
text = title,
style = MaterialTheme.typography.bodyLarge,
maxLines = 1,
overflow = TextOverflow.Ellipsis
@@ -69,9 +69,22 @@ class ProfileViewModelImpl(
nomCase = null
).listenValue(viewModelScope) { state ->
state.processState(
error = { error ->
// TODO: 12/07/2024, Danil Nikolaev: if local info is null then show error view
},
error = { error ->
VkUtils.parseError(error)?.let { newBaseError ->
baseError.setValue { newBaseError }
}
if (baseError.value == null) {
baseError.setValue { BaseError.InternalError }
}
screenState.setValue { old ->
old.copy(
avatarUrl = null,
fullName = null
)
}
},
success = { response ->
val user = requireNotNull(response)