Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mollysocket refused status #393

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/src/main/res/values/strings2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,15 @@
<string name="UnifiedPushSettingsFragment__status_summary_missing_endpoint">Waiting for UnifiedPush distributor response</string>
<string name="UnifiedPushSettingsFragment__status_summary_forbidden_endpoint">The endpoint is forbidden by the server</string>
<string name="UnifiedPushSettingsFragment__status_summary_no_distributor">No UnifiedPush distributor installed</string>
<string name="UnifiedPushSettingsFragment__status_summary_bad_password">The registration is no longer valid</string>
<string name="UnifiedPushSettingsFragment__status_summary_distributor_not_selected">No distributor app selected</string>
<string name="UnifiedPushSettingsFragment__air_gapped_summary">Enable if your MollySocket server can\'t be reached from the internet. You\'ll need to manually add your account to the server.</string>
<string name="UnifiedPushSettingsViewModel__mollysocket_server_not_found">"MollySocket server not found. Please check the URL and try again."</string>
<string name="UnifiedPushNotificationBuilder__mollysocket_device_limit_hit">You\'ve reached the limit of %d linked devices. To link your MollySocket server, please remove a device first.</string>
<string name="UnifiedPushNotificationBuilder__endpoint_changed_air_gapped">Your UnifiedPush endpoint has changed. You must update your connection on MollySocket.</string>
<string name="UnifiedPushNotificationBuilder__mollysocket_registration_changed">Your registration on MollySocket is no longer valid. Please remove the linked device and try registering again.</string>
<string name="UnifiedPushNotificationBuilder__mollysocket_forbidden_password">Your registration on MollySocket is no longer valid. Please remove the linked device and try registering again.</string>
<string name="UnifiedPushNotificationBuilder__mollysocket_forbidden_uuid">Your MollySocket server is configured to refuse this account.</string>
<string name="UnifiedPushNotificationBuilder__mollysocket_forbidden_endpoint">Your MollySocket server is configured to refuse this push server.</string>
<string name="UnifiedPushNotificationBuilder__registration_failed">Registration with your UnifiedPush distributor failed. This could be due to a network issue or a missing requirement from your distributor.</string>
<string name="UnifiedPushNotificationBuilder__this_is_a_test_notification">This is a test notification from the MollySocket server.</string>
<string name="NotificationDeliveryMethod__unifiedpush" translatable="false">UnifiedPush</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,17 @@ class UnifiedPushNotificationBuilder(val context: Context) {
notify(NOTIFICATION_ID, context.getString(R.string.UnifiedPushNotificationBuilder__mollysocket_device_limit_hit, deviceLimit - 1))
}

fun setNotificationMollySocketRegistrationChanged() {
notify(NOTIFICATION_ID, context.getString(R.string.UnifiedPushNotificationBuilder__mollysocket_registration_changed))

fun setNotificationMollySocketForbiddenEndpoint() {
notify(NOTIFICATION_ID, context.getString(R.string.UnifiedPushNotificationBuilder__mollysocket_forbidden_endpoint))
}

fun setNotificationMollySocketForbiddenUuid() {
notify(NOTIFICATION_ID, context.getString(R.string.UnifiedPushNotificationBuilder__mollysocket_forbidden_uuid))
}

fun setNotificationMollySocketForbiddenPassword() {
notify(NOTIFICATION_ID, context.getString(R.string.UnifiedPushNotificationBuilder__mollysocket_forbidden_password))
}

fun setNotificationEndpointChangedAirGapped() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class UnifiedPushSettingsFragment : DSLSettingsFragment(R.string.NotificationDel
RegistrationStatus.SERVER_ERROR -> R.string.UnifiedPushSettingsFragment__status_summary_bad_response

RegistrationStatus.REGISTERED -> android.R.string.ok
RegistrationStatus.FORBIDDEN_PASSWORD -> R.string.UnifiedPushSettingsFragment__status_summary_bad_password
RegistrationStatus.FORBIDDEN_UUID -> R.string.UnifiedPushSettingsFragment__status_summary_forbidden_uuid
RegistrationStatus.FORBIDDEN_ENDPOINT -> R.string.UnifiedPushSettingsFragment__status_summary_forbidden_endpoint
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ class UnifiedPushRefreshJob private constructor(
SignalStore.unifiedpush.registrationStatus = newStatus
}

if (newStatus == RegistrationStatus.REGISTERED) {
UnifiedPushNotificationBuilder(context).clearAlerts()
} else if (newStatus.notifyUser) {
UnifiedPushNotificationBuilder(context).setNotificationMollySocketRegistrationChanged()
when (newStatus) {
RegistrationStatus.REGISTERED -> UnifiedPushNotificationBuilder(context).clearAlerts()
RegistrationStatus.FORBIDDEN_ENDPOINT -> UnifiedPushNotificationBuilder(context).setNotificationMollySocketForbiddenEndpoint()
RegistrationStatus.FORBIDDEN_UUID -> UnifiedPushNotificationBuilder(context).setNotificationMollySocketForbiddenUuid()
RegistrationStatus.FORBIDDEN_PASSWORD -> UnifiedPushNotificationBuilder(context).setNotificationMollySocketForbiddenPassword()
else -> {}
}
} catch (t: Throwable) {
Log.e(TAG, "Error checking registration status", t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ data class MollySocketDevice(
}
}

enum class RegistrationStatus(val value: Int, val notifyUser: Boolean = false) {
enum class RegistrationStatus(val value: Int) {
UNKNOWN(0),
PENDING(1),
REGISTERED(2),
BAD_RESPONSE(3),
SERVER_ERROR(4),
FORBIDDEN_UUID(5, notifyUser = true),
FORBIDDEN_ENDPOINT(6, notifyUser = true);
/** The UUID is forbidden by the config of MollySocket */
FORBIDDEN_UUID(5),
/** The endpoint is forbidden by the config of MollySocket */
FORBIDDEN_ENDPOINT(6),
/** The account+password doesn't work anymore, and returns forbidden by Signal server */
FORBIDDEN_PASSWORD(7);

companion object {
fun fromValue(value: Int): RegistrationStatus? {
Expand All @@ -27,8 +31,8 @@ enum class RegistrationStatus(val value: Int, val notifyUser: Boolean = false) {

fun ConnectionResult?.toRegistrationStatus():RegistrationStatus = when (this) {
ConnectionResult.OK -> RegistrationStatus.REGISTERED
ConnectionResult.INTERNAL_ERROR,
ConnectionResult.FORBIDDEN -> RegistrationStatus.SERVER_ERROR
ConnectionResult.INTERNAL_ERROR -> RegistrationStatus.SERVER_ERROR
ConnectionResult.FORBIDDEN -> RegistrationStatus.FORBIDDEN_PASSWORD
ConnectionResult.INVALID_UUID -> RegistrationStatus.FORBIDDEN_UUID
ConnectionResult.INVALID_ENDPOINT -> RegistrationStatus.FORBIDDEN_ENDPOINT
null -> RegistrationStatus.BAD_RESPONSE
Expand Down