mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 03:29:28 +01:00
made the room and capabilities logic synchronous in a Coroutine
Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
This commit is contained in:
parent
0176a3e4f9
commit
7a04a9c9c6
@ -92,7 +92,10 @@ import io.reactivex.Observer
|
|||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.greenrobot.eventbus.Subscribe
|
import org.greenrobot.eventbus.Subscribe
|
||||||
import org.greenrobot.eventbus.ThreadMode
|
import org.greenrobot.eventbus.ThreadMode
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
@ -126,7 +129,6 @@ class ConversationInfoActivity :
|
|||||||
private lateinit var conversationUser: User
|
private lateinit var conversationUser: User
|
||||||
private var hasAvatarSpacing: Boolean = false
|
private var hasAvatarSpacing: Boolean = false
|
||||||
private lateinit var credentials: String
|
private lateinit var credentials: String
|
||||||
private var roomDisposable: Disposable? = null
|
|
||||||
private var participantsDisposable: Disposable? = null
|
private var participantsDisposable: Disposable? = null
|
||||||
|
|
||||||
private var databaseStorageModule: DatabaseStorageModule? = null
|
private var databaseStorageModule: DatabaseStorageModule? = null
|
||||||
@ -193,7 +195,30 @@ class ConversationInfoActivity :
|
|||||||
binding.addParticipantsAction.setOnClickListener { addParticipants() }
|
binding.addParticipantsAction.setOnClickListener { addParticipants() }
|
||||||
binding.listBansButton.setOnClickListener { listBans() }
|
binding.listBansButton.setOnClickListener { listBans() }
|
||||||
|
|
||||||
viewModel.getRoom(conversationUser, conversationToken)
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
val model = viewModel.getRoomBlocking(conversationUser, conversationToken)
|
||||||
|
spreedCapabilities = viewModel.getCapabilitiesBlocking(conversationUser, conversationToken, model)
|
||||||
|
conversation = model
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if (ConversationUtils.isNoteToSelfConversation(conversation)) {
|
||||||
|
binding.shareConversationButton.visibility = GONE
|
||||||
|
}
|
||||||
|
|
||||||
|
val canGeneratePrettyURL = CapabilitiesUtil.canGeneratePrettyURL(conversationUser)
|
||||||
|
binding.shareConversationButton.setOnClickListener {
|
||||||
|
ShareUtils.shareConversationLink(
|
||||||
|
this@ConversationInfoActivity,
|
||||||
|
conversationUser.baseUrl,
|
||||||
|
conversation?.token,
|
||||||
|
conversation?.name,
|
||||||
|
canGeneratePrettyURL
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
handleConversation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
themeTextViews()
|
themeTextViews()
|
||||||
themeSwitchPreferences()
|
themeSwitchPreferences()
|
||||||
@ -205,20 +230,6 @@ class ConversationInfoActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initObservers() {
|
private fun initObservers() {
|
||||||
initViewStateObserver()
|
|
||||||
|
|
||||||
viewModel.getCapabilitiesViewState.observe(this) { state ->
|
|
||||||
when (state) {
|
|
||||||
is ConversationInfoViewModel.GetCapabilitiesSuccessState -> {
|
|
||||||
spreedCapabilities = state.spreedCapabilities
|
|
||||||
|
|
||||||
handleConversation()
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
viewModel.getBanActorState.observe(this) { state ->
|
viewModel.getBanActorState.observe(this) { state ->
|
||||||
when (state) {
|
when (state) {
|
||||||
is ConversationInfoViewModel.BanActorSuccessState -> {
|
is ConversationInfoViewModel.BanActorSuccessState -> {
|
||||||
@ -264,36 +275,6 @@ class ConversationInfoActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initViewStateObserver() {
|
|
||||||
viewModel.viewState.observe(this) { state ->
|
|
||||||
when (state) {
|
|
||||||
is ConversationInfoViewModel.GetRoomSuccessState -> {
|
|
||||||
conversation = state.conversationModel
|
|
||||||
viewModel.getCapabilities(conversationUser, conversationToken, conversation!!)
|
|
||||||
if (ConversationUtils.isNoteToSelfConversation(conversation)) {
|
|
||||||
binding.shareConversationButton.visibility = GONE
|
|
||||||
}
|
|
||||||
val canGeneratePrettyURL = CapabilitiesUtil.canGeneratePrettyURL(conversationUser)
|
|
||||||
binding.shareConversationButton.setOnClickListener {
|
|
||||||
ShareUtils.shareConversationLink(
|
|
||||||
this,
|
|
||||||
conversationUser.baseUrl,
|
|
||||||
conversation?.token,
|
|
||||||
conversation?.name,
|
|
||||||
canGeneratePrettyURL
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
is ConversationInfoViewModel.GetRoomErrorState -> {
|
|
||||||
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupActionBar() {
|
private fun setupActionBar() {
|
||||||
setSupportActionBar(binding.conversationInfoToolbar)
|
setSupportActionBar(binding.conversationInfoToolbar)
|
||||||
binding.conversationInfoToolbar.setNavigationOnClickListener {
|
binding.conversationInfoToolbar.setNavigationOnClickListener {
|
||||||
@ -763,7 +744,7 @@ class ConversationInfoActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("LongMethod")
|
@Suppress("LongMethod", "CyclomaticComplexMethod")
|
||||||
private fun handleConversation() {
|
private fun handleConversation() {
|
||||||
val conversationCopy = conversation!!
|
val conversationCopy = conversation!!
|
||||||
|
|
||||||
|
@ -120,6 +120,9 @@ class ConversationInfoViewModel @Inject constructor(
|
|||||||
?.subscribe(GetRoomObserver())
|
?.subscribe(GetRoomObserver())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getRoomBlocking(user: User, token: String): ConversationModel =
|
||||||
|
chatNetworkDataSource.getRoom(user, token).blockingFirst()
|
||||||
|
|
||||||
fun getCapabilities(user: User, token: String, conversationModel: ConversationModel) {
|
fun getCapabilities(user: User, token: String, conversationModel: ConversationModel) {
|
||||||
_getCapabilitiesViewState.value = GetCapabilitiesStartState
|
_getCapabilitiesViewState.value = GetCapabilitiesStartState
|
||||||
|
|
||||||
@ -150,6 +153,14 @@ class ConversationInfoViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getCapabilitiesBlocking(user: User, token: String, conversationModel: ConversationModel): SpreedCapability {
|
||||||
|
return if (conversationModel.remoteServer.isNullOrEmpty()) {
|
||||||
|
user.capabilities!!.spreedCapability!!
|
||||||
|
} else {
|
||||||
|
chatNetworkDataSource.getCapabilities(user, token).blockingFirst()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Suppress("Detekt.TooGenericExceptionCaught")
|
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||||
fun listBans(user: User, token: String) {
|
fun listBans(user: User, token: String) {
|
||||||
val url = ApiUtils.getUrlForBans(user.baseUrl!!, token)
|
val url = ApiUtils.getUrlForBans(user.baseUrl!!, token)
|
||||||
|
Loading…
Reference in New Issue
Block a user