Allow group leave operations on blocked groups.

We should be leaving groups *before* they're blocked, but this helps
some other cases.
fork-5.53.8
Greyson Parrelli 2022-02-20 22:43:20 -05:00
rodzic 67f0ba8624
commit 19dc90b68b
2 zmienionych plików z 13 dodań i 7 usunięć

Wyświetl plik

@ -161,7 +161,7 @@ public final class GroupManager {
throws GroupChangeBusyException, GroupChangeFailedException, GroupInsufficientRightsException, GroupNotAMemberException, IOException throws GroupChangeBusyException, GroupChangeFailedException, GroupInsufficientRightsException, GroupNotAMemberException, IOException
{ {
try (GroupManagerV2.GroupEditor edit = new GroupManagerV2(context).edit(groupId.requireV2())) { try (GroupManagerV2.GroupEditor edit = new GroupManagerV2(context).edit(groupId.requireV2())) {
edit.ejectMember(recipient.getId()); edit.ejectMember(recipient.getId(), false);
Log.i(TAG, "Member removed from group " + groupId); Log.i(TAG, "Member removed from group " + groupId);
} }
} }

Wyświetl plik

@ -431,17 +431,17 @@ final class GroupManagerV2 {
throw new AssertionError(e); throw new AssertionError(e);
} }
} else { } else {
return ejectMember(self.getId()); return ejectMember(self.getId(), true);
} }
} }
@WorkerThread @WorkerThread
@NonNull GroupManager.GroupActionResult ejectMember(@NonNull RecipientId recipientId) @NonNull GroupManager.GroupActionResult ejectMember(@NonNull RecipientId recipientId, boolean allowWhenBlocked)
throws GroupChangeFailedException, GroupInsufficientRightsException, IOException, GroupNotAMemberException throws GroupChangeFailedException, GroupInsufficientRightsException, IOException, GroupNotAMemberException
{ {
Recipient recipient = Recipient.resolved(recipientId); Recipient recipient = Recipient.resolved(recipientId);
return commitChangeWithConflictResolution(groupOperations.createRemoveMembersChange(Collections.singleton(recipient.requireServiceId().uuid()))); return commitChangeWithConflictResolution(groupOperations.createRemoveMembersChange(Collections.singleton(recipient.requireServiceId().uuid())), allowWhenBlocked);
} }
@WorkerThread @WorkerThread
@ -554,12 +554,18 @@ final class GroupManagerV2 {
private @NonNull GroupManager.GroupActionResult commitChangeWithConflictResolution(@NonNull GroupChange.Actions.Builder change) private @NonNull GroupManager.GroupActionResult commitChangeWithConflictResolution(@NonNull GroupChange.Actions.Builder change)
throws GroupChangeFailedException, GroupNotAMemberException, GroupInsufficientRightsException, IOException throws GroupChangeFailedException, GroupNotAMemberException, GroupInsufficientRightsException, IOException
{
return commitChangeWithConflictResolution(change, false);
}
private @NonNull GroupManager.GroupActionResult commitChangeWithConflictResolution(@NonNull GroupChange.Actions.Builder change, boolean allowWhenBlocked)
throws GroupChangeFailedException, GroupNotAMemberException, GroupInsufficientRightsException, IOException
{ {
change.setSourceUuid(UuidUtil.toByteString(selfAci.uuid())); change.setSourceUuid(UuidUtil.toByteString(selfAci.uuid()));
for (int attempt = 0; attempt < 5; attempt++) { for (int attempt = 0; attempt < 5; attempt++) {
try { try {
return commitChange(change); return commitChange(change, allowWhenBlocked);
} catch (GroupPatchNotAcceptedException e) { } catch (GroupPatchNotAcceptedException e) {
throw new GroupChangeFailedException(e); throw new GroupChangeFailedException(e);
} catch (ConflictException e) { } catch (ConflictException e) {
@ -611,7 +617,7 @@ final class GroupManagerV2 {
} }
} }
private GroupManager.GroupActionResult commitChange(@NonNull GroupChange.Actions.Builder change) private GroupManager.GroupActionResult commitChange(@NonNull GroupChange.Actions.Builder change, boolean allowWhenBlocked)
throws GroupNotAMemberException, GroupChangeFailedException, IOException, GroupInsufficientRightsException throws GroupNotAMemberException, GroupChangeFailedException, IOException, GroupInsufficientRightsException
{ {
final GroupDatabase.GroupRecord groupRecord = groupDatabase.requireGroup(groupId); final GroupDatabase.GroupRecord groupRecord = groupDatabase.requireGroup(groupId);
@ -622,7 +628,7 @@ final class GroupManagerV2 {
final DecryptedGroup decryptedGroupState; final DecryptedGroup decryptedGroupState;
final DecryptedGroup previousGroupState; final DecryptedGroup previousGroupState;
if (Recipient.externalGroupExact(context, groupId).isBlocked()) { if (!allowWhenBlocked && Recipient.externalGroupExact(context, groupId).isBlocked()) {
throw new GroupChangeFailedException("Group is blocked."); throw new GroupChangeFailedException("Group is blocked.");
} }