@Test public void merge_returnRemoteIfEndResultMatchesRemote() { SignalGroupV1Record remote = new SignalGroupV1Record.Builder(byteArray(1), byteArray(100)) .setBlocked(false) .setProfileSharingEnabled(true) .setArchived(true) .build(); SignalGroupV1Record local = new SignalGroupV1Record.Builder(byteArray(2), byteArray(100)) .setBlocked(true) .setProfileSharingEnabled(false) .setArchived(false) .build(); SignalGroupV1Record merged = new GroupV1ConflictMerger(Collections.singletonList(local)).merge(remote, local, mock(KeyGenerator.class)); assertEquals(remote, merged); }
@Override public @NonNull SignalGroupV1Record merge(@NonNull SignalGroupV1Record remote, @NonNull SignalGroupV1Record 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 SignalGroupV1Record.Builder(keyGenerator.generate(), remote.getGroupId()) .setUnknownFields(unknownFields) .setBlocked(blocked) .setProfileSharingEnabled(blocked) .setForcedUnread(forcedUnread) .build(); } }
GroupV1ConflictMerger implements StorageSyncHelper.ConflictMerger<SignalGroupV1Record> { @Override public @NonNull SignalGroupV1Record merge(@NonNull SignalGroupV1Record remote, @NonNull SignalGroupV1Record 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 SignalGroupV1Record.Builder(keyGenerator.generate(), remote.getGroupId()) .setUnknownFields(unknownFields) .setBlocked(blocked) .setProfileSharingEnabled(blocked) .setForcedUnread(forcedUnread) .build(); } } }
GroupV1ConflictMerger implements StorageSyncHelper.ConflictMerger<SignalGroupV1Record> { @Override public @NonNull SignalGroupV1Record merge(@NonNull SignalGroupV1Record remote, @NonNull SignalGroupV1Record 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 SignalGroupV1Record.Builder(keyGenerator.generate(), remote.getGroupId()) .setUnknownFields(unknownFields) .setBlocked(blocked) .setProfileSharingEnabled(blocked) .setForcedUnread(forcedUnread) .build(); } } GroupV1ConflictMerger(@NonNull Collection<SignalGroupV1Record> localOnly); }
GroupV1ConflictMerger implements StorageSyncHelper.ConflictMerger<SignalGroupV1Record> { @Override public @NonNull SignalGroupV1Record merge(@NonNull SignalGroupV1Record remote, @NonNull SignalGroupV1Record 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 SignalGroupV1Record.Builder(keyGenerator.generate(), remote.getGroupId()) .setUnknownFields(unknownFields) .setBlocked(blocked) .setProfileSharingEnabled(blocked) .setForcedUnread(forcedUnread) .build(); } } GroupV1ConflictMerger(@NonNull Collection<SignalGroupV1Record> localOnly); @Override @NonNull Optional<SignalGroupV1Record> getMatching(@NonNull SignalGroupV1Record record); @Override @NonNull Collection<SignalGroupV1Record> getInvalidEntries(@NonNull Collection<SignalGroupV1Record> remoteRecords); @Override @NonNull SignalGroupV1Record merge(@NonNull SignalGroupV1Record remote, @NonNull SignalGroupV1Record local, @NonNull StorageSyncHelper.KeyGenerator keyGenerator); }
GroupV1ConflictMerger implements StorageSyncHelper.ConflictMerger<SignalGroupV1Record> { @Override public @NonNull SignalGroupV1Record merge(@NonNull SignalGroupV1Record remote, @NonNull SignalGroupV1Record 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 SignalGroupV1Record.Builder(keyGenerator.generate(), remote.getGroupId()) .setUnknownFields(unknownFields) .setBlocked(blocked) .setProfileSharingEnabled(blocked) .setForcedUnread(forcedUnread) .build(); } } GroupV1ConflictMerger(@NonNull Collection<SignalGroupV1Record> localOnly); @Override @NonNull Optional<SignalGroupV1Record> getMatching(@NonNull SignalGroupV1Record record); @Override @NonNull Collection<SignalGroupV1Record> getInvalidEntries(@NonNull Collection<SignalGroupV1Record> remoteRecords); @Override @NonNull SignalGroupV1Record merge(@NonNull SignalGroupV1Record remote, @NonNull SignalGroupV1Record local, @NonNull StorageSyncHelper.KeyGenerator keyGenerator);  }