Fix gateway

This commit is contained in:
sim 2022-09-08 10:35:19 +02:00
parent 0b9b8251f9
commit 6ba963b552
6 changed files with 24 additions and 13 deletions

View File

@ -41,7 +41,7 @@ class FirebaseReceiver : FirebaseMessagingService() {
Timber.d("New Firebase token")
fcmHelper.storeFcmToken(token)
if (vectorPreferences.areNotificationEnabledForDevice() && activeSessionHolder.hasActiveSession()) {
pushersManager.enqueueRegisterPusher(token, getString(R.string.default_push_gateway_http_url))
pushersManager.enqueueRegisterPusher(token, getString(R.string.pusher_http_url))
}
}

View File

@ -30,6 +30,7 @@ private const val DEFAULT_PUSHER_FILE_TAG = "mobile"
class PushersManager @Inject constructor(
private val unifiedPushStore: UnifiedPushStore,
private val unifiedPushHelper: UnifiedPushHelper,
private val activeSessionHolder: ActiveSessionHolder,
private val localeProvider: LocaleProvider,
private val stringProvider: StringProvider,
@ -39,9 +40,9 @@ class PushersManager @Inject constructor(
val currentSession = activeSessionHolder.getActiveSession()
currentSession.pushersService().testPush(
unifiedPushStore.getPushGateway()!!,
unifiedPushStore.getPushGateway(),
stringProvider.getString(R.string.pusher_app_id),
unifiedPushStore.getEndpointOrToken().orEmpty(),
unifiedPushHelper.getEndpointOrToken().orEmpty(),
TEST_EVENT_ID
)
}

View File

@ -184,7 +184,10 @@ class UnifiedPushHelper @Inject constructor(
val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME
vectorPreferences.setFdroidSyncBackgroundMode(mode)
try {
pushersManager?.unregisterPusher(unifiedPushStore.getEndpointOrToken().orEmpty())
getEndpointOrToken()?.let {
Timber.d("Removing $it")
pushersManager?.unregisterPusher(it)
}
} catch (e: Exception) {
Timber.d(e, "Probably unregistering a non existing pusher")
}
@ -261,7 +264,7 @@ class UnifiedPushHelper @Inject constructor(
}
fun getPrivacyFriendlyUpEndpoint(): String? {
val endpoint = unifiedPushStore.getEndpointOrToken()
val endpoint = getEndpointOrToken()
if (endpoint.isNullOrEmpty()) return null
if (isEmbeddedDistributor()) {
return endpoint
@ -274,4 +277,9 @@ class UnifiedPushHelper @Inject constructor(
null
}
}
fun getEndpointOrToken(): String? {
return if (isEmbeddedDistributor()) fcmHelper.getFcmToken()
else unifiedPushStore.getEndpoint()
}
}

View File

@ -18,11 +18,13 @@ package im.vector.app.core.pushers
import android.content.Context
import androidx.core.content.edit
import im.vector.app.R
import im.vector.app.core.di.DefaultSharedPreferences
import javax.inject.Inject
class UnifiedPushStore @Inject constructor(
context: Context,
val context: Context,
val fcmHelper: FcmHelper
) {
private val defaultPrefs = DefaultSharedPreferences.getInstance(context)
@ -31,7 +33,7 @@ class UnifiedPushStore @Inject constructor(
*
* @return the UnifiedPush Endpoint or null if not received
*/
fun getEndpointOrToken(): String? {
fun getEndpoint(): String? {
return defaultPrefs.getString(PREFS_ENDPOINT_OR_TOKEN, null)
}
@ -51,8 +53,9 @@ class UnifiedPushStore @Inject constructor(
*
* @return the Push Gateway or null if not defined
*/
fun getPushGateway(): String? {
fun getPushGateway(): String {
return defaultPrefs.getString(PREFS_PUSH_GATEWAY, null)
?: context.getString(R.string.pusher_http_url)
}
/**

View File

@ -65,11 +65,11 @@ class VectorMessagingReceiver : MessagingReceiver() {
if (vectorPreferences.areNotificationEnabledForDevice() && activeSessionHolder.hasActiveSession()) {
// If the endpoint has changed
// or the gateway has changed
if (unifiedPushStore.getEndpointOrToken() != endpoint) {
if (unifiedPushHelper.getEndpointOrToken() != endpoint) {
unifiedPushStore.storeUpEndpoint(endpoint)
coroutineScope.launch {
unifiedPushHelper.storeCustomOrDefaultGateway(endpoint) {
unifiedPushStore.getPushGateway()?.let {
unifiedPushStore.getPushGateway().let {
pushersManager.enqueueRegisterPusher(endpoint, it)
}
}
@ -97,7 +97,7 @@ class VectorMessagingReceiver : MessagingReceiver() {
guardServiceStarter.start()
runBlocking {
try {
pushersManager.unregisterPusher(unifiedPushStore.getEndpointOrToken().orEmpty())
pushersManager.unregisterPusher(unifiedPushHelper.getEndpointOrToken().orEmpty())
} catch (e: Exception) {
Timber.tag(loggerTag.value).d("Probably unregistering a non existing pusher")
}

View File

@ -37,12 +37,11 @@ class TestEndpointAsTokenRegistration @Inject constructor(
private val pushersManager: PushersManager,
private val activeSessionHolder: ActiveSessionHolder,
private val unifiedPushHelper: UnifiedPushHelper,
private val unifiedPushStore: UnifiedPushStore,
) : TroubleshootTest(R.string.settings_troubleshoot_test_endpoint_registration_title) {
override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) {
// Check if we have a registered pusher for this token
val endpoint = unifiedPushStore.getEndpointOrToken() ?: run {
val endpoint = unifiedPushHelper.getEndpointOrToken() ?: run {
status = TestStatus.FAILED
return
}