Improve auto-leave group behavior.
This commit is contained in:
parent
d3e71185e6
commit
ac4b0ed606
6 changed files with 15 additions and 14 deletions
|
@ -86,7 +86,7 @@ class DeleteAccountRepository {
|
|||
while (groupRecord != null) {
|
||||
if (groupRecord.getId().isPush() && groupRecord.isActive()) {
|
||||
if (!groupRecord.isV1Group()) {
|
||||
GroupManager.leaveGroup(ApplicationDependencies.getApplication(), groupRecord.getId().requirePush());
|
||||
GroupManager.leaveGroup(ApplicationDependencies.getApplication(), groupRecord.getId().requirePush(), true);
|
||||
}
|
||||
onDeleteAccountEvent.accept(new DeleteAccountEvent.LeaveGroupsProgress(groups.getCount(), ++groupsLeft));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -43,13 +43,13 @@ class LeaveGroupV2WorkerJob(parameters: Parameters, private val groupId: GroupId
|
|||
|
||||
val groupRecipient = Recipient.externalGroupExact(groupId)
|
||||
|
||||
GroupManager.leaveGroup(context, groupId)
|
||||
GroupManager.leaveGroup(context, groupId, false)
|
||||
|
||||
val threadId = SignalDatabase.threads.getThreadIdIfExistsFor(groupRecipient.id)
|
||||
if (threadId != -1L) {
|
||||
SignalDatabase.recipients.setProfileSharing(groupRecipient.id, true)
|
||||
SignalDatabase.recipients.setProfileSharing(groupRecipient.id, enabled = false)
|
||||
SignalDatabase.threads.setEntireThreadRead(threadId)
|
||||
SignalDatabase.threads.update(threadId, false, false)
|
||||
SignalDatabase.threads.update(threadId, unarchive = false, allowDeletion = false)
|
||||
ApplicationDependencies.getMessageNotifier().updateNotification(context)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,7 +147,7 @@ class GroupManagerV2Test_edit {
|
|||
}
|
||||
|
||||
editGroup {
|
||||
leaveGroup()
|
||||
leaveGroup(true)
|
||||
}
|
||||
|
||||
then { patchedGroup ->
|
||||
|
|
Loading…
Add table
Reference in a new issue