Add support for borderless images.

Added support for 'borderless' images. Basically images that we'd like to render 
as if they were stickers, even though they're not stickers. On iOS, this will be 
stuff like memoji and bitmoji. On Android, in my initial pass, I've just added 
support for Giphy stickers. However, we can also detect bitmoji and keyboard 
stickers in the future. This is kind of a 'best effort' thing, so as long as we 
support receiving, we can just add sending support for more things as we go.
This commit is contained in:
Greyson Parrelli
2020-07-06 14:13:08 -07:00
parent 1e250ee95c
commit 545ba80697
55 changed files with 348 additions and 150 deletions

View File

@@ -418,6 +418,7 @@ public class SignalServiceMessageSender {
Optional.of(attachmentIdAndDigest.second()),
attachment.getFileName(),
attachment.getVoiceNote(),
attachment.isBorderless(),
attachment.getCaption(),
attachment.getBlurHash(),
attachment.getUploadTimestamp());
@@ -457,6 +458,7 @@ public class SignalServiceMessageSender {
Optional.of(digest),
attachment.getFileName(),
attachment.getVoiceNote(),
attachment.isBorderless(),
attachment.getCaption(),
attachment.getBlurHash(),
attachment.getUploadTimestamp());
@@ -1380,6 +1382,10 @@ public class SignalServiceMessageSender {
builder.setFlags(AttachmentPointer.Flags.VOICE_MESSAGE_VALUE);
}
if (attachment.isBorderless()) {
builder.setFlags(AttachmentPointer.Flags.BORDERLESS_VALUE);
}
if (attachment.getCaption().isPresent()) {
builder.setCaption(attachment.getCaption().get());
}

View File

