Commit e6c19fe5 authored by Leonardo Aramaki's avatar Leonardo Aramaki

On entering a chat, initialization call a suspendable function

subscribeTypingStatus which is blocking the current execution thread
from continuing and thus, from making a call to subscribeState function.
parent 2a686bb5
...@@ -181,9 +181,7 @@ class ChatRoomPresenter @Inject constructor( ...@@ -181,9 +181,7 @@ class ChatRoomPresenter @Inject constructor(
} }
subscribeTypingStatus() subscribeTypingStatus()
if (offset == 0L) { subscribeState()
subscribeState()
}
} }
} }
...@@ -229,10 +227,9 @@ class ChatRoomPresenter @Inject constructor( ...@@ -229,10 +227,9 @@ class ChatRoomPresenter @Inject constructor(
) )
try { try {
messagesRepository.save(newMessage) messagesRepository.save(newMessage)
val message = client.sendMessage(id, chatRoomId, text)
view.showNewMessage(mapper.map(newMessage, RoomViewModel( view.showNewMessage(mapper.map(newMessage, RoomViewModel(
roles = chatRoles, isBroadcast = chatIsBroadcast))) roles = chatRoles, isBroadcast = chatIsBroadcast)))
message client.sendMessage(id, chatRoomId, text)
} catch (ex: Exception) { } catch (ex: Exception) {
// Ok, not very beautiful, but the backend sends us a not valid response // Ok, not very beautiful, but the backend sends us a not valid response
// When someone sends a message on a read-only channel, so we just ignore it // When someone sends a message on a read-only channel, so we just ignore it
...@@ -324,7 +321,7 @@ class ChatRoomPresenter @Inject constructor( ...@@ -324,7 +321,7 @@ class ChatRoomPresenter @Inject constructor(
} }
} }
private fun subscribeState() { private suspend fun subscribeState() {
Timber.d("Subscribing to Status changes") Timber.d("Subscribing to Status changes")
lastState = manager.state lastState = manager.state
manager.addStatusChannel(stateChannel) manager.addStatusChannel(stateChannel)
...@@ -790,12 +787,14 @@ class ChatRoomPresenter @Inject constructor( ...@@ -790,12 +787,14 @@ class ChatRoomPresenter @Inject constructor(
} }
private suspend fun subscribeTypingStatus() { private suspend fun subscribeTypingStatus() {
client.subscribeTypingStatus(chatRoomId.toString()) { _, id -> launch(CommonPool + strategy.jobs) {
typingStatusSubscriptionId = id client.subscribeTypingStatus(chatRoomId.toString()) { _, id ->
} typingStatusSubscriptionId = id
}
for (typingStatus in client.typingStatusChannel) { for (typingStatus in client.typingStatusChannel) {
processTypingStatus(typingStatus) processTypingStatus(typingStatus)
}
} }
} }
...@@ -837,6 +836,7 @@ class ChatRoomPresenter @Inject constructor( ...@@ -837,6 +836,7 @@ class ChatRoomPresenter @Inject constructor(
launchUI(strategy) { launchUI(strategy) {
val viewModelStreamedMessage = mapper.map(streamedMessage, RoomViewModel( val viewModelStreamedMessage = mapper.map(streamedMessage, RoomViewModel(
roles = chatRoles, isBroadcast = chatIsBroadcast)) roles = chatRoles, isBroadcast = chatIsBroadcast))
val roomMessages = messagesRepository.getByRoomId(streamedMessage.roomId) val roomMessages = messagesRepository.getByRoomId(streamedMessage.roomId)
val index = roomMessages.indexOfFirst { msg -> msg.id == streamedMessage.id } val index = roomMessages.indexOfFirst { msg -> msg.id == streamedMessage.id }
if (index > -1) { if (index > -1) {
......
...@@ -64,7 +64,7 @@ class MessageService : JobService() { ...@@ -64,7 +64,7 @@ class MessageService : JobService() {
Timber.e(ex) Timber.e(ex)
// TODO - remove the generic message when we implement :userId:/message subscription // TODO - remove the generic message when we implement :userId:/message subscription
if (ex is IllegalStateException) { if (ex is IllegalStateException) {
Timber.d(ex, "Probably a read-only problem...") Timber.e(ex, "Probably a read-only problem...")
// TODO: For now we are only going to reschedule when api is fixed. // TODO: For now we are only going to reschedule when api is fixed.
messageRepository.removeById(message.id) messageRepository.removeById(message.id)
jobFinished(params, false) jobFinished(params, false)
......
...@@ -3,16 +3,16 @@ package chat.rocket.android.server.infraestructure ...@@ -3,16 +3,16 @@ package chat.rocket.android.server.infraestructure
import chat.rocket.common.model.BaseRoom import chat.rocket.common.model.BaseRoom
import chat.rocket.common.model.User import chat.rocket.common.model.User
import chat.rocket.core.RocketChatClient import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.realtime.subscribeSubscriptions
import chat.rocket.core.internal.realtime.subscribeRooms
import chat.rocket.core.internal.realtime.subscribeUserData
import chat.rocket.core.internal.realtime.subscribeActiveUsers
import chat.rocket.core.internal.realtime.subscribeRoomMessages
import chat.rocket.core.internal.realtime.unsubscribe
import chat.rocket.core.internal.realtime.socket.connect import chat.rocket.core.internal.realtime.socket.connect
import chat.rocket.core.internal.realtime.socket.disconnect import chat.rocket.core.internal.realtime.socket.disconnect
import chat.rocket.core.internal.realtime.socket.model.State import chat.rocket.core.internal.realtime.socket.model.State
import chat.rocket.core.internal.realtime.socket.model.StreamMessage import chat.rocket.core.internal.realtime.socket.model.StreamMessage
import chat.rocket.core.internal.realtime.subscribeActiveUsers
import chat.rocket.core.internal.realtime.subscribeRoomMessages
import chat.rocket.core.internal.realtime.subscribeRooms
import chat.rocket.core.internal.realtime.subscribeSubscriptions
import chat.rocket.core.internal.realtime.subscribeUserData
import chat.rocket.core.internal.realtime.unsubscribe
import chat.rocket.core.internal.rest.chatRooms import chat.rocket.core.internal.rest.chatRooms
import chat.rocket.core.model.Message import chat.rocket.core.model.Message
import chat.rocket.core.model.Myself import chat.rocket.core.model.Myself
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment