different Pusher AppId

This commit is contained in:
S1m 2021-06-07 13:22:07 +02:00
parent 6c80b3a14b
commit 5f5b873414
7 changed files with 26 additions and 12 deletions

View file

@ -51,7 +51,7 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor(
mgr.addTest(testSystemSettings)
mgr.addTest(testAccountSettings)
mgr.addTest(testDeviceSettings)
if (UPHelper.DistributorExists(fragment.requireContext())) {
if (UPHelper.distributorExists(fragment.requireContext())) {
mgr.addTest(testBingRulesSettings)
mgr.addTest(testNewEndpoint)
mgr.addTest(testTokenRegistration)

View file

@ -53,7 +53,7 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor(
mgr.addTest(testSystemSettings)
mgr.addTest(testAccountSettings)
mgr.addTest(testDeviceSettings)
if (UPHelper.DistributorExists(fragment.requireContext())) {
if (UPHelper.distributorExists(fragment.requireContext())) {
mgr.addTest(testBingRulesSettings)
mgr.addTest(testPlayServices)
mgr.addTest(testNewEndpoint)

View file

@ -39,19 +39,19 @@ class PushersManager @Inject constructor(
currentSession.testPush(
UPHelper.getPushGateway(context)!!,
stringProvider.getString(R.string.pusher_app_id),
getPusherAppId(context),
UPHelper.getUpEndpoint(context)!!,
TEST_EVENT_ID
)
}
fun registerPusher(pushKey: String, gateway: String): UUID {
fun registerPusher(context: Context, pushKey: String, gateway: String): UUID {
val currentSession = activeSessionHolder.getActiveSession()
val profileTag = DEFAULT_PUSHER_FILE_TAG + "_" + abs(currentSession.myUserId.hashCode())
return currentSession.addHttpPusher(
pushKey, // this is the UnifiedPush endpoint
stringProvider.getString(R.string.pusher_app_id),
getPusherAppId(context),
profileTag,
localeProvider.current().language,
appNameProvider.getAppName(),
@ -62,9 +62,17 @@ class PushersManager @Inject constructor(
)
}
suspend fun unregisterPusher(pushKey: String) {
suspend fun unregisterPusher(context: Context, pushKey: String) {
val currentSession = activeSessionHolder.getSafeActiveSession() ?: return
currentSession.removeHttpPusher(pushKey, stringProvider.getString(R.string.pusher_app_id))
currentSession.removeHttpPusher(pushKey, getPusherAppId(context))
}
private fun getPusherAppId(context: Context) : String {
val appId = stringProvider.getString(R.string.pusher_app_id)
return if (UPHelper.isEmbeddedDistributor(context)) {
"${appId}.fcm"
} else
"${appId}.up"
}
companion object {

View file

@ -153,8 +153,14 @@ object UPHelper {
return false
}
fun DistributorExists(context: Context): Boolean {
fun distributorExists(context: Context): Boolean {
val up = Registration()
return up.getDistributor(context).isNotEmpty()
}
fun isEmbeddedDistributor(context: Context) : Boolean {
val up = Registration()
return up.getDistributor(context) == context.packageName
}
}

View file

@ -151,7 +151,7 @@ val upHandler = object: MessagingReceiverHandler {
val gateway = UPHelper.customOrDefaultGateway(context, endpoint)
UPHelper.storePushGateway(context, gateway)
UPHelper.storeUpEndpoint(context, endpoint)
pusherManager.registerPusher(endpoint, gateway)
pusherManager.registerPusher(context, endpoint, gateway)
}
val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_DISABLED
vectorPreferences.setFdroidSyncBackgroundMode(mode)
@ -172,7 +172,7 @@ val upHandler = object: MessagingReceiverHandler {
vectorPreferences.setFdroidSyncBackgroundMode(mode)
runBlocking {
try {
pusherManager.unregisterPusher(UPHelper.getUpEndpoint(context)!!)
pusherManager.unregisterPusher(context, UPHelper.getUpEndpoint(context)!!)
} catch (e: Exception) {
Timber.d("Probably unregistering a non existant pusher")
}

View file

@ -296,7 +296,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
lifecycleScope.launch {
runCatching {
try {
pushManager.unregisterPusher(it)
pushManager.unregisterPusher(requireContext(), it)
} catch (e: Exception) {
Timber.d("Probably unregistering a non existant pusher")
}

View file

@ -60,7 +60,7 @@ class TestTokenRegistration @Inject constructor(private val context: AppCompatAc
stringProvider.getString(R.string.sas_error_unknown))
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_token_registration_quick_fix) {
override fun doFix() {
val workId = pushersManager.registerPusher(pushToken, pushGateway)
val workId = pushersManager.registerPusher(context, pushToken, pushGateway)
WorkManager.getInstance(context).getWorkInfoByIdLiveData(workId).observe(context, Observer { workInfo ->
if (workInfo != null) {
if (workInfo.state == WorkInfo.State.SUCCEEDED) {