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") Timber.d("New Firebase token")
fcmHelper.storeFcmToken(token) fcmHelper.storeFcmToken(token)
if (vectorPreferences.areNotificationEnabledForDevice() && activeSessionHolder.hasActiveSession()) { 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( class PushersManager @Inject constructor(
private val unifiedPushStore: UnifiedPushStore, private val unifiedPushStore: UnifiedPushStore,
private val unifiedPushHelper: UnifiedPushHelper,
private val activeSessionHolder: ActiveSessionHolder, private val activeSessionHolder: ActiveSessionHolder,
private val localeProvider: LocaleProvider, private val localeProvider: LocaleProvider,
private val stringProvider: StringProvider, private val stringProvider: StringProvider,
@ -39,9 +40,9 @@ class PushersManager @Inject constructor(
val currentSession = activeSessionHolder.getActiveSession() val currentSession = activeSessionHolder.getActiveSession()
currentSession.pushersService().testPush( currentSession.pushersService().testPush(
unifiedPushStore.getPushGateway()!!, unifiedPushStore.getPushGateway(),
stringProvider.getString(R.string.pusher_app_id), stringProvider.getString(R.string.pusher_app_id),
unifiedPushStore.getEndpointOrToken().orEmpty(), unifiedPushHelper.getEndpointOrToken().orEmpty(),
TEST_EVENT_ID TEST_EVENT_ID
) )
} }

View file

@ -184,7 +184,10 @@ class UnifiedPushHelper @Inject constructor(
val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME
vectorPreferences.setFdroidSyncBackgroundMode(mode) vectorPreferences.setFdroidSyncBackgroundMode(mode)
try { try {
pushersManager?.unregisterPusher(unifiedPushStore.getEndpointOrToken().orEmpty()) getEndpointOrToken()?.let {
Timber.d("Removing $it")
pushersManager?.unregisterPusher(it)
}
} catch (e: Exception) { } catch (e: Exception) {
Timber.d(e, "Probably unregistering a non existing pusher") Timber.d(e, "Probably unregistering a non existing pusher")
} }
@ -261,7 +264,7 @@ class UnifiedPushHelper @Inject constructor(
} }
fun getPrivacyFriendlyUpEndpoint(): String? { fun getPrivacyFriendlyUpEndpoint(): String? {
val endpoint = unifiedPushStore.getEndpointOrToken() val endpoint = getEndpointOrToken()
if (endpoint.isNullOrEmpty()) return null if (endpoint.isNullOrEmpty()) return null
if (isEmbeddedDistributor()) { if (isEmbeddedDistributor()) {
return endpoint return endpoint
@ -274,4 +277,9 @@ class UnifiedPushHelper @Inject constructor(
null 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 android.content.Context
import androidx.core.content.edit import androidx.core.content.edit
import im.vector.app.R
import im.vector.app.core.di.DefaultSharedPreferences import im.vector.app.core.di.DefaultSharedPreferences
import javax.inject.Inject import javax.inject.Inject
class UnifiedPushStore @Inject constructor( class UnifiedPushStore @Inject constructor(
context: Context, val context: Context,
val fcmHelper: FcmHelper
) { ) {
private val defaultPrefs = DefaultSharedPreferences.getInstance(context) private val defaultPrefs = DefaultSharedPreferences.getInstance(context)
@ -31,7 +33,7 @@ class UnifiedPushStore @Inject constructor(
* *
* @return the UnifiedPush Endpoint or null if not received * @return the UnifiedPush Endpoint or null if not received
*/ */
fun getEndpointOrToken(): String? { fun getEndpoint(): String? {
return defaultPrefs.getString(PREFS_ENDPOINT_OR_TOKEN, null) 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 * @return the Push Gateway or null if not defined
*/ */
fun getPushGateway(): String? { fun getPushGateway(): String {
return defaultPrefs.getString(PREFS_PUSH_GATEWAY, null) 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 (vectorPreferences.areNotificationEnabledForDevice() && activeSessionHolder.hasActiveSession()) {
// If the endpoint has changed // If the endpoint has changed
// or the gateway has changed // or the gateway has changed
if (unifiedPushStore.getEndpointOrToken() != endpoint) { if (unifiedPushHelper.getEndpointOrToken() != endpoint) {
unifiedPushStore.storeUpEndpoint(endpoint) unifiedPushStore.storeUpEndpoint(endpoint)
coroutineScope.launch { coroutineScope.launch {
unifiedPushHelper.storeCustomOrDefaultGateway(endpoint) { unifiedPushHelper.storeCustomOrDefaultGateway(endpoint) {
unifiedPushStore.getPushGateway()?.let { unifiedPushStore.getPushGateway().let {
pushersManager.enqueueRegisterPusher(endpoint, it) pushersManager.enqueueRegisterPusher(endpoint, it)
} }
} }
@ -97,7 +97,7 @@ class VectorMessagingReceiver : MessagingReceiver() {
guardServiceStarter.start() guardServiceStarter.start()
runBlocking { runBlocking {
try { try {
pushersManager.unregisterPusher(unifiedPushStore.getEndpointOrToken().orEmpty()) pushersManager.unregisterPusher(unifiedPushHelper.getEndpointOrToken().orEmpty())
} catch (e: Exception) { } catch (e: Exception) {
Timber.tag(loggerTag.value).d("Probably unregistering a non existing pusher") 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 pushersManager: PushersManager,
private val activeSessionHolder: ActiveSessionHolder, private val activeSessionHolder: ActiveSessionHolder,
private val unifiedPushHelper: UnifiedPushHelper, private val unifiedPushHelper: UnifiedPushHelper,
private val unifiedPushStore: UnifiedPushStore,
) : TroubleshootTest(R.string.settings_troubleshoot_test_endpoint_registration_title) { ) : TroubleshootTest(R.string.settings_troubleshoot_test_endpoint_registration_title) {
override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) { override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) {
// Check if we have a registered pusher for this token // Check if we have a registered pusher for this token
val endpoint = unifiedPushStore.getEndpointOrToken() ?: run { val endpoint = unifiedPushHelper.getEndpointOrToken() ?: run {
status = TestStatus.FAILED status = TestStatus.FAILED
return return
} }