Fix contact sync by not requiring upload specs for avatars.

This commit is contained in:
Cody Henthorne 2024-08-22 13:33:49 -04:00 committed by mtang-signal
parent 46bc2589b5
commit 4447433ffe
4 changed files with 43 additions and 46 deletions

View file

@ -36,6 +36,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
import org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage;
import org.whispersystems.signalservice.api.messages.multidevice.DeviceContact;
import org.whispersystems.signalservice.api.messages.multidevice.DeviceContactAvatar;
import org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream;
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage;
@ -307,7 +308,7 @@ public class MultiDeviceContactUpdateJob extends BaseJob {
}
}
private Optional<SignalServiceAttachmentStream> getSystemAvatar(@Nullable Uri uri) throws IOException {
private Optional<DeviceContactAvatar> getSystemAvatar(@Nullable Uri uri) throws IOException {
if (uri == null) {
return Optional.empty();
}
@ -325,12 +326,7 @@ public class MultiDeviceContactUpdateJob extends BaseJob {
return Optional.empty();
}
return Optional.of(SignalServiceAttachment.newStreamBuilder()
.withStream(fd.createInputStream())
.withContentType("image/*")
.withLength(fd.getLength())
.withResumableUploadSpec(AppDependencies.getSignalServiceMessageSender().getResumableUploadSpec())
.build());
return Optional.of(new DeviceContactAvatar(fd.createInputStream(), fd.getLength(), "image/*"));
} catch (IOException e) {
// Ignored
}
@ -352,12 +348,7 @@ public class MultiDeviceContactUpdateJob extends BaseJob {
byte[] data = cursor.getBlob(0);
if (data != null) {
return Optional.of(SignalServiceAttachment.newStreamBuilder()
.withStream(new ByteArrayInputStream(data))
.withContentType("image/*")
.withLength(data.length)
.withResumableUploadSpec(AppDependencies.getSignalServiceMessageSender().getResumableUploadSpec())
.build());
return Optional.of(new DeviceContactAvatar(new ByteArrayInputStream(data), data.length, "image/*"));
}
}

View file

@ -1,36 +1,33 @@
/**
* Copyright (C) 2014-2016 Open Whisper Systems
*
* <p>
* Licensed according to the LICENSE file in this repository.
*/
package org.whispersystems.signalservice.api.messages.multidevice;
import org.signal.libsignal.zkgroup.profiles.ProfileKey;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.Optional;
public class DeviceContact {
private final Optional<ACI> aci;
private final Optional<String> e164;
private final Optional<String> name;
private final Optional<SignalServiceAttachmentStream> avatar;
private final Optional<String> color;
private final Optional<VerifiedMessage> verified;
private final Optional<ProfileKey> profileKey;
private final Optional<Integer> expirationTimer;
private final Optional<Integer> inboxPosition;
private final boolean archived;
private final Optional<ACI> aci;
private final Optional<String> e164;
private final Optional<String> name;
private final Optional<DeviceContactAvatar> avatar;
private final Optional<String> color;
private final Optional<VerifiedMessage> verified;
private final Optional<ProfileKey> profileKey;
private final Optional<Integer> expirationTimer;
private final Optional<Integer> inboxPosition;
private final boolean archived;
public DeviceContact(Optional<ACI> aci,
Optional<String> e164,
Optional<String> name,
Optional<SignalServiceAttachmentStream> avatar,
Optional<DeviceContactAvatar> avatar,
Optional<String> color,
Optional<VerifiedMessage> verified,
Optional<ProfileKey> profileKey,
@ -54,7 +51,7 @@ public class DeviceContact {
this.archived = archived;
}
public Optional<SignalServiceAttachmentStream> getAvatar() {
public Optional<DeviceContactAvatar> getAvatar() {
return avatar;
}

View file

@ -0,0 +1,13 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.signalservice.api.messages.multidevice
import java.io.InputStream
/**
* Data needed to sync a device contact avatar to/from other devices.
*/
data class DeviceContactAvatar(val inputStream: InputStream, val length: Long, val contentType: String)

View file

@ -47,27 +47,23 @@ public class DeviceContactsInputStream extends ChunkedInputStream {
throw new IOException("Missing contact address!");
}
Optional<ACI> aci = Optional.ofNullable(ACI.parseOrNull(details.aci));
Optional<String> e164 = Optional.ofNullable(details.number);
Optional<String> name = Optional.ofNullable(details.name);
Optional<SignalServiceAttachmentStream> avatar = Optional.empty();
Optional<String> color = details.color != null ? Optional.of(details.color) : Optional.empty();
Optional<VerifiedMessage> verified = Optional.empty();
Optional<ProfileKey> profileKey = Optional.empty();
Optional<Integer> expireTimer = Optional.empty();
Optional<Integer> inboxPosition = Optional.empty();
boolean archived = false;
Optional<ACI> aci = Optional.ofNullable(ACI.parseOrNull(details.aci));
Optional<String> e164 = Optional.ofNullable(details.number);
Optional<String> name = Optional.ofNullable(details.name);
Optional<DeviceContactAvatar> avatar = Optional.empty();
Optional<String> color = details.color != null ? Optional.of(details.color) : Optional.empty();
Optional<VerifiedMessage> verified = Optional.empty();
Optional<ProfileKey> profileKey = Optional.empty();
Optional<Integer> expireTimer = Optional.empty();
Optional<Integer> inboxPosition = Optional.empty();
boolean archived = false;
if (details.avatar != null) {
if (details.avatar != null && details.avatar.length != null) {
long avatarLength = details.avatar.length;
InputStream avatarStream = new LimitedInputStream(in, avatarLength);
String avatarContentType = details.avatar.contentType;
String avatarContentType = details.avatar.contentType != null ? details.avatar.contentType : "image/*";
avatar = Optional.of(SignalServiceAttachment.newStreamBuilder()
.withStream(avatarStream)
.withContentType(avatarContentType)
.withLength(avatarLength)
.build());
avatar = Optional.of(new DeviceContactAvatar(avatarStream, avatarLength, avatarContentType));
}
if (details.verified != null) {