Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions app/src/main/java/com/nextcloud/talk/api/NcApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ Observable<RoomOverall> joinRoom(@Nullable @Header("Authorization") String autho
@Url String url,
@Nullable @Field("password") String password);

@DELETE
Observable<GenericOverall> leaveRoom(@Nullable @Header("Authorization") String authorization, @Url String url);

/*
Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken
*/
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ interface NcApiCoroutines {
@DELETE
suspend fun unbindRoom(@Header("Authorization") authorization: String, @Url url: String): GenericOverall

@DELETE
suspend fun leaveRoom(@Header("Authorization") authorization: String, @Url url: String): GenericOverall

@GET
suspend fun getThreads(
@Header("Authorization") authorization: String,
Expand Down
40 changes: 10 additions & 30 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1471,34 +1471,6 @@ class ChatActivity :
}
}

chatViewModel.leaveRoomViewState.observe(this) { state ->
when (state) {
is ChatViewModel.LeaveRoomSuccessState -> {
logConversationInfos("leaveRoom#onNext")

if (getRoomInfoTimerHandler != null) {
getRoomInfoTimerHandler?.removeCallbacksAndMessages(null)
}

if (webSocketInstance != null && currentConversation != null) {
webSocketInstance?.joinRoomWithRoomTokenAndSession(
"",
sessionIdAfterRoomJoined
)
}

sessionIdAfterRoomJoined = "0"

if (state.funToCallWhenLeaveSuccessful != null) {
Log.d(TAG, "a callback action was set and is now executed because room was left successfully")
state.funToCallWhenLeaveSuccessful.invoke()
}
}

else -> {}
}
}

