Add ability to edit member label from the about you sheet.

This commit is contained in:
jeffrey-signal
2026-02-19 11:22:55 -05:00
committed by Cody Henthorne
parent bd121e47c8
commit 28c37cb3ac
8 changed files with 186 additions and 20 deletions

View File

@@ -1,8 +1,10 @@
package org.thoughtcrime.securesms.groups;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.database.GroupTable;
public enum GroupAccessControl {
ALL_MEMBERS(R.string.GroupManagement_access_level_all_members),
@@ -18,4 +20,15 @@ public enum GroupAccessControl {
public @StringRes int getString() {
return string;
}
/**
* Returns true if the given [memberLevel] meets this access requirement.
*/
public boolean allows(@NonNull GroupTable.MemberLevel memberLevel) {
return switch (this) {
case ALL_MEMBERS -> memberLevel.isInGroup();
case ONLY_ADMINS -> memberLevel == GroupTable.MemberLevel.ADMINISTRATOR;
case NO_ONE -> false;
};
}
}

View File

@@ -243,12 +243,7 @@ public final class LiveGroup {
}
private static boolean applyAccessControl(@NonNull GroupTable.MemberLevel memberLevel, @NonNull GroupAccessControl rights) {
switch (rights) {
case ALL_MEMBERS: return memberLevel.isInGroup();
case ONLY_ADMINS: return memberLevel == GroupTable.MemberLevel.ADMINISTRATOR;
case NO_ONE : return false;
default: throw new AssertionError();
}
return rights.allows(memberLevel);
}
public LiveData<GroupLinkUrlAndStatus> getGroupLink() {

View File

@@ -80,6 +80,15 @@ class MemberLabelRepository private constructor(
}
}
/**
* Checks whether the [Recipient] has permission to set their member label in the given group.
*/
suspend fun canSetLabel(groupId: GroupId.V2, recipient: Recipient): Boolean = withContext(Dispatchers.IO) {
if (!RemoteConfig.sendMemberLabels) return@withContext false
val groupRecord = groupsTable.getGroup(groupId).orNull() ?: return@withContext false
groupRecord.attributesAccessControl.allows(groupRecord.memberLevel(recipient))
}
/**
* Sets the group member label for the current user.
*/