Improve auto-leave group behavior.

This commit is contained in:
Cody Henthorne
2023-05-31 15:28:39 -04:00
parent d3e71185e6
commit ac4b0ed606
6 changed files with 15 additions and 14 deletions

View File

@@ -118,12 +118,12 @@ public final class GroupManager {
}
@WorkerThread
public static void leaveGroup(@NonNull Context context, @NonNull GroupId.Push groupId)
public static void leaveGroup(@NonNull Context context, @NonNull GroupId.Push groupId, boolean sendToMembers)
throws GroupChangeBusyException, GroupChangeFailedException, IOException
{
if (groupId.isV2()) {
try (GroupManagerV2.GroupEditor edit = new GroupManagerV2(context).edit(groupId.requireV2())) {
edit.leaveGroup();
edit.leaveGroup(sendToMembers);
Log.i(TAG, "Left group " + groupId);
} catch (GroupInsufficientRightsException e) {
Log.w(TAG, "Unexpected prevention from leaving " + groupId + " due to rights", e);
@@ -146,7 +146,7 @@ public final class GroupManager {
throws IOException, GroupChangeBusyException, GroupChangeFailedException
{
if (groupId.isV2()) {
leaveGroup(context, groupId.requireV2());
leaveGroup(context, groupId.requireV2(), true);
} else {
if (!GroupManagerV1.silentLeaveGroup(context, groupId.requireV1())) {
throw new GroupChangeFailedException();
@@ -169,7 +169,7 @@ public final class GroupManager {
throws GroupChangeBusyException, GroupChangeFailedException, GroupInsufficientRightsException, GroupNotAMemberException, IOException
{
try (GroupManagerV2.GroupEditor edit = new GroupManagerV2(context).edit(groupId.requireV2())) {
edit.ejectMember(recipient.requireServiceId(), false, true);
edit.ejectMember(recipient.requireServiceId(), false, true, true);
Log.i(TAG, "Member removed from group " + groupId);
}
}

View File

@@ -458,7 +458,7 @@ final class GroupManagerV2 {
}
@WorkerThread
void leaveGroup()
void leaveGroup(boolean sendToMembers)
throws GroupChangeFailedException, GroupInsufficientRightsException, IOException, GroupNotAMemberException
{
GroupRecord groupRecord = groupDatabase.requireGroup(groupId);
@@ -483,14 +483,14 @@ final class GroupManagerV2 {
throw new AssertionError(e);
}
} else if (selfMember.isPresent()) {
ejectMember(serviceId, true, false);
ejectMember(serviceId, true, false, sendToMembers);
} else {
Log.i(TAG, "Unable to leave group we are not pending or in");
}
}
@WorkerThread
@NonNull GroupManager.GroupActionResult ejectMember(@NonNull ServiceId serviceId, boolean allowWhenBlocked, boolean ban)
@NonNull GroupManager.GroupActionResult ejectMember(@NonNull ServiceId serviceId, boolean allowWhenBlocked, boolean ban, boolean sendToMembers)
throws GroupChangeFailedException, GroupInsufficientRightsException, IOException, GroupNotAMemberException
{
return commitChangeWithConflictResolution(selfAci,
@@ -498,7 +498,8 @@ final class GroupManagerV2 {
ban,
ban ? v2GroupProperties.getDecryptedGroup().getBannedMembersList()
: Collections.emptyList()),
allowWhenBlocked);
allowWhenBlocked,
sendToMembers);
}
@WorkerThread

View File

@@ -104,7 +104,7 @@ public final class LeaveGroupDialog {
private @NonNull GroupChangeResult leaveGroup() {
try {
GroupManager.leaveGroup(activity, groupId);
GroupManager.leaveGroup(activity, groupId, true);
return GroupChangeResult.SUCCESS;
} catch (GroupChangeException | IOException e) {
Log.w(TAG, e);