messageInputViewModel.sendChatMessageViewState.observe(this) { state ->
when (state) {
is MessageInputViewModel.SendChatMessageSuccessState -> {
Expand Down Expand Up @@ -2842,9 +2814,17 @@ class ChatActivity :
}
}

fun leaveRoom(funToCallWhenLeaveSuccessful: (() -> Unit)?) {
fun leaveRoom(functionToCallAfterLeave: (() -> Unit)?) {
logConversationInfos("leaveRoom")

// Send the HPB "leave room" immediately, before waiting for the backend DELETE to
// confirm. This minimises the window in which the HPB could still consider the user
// "in" the room and cause the server to delete a freshly-created notification.
if (webSocketInstance != null && currentConversation != null) {
webSocketInstance?.joinRoomWithRoomTokenAndSession("", sessionIdAfterRoomJoined)
}
sessionIdAfterRoomJoined = "0"

var apiVersion = 1
// FIXME Fix API checking with guests?
if (conversationUser != null) {
Expand All @@ -2860,7 +2840,7 @@ class ChatActivity :
conversationUser?.baseUrl!!,
roomToken
),
funToCallWhenLeaveSuccessful
functionToCallAfterLeave
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface ChatNetworkDataSource {
metadata: String
): Observable<GenericOverall>

fun leaveRoom(credentials: String, url: String): Observable<GenericOverall>
suspend fun leaveRoom(credentials: String, url: String): GenericOverall
suspend fun sendChatMessage(
credentials: String,
url: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,8 @@ class RetrofitChatNetwork(private val ncApi: NcApi, private val ncApiCoroutines:
metadata: String
): Observable<GenericOverall> = ncApi.sendLocation(credentials, url, objectType, objectId, metadata).map { it }

override fun leaveRoom(credentials: String, url: String): Observable<GenericOverall> =
ncApi.leaveRoom(credentials, url).map {
it
}
override suspend fun leaveRoom(credentials: String, url: String): GenericOverall =
ncApiCoroutines.leaveRoom(credentials, url)

override suspend fun sendChatMessage(
credentials: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import com.nextcloud.talk.dagger.modules.ApplicationScope
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -133,6 +135,7 @@ class ChatViewModel @AssistedInject constructor(
private val mediaRecorderManager: MediaRecorderManager,
private val audioFocusRequestManager: AudioFocusRequestManager,
private val currentUserProvider: CurrentUserProvider,
@ApplicationScope private val appScope: CoroutineScope,
@Assisted private val chatRoomToken: String,
@Assisted private val conversationThreadId: Long?
) : ViewModel(),
Expand Down Expand Up @@ -373,7 +376,7 @@ class ChatViewModel @AssistedInject constructor(
get() = _joinRoomViewState

object LeaveRoomStartState : ViewState
class LeaveRoomSuccessState(val funToCallWhenLeaveSuccessful: (() -> Unit)?) : ViewState
object LeaveRoomSuccessState : ViewState

private val _leaveRoomViewState: MutableLiveData<ViewState> = MutableLiveData(LeaveRoomStartState)
val leaveRoomViewState: LiveData<ViewState>
Expand Down Expand Up @@ -1537,29 +1540,24 @@ class ChatViewModel @AssistedInject constructor(
})
}

fun leaveRoom(credentials: String, url: String, funToCallWhenLeaveSuccessful: (() -> Unit)?) {
val startNanoTime = System.nanoTime()
chatNetworkDataSource.leaveRoom(credentials, url)
.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) {
disposableSet.add(d)
}

override fun onError(e: Throwable) {
Log.e(TAG, "leaveRoom - leaveRoom - ERROR", e)
}

override fun onComplete() {
Log.d(TAG, "leaveRoom - leaveRoom - completed: $startNanoTime")
fun leaveRoom(credentials: String, url: String, functionToCallAfterLeave: (() -> Unit)?) {
appScope.launch {
try {
val result = chatNetworkDataSource.leaveRoom(credentials, url)
if (result.ocs?.meta?.statusCode == HTTP_CODE_OK) {
Log.d(TAG, "leaveRoom completed")
} else {
Log.e(TAG, "leaveRoom failed with OCS status: ${result.ocs?.meta?.statusCode}")
}

override fun onNext(t: GenericOverall) {
_leaveRoomViewState.value = LeaveRoomSuccessState(funToCallWhenLeaveSuccessful)
withContext(Dispatchers.Main) {
_leaveRoomViewState.value = LeaveRoomSuccessState
_getCapabilitiesViewState.value = GetCapabilitiesStartState
functionToCallAfterLeave?.invoke()
}
})
} catch (e: Exception) {
Log.e(TAG, "leaveRoom - ERROR", e)
}
}
}

fun createRoom(credentials: String, url: String, queryMap: Map<String, String>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Nextcloud Talk - Android Client
*
* SPDX-FileCopyrightText: 2025 Marcel Hibbe <dev@mhibbe.de>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package com.nextcloud.talk.dagger.modules

import javax.inject.Qualifier

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class ApplicationScope
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import com.nextcloud.talk.utils.permissions.PlatformPermissionUtilImpl
import dagger.Module
import dagger.Provides
import dagger.Reusable
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import javax.inject.Singleton

@Module(includes = [ContextModule::class])
class UtilsModule {
Expand All @@ -29,4 +33,9 @@ class UtilsModule {
@Provides
@Reusable
fun provideMessageUtils(context: Context): MessageUtils = MessageUtils(context)

@Provides
@Singleton
@ApplicationScope
fun provideApplicationScope(): CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ import com.nextcloud.talk.utils.message.MessageUtils
import com.nextcloud.talk.utils.preferences.AppPreferences
import com.nextcloud.talk.utils.preferences.AppPreferencesImpl
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.SupervisorJob
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
Expand Down Expand Up @@ -194,6 +197,7 @@ class ComposePreviewUtils private constructor(context: Context) {
mediaRecorderManager = mediaRecorderManager,
audioFocusRequestManager = audioFocusRequestManager,
currentUserProvider = currentUserProvider,
appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO),
chatRoomToken = "",
conversationThreadId = null
)
Expand Down
Loading