Skip to content

Commit 0bc1391

Browse files
fix(notifications): anchor the push prefetch at the unread boundary
The catch-up triggered by a push notification fetched the newest page for rooms without any cached chat block, so a large unread backlog left a chat block floating above the unread boundary — the same window shape that misplaces the unread marker on chat open. Look up the pushed room in the local conversations cache and pass its lastReadMessage and unread count to catchUpRoom, so the initial fetch is anchored at the boundary when the backlog calls for it. The boundary is room-level state and therefore not passed for thread catch-ups. Assisted-by: Claude Code:claude-fable-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
1 parent 3e39606 commit 0bc1391

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

app/src/main/java/com/nextcloud/talk/jobs/ChatMessageCatchUpWorker.kt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ import autodagger.AutoInjector
2222
import com.nextcloud.talk.application.NextcloudTalkApplication
2323
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
2424
import com.nextcloud.talk.chat.data.network.ChatMessageSyncer
25+
import com.nextcloud.talk.data.database.dao.ConversationsDao
2526
import com.nextcloud.talk.users.UserManager
2627
import com.nextcloud.talk.utils.ApiUtils
2728
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID
2829
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
2930
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_THREAD_ID
31+
import kotlinx.coroutines.flow.first
3032
import java.util.concurrent.TimeUnit
3133
import javax.inject.Inject
3234

@@ -51,6 +53,9 @@ class ChatMessageCatchUpWorker(context: Context, workerParams: WorkerParameters)
5153
@Inject
5254
lateinit var chatMessageSyncer: ChatMessageSyncer
5355

56+
@Inject
57+
lateinit var conversationsDao: ConversationsDao
58+
5459
override suspend fun doWork(): Result {
5560
sharedApplication!!.componentApplication.inject(this)
5661

@@ -89,7 +94,23 @@ class ChatMessageCatchUpWorker(context: Context, workerParams: WorkerParameters)
8994
urlForChatting = ApiUtils.getUrlForChat(CHAT_API_VERSION, user.baseUrl!!, roomToken)
9095
)
9196

92-
val outcome = runCatching { chatMessageSyncer.catchUpRoom(target) }.getOrElse { throwable ->
97+
// For a room without any cached chat block the unread boundary of the locally cached
98+
// conversation is passed along, so a large backlog is fetched anchored at the last read
99+
// message and the unread marker can be placed when the chat is opened. The boundary is
100+
// room-level state and therefore not passed for thread catch-ups.
101+
val conversation = if (threadId == null) {
102+
conversationsDao.getConversationForUser(user.id!!, roomToken).first()
103+
} else {
104+
null
105+
}
106+
107+
val outcome = runCatching {
108+
chatMessageSyncer.catchUpRoom(
109+
target = target,
110+
lastReadMessage = conversation?.lastReadMessage,
111+
unreadMessages = conversation?.unreadMessages ?: 0
112+
)
113+
}.getOrElse { throwable ->
93114
Log.e(TAG, "Message catch-up failed for room $roomToken", throwable)
94115
null
95116
}

0 commit comments

Comments
 (0)