From ffa280bc1b79ffe9fcf403425d2bb97e3e3ae271 Mon Sep 17 00:00:00 2001 From: charles Date: Mon, 3 Oct 2022 13:15:14 +1100 Subject: [PATCH 1/2] fix: Disable typing and message requests in read-only open groups --- .../conversation/v2/ConversationActivityV2.kt | 1 + .../conversation/v2/messages/VisibleMessageView.kt | 5 +++-- .../securesms/groups/OpenGroupManager.kt | 2 +- .../libsession/messaging/open_groups/OpenGroup.kt | 13 ++++++++----- .../sending_receiving/pollers/OpenGroupPoller.kt | 1 + 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index 467be2c0b6b..d4e09b6b67b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -466,6 +466,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe // called from onCreate private fun setUpInputBar() { + binding!!.inputBar.isVisible = viewModel.openGroup == null || viewModel.openGroup?.canWrite == true binding!!.inputBar.delegate = this binding!!.inputBarRecordingView.delegate = this // GIF button diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt index bd68693005f..0507394dbd6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt @@ -153,12 +153,13 @@ class VisibleMessageView : LinearLayout { if (isGroupThread && !message.isOutgoing) { if (isEndOfMessageCluster) { + val openGroup = lokiThreadDb.getOpenGroupChat(threadID) binding.profilePictureView.root.publicKey = senderSessionID binding.profilePictureView.root.glide = glide binding.profilePictureView.root.update(message.individualRecipient) binding.profilePictureView.root.setOnClickListener { if (thread.isOpenGroupRecipient) { - if (IdPrefix.fromValue(senderSessionID) == IdPrefix.BLINDED) { + if (IdPrefix.fromValue(senderSessionID) == IdPrefix.BLINDED && openGroup?.canWrite == true) { val intent = Intent(context, ConversationActivityV2::class.java) intent.putExtra(ConversationActivityV2.FROM_GROUP_THREAD_ID, threadID) intent.putExtra(ConversationActivityV2.ADDRESS, Address.fromSerialized(senderSessionID)) @@ -169,7 +170,7 @@ class VisibleMessageView : LinearLayout { } } if (thread.isOpenGroupRecipient) { - val openGroup = lokiThreadDb.getOpenGroupChat(threadID) ?: return + openGroup ?: return var standardPublicKey = "" var blindedPublicKey: String? = null if (IdPrefix.fromValue(senderSessionID) == IdPrefix.BLINDED) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/OpenGroupManager.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/OpenGroupManager.kt index d39ba709df9..ee83427ab5a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/OpenGroupManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/OpenGroupManager.kt @@ -83,7 +83,7 @@ object OpenGroupManager { if (threadID < 0) { threadID = GroupManager.createOpenGroup(openGroupID, context, null, info.name).threadId } - val openGroup = OpenGroup(server, room, info.name, info.infoUpdates, publicKey) + val openGroup = OpenGroup(server, room, info.name, info.infoUpdates, publicKey, info.write) threadDB.setOpenGroupChat(openGroup, threadID) } diff --git a/libsession/src/main/java/org/session/libsession/messaging/open_groups/OpenGroup.kt b/libsession/src/main/java/org/session/libsession/messaging/open_groups/OpenGroup.kt index 9efeaf15d03..5a31e374d40 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/open_groups/OpenGroup.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/open_groups/OpenGroup.kt @@ -12,15 +12,17 @@ data class OpenGroup( val name: String, val publicKey: String, val infoUpdates: Int, + val canWrite: Boolean, ) { - constructor(server: String, room: String, name: String, infoUpdates: Int, publicKey: String) : this( + constructor(server: String, room: String, name: String, infoUpdates: Int, publicKey: String, canWrite: Boolean) : this( server = server, room = room, id = "$server.$room", name = name, publicKey = publicKey, infoUpdates = infoUpdates, + canWrite = canWrite ) companion object { @@ -29,13 +31,13 @@ data class OpenGroup( return try { val json = JsonUtil.fromJson(jsonAsString) if (!json.has("room")) return null - val room = json.get("room").asText().toLowerCase(Locale.US) - val server = json.get("server").asText().toLowerCase(Locale.US) + val room = json.get("room").asText().lowercase(Locale.US) + val server = json.get("server").asText().lowercase(Locale.US) val displayName = json.get("displayName").asText() val publicKey = json.get("publicKey").asText() val infoUpdates = json.get("infoUpdates")?.asText()?.toIntOrNull() ?: 0 - val capabilities = json.get("capabilities")?.asText()?.split(",") ?: emptyList() - OpenGroup(server, room, displayName, infoUpdates, publicKey) + val canWrite = json.get("canWrite")?.asText()?.toBoolean() ?: true + OpenGroup(server, room, displayName, infoUpdates, publicKey, canWrite) } catch (e: Exception) { Log.w("Loki", "Couldn't parse open group from JSON: $jsonAsString.", e); null @@ -59,6 +61,7 @@ data class OpenGroup( "displayName" to name, "publicKey" to publicKey, "infoUpdates" to infoUpdates.toString(), + "canWrite" to canWrite.toString() ) val joinURL: String get() = "$server/$room?public_key=$publicKey" diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt index 7bb00f8f35c..fba70137184 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt @@ -126,6 +126,7 @@ class OpenGroupPoller(private val server: String, private val executorService: S name = pollInfo.details?.name ?: "", infoUpdates = pollInfo.details?.infoUpdates ?: 0, publicKey = publicKey, + canWrite = pollInfo.write ) // - Open Group changes storage.updateOpenGroup(openGroup) From 99f70e5c216b110a62993bd8fdd8c5ec7dd5e52e Mon Sep 17 00:00:00 2001 From: charles Date: Mon, 3 Oct 2022 13:42:47 +1100 Subject: [PATCH 2/2] Move open group query into click handler --- .../securesms/conversation/v2/messages/VisibleMessageView.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt index 0507394dbd6..834f00ca98d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt @@ -153,12 +153,12 @@ class VisibleMessageView : LinearLayout { if (isGroupThread && !message.isOutgoing) { if (isEndOfMessageCluster) { - val openGroup = lokiThreadDb.getOpenGroupChat(threadID) binding.profilePictureView.root.publicKey = senderSessionID binding.profilePictureView.root.glide = glide binding.profilePictureView.root.update(message.individualRecipient) binding.profilePictureView.root.setOnClickListener { if (thread.isOpenGroupRecipient) { + val openGroup = lokiThreadDb.getOpenGroupChat(threadID) if (IdPrefix.fromValue(senderSessionID) == IdPrefix.BLINDED && openGroup?.canWrite == true) { val intent = Intent(context, ConversationActivityV2::class.java) intent.putExtra(ConversationActivityV2.FROM_GROUP_THREAD_ID, threadID) @@ -170,7 +170,7 @@ class VisibleMessageView : LinearLayout { } } if (thread.isOpenGroupRecipient) { - openGroup ?: return + val openGroup = lokiThreadDb.getOpenGroupChat(threadID) ?: return var standardPublicKey = "" var blindedPublicKey: String? = null if (IdPrefix.fromValue(senderSessionID) == IdPrefix.BLINDED) {