@@ -114,18 +114,19 @@ class ThreadViewModel @Inject constructor(
114
114
}
115
115
}
116
116
117
- fun reassignMessagesLive (threadUid : String ) {
117
+ fun reassignMessagesLive (threadUid : String , withSuperCollapsedBlock : Boolean = true ) {
118
118
messagesLiveJob?.cancel()
119
119
messagesLiveJob = viewModelScope.launch(ioCoroutineContext) {
120
120
messageController.getSortedAndNotDeletedMessagesAsync(threadUid)
121
- ?.map { mapRealmMessagesResult(it.list, threadUid) }
121
+ ?.map { mapRealmMessagesResult(it.list, threadUid, withSuperCollapsedBlock ) }
122
122
?.collect(messagesLive::postValue)
123
123
}
124
124
}
125
125
126
126
private suspend fun mapRealmMessagesResult (
127
127
messages : RealmResults <Message >,
128
128
threadUid : String ,
129
+ withSuperCollapsedBlock : Boolean ,
129
130
): Pair <ThreadAdapterItems , MessagesWithoutHeavyData > {
130
131
131
132
superCollapsedBlock = superCollapsedBlock ? : SuperCollapsedBlock ()
@@ -134,7 +135,8 @@ class ThreadViewModel @Inject constructor(
134
135
val messagesToFetch = mutableListOf<Message >()
135
136
val thread = messages.firstOrNull()?.threads?.firstOrNull { it.uid == threadUid } ? : return items to messagesToFetch
136
137
val firstIndexAfterBlock = computeFirstIndexAfterBlock(thread, messages)
137
- superCollapsedBlock!! .shouldBeDisplayed = shouldBlockBeDisplayed(messages.count(), firstIndexAfterBlock)
138
+ superCollapsedBlock!! .shouldBeDisplayed =
139
+ shouldBlockBeDisplayed(messages.count(), firstIndexAfterBlock, withSuperCollapsedBlock)
138
140
139
141
suspend fun addMessage (message : Message ) {
140
142
splitBody(message).let {
@@ -219,9 +221,9 @@ class ThreadViewModel @Inject constructor(
219
221
* - If there's any unread Message in between, it will be displayed (hence, all following Messages will be displayed too).
220
222
* After all these Messages are displayed, if there's at least 2 remaining Messages, they're gonna be collapsed in the Block.
221
223
*/
222
- private fun shouldBlockBeDisplayed (messagesCount : Int , firstIndexAfterBlock : Int ): Boolean {
223
-
224
- return superCollapsedBlock?.shouldBeDisplayed == true && // If the Block was hidden for any reason, we mustn't ever display it again
224
+ private fun shouldBlockBeDisplayed (messagesCount : Int , firstIndexAfterBlock : Int , withSuperCollapsedBlock : Boolean ): Boolean {
225
+ return withSuperCollapsedBlock && // When we want to print a mail, we need the full list of Messages
226
+ superCollapsedBlock?.shouldBeDisplayed == true && // If the Block was hidden for any reason, we mustn't ever display it again
225
227
superCollapsedBlock?.hasBeenClicked == false && // Block hasn't been expanded by the user
226
228
messagesCount >= SUPER_COLLAPSED_BLOCK_MINIMUM_MESSAGES_LIMIT && // At least 5 Messages in the Thread
227
229
firstIndexAfterBlock >= SUPER_COLLAPSED_BLOCK_FIRST_INDEX_LIMIT // At least 2 Messages in the Block
0 commit comments