forked from melod1n/fast-messenger
refactor: trim message history orchestration
This commit is contained in:
+13
-9
@@ -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)
|
||||
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
+6
-6
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user