Prevent group leave event from bumping conversation.

This commit is contained in:
Cody Henthorne
2021-09-16 12:36:00 -04:00
committed by Alex Hart
parent b4465953d8
commit 5e968eb831
20 changed files with 989 additions and 51 deletions

View File

@@ -0,0 +1,45 @@
package org.thoughtcrime.securesms.sms;
import androidx.annotation.NonNull;
import org.signal.storageservice.protos.groups.local.DecryptedGroupChange;
import org.thoughtcrime.securesms.mms.MessageGroupContext;
import org.whispersystems.signalservice.api.groupsv2.DecryptedGroupUtil;
/**
* Helper util for inspecting GV2 {@link MessageGroupContext} for various message processing.
*/
public final class GroupV2UpdateMessageUtil {
public static boolean isGroupV2(@NonNull MessageGroupContext groupContext) {
return groupContext.isV2Group();
}
public static boolean isUpdate(@NonNull MessageGroupContext groupContext) {
return groupContext.isV2Group();
}
public static boolean isJustAGroupLeave(@NonNull MessageGroupContext groupContext) {
if (isGroupV2(groupContext) && isUpdate(groupContext)) {
DecryptedGroupChange decryptedGroupChange = groupContext.requireGroupV2Properties()
.getChange();
return changeEditorOnlyWasRemoved(decryptedGroupChange) &&
noChangesOtherThanDeletes(decryptedGroupChange);
}
return false;
}
private static boolean changeEditorOnlyWasRemoved(@NonNull DecryptedGroupChange decryptedGroupChange) {
return decryptedGroupChange.getDeleteMembersCount() == 1 &&
decryptedGroupChange.getDeleteMembers(0).equals(decryptedGroupChange.getEditor());
}
private static boolean noChangesOtherThanDeletes(@NonNull DecryptedGroupChange decryptedGroupChange) {
DecryptedGroupChange withoutDeletedMembers = decryptedGroupChange.toBuilder()
.clearDeleteMembers()
.build();
return DecryptedGroupUtil.changeIsEmpty(withoutDeletedMembers);
}
}

View File

@@ -1,11 +1,7 @@
package org.thoughtcrime.securesms.sms;
import androidx.annotation.NonNull;
import org.signal.storageservice.protos.groups.local.DecryptedGroupChange;
import org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context;
import org.thoughtcrime.securesms.mms.MessageGroupContext;
import org.whispersystems.signalservice.api.groupsv2.DecryptedGroupUtil;
import static org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext;
@@ -32,39 +28,19 @@ public final class IncomingGroupUpdateMessage extends IncomingTextMessage {
}
public boolean isUpdate() {
return groupContext.isV2Group() || groupContext.requireGroupV1Properties().isUpdate();
return GroupV2UpdateMessageUtil.isUpdate(groupContext) || groupContext.requireGroupV1Properties().isUpdate();
}
public boolean isGroupV2() {
return groupContext.isV2Group();
return GroupV2UpdateMessageUtil.isGroupV2(groupContext);
}
public boolean isQuit() {
return !groupContext.isV2Group() && groupContext.requireGroupV1Properties().isQuit();
return !isGroupV2() && groupContext.requireGroupV1Properties().isQuit();
}
@Override
public boolean isJustAGroupLeave() {
if (isGroupV2() && isUpdate()) {
DecryptedGroupChange decryptedGroupChange = groupContext.requireGroupV2Properties()
.getChange();
return changeEditorOnlyWasRemoved(decryptedGroupChange) &&
noChangesOtherThanDeletes(decryptedGroupChange);
}
return false;
}
protected boolean changeEditorOnlyWasRemoved(@NonNull DecryptedGroupChange decryptedGroupChange) {
return decryptedGroupChange.getDeleteMembersCount() == 1 &&
decryptedGroupChange.getDeleteMembers(0).equals(decryptedGroupChange.getEditor());
}
protected boolean noChangesOtherThanDeletes(@NonNull DecryptedGroupChange decryptedGroupChange) {
DecryptedGroupChange withoutDeletedMembers = decryptedGroupChange.toBuilder()
.clearDeleteMembers()
.build();
return DecryptedGroupUtil.changeIsEmpty(withoutDeletedMembers);
return GroupV2UpdateMessageUtil.isJustAGroupLeave(groupContext);
}
}