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: Disable typing and message requests in read-only open groups #990

Merged
merged 3 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ class VisibleMessageView : LinearLayout {
binding.profilePictureView.root.update(message.individualRecipient)
binding.profilePictureView.root.setOnClickListener {
if (thread.isOpenGroupRecipient) {
if (IdPrefix.fromValue(senderSessionID) == IdPrefix.BLINDED) {
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)
intent.putExtra(ConversationActivityV2.ADDRESS, Address.fromSerialized(senderSessionID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down