Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Consider UP correctly setup once a ping from MollySocket is received
Browse files Browse the repository at this point in the history
  • Loading branch information
p1gp1g authored and valldrac committed Oct 24, 2024
1 parent 34b6498 commit 3751e63
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,22 @@ class InternalSettingsFragment : DSLSettingsFragment(R.string.preferences__inter
}
)

clickPref(
title = DSLSettingsText.from("Delete UnifiedPush ping"),
summary = DSLSettingsText.from("Make as Molly never received the ping from MollySocket. Will cause UnifiedPush to stop and Websocket to restart."),
onClick = {
MaterialAlertDialogBuilder(requireContext())
.setTitle("Delete UnifiedPush ping?")
.setMessage("Are you sure?")
.setPositiveButton(android.R.string.ok) { _, _ ->
SignalStore.unifiedpush.pinged = false
Toast.makeText(requireContext(), "UnifiedPush ping deleted!", Toast.LENGTH_SHORT).show()
}
.setNegativeButton(android.R.string.cancel, null)
.show()
}
)

dividerPref()

sectionHeaderPref(DSLSettingsText.from("Logging"))
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@
<string name="UnifiedPushSettingsFragment__status_summary_air_gaped">OK: Air Gapped</string>
<string name="UnifiedPushSettingsFragment__status_summary_mollysocket_url_missing">MollySocket url missing</string>
<string name="UnifiedPushSettingsFragment__status_summary_pending">Pending</string>
<string name="UnifiedPushSettingsFragment__status_summary_not_pinged">Waiting for test notification</string>
<string name="UnifiedPushSettingsFragment__status_summary_air_gaped_not_pinged">Air Gapped, waiting for test notification</string>
<string name="UnifiedPushSettingsFragment__status_summary_mollysocket_server_not_found">MollySocket server not found</string>
<string name="UnifiedPushSettingsFragment__status_summary_internal_error">An internal Error occurred, please try again</string>
<string name="UnifiedPushSettingsFragment__status_summary_forbidden_uuid">The account ID is refused by the server</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ class UnifiedPushSettingsFragment : DSLSettingsFragment(R.string.NotificationsSe
UnifiedPushStatus.FORBIDDEN_ENDPOINT -> getString(R.string.UnifiedPushSettingsFragment__status_summary_forbidden_endpoint)
UnifiedPushStatus.NO_DISTRIBUTOR -> getString(R.string.UnifiedPushSettingsFragment__status_summary_no_distributor)
UnifiedPushStatus.PENDING -> getString(R.string.UnifiedPushSettingsFragment__status_summary_pending)
UnifiedPushStatus.AIR_GAPED_NOT_PINGED -> getString(R.string.UnifiedPushSettingsFragment__status_summary_air_gaped_not_pinged)
UnifiedPushStatus.NOT_PINGED -> getString(R.string.UnifiedPushSettingsFragment__status_summary_not_pinged)
UnifiedPushStatus.OK -> getString(R.string.UnifiedPushSettingsFragment__ok)
UnifiedPushStatus.INTERNAL_ERROR -> getString(R.string.UnifiedPushSettingsFragment__status_summary_internal_error)
UnifiedPushStatus.UNKNOWN -> getString(R.string.UnifiedPushSettingsFragment__status_summary_unknown_error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class MollySocketLinkedDevice(val context: Context) {
}
device = SignalStore.unifiedpush.device
?: run {
SignalStore.unifiedpush.pinged = false
newDevice()
SignalStore.unifiedpush.device
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class UnifiedPushRefreshJob private constructor(parameters: Parameters) : BaseJo
UnifiedPushStatus.MISSING_ENDPOINT,
UnifiedPushStatus.NO_DISTRIBUTOR,
UnifiedPushStatus.LINK_DEVICE_ERROR,
UnifiedPushStatus.AIR_GAPED_NOT_PINGED,
UnifiedPushStatus.SERVER_NOT_FOUND_AT_URL-> {
Log.i(TAG, "UnifiedPush enabled, but this is currently unavailable. Status=$status.")
reInitializeNotificationServices()
Expand All @@ -81,6 +82,7 @@ class UnifiedPushRefreshJob private constructor(parameters: Parameters) : BaseJo
// We try to register to MollySocket server,
// Then re-init the services
UnifiedPushStatus.PENDING,
UnifiedPushStatus.NOT_PINGED,
UnifiedPushStatus.FORBIDDEN_UUID,
UnifiedPushStatus.FORBIDDEN_ENDPOINT,
UnifiedPushStatus.INTERNAL_ERROR -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ enum class UnifiedPushStatus {
NO_DISTRIBUTOR,
PENDING,
LINK_DEVICE_ERROR,
AIR_GAPED_NOT_PINGED,
NOT_PINGED,
OK,
INTERNAL_ERROR,
UNKNOWN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class UnifiedPushReceiver : MessagingReceiver() {
val msg = message.toString(Charsets.UTF_8)
if (msg.contains("\"test\":true")) {
Log.d(TAG, "Test message received.")
SignalStore.unifiedpush.pinged = true
UnifiedPushNotificationBuilder(context).setNotificationTest()
AppDependencies.jobManager.add(UnifiedPushRefreshJob())
return
}
if (KeyCachingService.isLocked()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class UnifiedPushValues(store: KeyValueStore) : SignalStoreValues(store) {
private const val UNIFIEDPUSH_ENABLED = "unifiedpush.enabled"
private const val UNIFIEDPUSH_PENDING = "unifiedpush.pending"
private const val UNIFIEDPUSH_AIR_GAPED = "unifiedpush.air_gaped"
private const val UNIFIEDPUSH_PINGED = "unifiedpush.pinged"
}

override fun onFirstEverAppLaunch() = Unit
Expand Down Expand Up @@ -50,6 +51,11 @@ class UnifiedPushValues(store: KeyValueStore) : SignalStoreValues(store) {

var airGaped: Boolean by booleanValue(UNIFIEDPUSH_AIR_GAPED, false)

// This is set to true by default to avoid warning previous users,
// It is set to false when registering a new device in
// im.molly.unifiedpush.device.MollySocketLinkedDevice
var pinged: Boolean by booleanValue(UNIFIEDPUSH_PINGED, true)

var mollySocketUrl: String? by stringValue(MOLLYSOCKET_URL, null)

var mollySocketFound: Boolean by booleanValue(MOLLYSOCKET_OK, false)
Expand All @@ -66,12 +72,15 @@ class UnifiedPushValues(store: KeyValueStore) : SignalStoreValues(store) {
SignalStore.unifiedpush.pending -> UnifiedPushStatus.PENDING
SignalStore.unifiedpush.device == null -> UnifiedPushStatus.LINK_DEVICE_ERROR
SignalStore.unifiedpush.endpoint == null -> UnifiedPushStatus.MISSING_ENDPOINT
SignalStore.unifiedpush.airGaped &&
!SignalStore.unifiedpush.pinged -> UnifiedPushStatus.AIR_GAPED_NOT_PINGED
SignalStore.unifiedpush.airGaped -> UnifiedPushStatus.AIR_GAPED
SignalStore.unifiedpush.mollySocketUrl.isNullOrBlank() ||
!SignalStore.unifiedpush.mollySocketFound -> UnifiedPushStatus.SERVER_NOT_FOUND_AT_URL
SignalStore.unifiedpush.mollySocketInternalError -> UnifiedPushStatus.INTERNAL_ERROR
SignalStore.unifiedpush.forbiddenUuid -> UnifiedPushStatus.FORBIDDEN_UUID
SignalStore.unifiedpush.forbiddenEndpoint -> UnifiedPushStatus.FORBIDDEN_ENDPOINT
!SignalStore.unifiedpush.pinged -> UnifiedPushStatus.NOT_PINGED
else -> UnifiedPushStatus.OK
}
}

0 comments on commit 3751e63

Please sign in to comment.