Skip to content

Commit

Permalink
Fix to get websocketInstance.
Browse files Browse the repository at this point in the history
Solution was to pass userId to CapabilitiesWorker in NextcloudTalkApplication.

Otherwise internalUserId in CapabilitiesWorker became -1 so the user was not found and not updated with it's capabilities.

This may have resulted in multiple errors. One of them is:

In WebsocketConnectionsWorker
getExternalSignalingServer() of the user was null.
Because of this,
webSocketConnectionHelper.getExternalSignalingInstanceForServer(..) was not called.
So the magicWebSocketInstanceMap in WebSocketConnectionHelper was never filled.

This is why
WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(..)
in ChatController failed to get a webSocketInstance.

Furthermore, setupWebsocket() was moved to onAttach() in ChatController

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
  • Loading branch information
mahibi committed Mar 9, 2023
1 parent 1a820a9 commit 7d7af29
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.emoji2.text.EmojiCompat
import androidx.lifecycle.LifecycleObserver
import androidx.multidex.MultiDex
import androidx.multidex.MultiDexApplication
import androidx.work.Data
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.OneTimeWorkRequest
import androidx.work.PeriodicWorkRequest
Expand All @@ -62,9 +63,11 @@ import com.nextcloud.talk.jobs.AccountRemovalWorker
import com.nextcloud.talk.jobs.CapabilitiesWorker
import com.nextcloud.talk.jobs.SignalingSettingsWorker
import com.nextcloud.talk.ui.theme.ThemeModule
import com.nextcloud.talk.users.UserManager
import com.nextcloud.talk.utils.ClosedInterfaceImpl
import com.nextcloud.talk.utils.DeviceUtils
import com.nextcloud.talk.utils.NotificationUtils
import com.nextcloud.talk.utils.bundle.BundleKeys
import com.nextcloud.talk.utils.database.arbitrarystorage.ArbitraryStorageModule
import com.nextcloud.talk.utils.database.user.UserModule
import com.nextcloud.talk.utils.preferences.AppPreferences
Expand Down Expand Up @@ -114,6 +117,10 @@ class NextcloudTalkApplication : MultiDexApplication(), LifecycleObserver {

@Inject
lateinit var okHttpClient: OkHttpClient

@JvmField
@Inject
var userManager: UserManager? = null
//endregion

val hook: SQLiteDatabaseHook = object : SQLiteDatabaseHook {
Expand Down Expand Up @@ -182,7 +189,16 @@ class NextcloudTalkApplication : MultiDexApplication(), LifecycleObserver {
HALF_DAY,
TimeUnit.HOURS
).build()
val capabilitiesUpdateWork = OneTimeWorkRequest.Builder(CapabilitiesWorker::class.java).build()

val currentUser = userManager?.currentUser?.blockingGet()
val userData =
Data.Builder()
.putLong(BundleKeys.KEY_INTERNAL_USER_ID, currentUser?.id ?: -1)
.build()

val capabilitiesUpdateWork = OneTimeWorkRequest.Builder(CapabilitiesWorker::class.java)
.setInputData(userData)
.build()
val signalingSettingsWork = OneTimeWorkRequest.Builder(SignalingSettingsWorker::class.java).build()

WorkManager.getInstance(applicationContext).enqueue(accountRemovalWork)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,7 @@ class ChatController(args: Bundle) :

eventBus.register(this)

setupWebsocket()
webSocketInstance?.getSignalingMessageReceiver()?.addListener(localParticipantMessageListener)

if (conversationUser?.userId != "?" &&
Expand Down Expand Up @@ -2002,11 +2003,6 @@ class ChatController(args: Bundle) :

logConversationInfos("joinRoomWithPassword#onNext")

// FIXME The web socket should be set up in onAttach(). It is currently setup after joining the
// room to "ensure" (rather, increase the chances) that the WebsocketConnectionsWorker job
// was able to finish and, therefore, that the web socket instance can be got.
setupWebsocket()

// Ensure that the listener is added if the web socket instance was not set up yet when
// onAttach() was called.
webSocketInstance?.getSignalingMessageReceiver()?.addListener(localParticipantMessageListener)
Expand Down Expand Up @@ -2228,7 +2224,10 @@ class ChatController(args: Bundle) :
webSocketInstance = WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser.id!!)

if (webSocketInstance == null) {
Log.d(TAG, "magicWebSocketInstance became null")
Log.e(TAG, "magicWebSocketInstance became null")
if (BuildConfig.DEBUG) {
Toast.makeText(context, "failed to setup webSocketInstance", Toast.LENGTH_LONG).show()
}
}
}

Expand Down

0 comments on commit 7d7af29

Please sign in to comment.