mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-03 23:15:44 +01:00
Add ability to edit member label from the about you sheet.
This commit is contained in:
committed by
Cody Henthorne
parent
bd121e47c8
commit
28c37cb3ac
@@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user