@Test public void merge_alwaysPreferRemote() { SignalGroupV2Record remote = new SignalGroupV2Record.Builder(byteArray(1), groupKey(100)) .setBlocked(false) .setProfileSharingEnabled(false) .setArchived(false) .setForcedUnread(false) .build(); SignalGroupV2Record local = new SignalGroupV2Record.Builder(byteArray(2), groupKey(100)) .setBlocked(true) .setProfileSharingEnabled(true) .setArchived(true) .setForcedUnread(true) .build(); SignalGroupV2Record merged = new GroupV2ConflictMerger(Collections.singletonList(local)).merge(remote, local, KEY_GENERATOR); assertArrayEquals(remote.getId().getRaw(), merged.getId().getRaw()); assertArrayEquals(groupKey(100), merged.getMasterKeyBytes()); assertFalse(merged.isProfileSharingEnabled()); assertFalse(merged.isBlocked()); assertFalse(merged.isArchived()); assertFalse(merged.isForcedUnread()); }
@Override public @NonNull SignalGroupV2Record merge(@NonNull SignalGroupV2Record remote, @NonNull SignalGroupV2Record local, @NonNull StorageSyncHelper.KeyGenerator keyGenerator) { byte[] unknownFields = remote.serializeUnknownFields(); boolean blocked = remote.isBlocked(); boolean profileSharing = remote.isProfileSharingEnabled(); boolean archived = remote.isArchived(); boolean forcedUnread = remote.isForcedUnread(); boolean matchesRemote = Arrays.equals(unknownFields, remote.serializeUnknownFields()) && blocked == remote.isBlocked() && profileSharing == remote.isProfileSharingEnabled() && archived == remote.isArchived() && forcedUnread == remote.isForcedUnread(); boolean matchesLocal = Arrays.equals(unknownFields, local.serializeUnknownFields()) && blocked == local.isBlocked() && profileSharing == local.isProfileSharingEnabled() && archived == local.isArchived() && forcedUnread == local.isForcedUnread(); if (matchesRemote) { return remote; } else if (matchesLocal) { return local; } else { return new SignalGroupV2Record.Builder(keyGenerator.generate(), remote.getMasterKeyBytes()) .setUnknownFields(unknownFields) .setBlocked(blocked) .setProfileSharingEnabled(blocked) .setArchived(archived) .setForcedUnread(forcedUnread) .build(); } }
GroupV2ConflictMerger implements StorageSyncHelper.ConflictMerger<SignalGroupV2Record> { @Override public @NonNull SignalGroupV2Record merge(@NonNull SignalGroupV2Record remote, @NonNull SignalGroupV2Record local, @NonNull StorageSyncHelper.KeyGenerator keyGenerator) { byte[] unknownFields = remote.serializeUnknownFields(); boolean blocked = remote.isBlocked(); boolean profileSharing = remote.isProfileSharingEnabled(); boolean archived = remote.isArchived(); boolean forcedUnread = remote.isForcedUnread(); boolean matchesRemote = Arrays.equals(unknownFields, remote.serializeUnknownFields()) && blocked == remote.isBlocked() && profileSharing == remote.isProfileSharingEnabled() && archived == remote.isArchived() && forcedUnread == remote.isForcedUnread(); boolean matchesLocal = Arrays.equals(unknownFields, local.serializeUnknownFields()) && blocked == local.isBlocked() && profileSharing == local.isProfileSharingEnabled() && archived == local.isArchived() && forcedUnread == local.isForcedUnread(); if (matchesRemote) { return remote; } else if (matchesLocal) { return local; } else { return new SignalGroupV2Record.Builder(keyGenerator.generate(), remote.getMasterKeyBytes()) .setUnknownFields(unknownFields) .setBlocked(blocked) .setProfileSharingEnabled(blocked) .setArchived(archived) .setForcedUnread(forcedUnread) .build(); } } }
GroupV2ConflictMerger implements StorageSyncHelper.ConflictMerger<SignalGroupV2Record> { @Override public @NonNull SignalGroupV2Record merge(@NonNull SignalGroupV2Record remote, @NonNull SignalGroupV2Record local, @NonNull StorageSyncHelper.KeyGenerator keyGenerator) { byte[] unknownFields = remote.serializeUnknownFields(); boolean blocked = remote.isBlocked(); boolean profileSharing = remote.isProfileSharingEnabled(); boolean archived = remote.isArchived(); boolean forcedUnread = remote.isForcedUnread(); boolean matchesRemote = Arrays.equals(unknownFields, remote.serializeUnknownFields()) && blocked == remote.isBlocked() && profileSharing == remote.isProfileSharingEnabled() && archived == remote.isArchived() && forcedUnread == remote.isForcedUnread(); boolean matchesLocal = Arrays.equals(unknownFields, local.serializeUnknownFields()) && blocked == local.isBlocked() && profileSharing == local.isProfileSharingEnabled() && archived == local.isArchived() && forcedUnread == local.isForcedUnread(); if (matchesRemote) { return remote; } else if (matchesLocal) { return local; } else { return new SignalGroupV2Record.Builder(keyGenerator.generate(), remote.getMasterKeyBytes()) .setUnknownFields(unknownFields) .setBlocked(blocked) .setProfileSharingEnabled(blocked) .setArchived(archived) .setForcedUnread(forcedUnread) .build(); } } GroupV2ConflictMerger(@NonNull Collection<SignalGroupV2Record> localOnly); }
GroupV2ConflictMerger implements StorageSyncHelper.ConflictMerger<SignalGroupV2Record> { @Override public @NonNull SignalGroupV2Record merge(@NonNull SignalGroupV2Record remote, @NonNull SignalGroupV2Record local, @NonNull StorageSyncHelper.KeyGenerator keyGenerator) { byte[] unknownFields = remote.serializeUnknownFields(); boolean blocked = remote.isBlocked(); boolean profileSharing = remote.isProfileSharingEnabled(); boolean archived = remote.isArchived(); boolean forcedUnread = remote.isForcedUnread(); boolean matchesRemote = Arrays.equals(unknownFields, remote.serializeUnknownFields()) && blocked == remote.isBlocked() && profileSharing == remote.isProfileSharingEnabled() && archived == remote.isArchived() && forcedUnread == remote.isForcedUnread(); boolean matchesLocal = Arrays.equals(unknownFields, local.serializeUnknownFields()) && blocked == local.isBlocked() && profileSharing == local.isProfileSharingEnabled() && archived == local.isArchived() && forcedUnread == local.isForcedUnread(); if (matchesRemote) { return remote; } else if (matchesLocal) { return local; } else { return new SignalGroupV2Record.Builder(keyGenerator.generate(), remote.getMasterKeyBytes()) .setUnknownFields(unknownFields) .setBlocked(blocked) .setProfileSharingEnabled(blocked) .setArchived(archived) .setForcedUnread(forcedUnread) .build(); } } GroupV2ConflictMerger(@NonNull Collection<SignalGroupV2Record> localOnly); @Override @NonNull Optional<SignalGroupV2Record> getMatching(@NonNull SignalGroupV2Record record); @Override @NonNull Collection<SignalGroupV2Record> getInvalidEntries(@NonNull Collection<SignalGroupV2Record> remoteRecords); @Override @NonNull SignalGroupV2Record merge(@NonNull SignalGroupV2Record remote, @NonNull SignalGroupV2Record local, @NonNull StorageSyncHelper.KeyGenerator keyGenerator); }
GroupV2ConflictMerger implements StorageSyncHelper.ConflictMerger<SignalGroupV2Record> { @Override public @NonNull SignalGroupV2Record merge(@NonNull SignalGroupV2Record remote, @NonNull SignalGroupV2Record local, @NonNull StorageSyncHelper.KeyGenerator keyGenerator) { byte[] unknownFields = remote.serializeUnknownFields(); boolean blocked = remote.isBlocked(); boolean profileSharing = remote.isProfileSharingEnabled(); boolean archived = remote.isArchived(); boolean forcedUnread = remote.isForcedUnread(); boolean matchesRemote = Arrays.equals(unknownFields, remote.serializeUnknownFields()) && blocked == remote.isBlocked() && profileSharing == remote.isProfileSharingEnabled() && archived == remote.isArchived() && forcedUnread == remote.isForcedUnread(); boolean matchesLocal = Arrays.equals(unknownFields, local.serializeUnknownFields()) && blocked == local.isBlocked() && profileSharing == local.isProfileSharingEnabled() && archived == local.isArchived() && forcedUnread == local.isForcedUnread(); if (matchesRemote) { return remote; } else if (matchesLocal) { return local; } else { return new SignalGroupV2Record.Builder(keyGenerator.generate(), remote.getMasterKeyBytes()) .setUnknownFields(unknownFields) .setBlocked(blocked) .setProfileSharingEnabled(blocked) .setArchived(archived) .setForcedUnread(forcedUnread) .build(); } } GroupV2ConflictMerger(@NonNull Collection<SignalGroupV2Record> localOnly); @Override @NonNull Optional<SignalGroupV2Record> getMatching(@NonNull SignalGroupV2Record record); @Override @NonNull Collection<SignalGroupV2Record> getInvalidEntries(@NonNull Collection<SignalGroupV2Record> remoteRecords); @Override @NonNull SignalGroupV2Record merge(@NonNull SignalGroupV2Record remote, @NonNull SignalGroupV2Record local, @NonNull StorageSyncHelper.KeyGenerator keyGenerator);  }