From 18c7bc2b5b9055a486df000d55b428e72abfa822 Mon Sep 17 00:00:00 2001 From: Alan Evans Date: Sat, 6 Jun 2020 20:24:42 -0300 Subject: [PATCH] Prevent edit of a group post leave. --- .../securesms/groups/LiveGroup.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/LiveGroup.java b/app/src/main/java/org/thoughtcrime/securesms/groups/LiveGroup.java index fc97b1d7ac..f1d3737888 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/LiveGroup.java +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/LiveGroup.java @@ -93,11 +93,11 @@ public final class LiveGroup { } public LiveData selfCanEditGroupAttributes() { - return LiveDataUtil.combineLatest(isSelfAdmin(), getAttributesAccessControl(), this::applyAccessControl); + return LiveDataUtil.combineLatest(selfMemberLevel(), getAttributesAccessControl(), LiveGroup::applyAccessControl); } public LiveData selfCanAddMembers() { - return LiveDataUtil.combineLatest(isSelfAdmin(), getMembershipAdditionAccessControl(), this::applyAccessControl); + return LiveDataUtil.combineLatest(selfMemberLevel(), getMembershipAdditionAccessControl(), LiveGroup::applyAccessControl); } /** @@ -123,11 +123,28 @@ public final class LiveGroup { fullMemberCount); } - private boolean applyAccessControl(boolean isAdmin, @NonNull GroupAccessControl rights) { + private LiveData selfMemberLevel() { + return Transformations.map(groupRecord, g -> { + if (g.isAdmin(Recipient.self())) { + return MemberLevel.ADMIN; + } else { + return g.isActive() ? MemberLevel.MEMBER + : MemberLevel.NOT_A_MEMBER; + } + }); + } + + private static boolean applyAccessControl(@NonNull MemberLevel memberLevel, @NonNull GroupAccessControl rights) { switch (rights) { - case ALL_MEMBERS: return true; - case ONLY_ADMINS: return isAdmin; + case ALL_MEMBERS: return memberLevel != MemberLevel.NOT_A_MEMBER; + case ONLY_ADMINS: return memberLevel == MemberLevel.ADMIN; default: throw new AssertionError(); } } + + private enum MemberLevel { + NOT_A_MEMBER, + MEMBER, + ADMIN + } } \ No newline at end of file