mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-02 08:23:00 +01:00
Introduce new add member labels permission.
This commit is contained in:
@@ -10,6 +10,7 @@ import org.thoughtcrime.securesms.components.settings.DSLSettingsText
|
||||
import org.thoughtcrime.securesms.components.settings.configure
|
||||
import org.thoughtcrime.securesms.groups.GroupId
|
||||
import org.thoughtcrime.securesms.groups.ui.GroupErrors
|
||||
import org.thoughtcrime.securesms.util.RemoteConfig
|
||||
import org.thoughtcrime.securesms.util.adapter.mapping.MappingAdapter
|
||||
|
||||
class PermissionsSettingsFragment : DSLSettingsFragment(
|
||||
@@ -83,6 +84,20 @@ class PermissionsSettingsFragment : DSLSettingsFragment(
|
||||
viewModel.setAnnouncementGroup(it == 0)
|
||||
}
|
||||
)
|
||||
|
||||
if (RemoteConfig.sendMemberLabels) {
|
||||
radioListPref(
|
||||
title = DSLSettingsText.from(R.string.PermissionsSettingsFragment__add_member_labels),
|
||||
isEnabled = state.selfCanEditSettings,
|
||||
listItems = permissionsOptions,
|
||||
dialogTitle = DSLSettingsText.from(R.string.PermissionsSettingsFragment__who_can_add_member_labels),
|
||||
selected = getSelected(state.nonAdminCanSetMemberLabel),
|
||||
confirmAction = true,
|
||||
onSelected = { selectedIndex ->
|
||||
viewModel.setNonAdminCanSetMemberLabel(selectedIndex == 1)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,4 +56,18 @@ class PermissionsSettingsRepository(private val context: Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun applyMemberLabelRightsChange(groupId: GroupId, newRights: GroupAccessControl, errorCallback: GroupChangeErrorCallback) {
|
||||
SignalExecutors.UNBOUNDED.execute {
|
||||
try {
|
||||
GroupManager.applyMemberLabelRightsChange(context, groupId.requireV2(), newRights)
|
||||
} catch (e: GroupChangeException) {
|
||||
Log.w(TAG, e)
|
||||
errorCallback.onError(GroupChangeFailureReason.fromException(e))
|
||||
} catch (e: IOException) {
|
||||
Log.w(TAG, e)
|
||||
errorCallback.onError(GroupChangeFailureReason.fromException(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,5 +4,6 @@ data class PermissionsSettingsState(
|
||||
val selfCanEditSettings: Boolean = false,
|
||||
val nonAdminCanAddMembers: Boolean = false,
|
||||
val nonAdminCanEditGroupInfo: Boolean = false,
|
||||
val announcementGroup: Boolean = false
|
||||
val announcementGroup: Boolean = false,
|
||||
val nonAdminCanSetMemberLabel: Boolean = false
|
||||
)
|
||||
|
||||
@@ -37,6 +37,10 @@ class PermissionsSettingsViewModel(
|
||||
store.update(liveGroup.isAnnouncementGroup) { isAnnouncementGroup, state ->
|
||||
state.copy(announcementGroup = isAnnouncementGroup)
|
||||
}
|
||||
|
||||
store.update(liveGroup.memberLabelAccessControl) { memberLabelAccessControl, state ->
|
||||
state.copy(nonAdminCanSetMemberLabel = memberLabelAccessControl == GroupAccessControl.ALL_MEMBERS)
|
||||
}
|
||||
}
|
||||
|
||||
fun setNonAdminCanAddMembers(nonAdminCanAddMembers: Boolean) {
|
||||
@@ -57,6 +61,15 @@ class PermissionsSettingsViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
fun setNonAdminCanSetMemberLabel(nonAdminCanSetMemberLabel: Boolean) {
|
||||
repository.applyMemberLabelRightsChange(
|
||||
groupId = groupId,
|
||||
newRights = nonAdminCanSetMemberLabel.asGroupAccessControl()
|
||||
) { failureReason ->
|
||||
internalEvents.postValue(PermissionsSettingsEvents.GroupChangeError(failureReason))
|
||||
}
|
||||
}
|
||||
|
||||
private fun Boolean.asGroupAccessControl(): GroupAccessControl {
|
||||
return if (this) {
|
||||
GroupAccessControl.ALL_MEMBERS
|
||||
|
||||
@@ -118,6 +118,27 @@ class GroupRecord(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Who is allowed to add member labels in this group.
|
||||
*
|
||||
* Defaults to ALL_MEMBERS for groups created before this permission was added.
|
||||
*/
|
||||
val memberLabelAccessControl: GroupAccessControl
|
||||
get() {
|
||||
if (!isV2Group) {
|
||||
return GroupAccessControl.ALL_MEMBERS
|
||||
}
|
||||
|
||||
return when ((requireV2GroupProperties().decryptedGroup.accessControl ?: AccessControl()).memberLabel) {
|
||||
AccessControl.AccessRequired.ADMINISTRATOR -> GroupAccessControl.ONLY_ADMINS
|
||||
|
||||
AccessControl.AccessRequired.MEMBER,
|
||||
AccessControl.AccessRequired.UNKNOWN, // groups predating this permission
|
||||
AccessControl.AccessRequired.ANY,
|
||||
AccessControl.AccessRequired.UNSATISFIABLE -> GroupAccessControl.ALL_MEMBERS
|
||||
}
|
||||
}
|
||||
|
||||
val actionableRequestingMembersCount: Int by lazy {
|
||||
if (isV2Group && memberLevel(Recipient.self()) == GroupTable.MemberLevel.ADMINISTRATOR) {
|
||||
requireV2GroupProperties()
|
||||
|
||||
@@ -299,6 +299,17 @@ public final class GroupManager {
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public static void applyMemberLabelRightsChange(@NonNull Context context,
|
||||
@NonNull GroupId.V2 groupId,
|
||||
@NonNull GroupAccessControl newRights)
|
||||
throws GroupChangeFailedException, GroupInsufficientRightsException, IOException, GroupNotAMemberException, GroupChangeBusyException
|
||||
{
|
||||
try (GroupManagerV2.GroupEditor editor = new GroupManagerV2(context).edit(groupId.requireV2())) {
|
||||
editor.updateMemberLabelRights(newRights);
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public static void applyAnnouncementGroupChange(@NonNull Context context,
|
||||
@NonNull GroupId.V2 groupId,
|
||||
|
||||
@@ -321,6 +321,14 @@ final class GroupManagerV2 {
|
||||
return commitChangeWithConflictResolution(selfAci, groupOperations.createChangeMembershipRights(rightsToAccessControl(newRights)));
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
@NonNull GroupManager.GroupActionResult updateMemberLabelRights(@NonNull GroupAccessControl newRights)
|
||||
throws GroupChangeFailedException, GroupInsufficientRightsException, IOException, GroupNotAMemberException
|
||||
{
|
||||
AccessControl.AccessRequired accessRequired = rightsToAccessControl(newRights);
|
||||
return commitChangeWithConflictResolution(selfAci, groupOperations.createChangeMemberLabelRights(accessRequired));
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
@NonNull GroupManager.GroupActionResult updateAnnouncementGroup(boolean isAnnouncementGroup)
|
||||
throws GroupChangeFailedException, GroupInsufficientRightsException, IOException, GroupNotAMemberException
|
||||
|
||||
@@ -12,6 +12,7 @@ import androidx.lifecycle.Transformations;
|
||||
import com.annimon.stream.ComparatorCompat;
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.signal.core.models.ServiceId;
|
||||
import org.signal.core.util.concurrent.SignalExecutors;
|
||||
import org.signal.storageservice.storage.protos.groups.AccessControl;
|
||||
import org.signal.storageservice.storage.protos.groups.local.DecryptedGroup;
|
||||
@@ -28,7 +29,6 @@ import org.thoughtcrime.securesms.recipients.LiveRecipient;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
|
||||
import org.signal.core.models.ServiceId;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.Collections;
|
||||
@@ -182,6 +182,11 @@ public final class LiveGroup {
|
||||
return Transformations.map(groupRecord, GroupRecord::getAttributesAccessControl);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public LiveData<GroupAccessControl> getMemberLabelAccessControl() {
|
||||
return Transformations.map(groupRecord, GroupRecord::getMemberLabelAccessControl);
|
||||
}
|
||||
|
||||
public LiveData<List<GroupMemberEntry.FullMember>> getNonAdminFullMembers() {
|
||||
return Transformations.map(fullMembers,
|
||||
members -> Stream.of(members)
|
||||
|
||||
@@ -6010,6 +6010,10 @@
|
||||
<string name="PermissionsSettingsFragment__who_can_add_new_members">Who can add new members?</string>
|
||||
<string name="PermissionsSettingsFragment__who_can_edit_this_groups_info">Who can edit this group\'s info?</string>
|
||||
<string name="PermissionsSettingsFragment__who_can_send_messages">Who can send messages and start calls?</string>
|
||||
<!-- Label for the member labels permission button in the group permissions settings screen. -->
|
||||
<string name="PermissionsSettingsFragment__add_member_labels">Add member labels</string>
|
||||
<!-- Dialog title shown when choosing who has permission to add member labels in the group. -->
|
||||
<string name="PermissionsSettingsFragment__who_can_add_member_labels">Who can add member labels?</string>
|
||||
|
||||
<!-- SoundsAndNotificationsSettingsFragment -->
|
||||
<!-- Label for the setting to mute notifications for a conversation -->
|
||||
|
||||
Reference in New Issue
Block a user