mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 17:29:32 +01:00
Prevent group leave event from bumping conversation.
This commit is contained in:
committed by
Alex Hart
parent
b4465953d8
commit
5e968eb831
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user