Skip to content

Commit

Permalink
Show dialog to register UnifiedPush again if needed
Browse files Browse the repository at this point in the history
on MainActivity. This could occur if the Distributor unregister
Molly or if the distributor has been uninstalled
  • Loading branch information
p1gp1g committed Jan 24, 2024
1 parent 4e61ad6 commit dd89bec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.thoughtcrime.securesms.util.SplashScreenUtil;
import org.thoughtcrime.securesms.util.WindowUtil;

import static im.molly.unifiedpush.util.UnifiedPushHelper.registerAppWithDialogIfNeeded;

public class MainActivity extends PassphraseRequiredActivity implements VoiceNoteMediaControllerOwner {

public static final int RESULT_CONFIG_CHANGED = Activity.RESULT_FIRST_USER + 901;
Expand Down Expand Up @@ -92,6 +94,8 @@ public boolean onPreDraw() {

conversationListTabsViewModel = new ViewModelProvider(this, factory).get(ConversationListTabsViewModel.class);
updateTabVisibility();

registerAppWithDialogIfNeeded(this);
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,9 @@
<string name="NotificationMethod__label_unifiedpush">UnifiedPush</string>
<string name="NotificationMethod__label_fcm">Google Services</string>
<string name="NotificationMethod__label_websocket">WebSocket</string>
<string name="UnifiedPush_RegistrationDialog_NoDistrib_title">No notification method found</string>
<string name="UnifiedPush_RegistrationDialog_NoDistrib_message">You have configure Molly to use UnifiedPush, but you haven\'t installed any distributor. For more information, visit https://unifiedpush.org/</string>
<string name="UnifiedPush_RegistrationDialog_NoDistrib_ok">OK</string>
<string name="UnifiedPush_RegistrationDialog_NoDistrib_ignore">Ignore</string>
<string name="UnifiedPush_RegistrationDialog_Choose_title">Choose your notification method</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import android.content.Context
import im.molly.unifiedpush.device.MollySocketLinkedDevice
import im.molly.unifiedpush.model.UnifiedPushStatus
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.unifiedpush.android.connector.ChooseDialog
import org.unifiedpush.android.connector.NoDistributorDialog
import org.unifiedpush.android.connector.RegistrationDialogContent
import org.unifiedpush.android.connector.UnifiedPush

object UnifiedPushHelper {
Expand All @@ -25,6 +29,23 @@ object UnifiedPushHelper {
return true
}

@JvmStatic
fun registerAppWithDialogIfNeeded(context: Context) {
checkDistributorPresence(context)
if (SignalStore.unifiedpush().status == UnifiedPushStatus.MISSING_ENDPOINT) {
val dialogContent = RegistrationDialogContent(
noDistributorDialog = NoDistributorDialog(
title = context.getString(R.string.UnifiedPush_RegistrationDialog_NoDistrib_title),
message = context.getString(R.string.UnifiedPush_RegistrationDialog_NoDistrib_message),
okButton = context.getString(R.string.UnifiedPush_RegistrationDialog_NoDistrib_ok),
ignoreButton = context.getString(R.string.UnifiedPush_RegistrationDialog_NoDistrib_ignore)
),
chooseDialog = ChooseDialog(context.getString(R.string.UnifiedPush_RegistrationDialog_Choose_title))
)
UnifiedPush.registerAppWithDialog(context, registrationDialogContent = dialogContent)
}
}

@JvmStatic
fun isUnifiedPushAvailable(): Boolean {
return SignalStore.unifiedpush().status in listOf(UnifiedPushStatus.OK, UnifiedPushStatus.AIR_GAPED)
Expand Down

0 comments on commit dd89bec

Please sign in to comment.