refactor: trim message history orchestration
This commit is contained in:
+13
-9
@@ -139,15 +139,7 @@ class MessagesHistoryViewModelImpl(
|
|||||||
loaders.loadConvo()
|
loaders.loadConvo()
|
||||||
loaders.loadMessagesHistory(currentOffset.value)
|
loaders.loadMessagesHistory(currentOffset.value)
|
||||||
|
|
||||||
updatesReducer.newMessages.onEach(longPollEventHandler::onNewMessage).launchIn(viewModelScope)
|
observeLongPollUpdates()
|
||||||
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 fun onNavigationConsumed() {
|
override fun onNavigationConsumed() {
|
||||||
@@ -239,6 +231,18 @@ class MessagesHistoryViewModelImpl(
|
|||||||
override fun onKeyboardShown() =
|
override fun onKeyboardShown() =
|
||||||
messageActions.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 =
|
override suspend fun loadMessageReadPeers(peerId: Long, cmId: Long): Int =
|
||||||
readPeersLoader.loadMessageReadPeers(peerId = peerId, cmId = cmId)
|
readPeersLoader.loadMessageReadPeers(peerId = peerId, cmId = cmId)
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -182,7 +182,7 @@ fun MessagesList(
|
|||||||
item = item,
|
item = item,
|
||||||
onClick = {
|
onClick = {
|
||||||
if (item.actionCmId != null) {
|
if (item.actionCmId != null) {
|
||||||
onRequestScrollToCmId(item.actionCmId!!)
|
onRequestScrollToCmId(item.actionCmId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -301,7 +301,7 @@ fun MessagesList(
|
|||||||
},
|
},
|
||||||
onReplyClick = {
|
onReplyClick = {
|
||||||
if (item.replyCmId != null) {
|
if (item.replyCmId != null) {
|
||||||
onRequestScrollToCmId(item.replyCmId!!)
|
onRequestScrollToCmId(item.replyCmId)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
offsetX = offsetAnimatable.value
|
offsetX = offsetAnimatable.value
|
||||||
@@ -328,7 +328,7 @@ fun MessagesList(
|
|||||||
},
|
},
|
||||||
onReplyClick = {
|
onReplyClick = {
|
||||||
if (item.replyCmId != null) {
|
if (item.replyCmId != null) {
|
||||||
onRequestScrollToCmId(item.replyCmId!!)
|
onRequestScrollToCmId(item.replyCmId)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
offsetX = offsetAnimatable.value
|
offsetX = offsetAnimatable.value
|
||||||
|
|||||||
+6
-6
@@ -214,10 +214,10 @@ fun Attachments(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun VkAttachment.asUiPhoto(): UiPreview {
|
fun VkAttachment.asUiPhoto(): UiPreview? {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is VkPhotoDomain -> {
|
is VkPhotoDomain -> {
|
||||||
val size = this.getDefault()!!
|
val size = this.getDefault() ?: return null
|
||||||
UiPreview(
|
UiPreview(
|
||||||
id = this.id,
|
id = this.id,
|
||||||
url = size.url,
|
url = size.url,
|
||||||
@@ -247,7 +247,7 @@ fun VkAttachment.asUiPhoto(): UiPreview {
|
|||||||
is VkFileDomain -> {
|
is VkFileDomain -> {
|
||||||
when {
|
when {
|
||||||
this.preview?.video != null -> {
|
this.preview?.video != null -> {
|
||||||
val video = this.preview?.video!!
|
val video = this.preview?.video ?: return null
|
||||||
|
|
||||||
UiPreview(
|
UiPreview(
|
||||||
id = id,
|
id = id,
|
||||||
@@ -259,7 +259,7 @@ fun VkAttachment.asUiPhoto(): UiPreview {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.preview?.photo != null -> {
|
this.preview?.photo != null -> {
|
||||||
val photoSize = this.preview?.photo?.sizes?.first()!!
|
val photoSize = this.preview?.photo?.sizes?.firstOrNull() ?: return null
|
||||||
|
|
||||||
UiPreview(
|
UiPreview(
|
||||||
id = id,
|
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)) {
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
if (item.title != null) {
|
if (item.title != null) {
|
||||||
|
val title = item.title
|
||||||
Text(
|
Text(
|
||||||
text = item.title!!,
|
text = title,
|
||||||
style = MaterialTheme.typography.bodyLarge,
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis
|
overflow = TextOverflow.Ellipsis
|
||||||
|
|||||||
@@ -70,7 +70,20 @@ class ProfileViewModelImpl(
|
|||||||
).listenValue(viewModelScope) { state ->
|
).listenValue(viewModelScope) { state ->
|
||||||
state.processState(
|
state.processState(
|
||||||
error = { error ->
|
error = { error ->
|
||||||
// TODO: 12/07/2024, Danil Nikolaev: if local info is null then show error view
|
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 ->
|
success = { response ->
|
||||||
val user = requireNotNull(response)
|
val user = requireNotNull(response)
|
||||||
|
|||||||
Reference in New Issue
Block a user