Unverified Commit afaf3af1 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito Committed by GitHub

Merge pull request #1519 from RocketChat/fix/fix-temporary-status-on-reconnection

[FIX] fix temporary status on reconnection
parents 33adccb6 ec005ba9
...@@ -5,6 +5,7 @@ import androidx.lifecycle.LifecycleObserver ...@@ -5,6 +5,7 @@ import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent import androidx.lifecycle.OnLifecycleEvent
import chat.rocket.android.server.domain.GetAccountInteractor import chat.rocket.android.server.domain.GetAccountInteractor
import chat.rocket.android.server.domain.GetCurrentServerInteractor import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.infraestructure.ConnectionManagerFactory
import chat.rocket.android.server.infraestructure.RocketChatClientFactory import chat.rocket.android.server.infraestructure.RocketChatClientFactory
import chat.rocket.common.RocketChatException import chat.rocket.common.RocketChatException
import chat.rocket.common.model.UserStatus import chat.rocket.common.model.UserStatus
...@@ -15,8 +16,7 @@ import javax.inject.Inject ...@@ -15,8 +16,7 @@ import javax.inject.Inject
class AppLifecycleObserver @Inject constructor( class AppLifecycleObserver @Inject constructor(
private val serverInteractor: GetCurrentServerInteractor, private val serverInteractor: GetCurrentServerInteractor,
private val factory: RocketChatClientFactory, private val factory: ConnectionManagerFactory
private val getAccountInteractor: GetAccountInteractor
) : LifecycleObserver { ) : LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_START) @OnLifecycleEvent(Lifecycle.Event.ON_START)
...@@ -31,14 +31,8 @@ class AppLifecycleObserver @Inject constructor( ...@@ -31,14 +31,8 @@ class AppLifecycleObserver @Inject constructor(
private fun changeTemporaryStatus(userStatus: UserStatus) { private fun changeTemporaryStatus(userStatus: UserStatus) {
launch { launch {
val currentServer = serverInteractor.get() serverInteractor.get()?.let { currentServer ->
val account = currentServer?.let { getAccountInteractor.get(currentServer) } factory.create(currentServer).setTemporaryStatus(userStatus)
val client = account?.let { factory.create(currentServer) }
try {
client?.setTemporaryStatus(userStatus)
} catch (exception: RocketChatException) {
Timber.e(exception)
} }
} }
} }
......
...@@ -176,7 +176,7 @@ class MainPresenter @Inject constructor( ...@@ -176,7 +176,7 @@ class MainPresenter @Inject constructor(
fun changeDefaultStatus(userStatus: UserStatus) { fun changeDefaultStatus(userStatus: UserStatus) {
launchUI(strategy) { launchUI(strategy) {
try { try {
client.setDefaultStatus(userStatus) manager.setDefaultStatus(userStatus)
view.showUserStatus(userStatus) view.showUserStatus(userStatus)
} catch (ex: RocketChatException) { } catch (ex: RocketChatException) {
ex.message?.let { ex.message?.let {
......
...@@ -5,7 +5,10 @@ import chat.rocket.android.db.DatabaseManager ...@@ -5,7 +5,10 @@ import chat.rocket.android.db.DatabaseManager
import chat.rocket.android.infrastructure.LocalRepository import chat.rocket.android.infrastructure.LocalRepository
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.common.model.UserStatus
import chat.rocket.core.RocketChatClient import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.realtime.setDefaultStatus
import chat.rocket.core.internal.realtime.setTemporaryStatus
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
...@@ -49,6 +52,7 @@ class ConnectionManager( ...@@ -49,6 +52,7 @@ class ConnectionManager(
private var roomsId: String? = null private var roomsId: String? = null
private var userDataId: String? = null private var userDataId: String? = null
private var activeUserId: String? = null private var activeUserId: String? = null
private var temporaryStatus: UserStatus? = null
private val activeUsersContext = newSingleThreadContext("activeUsersContext") private val activeUsersContext = newSingleThreadContext("activeUsersContext")
private val roomsContext = newSingleThreadContext("roomsContext") private val roomsContext = newSingleThreadContext("roomsContext")
...@@ -90,6 +94,10 @@ class ConnectionManager( ...@@ -90,6 +94,10 @@ class ConnectionManager(
} }
resubscribeRooms() resubscribeRooms()
temporaryStatus?.let { status ->
client.setTemporaryStatus(status)
}
} }
is State.Waiting -> { is State.Waiting -> {
Timber.d("Connection in: ${status.seconds}") Timber.d("Connection in: ${status.seconds}")
...@@ -176,6 +184,16 @@ class ConnectionManager( ...@@ -176,6 +184,16 @@ class ConnectionManager(
} }
} }
fun setDefaultStatus(userStatus: UserStatus) {
temporaryStatus = null
client.setDefaultStatus(userStatus)
}
fun setTemporaryStatus(userStatus: UserStatus) {
temporaryStatus = userStatus
client.setTemporaryStatus(userStatus)
}
private fun resubscribeRooms() { private fun resubscribeRooms() {
roomMessagesChannels.toList().map { (roomId, channel) -> roomMessagesChannels.toList().map { (roomId, channel) ->
client.subscribeRoomMessages(roomId) { _, id -> client.subscribeRoomMessages(roomId) { _, id ->
...@@ -190,6 +208,7 @@ class ConnectionManager( ...@@ -190,6 +208,7 @@ class ConnectionManager(
client.removeStateChannel(statusChannel) client.removeStateChannel(statusChannel)
client.disconnect() client.disconnect()
connectJob?.cancel() connectJob?.cancel()
temporaryStatus = null
} }
fun addStatusChannel(channel: Channel<State>) = statusChannelList.add(channel) fun addStatusChannel(channel: Channel<State>) = statusChannelList.add(channel)
......
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