more improvements
This commit is contained in:
+9
-40
@@ -350,9 +350,7 @@ class ConversationsViewModelImpl(
|
|||||||
private fun deleteConversation(peerId: Int) {
|
private fun deleteConversation(peerId: Int) {
|
||||||
conversationsUseCase.delete(peerId).listenValue(viewModelScope) { state ->
|
conversationsUseCase.delete(peerId).listenValue(viewModelScope) { state ->
|
||||||
state.processState(
|
state.processState(
|
||||||
error = { error ->
|
error = {},
|
||||||
|
|
||||||
},
|
|
||||||
success = {
|
success = {
|
||||||
val newConversations = conversations.value.toMutableList()
|
val newConversations = conversations.value.toMutableList()
|
||||||
val conversationIndex =
|
val conversationIndex =
|
||||||
@@ -361,16 +359,7 @@ class ConversationsViewModelImpl(
|
|||||||
|
|
||||||
newConversations.removeAt(conversationIndex)
|
newConversations.removeAt(conversationIndex)
|
||||||
conversations.update { newConversations }
|
conversations.update { newConversations }
|
||||||
screenState.setValue { old ->
|
sortConversations()
|
||||||
old.copy(
|
|
||||||
conversations = newConversations.map {
|
|
||||||
it.asPresentation(
|
|
||||||
resources = resources,
|
|
||||||
useContactName = useContactNames
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
screenState.emit(screenState.value.copy(isLoading = state.isLoading()))
|
screenState.emit(screenState.value.copy(isLoading = state.isLoading()))
|
||||||
@@ -381,9 +370,7 @@ class ConversationsViewModelImpl(
|
|||||||
conversationsUseCase.changePinState(peerId, pin)
|
conversationsUseCase.changePinState(peerId, pin)
|
||||||
.listenValue(viewModelScope) { state ->
|
.listenValue(viewModelScope) { state ->
|
||||||
state.processState(
|
state.processState(
|
||||||
error = { error ->
|
error = {},
|
||||||
|
|
||||||
},
|
|
||||||
success = {
|
success = {
|
||||||
handleChatMajorChanged(
|
handleChatMajorChanged(
|
||||||
LongPollParsedEvent.ChatMajorChanged(
|
LongPollParsedEvent.ChatMajorChanged(
|
||||||
@@ -413,28 +400,14 @@ class ConversationsViewModelImpl(
|
|||||||
loadConversationsByIdUseCase(peerIds = listOf(message.peerId))
|
loadConversationsByIdUseCase(peerIds = listOf(message.peerId))
|
||||||
.listenValue(viewModelScope) { state ->
|
.listenValue(viewModelScope) { state ->
|
||||||
state.processState(
|
state.processState(
|
||||||
error = { error ->
|
error = {},
|
||||||
|
|
||||||
},
|
|
||||||
success = { response ->
|
success = { response ->
|
||||||
val conversation = (response.firstOrNull() ?: return@listenValue)
|
val conversation = (response.firstOrNull() ?: return@listenValue)
|
||||||
.copy(lastMessage = message)
|
.copy(lastMessage = message)
|
||||||
|
|
||||||
// TODO: 22-Dec-24, Danil Nikolaev: handle interactions and pinned state
|
|
||||||
|
|
||||||
newConversations.add(pinnedConversationsCount.value, conversation)
|
newConversations.add(pinnedConversationsCount.value, conversation)
|
||||||
conversations.update { newConversations }
|
conversations.update { newConversations }
|
||||||
|
sortConversations()
|
||||||
screenState.setValue { old ->
|
|
||||||
old.copy(
|
|
||||||
conversations = newConversations.map {
|
|
||||||
it.asPresentation(
|
|
||||||
resources = resources,
|
|
||||||
useContactName = useContactNames
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -695,7 +668,7 @@ class ConversationsViewModelImpl(
|
|||||||
val timerJob: Job
|
val timerJob: Job
|
||||||
)
|
)
|
||||||
|
|
||||||
private object NewInteractionException : CancellationException()
|
private class NewInteractionException : CancellationException()
|
||||||
|
|
||||||
private fun handleInteraction(event: LongPollParsedEvent.Interaction) {
|
private fun handleInteraction(event: LongPollParsedEvent.Interaction) {
|
||||||
val interactionType = event.interactionType
|
val interactionType = event.interactionType
|
||||||
@@ -706,9 +679,7 @@ class ConversationsViewModelImpl(
|
|||||||
val conversationAndIndex =
|
val conversationAndIndex =
|
||||||
newConversations.findWithIndex { it.id == peerId }
|
newConversations.findWithIndex { it.id == peerId }
|
||||||
|
|
||||||
if (conversationAndIndex == null) { // диалога нет в списке
|
if (conversationAndIndex != null) {
|
||||||
// pizdets
|
|
||||||
} else {
|
|
||||||
newConversations[conversationAndIndex.first] =
|
newConversations[conversationAndIndex.first] =
|
||||||
conversationAndIndex.second.copy(
|
conversationAndIndex.second.copy(
|
||||||
interactionType = interactionType.value,
|
interactionType = interactionType.value,
|
||||||
@@ -730,7 +701,7 @@ class ConversationsViewModelImpl(
|
|||||||
|
|
||||||
interactionsTimers[peerId]?.let { interactionJob ->
|
interactionsTimers[peerId]?.let { interactionJob ->
|
||||||
if (interactionJob.interactionType == interactionType) {
|
if (interactionJob.interactionType == interactionType) {
|
||||||
interactionJob.timerJob.cancel(NewInteractionException)
|
interactionJob.timerJob.cancel(NewInteractionException())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -789,9 +760,7 @@ class ConversationsViewModelImpl(
|
|||||||
startMessageId = startMessageId
|
startMessageId = startMessageId
|
||||||
).listenValue(viewModelScope) { state ->
|
).listenValue(viewModelScope) { state ->
|
||||||
state.processState(
|
state.processState(
|
||||||
error = { error ->
|
error = {},
|
||||||
|
|
||||||
},
|
|
||||||
success = {
|
success = {
|
||||||
val newConversations = conversations.value.toMutableList()
|
val newConversations = conversations.value.toMutableList()
|
||||||
val conversationIndex =
|
val conversationIndex =
|
||||||
|
|||||||
Reference in New Issue
Block a user