Prevent renaming of MollySocket device

Closes mollyim/mollysocket#83
This commit is contained in:
Oscar Mira 2025-04-07 01:50:22 +02:00
parent 75a14fe543
commit 6351f730a2
No known key found for this signature in database
GPG key ID: B371B98C5DC32237
5 changed files with 10 additions and 3 deletions

View file

@ -41,6 +41,9 @@ class UnifiedPushValues(store: KeyValueStore) : SignalStoreValues(store) {
.apply()
}
fun isMollySocketDevice(deviceId: Int): Boolean =
deviceId != 0 && getInteger(MOLLYSOCKET_DEVICE_ID, 0) == deviceId
var registrationStatus: RegistrationStatus
get() = RegistrationStatus.fromValue(getInteger(MOLLYSOCKET_STATUS, -1)) ?: RegistrationStatus.UNKNOWN
set(status) {

View file

@ -3,4 +3,4 @@ package org.thoughtcrime.securesms.linkdevice
/**
* Class that represents a linked device
*/
data class Device(val id: Int, val name: String?, val createdMillis: Long, val lastSeenMillis: Long)
data class Device(val id: Int, val name: String?, val createdMillis: Long, val lastSeenMillis: Long, val canRename: Boolean = true)

View file

@ -578,6 +578,7 @@ fun DeviceRow(device: Device, setDeviceToRemove: (Device) -> Unit, onEditDevice:
)
}
},
enabled = device.canRename,
onClick = {
onEditDevice(device)
controller.hide()

View file

@ -85,7 +85,8 @@ object LinkDeviceRepository {
}
private fun DeviceInfo.toDevice(): Device {
val defaultDevice = Device(getId(), getName(), getCreated(), getLastSeen())
val canRename = !SignalStore.unifiedpush.isMollySocketDevice(getId())
val defaultDevice = Device(getId(), getName(), getCreated(), getLastSeen(), canRename = canRename)
try {
if (getName().isNullOrEmpty() || getName().length < 4) {
Log.w(TAG, "Invalid DeviceInfo name.")
@ -104,7 +105,7 @@ object LinkDeviceRepository {
return defaultDevice
}
return Device(getId(), String(plaintext), getCreated(), getLastSeen())
return Device(getId(), String(plaintext), getCreated(), getLastSeen(), canRename = canRename)
} catch (e: Exception) {
Log.w(TAG, "Failed while reading the protobuf.", e)
}

View file

@ -60,12 +60,14 @@ object DropdownMenus {
contentPadding: PaddingValues = PaddingValues(horizontal = 16.dp),
text: @Composable () -> Unit,
onClick: () -> Unit,
enabled: Boolean = true,
modifier: Modifier = Modifier
) {
DropdownMenuItem(
contentPadding = contentPadding,
text = text,
onClick = onClick,
enabled = enabled,
modifier = modifier
)
}