@@ -48,6 +48,7 @@ public abstract class SignalServiceAttachment {
private ProgressListener listener;
private CancelationSignal cancelationSignal;
private boolean voiceNote;
private boolean borderless;
private int width;
private int height;
private String caption;
@@ -92,6 +93,11 @@ public abstract class SignalServiceAttachment {
return this;
}
public Builder withBorderless(boolean borderless) {
this.borderless = borderless;
return this;
}
public Builder withWidth(int width) {
this.width = width;
return this;
@@ -132,6 +138,7 @@ public abstract class SignalServiceAttachment {
length,
Optional.fromNullable(fileName),
voiceNote,
borderless,
Optional.<byte[]>absent(),
width,
height,

View File

@@ -26,18 +26,27 @@ public class SignalServiceAttachmentPointer extends SignalServiceAttachment {
private final Optional<byte[]> digest;
private final Optional<String> fileName;
private final boolean voiceNote;
private final boolean borderless;
private final int width;
private final int height;
private final Optional<String> caption;
private final Optional<String> blurHash;
private final long uploadTimestamp;
public SignalServiceAttachmentPointer(int cdnNumber, SignalServiceAttachmentRemoteId remoteId,
String contentType, byte[] key,
Optional<Integer> size, Optional<byte[]> preview, int width,
int height, Optional<byte[]> digest,
Optional<String> fileName, boolean voiceNote,
Optional<String> caption, Optional<String> blurHash,
public SignalServiceAttachmentPointer(int cdnNumber,
SignalServiceAttachmentRemoteId remoteId,
String contentType,
byte[] key,
Optional<Integer> size,
Optional<byte[]> preview,
int width,
int height,
Optional<byte[]> digest,
Optional<String> fileName,
boolean voiceNote,
boolean borderless,
Optional<String> caption,
Optional<String> blurHash,
long uploadTimestamp)
{
super(contentType);
@@ -51,6 +60,7 @@ public class SignalServiceAttachmentPointer extends SignalServiceAttachment {
this.digest = digest;
this.fileName = fileName;
this.voiceNote = voiceNote;
this.borderless = borderless;
this.caption = caption;
this.blurHash = blurHash;
this.uploadTimestamp = uploadTimestamp;
@@ -98,6 +108,10 @@ public class SignalServiceAttachmentPointer extends SignalServiceAttachment {
return voiceNote;
}
public boolean isBorderless() {
return borderless;
}
public int getWidth() {
return width;
}

View File

@@ -24,6 +24,7 @@ public class SignalServiceAttachmentStream extends SignalServiceAttachment {
private final CancelationSignal cancelationSignal;
private final Optional<byte[]> preview;
private final boolean voiceNote;
private final boolean borderless;
private final int width;
private final int height;
private final long uploadTimestamp;
@@ -31,8 +32,16 @@ public class SignalServiceAttachmentStream extends SignalServiceAttachment {
private final Optional<String> blurHash;
private final Optional<ResumableUploadSpec> resumableUploadSpec;
public SignalServiceAttachmentStream(InputStream inputStream, String contentType, long length, Optional<String> fileName, boolean voiceNote, ProgressListener listener, CancelationSignal cancelationSignal) {
this(inputStream, contentType, length, fileName, voiceNote, Optional.<byte[]>absent(), 0, 0, System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent(), listener, cancelationSignal, Optional.absent());
public SignalServiceAttachmentStream(InputStream inputStream,
String contentType,
long length,
Optional<String> fileName,
boolean voiceNote,
boolean borderless,
ProgressListener listener,
CancelationSignal cancelationSignal)
{
this(inputStream, contentType, length, fileName, voiceNote, borderless, Optional.<byte[]>absent(), 0, 0, System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent(), listener, cancelationSignal, Optional.absent());
}
public SignalServiceAttachmentStream(InputStream inputStream,
@@ -40,6 +49,7 @@ public class SignalServiceAttachmentStream extends SignalServiceAttachment {
long length,
Optional<String> fileName,
boolean voiceNote,
boolean borderless,
Optional<byte[]> preview,
int width,
int height,
@@ -56,6 +66,7 @@ public class SignalServiceAttachmentStream extends SignalServiceAttachment {
this.fileName = fileName;
this.listener = listener;
this.voiceNote = voiceNote;
this.borderless = borderless;
this.preview = preview;
this.width = width;
this.height = height;
@@ -104,6 +115,10 @@ public class SignalServiceAttachmentStream extends SignalServiceAttachment {
return voiceNote;
}
public boolean isBorderless() {
return borderless;
}
public int getWidth() {
return width;
}

View File

@@ -840,6 +840,7 @@ public final class SignalServiceContent {
pointer.hasDigest() ? Optional.of(pointer.getDigest().toByteArray()) : Optional.<byte[]>absent(),
pointer.hasFileName() ? Optional.of(pointer.getFileName()) : Optional.<String>absent(),
(pointer.getFlags() & SignalServiceProtos.AttachmentPointer.Flags.VOICE_MESSAGE_VALUE) != 0,
(pointer.getFlags() & SignalServiceProtos.AttachmentPointer.Flags.BORDERLESS_VALUE) != 0,
pointer.hasCaption() ? Optional.of(pointer.getCaption()) : Optional.<String>absent(),
pointer.hasBlurHash() ? Optional.of(pointer.getBlurHash()) : Optional.<String>absent(),
pointer.hasUploadTimestamp() ? pointer.getUploadTimestamp() : 0);
@@ -898,6 +899,7 @@ public final class SignalServiceContent {
Optional.fromNullable(pointer.hasDigest() ? pointer.getDigest().toByteArray() : null),
Optional.<String>absent(),
false,
false,
Optional.<String>absent(),
Optional.<String>absent(),
pointer.hasUploadTimestamp() ? pointer.getUploadTimestamp() : 0);

View File

@@ -57,7 +57,7 @@ public class DeviceContactsInputStream extends ChunkedInputStream {
InputStream avatarStream = new LimitedInputStream(in, avatarLength);
String avatarContentType = details.getAvatar().getContentType();
avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, Optional.<String>absent(), false, null, null));
avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, Optional.<String>absent(), false, false, null, null));
}
if (details.hasVerified()) {

View File

@@ -52,7 +52,7 @@ public class DeviceGroupsInputStream extends ChunkedInputStream{
InputStream avatarStream = new ChunkedInputStream.LimitedInputStream(in, avatarLength);
String avatarContentType = details.getAvatar().getContentType();
avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, Optional.<String>absent(), false, null, null));
avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, Optional.<String>absent(), false, false, null, null));
}
if (details.hasExpireTimer() && details.getExpireTimer() > 0) {

View File

@@ -402,6 +402,7 @@ message SyncMessage {
message AttachmentPointer {
enum Flags {
VOICE_MESSAGE = 1;
BORDERLESS = 2;
}
oneof attachment_identifier {