diff --git a/app/src/unifiedpush/java/im/molly/unifiedpush/components/settings/app/notifications/UnifiedPushSettingsViewModel.kt b/app/src/unifiedpush/java/im/molly/unifiedpush/components/settings/app/notifications/UnifiedPushSettingsViewModel.kt
index 90d81b8b7a..7966ca4577 100644
--- a/app/src/unifiedpush/java/im/molly/unifiedpush/components/settings/app/notifications/UnifiedPushSettingsViewModel.kt
+++ b/app/src/unifiedpush/java/im/molly/unifiedpush/components/settings/app/notifications/UnifiedPushSettingsViewModel.kt
@@ -108,6 +108,8 @@ class UnifiedPushSettingsViewModel(private val application: Application) : ViewM
} ?: return
} else {
UnifiedPush.unregisterApp(application)
+ SignalStore.unifiedpush().airGaped = false
+ SignalStore.unifiedpush().mollySocketUrl = null
processNewStatus()
}
}
diff --git a/app/src/unifiedpush/java/im/molly/unifiedpush/jobs/UnifiedPushRefreshJob.kt b/app/src/unifiedpush/java/im/molly/unifiedpush/jobs/UnifiedPushRefreshJob.kt
index a6bda6dc81..7fa23cff86 100644
--- a/app/src/unifiedpush/java/im/molly/unifiedpush/jobs/UnifiedPushRefreshJob.kt
+++ b/app/src/unifiedpush/java/im/molly/unifiedpush/jobs/UnifiedPushRefreshJob.kt
@@ -1,9 +1,11 @@
+
package im.molly.unifiedpush.jobs
import im.molly.unifiedpush.model.RegistrationStatus
import im.molly.unifiedpush.model.saveStatus
import im.molly.unifiedpush.util.MollySocketRequest
import im.molly.unifiedpush.util.UnifiedPushHelper
+import im.molly.unifiedpush.util.UnifiedPushNotificationBuilder
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.jobmanager.Data
@@ -46,12 +48,9 @@ class UnifiedPushRefreshJob private constructor(parameters: Parameters) : BaseJo
Log.w(TAG, "The registration status has changed!")
status.saveStatus()
ApplicationContext.getInstance().initializeFcmCheck()
- // TODO: alert user
+ UnifiedPushNotificationBuilder(context).setNotificationMollySocketRegistrationChanged()
}
}
- } else {
- ApplicationContext.getInstance().initializeFcmCheck()
- // TODO: alert user
}
}
diff --git a/app/src/unifiedpush/java/im/molly/unifiedpush/receiver/UnifiedPushReceiver.kt b/app/src/unifiedpush/java/im/molly/unifiedpush/receiver/UnifiedPushReceiver.kt
index 0420165d2b..3c5617316d 100644
--- a/app/src/unifiedpush/java/im/molly/unifiedpush/receiver/UnifiedPushReceiver.kt
+++ b/app/src/unifiedpush/java/im/molly/unifiedpush/receiver/UnifiedPushReceiver.kt
@@ -9,6 +9,7 @@ import im.molly.unifiedpush.model.UnifiedPushStatus
import im.molly.unifiedpush.model.saveStatus
import im.molly.unifiedpush.util.MollySocketRequest
import im.molly.unifiedpush.util.UnifiedPushHelper
+import im.molly.unifiedpush.util.UnifiedPushNotificationBuilder
import org.greenrobot.eventbus.EventBus
import org.signal.core.util.concurrent.SignalExecutors
import org.signal.core.util.logging.Log
@@ -32,18 +33,23 @@ class UnifiedPushReceiver : MessagingReceiver() {
SignalStore.unifiedpush().endpoint = endpoint
when (SignalStore.unifiedpush().status) {
UnifiedPushStatus.AIR_GAPED -> {
- // TODO: alert if air gaped and endpoint changes
EventBus.getDefault().post(UnifiedPushRegistrationEvent)
+ UnifiedPushNotificationBuilder(context).setNotificationEndpointChangedAirGaped()
+ }
+ UnifiedPushStatus.OK -> {
+ EXECUTOR.enqueue {
+ MollySocketRequest.registerToMollySocketServer().saveStatus()
+ EventBus.getDefault().post(UnifiedPushRegistrationEvent)
+ UnifiedPushNotificationBuilder(context).setNotificationEndpointChangedError()
+ }
}
in listOf(
UnifiedPushStatus.INTERNAL_ERROR,
UnifiedPushStatus.MISSING_ENDPOINT,
- UnifiedPushStatus.OK,
) -> {
EXECUTOR.enqueue {
MollySocketRequest.registerToMollySocketServer().saveStatus()
EventBus.getDefault().post(UnifiedPushRegistrationEvent)
- // TODO: alert if status changes from Ok to something else
}
}
else -> {
@@ -55,7 +61,7 @@ class UnifiedPushReceiver : MessagingReceiver() {
override fun onRegistrationFailed(context: Context, instance: String) {
// called when the registration is not possible, eg. no network
- // TODO: alert user the registration has failed
+ UnifiedPushNotificationBuilder(context).setNotificationRegistrationFailed()
}
override fun onUnregistered(context: Context, instance: String) {
diff --git a/app/src/unifiedpush/java/im/molly/unifiedpush/util/UnifiedPushNotificationBuilder.kt b/app/src/unifiedpush/java/im/molly/unifiedpush/util/UnifiedPushNotificationBuilder.kt
new file mode 100644
index 0000000000..05868e7e1d
--- /dev/null
+++ b/app/src/unifiedpush/java/im/molly/unifiedpush/util/UnifiedPushNotificationBuilder.kt
@@ -0,0 +1,46 @@
+package im.molly.unifiedpush.util
+
+import android.app.Notification
+import android.app.NotificationManager
+import android.content.Context
+import androidx.core.app.NotificationCompat
+import org.thoughtcrime.securesms.R
+import org.thoughtcrime.securesms.notifications.NotificationChannels
+
+class UnifiedPushNotificationBuilder(val context: Context) {
+
+ private val NOTIFICATION_ID_UNIFIEDPUSH = 51215
+
+ private val builder: NotificationCompat.Builder = NotificationCompat.Builder(context, NotificationChannels.getInstance().APP_ALERTS)
+ .setSmallIcon(R.drawable.ic_notification)
+ .setContentTitle(context.getString(R.string.UnifiedPushNotificationBuilder__title))
+ .setContentIntent(null)
+ .setPriority(NotificationCompat.PRIORITY_DEFAULT)
+
+ private fun getNotification(content: String): Notification {
+ return builder.setContentText(content).setStyle(
+ NotificationCompat.BigTextStyle()
+ .bigText(content)
+ ).build()
+ }
+
+ fun setNotificationMollySocketRegistrationChanged() {
+ (context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager)
+ .notify(NOTIFICATION_ID_UNIFIEDPUSH, getNotification(context.getString(R.string.UnifiedPushNotificationBuilder__mollysocket_registration_changed)))
+ }
+
+ fun setNotificationEndpointChangedAirGaped() {
+ (context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager)
+ .notify(NOTIFICATION_ID_UNIFIEDPUSH, getNotification(context.getString(R.string.UnifiedPushNotificationBuilder__endpoint_changed_airgaped)))
+ }
+
+ fun setNotificationEndpointChangedError() {
+ (context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager)
+ .notify(NOTIFICATION_ID_UNIFIEDPUSH, getNotification(context.getString(R.string.UnifiedPushNotificationBuilder__endpoint_changed_error)))
+ }
+
+ fun setNotificationRegistrationFailed() {
+ (context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager)
+ .notify(NOTIFICATION_ID_UNIFIEDPUSH, getNotification(context.getString(R.string.UnifiedPushNotificationBuilder__registration_failed)))
+ }
+}
diff --git a/app/src/unifiedpush/res/values/strings.xml b/app/src/unifiedpush/res/values/strings.xml
index 618ff59599..2d078f90bf 100644
--- a/app/src/unifiedpush/res/values/strings.xml
+++ b/app/src/unifiedpush/res/values/strings.xml
@@ -35,4 +35,9 @@
Unknown error
The websocket strategy may drain a little more battery but reduces the number of requests sent to the provider.
Enable if your MollySocket server can\'t be reach on the Internet. You will have to register the connection manually
+ UnifiedPush
+ Your registration on MollySocket isn\'t valid anymore. Try to remove the linked device and register again.
+ Your UnifiedPush endpoint has changed. You must update your connection on MollySocket.
+ An error occurred while changing your UnifiedPush endpoint. Try to register again to MollySocket.
+ Your UnifiedPush distributor refused the registration. You may not have any connection or a requirement is missing for your distributor.
\ No newline at end of file