Cleanup and fix a bug

This commit is contained in:
Benoit Marty 2020-01-13 10:13:12 +01:00
parent f3e52b96c0
commit ecc463e920
2 changed files with 17 additions and 19 deletions

View file

@ -29,8 +29,9 @@ internal interface SendTypingTask : Task<SendTypingTask.Params, Unit> {
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<Unit>(eventBus) {
apiCall = roomAPI.sendTypingState(params.roomId, userId, body)
apiCall = roomAPI.sendTypingState(
params.roomId,
userId,
TypingBody(params.isTyping, params.typingTimeoutMillis?.takeIf { params.isTyping })
)
}
}
}

View file

@ -126,11 +126,12 @@ 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))
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)
}