diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/typing/SendTypingTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/typing/SendTypingTask.kt index a668676161..6460933621 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/typing/SendTypingTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/typing/SendTypingTask.kt @@ -29,8 +29,9 @@ internal interface SendTypingTask : Task { data class Params( val roomId: String, val isTyping: Boolean, - val delay: Long? = null, - val typingTimeoutMillis: Int? = 30_000 + val typingTimeoutMillis: Int? = 30_000, + // Optional delay before sending the request to the homeserver + val delay: Long? = null ) } @@ -41,18 +42,14 @@ internal class DefaultSendTypingTask @Inject constructor( ) : SendTypingTask { override suspend fun execute(params: SendTypingTask.Params) { - if (params.delay != null) { - delay(params.delay) - } - - val body = if (params.isTyping) { - TypingBody(true, params.typingTimeoutMillis) - } else { - TypingBody(false, null) - } + delay(params.delay ?: -1) executeRequest(eventBus) { - apiCall = roomAPI.sendTypingState(params.roomId, userId, body) + apiCall = roomAPI.sendTypingState( + params.roomId, + userId, + TypingBody(params.isTyping, params.typingTimeoutMillis?.takeIf { params.isTyping }) + ) } } } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomSummaryItemFactory.kt b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomSummaryItemFactory.kt index d53cd7b8c0..b5c0a77c38 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomSummaryItemFactory.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomSummaryItemFactory.kt @@ -126,13 +126,14 @@ class RoomSummaryItemFactory @Inject constructor(private val noticeEventFormatte } } - val typingString = if (typingHelper.excludeCurrentUser(roomSummary.typingRoomMemberIds).isEmpty()) { - null - } else { - // TODO Check how costly it is to create a Room here - val typingRoomMembers = typingHelper.toTypingRoomMembers(roomSummary.typingRoomMemberIds, session.getRoom(roomSummary.roomId)) - typingHelper.toTypingMessage(typingRoomMembers) - } + val typingString = typingHelper.excludeCurrentUser(roomSummary.typingRoomMemberIds) + .takeIf { it.isNotEmpty() } + ?.let { typingMembers -> + // It's not ideal to get a Room and to fetch data from DB here, but let's keep it like this for the moment + val room = session.getRoom(roomSummary.roomId) + val typingRoomMembers = typingHelper.toTypingRoomMembers(typingMembers, room) + typingHelper.toTypingMessage(typingRoomMembers) + } return RoomSummaryItem_() .id(roomSummary.roomId)