@@ -121,6 +121,7 @@ class ChatContainer @Inject constructor(
121
121
122
122
val initial = buildList<Chat .Message > {
123
123
if (state.hasUnReadMessages && ! state.oldestMessageOrderId.isNullOrEmpty()) {
124
+ // Starting from the unread-messages window.
124
125
val aroundUnread = loadAroundMessageOrder(
125
126
chat = chat,
126
127
order = state.oldestMessageOrderId.orEmpty()
@@ -132,6 +133,7 @@ class ChatContainer @Inject constructor(
132
133
}
133
134
addAll(aroundUnread)
134
135
} else {
136
+ // Starting with the latest messages.
135
137
addAll(response.messages)
136
138
}
137
139
}
@@ -183,21 +185,7 @@ class ChatContainer @Inject constructor(
183
185
val lastShown = state.messages.last()
184
186
val lastTracked = lastMessages.entries.first().value
185
187
if (lastShown.id == lastTracked.id) {
186
- // No need to paginate.
187
- if (state.state.hasUnReadMessages) {
188
- // TODO Fix race condition here
189
- runCatching {
190
- repo.readChatMessages(
191
- Command .ChatCommand .ReadMessages (
192
- chat = chat,
193
- beforeOrderId = lastTracked.order,
194
- lastStateId = state.state.lastStateId
195
- )
196
- )
197
- }.onFailure {
198
- logger.logException(it, " DROID-2966 Error while reading messages" )
199
- }
200
- }
188
+ // No need to paginate, just scroll to bottom.
201
189
state.copy(
202
190
intent = Intent .ScrollToBottom
203
191
)
@@ -209,20 +197,6 @@ class ChatContainer @Inject constructor(
209
197
logger.logException(e, " DROID-2966 Error while scrolling to bottom" )
210
198
}
211
199
}
212
- if (messages.isNotEmpty() && state.state.hasUnReadMessages) {
213
- runCatching {
214
- // TODO Fix race condition here
215
- repo.readChatMessages(
216
- Command .ChatCommand .ReadMessages (
217
- chat = chat,
218
- beforeOrderId = messages.last().order,
219
- lastStateId = state.state.lastStateId
220
- )
221
- )
222
- }.onFailure {
223
- logger.logException(it, " DROID-2966 Error while reading messages" )
224
- }
225
- }
226
200
ChatStreamState (
227
201
messages = messages,
228
202
intent = Intent .ScrollToBottom ,
0 commit comments