Skip to content

Commit 5115717

Browse files
Show internal conversation settings for groups.
1 parent 33ac48e commit 5115717

File tree

4 files changed

+111
-89
lines changed

4 files changed

+111
-89
lines changed

app/src/main/java/org/thoughtcrime/securesms/components/settings/conversation/ConversationSettingsFragment.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -314,18 +314,16 @@ class ConversationSettingsFragment : DSLSettingsFragment(
314314
}
315315
}
316316

317-
state.withRecipientSettingsState { recipientState ->
318-
if (recipientState.displayInternalRecipientDetails) {
319-
customPref(
320-
InternalPreference.Model(
321-
recipient = state.recipient,
322-
onInternalDetailsClicked = {
323-
val action = ConversationSettingsFragmentDirections.actionConversationSettingsFragmentToInternalDetailsSettingsFragment(state.recipient.id)
324-
navController.navigate(action)
325-
}
326-
)
317+
if (state.displayInternalRecipientDetails) {
318+
customPref(
319+
InternalPreference.Model(
320+
recipient = state.recipient,
321+
onInternalDetailsClicked = {
322+
val action = ConversationSettingsFragmentDirections.actionConversationSettingsFragmentToInternalDetailsSettingsFragment(state.recipient.id)
323+
navController.navigate(action)
324+
}
327325
)
328-
}
326+
)
329327
}
330328

331329
customPref(

app/src/main/java/org/thoughtcrime/securesms/components/settings/conversation/ConversationSettingsState.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ data class ConversationSettingsState(
1616
val canModifyBlockedState: Boolean = false,
1717
val sharedMedia: Cursor? = null,
1818
val sharedMediaIds: List<Long> = listOf(),
19+
val displayInternalRecipientDetails: Boolean = false,
1920
private val sharedMediaLoaded: Boolean = false,
2021
private val specificSettingsState: SpecificSettingsState,
2122
) {
@@ -49,8 +50,7 @@ sealed class SpecificSettingsState {
4950
val selfHasGroups: Boolean = false,
5051
val canShowMoreGroupsInCommon: Boolean = false,
5152
val groupsInCommonExpanded: Boolean = false,
52-
val contactLinkState: ContactLinkState = ContactLinkState.NONE,
53-
val displayInternalRecipientDetails: Boolean
53+
val contactLinkState: ContactLinkState = ContactLinkState.NONE
5454
) : SpecificSettingsState() {
5555

5656
override val isLoaded: Boolean = true

app/src/main/java/org/thoughtcrime/securesms/components/settings/conversation/ConversationSettingsViewModel.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ sealed class ConversationSettingsViewModel(
7171
state.copy(
7272
sharedMedia = cursor.orNull(),
7373
sharedMediaIds = ids,
74-
sharedMediaLoaded = true
74+
sharedMediaLoaded = true,
75+
displayInternalRecipientDetails = repository.isInternalRecipientDetailsEnabled()
7576
)
7677
} else {
7778
cursor.orNull().ensureClosed()
@@ -121,9 +122,7 @@ sealed class ConversationSettingsViewModel(
121122
private val repository: ConversationSettingsRepository
122123
) : ConversationSettingsViewModel(
123124
repository,
124-
SpecificSettingsState.RecipientSettingsState(
125-
displayInternalRecipientDetails = repository.isInternalRecipientDetailsEnabled()
126-
)
125+
SpecificSettingsState.RecipientSettingsState()
127126
) {
128127

129128
private val liveRecipient = Recipient.live(recipientId)

app/src/main/java/org/thoughtcrime/securesms/components/settings/conversation/InternalConversationSettingsFragment.kt

Lines changed: 97 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.thoughtcrime.securesms.components.settings.conversation
22

3+
import android.content.Context
34
import android.graphics.Color
45
import android.text.TextUtils
56
import android.widget.Toast
@@ -16,6 +17,7 @@ import org.thoughtcrime.securesms.components.settings.DSLSettingsText
1617
import org.thoughtcrime.securesms.components.settings.configure
1718
import org.thoughtcrime.securesms.database.DatabaseFactory
1819
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
20+
import org.thoughtcrime.securesms.groups.GroupId
1921
import org.thoughtcrime.securesms.recipients.Recipient
2022
import org.thoughtcrime.securesms.recipients.RecipientForeverObserver
2123
import org.thoughtcrime.securesms.recipients.RecipientId
@@ -57,12 +59,23 @@ class InternalConversationSettingsFragment : DSLSettingsFragment(
5759
summary = DSLSettingsText.from(recipient.id.serialize())
5860
)
5961

60-
val uuid = recipient.uuid.transform(UUID::toString).or("null")
61-
longClickPref(
62-
title = DSLSettingsText.from("UUID"),
63-
summary = DSLSettingsText.from(uuid),
64-
onLongClick = { copyToClipboard(uuid) }
65-
)
62+
if (!recipient.isGroup) {
63+
val uuid = recipient.uuid.transform(UUID::toString).or("null")
64+
longClickPref(
65+
title = DSLSettingsText.from("UUID"),
66+
summary = DSLSettingsText.from(uuid),
67+
onLongClick = { copyToClipboard(uuid) }
68+
)
69+
}
70+
71+
if (state.groupId != null) {
72+
val groupId: String = state.groupId.toString()
73+
longClickPref(
74+
title = DSLSettingsText.from("GroupId"),
75+
summary = DSLSettingsText.from(groupId),
76+
onLongClick = { copyToClipboard(groupId) }
77+
)
78+
}
6679

6780
val threadId: String = if (state.threadId != null) state.threadId.toString() else "N/A"
6881
longClickPref(
@@ -71,72 +84,78 @@ class InternalConversationSettingsFragment : DSLSettingsFragment(
7184
onLongClick = { copyToClipboard(threadId) }
7285
)
7386

74-
textPref(
75-
title = DSLSettingsText.from("Profile Name"),
76-
summary = DSLSettingsText.from("[${recipient.profileName.givenName}] [${state.recipient.profileName.familyName}]")
77-
)
78-
79-
val profileKeyBase64 = recipient.profileKey?.let(Base64::encodeBytes) ?: "None"
80-
longClickPref(
81-
title = DSLSettingsText.from("Profile Key (Base64)"),
82-
summary = DSLSettingsText.from(profileKeyBase64),
83-
onLongClick = { copyToClipboard(profileKeyBase64) }
84-
)
85-
86-
val profileKeyHex = recipient.profileKey?.let(Hex::toStringCondensed) ?: ""
87-
longClickPref(
88-
title = DSLSettingsText.from("Profile Key (Hex)"),
89-
summary = DSLSettingsText.from(profileKeyHex),
90-
onLongClick = { copyToClipboard(profileKeyHex) }
91-
)
92-
93-
textPref(
94-
title = DSLSettingsText.from("Sealed Sender Mode"),
95-
summary = DSLSettingsText.from(recipient.unidentifiedAccessMode.toString())
96-
)
87+
if (!recipient.isGroup) {
88+
textPref(
89+
title = DSLSettingsText.from("Profile Name"),
90+
summary = DSLSettingsText.from("[${recipient.profileName.givenName}] [${state.recipient.profileName.familyName}]")
91+
)
92+
93+
val profileKeyBase64 = recipient.profileKey?.let(Base64::encodeBytes) ?: "None"
94+
longClickPref(
95+
title = DSLSettingsText.from("Profile Key (Base64)"),
96+
summary = DSLSettingsText.from(profileKeyBase64),
97+
onLongClick = { copyToClipboard(profileKeyBase64) }
98+
)
99+
100+
val profileKeyHex = recipient.profileKey?.let(Hex::toStringCondensed) ?: ""
101+
longClickPref(
102+
title = DSLSettingsText.from("Profile Key (Hex)"),
103+
summary = DSLSettingsText.from(profileKeyHex),
104+
onLongClick = { copyToClipboard(profileKeyHex) }
105+
)
106+
107+
textPref(
108+
title = DSLSettingsText.from("Sealed Sender Mode"),
109+
summary = DSLSettingsText.from(recipient.unidentifiedAccessMode.toString())
110+
)
111+
}
97112

98113
textPref(
99114
title = DSLSettingsText.from("Profile Sharing (AKA \"Whitelisted\")"),
100115
summary = DSLSettingsText.from(recipient.isProfileSharing.toString())
101116
)
102117

103-
textPref(
104-
title = DSLSettingsText.from("Capabilities"),
105-
summary = DSLSettingsText.from(buildCapabilitySpan(recipient))
106-
)
107-
108-
sectionHeaderPref(DSLSettingsText.from("Actions"))
109-
110-
clickPref(
111-
title = DSLSettingsText.from("Disable Profile Sharing"),
112-
summary = DSLSettingsText.from("Clears profile sharing/whitelisted status, which should cause the Message Request UI to show."),
113-
onClick = {
114-
MaterialAlertDialogBuilder(requireContext())
115-
.setTitle("Are you sure?")
116-
.setNegativeButton(android.R.string.cancel) { d, _ -> d.dismiss() }
117-
.setPositiveButton(android.R.string.ok) { _, _ -> DatabaseFactory.getRecipientDatabase(requireContext()).setProfileSharing(recipient.id, false) }
118-
.show()
119-
}
120-
)
118+
if (!recipient.isGroup) {
119+
textPref(
120+
title = DSLSettingsText.from("Capabilities"),
121+
summary = DSLSettingsText.from(buildCapabilitySpan(recipient))
122+
)
123+
}
121124

122-
clickPref(
123-
title = DSLSettingsText.from("Delete Session"),
124-
summary = DSLSettingsText.from("Deletes the session, essentially guaranteeing an encryption error if they send you a message."),
125-
onClick = {
126-
MaterialAlertDialogBuilder(requireContext())
127-
.setTitle("Are you sure?")
128-
.setNegativeButton(android.R.string.cancel) { d, _ -> d.dismiss() }
129-
.setPositiveButton(android.R.string.ok) { _, _ ->
130-
if (recipient.hasUuid()) {
131-
DatabaseFactory.getSessionDatabase(context).deleteAllFor(recipient.requireUuid().toString())
125+
if (!recipient.isGroup) {
126+
sectionHeaderPref(DSLSettingsText.from("Actions"))
127+
128+
clickPref(
129+
title = DSLSettingsText.from("Disable Profile Sharing"),
130+
summary = DSLSettingsText.from("Clears profile sharing/whitelisted status, which should cause the Message Request UI to show."),
131+
onClick = {
132+
MaterialAlertDialogBuilder(requireContext())
133+
.setTitle("Are you sure?")
134+
.setNegativeButton(android.R.string.cancel) { d, _ -> d.dismiss() }
135+
.setPositiveButton(android.R.string.ok) { _, _ -> DatabaseFactory.getRecipientDatabase(requireContext()).setProfileSharing(recipient.id, false) }
136+
.show()
137+
}
138+
)
139+
140+
clickPref(
141+
title = DSLSettingsText.from("Delete Session"),
142+
summary = DSLSettingsText.from("Deletes the session, essentially guaranteeing an encryption error if they send you a message."),
143+
onClick = {
144+
MaterialAlertDialogBuilder(requireContext())
145+
.setTitle("Are you sure?")
146+
.setNegativeButton(android.R.string.cancel) { d, _ -> d.dismiss() }
147+
.setPositiveButton(android.R.string.ok) { _, _ ->
148+
if (recipient.hasUuid()) {
149+
DatabaseFactory.getSessionDatabase(context).deleteAllFor(recipient.requireUuid().toString())
150+
}
151+
if (recipient.hasE164()) {
152+
DatabaseFactory.getSessionDatabase(context).deleteAllFor(recipient.requireE164())
153+
}
132154
}
133-
if (recipient.hasE164()) {
134-
DatabaseFactory.getSessionDatabase(context).deleteAllFor(recipient.requireE164())
135-
}
136-
}
137-
.show()
138-
}
139-
)
155+
.show()
156+
}
157+
)
158+
}
140159
}
141160
}
142161

@@ -171,7 +190,13 @@ class InternalConversationSettingsFragment : DSLSettingsFragment(
171190
val recipientId: RecipientId
172191
) : ViewModel(), RecipientForeverObserver {
173192

174-
private val store = Store(InternalState(Recipient.resolved(recipientId), null))
193+
private val store = Store(
194+
InternalState(
195+
recipient = Recipient.resolved(recipientId),
196+
threadId = null,
197+
groupId = null
198+
)
199+
)
175200

176201
val state = store.stateLiveData
177202
val liveRecipient = Recipient.live(recipientId)
@@ -180,16 +205,15 @@ class InternalConversationSettingsFragment : DSLSettingsFragment(
180205
liveRecipient.observeForever(this)
181206

182207
SignalExecutors.BOUNDED.execute {
183-
val threadId: Long? = DatabaseFactory.getThreadDatabase(ApplicationDependencies.getApplication()).getThreadIdFor(recipientId)
184-
store.update { state -> state.copy(threadId = threadId) }
208+
val context: Context = ApplicationDependencies.getApplication()
209+
val threadId: Long? = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipientId)
210+
val groupId: GroupId? = DatabaseFactory.getGroupDatabase(context).getGroup(recipientId).transform { it.id }.orNull()
211+
store.update { state -> state.copy(threadId = threadId, groupId = groupId) }
185212
}
186213
}
187214

188215
override fun onRecipientChanged(recipient: Recipient) {
189-
SignalExecutors.BOUNDED.execute {
190-
val threadId: Long? = DatabaseFactory.getThreadDatabase(ApplicationDependencies.getApplication()).getThreadIdFor(recipient.id)
191-
store.update { InternalState(recipient, threadId) }
192-
}
216+
store.update { state -> state.copy(recipient = recipient) }
193217
}
194218

195219
override fun onCleared() {
@@ -205,6 +229,7 @@ class InternalConversationSettingsFragment : DSLSettingsFragment(
205229

206230
data class InternalState(
207231
val recipient: Recipient,
208-
val threadId: Long?
232+
val threadId: Long?,
233+
val groupId: GroupId?
209234
)
210235
}

0 commit comments

Comments
 (0)