1
1
package org.thoughtcrime.securesms.components.settings.conversation
2
2
3
+ import android.content.Context
3
4
import android.graphics.Color
4
5
import android.text.TextUtils
5
6
import android.widget.Toast
@@ -16,6 +17,7 @@ import org.thoughtcrime.securesms.components.settings.DSLSettingsText
16
17
import org.thoughtcrime.securesms.components.settings.configure
17
18
import org.thoughtcrime.securesms.database.DatabaseFactory
18
19
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
20
+ import org.thoughtcrime.securesms.groups.GroupId
19
21
import org.thoughtcrime.securesms.recipients.Recipient
20
22
import org.thoughtcrime.securesms.recipients.RecipientForeverObserver
21
23
import org.thoughtcrime.securesms.recipients.RecipientId
@@ -57,12 +59,23 @@ class InternalConversationSettingsFragment : DSLSettingsFragment(
57
59
summary = DSLSettingsText .from(recipient.id.serialize())
58
60
)
59
61
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
+ }
66
79
67
80
val threadId: String = if (state.threadId != null ) state.threadId.toString() else " N/A"
68
81
longClickPref(
@@ -71,72 +84,78 @@ class InternalConversationSettingsFragment : DSLSettingsFragment(
71
84
onLongClick = { copyToClipboard(threadId) }
72
85
)
73
86
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
+ }
97
112
98
113
textPref(
99
114
title = DSLSettingsText .from(" Profile Sharing (AKA \" Whitelisted\" )" ),
100
115
summary = DSLSettingsText .from(recipient.isProfileSharing.toString())
101
116
)
102
117
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
+ }
121
124
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
+ }
132
154
}
133
- if (recipient.hasE164()) {
134
- DatabaseFactory .getSessionDatabase(context).deleteAllFor(recipient.requireE164())
135
- }
136
- }
137
- .show()
138
- }
139
- )
155
+ .show()
156
+ }
157
+ )
158
+ }
140
159
}
141
160
}
142
161
@@ -171,7 +190,13 @@ class InternalConversationSettingsFragment : DSLSettingsFragment(
171
190
val recipientId : RecipientId
172
191
) : ViewModel(), RecipientForeverObserver {
173
192
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
+ )
175
200
176
201
val state = store.stateLiveData
177
202
val liveRecipient = Recipient .live(recipientId)
@@ -180,16 +205,15 @@ class InternalConversationSettingsFragment : DSLSettingsFragment(
180
205
liveRecipient.observeForever(this )
181
206
182
207
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) }
185
212
}
186
213
}
187
214
188
215
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) }
193
217
}
194
218
195
219
override fun onCleared () {
@@ -205,6 +229,7 @@ class InternalConversationSettingsFragment : DSLSettingsFragment(
205
229
206
230
data class InternalState (
207
231
val recipient : Recipient ,
208
- val threadId : Long?
232
+ val threadId : Long? ,
233
+ val groupId : GroupId ?
209
234
)
210
235
}
0 commit comments