Skip to content

Commit bc8309a

Browse files
committed
DROID-3298 fixes
1 parent 3658e09 commit bc8309a

File tree

1 file changed

+3
-29
lines changed

1 file changed

+3
-29
lines changed

domain/src/main/java/com/anytypeio/anytype/domain/chats/ChatContainer.kt

+3-29
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class ChatContainer @Inject constructor(
121121

122122
val initial = buildList<Chat.Message> {
123123
if (state.hasUnReadMessages && !state.oldestMessageOrderId.isNullOrEmpty()) {
124+
// Starting from the unread-messages window.
124125
val aroundUnread = loadAroundMessageOrder(
125126
chat = chat,
126127
order = state.oldestMessageOrderId.orEmpty()
@@ -132,6 +133,7 @@ class ChatContainer @Inject constructor(
132133
}
133134
addAll(aroundUnread)
134135
} else {
136+
// Starting with the latest messages.
135137
addAll(response.messages)
136138
}
137139
}
@@ -183,21 +185,7 @@ class ChatContainer @Inject constructor(
183185
val lastShown = state.messages.last()
184186
val lastTracked = lastMessages.entries.first().value
185187
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.
201189
state.copy(
202190
intent = Intent.ScrollToBottom
203191
)
@@ -209,20 +197,6 @@ class ChatContainer @Inject constructor(
209197
logger.logException(e, "DROID-2966 Error while scrolling to bottom")
210198
}
211199
}
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-
}
226200
ChatStreamState(
227201
messages = messages,
228202
intent = Intent.ScrollToBottom,

0 commit comments

Comments
 (0)