diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustTimeline.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustTimeline.kt index 8a184311de..7b398529a0 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustTimeline.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustTimeline.kt @@ -130,6 +130,8 @@ class RustTimeline( Timeline.PaginationStatus(isPaginating = false, hasMoreToLoad = mode is Timeline.Mode.FocusedOnEvent) ) + private val loggerTag = "Timeline($mode)" + init { when (mode) { is Timeline.Mode.Live, is Timeline.Mode.FocusedOnEvent -> coroutineScope.fetchMembers() @@ -177,10 +179,11 @@ class RustTimeline( } private fun updatePaginationStatus(direction: Timeline.PaginationDirection, update: (Timeline.PaginationStatus) -> Timeline.PaginationStatus) { - when (direction) { + val result = when (direction) { Timeline.PaginationDirection.BACKWARDS -> backwardPaginationStatus.getAndUpdate(update) Timeline.PaginationDirection.FORWARDS -> forwardPaginationStatus.getAndUpdate(update) } + Timber.tag(loggerTag).d("updatePaginationStatus $direction: $result") } // Use NonCancellable to avoid breaking the timeline when the coroutine is cancelled. @@ -195,12 +198,13 @@ class RustTimeline( } }.onFailure { error -> if (error is TimelineException.CannotPaginate) { - Timber.d("Can't paginate $direction on room ${joinedRoom.roomId} with paginationStatus: ${backwardPaginationStatus.value}") + Timber.tag(loggerTag).d("Can't paginate $direction on room ${joinedRoom.roomId} with paginationStatus: ${backwardPaginationStatus.value}") } else { updatePaginationStatus(direction) { it.copy(isPaginating = false) } - Timber.e(error, "Error paginating $direction on room ${joinedRoom.roomId}") + Timber.tag(loggerTag).e(error, "Error paginating $direction on room ${joinedRoom.roomId}") } }.onSuccess { hasReachedEnd -> + Timber.tag(loggerTag).d("Finished paginating $direction on room ${joinedRoom.roomId}, hasReachedEnd: $hasReachedEnd") updatePaginationStatus(direction) { it.copy(isPaginating = false, hasMoreToLoad = !hasReachedEnd) } } } @@ -264,7 +268,7 @@ class RustTimeline( try { inner.fetchMembers() } catch (exception: Exception) { - Timber.e(exception, "Error fetching members for room ${joinedRoom.roomId}") + Timber.tag(loggerTag).e(exception, "Error fetching members for room ${joinedRoom.roomId}") } } @@ -370,7 +374,7 @@ class RustTimeline( formattedCaption: String?, inReplyToEventId: EventId?, ): Result { - Timber.d("Sending image ${file.path.hash()}") + Timber.tag(loggerTag).d("Sending image ${file.path.hash()}") return sendAttachment(listOfNotNull(file, thumbnailFile)) { inner.sendImage( params = UploadParameters( @@ -396,7 +400,7 @@ class RustTimeline( formattedCaption: String?, inReplyToEventId: EventId?, ): Result { - Timber.d("Sending video ${file.path.hash()}") + Timber.tag(loggerTag).d("Sending video ${file.path.hash()}") return sendAttachment(listOfNotNull(file, thumbnailFile)) { inner.sendVideo( params = UploadParameters( @@ -421,7 +425,7 @@ class RustTimeline( formattedCaption: String?, inReplyToEventId: EventId?, ): Result { - Timber.d("Sending audio ${file.path.hash()}") + Timber.tag(loggerTag).d("Sending audio ${file.path.hash()}") return sendAttachment(listOf(file)) { inner.sendAudio( params = UploadParameters( @@ -445,7 +449,7 @@ class RustTimeline( formattedCaption: String?, inReplyToEventId: EventId?, ): Result { - Timber.d("Sending file ${file.path.hash()}") + Timber.tag(loggerTag).d("Sending file ${file.path.hash()}") return sendAttachment(listOf(file)) { inner.sendFile( params = UploadParameters( @@ -475,7 +479,7 @@ class RustTimeline( runCatchingExceptions { roomContentForwarder.forward(fromTimeline = inner, eventId = eventId, toRoomIds = roomIds) }.onFailure { - Timber.e(it) + Timber.tag(loggerTag).e(it) } }