mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 20:48:43 +00:00
Fix GIF attachment flags.
This commit is contained in:
@@ -4,7 +4,6 @@ import org.whispersystems.signalservice.api.InvalidMessageStructureException;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId;
|
||||
import org.whispersystems.signalservice.internal.push.AttachmentPointer;
|
||||
import org.whispersystems.util.FlagUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
@@ -30,9 +29,9 @@ public final class AttachmentPointerUtil {
|
||||
pointer.incrementalMac != null ? Optional.of(pointer.incrementalMac.toByteArray()) : Optional.empty(),
|
||||
pointer.chunkSize != null ? pointer.chunkSize : 0,
|
||||
pointer.fileName != null ? Optional.of(pointer.fileName) : Optional.empty(),
|
||||
((pointer.flags != null ? pointer.flags : 0) & FlagUtil.toBinaryFlag(AttachmentPointer.Flags.VOICE_MESSAGE.getValue())) != 0,
|
||||
((pointer.flags != null ? pointer.flags : 0) & FlagUtil.toBinaryFlag(AttachmentPointer.Flags.BORDERLESS.getValue())) != 0,
|
||||
((pointer.flags != null ? pointer.flags : 0) & FlagUtil.toBinaryFlag(AttachmentPointer.Flags.GIF.getValue())) != 0,
|
||||
((pointer.flags != null ? pointer.flags : 0) & AttachmentPointer.Flags.VOICE_MESSAGE.getValue()) != 0,
|
||||
((pointer.flags != null ? pointer.flags : 0) & AttachmentPointer.Flags.BORDERLESS.getValue()) != 0,
|
||||
((pointer.flags != null ? pointer.flags : 0) & AttachmentPointer.Flags.GIF.getValue()) != 0,
|
||||
pointer.caption != null ? Optional.of(pointer.caption) : Optional.empty(),
|
||||
pointer.blurHash != null ? Optional.of(pointer.blurHash) : Optional.empty(),
|
||||
pointer.uploadTimestamp != null ? pointer.uploadTimestamp : 0,
|
||||
@@ -83,15 +82,15 @@ public final class AttachmentPointerUtil {
|
||||
int flags = 0;
|
||||
|
||||
if (attachment.getVoiceNote()) {
|
||||
flags |= FlagUtil.toBinaryFlag(AttachmentPointer.Flags.VOICE_MESSAGE.getValue());
|
||||
flags |= AttachmentPointer.Flags.VOICE_MESSAGE.getValue();
|
||||
}
|
||||
|
||||
if (attachment.isBorderless()) {
|
||||
flags |= FlagUtil.toBinaryFlag(AttachmentPointer.Flags.BORDERLESS.getValue());
|
||||
flags |= AttachmentPointer.Flags.BORDERLESS.getValue();
|
||||
}
|
||||
|
||||
if (attachment.isGif()) {
|
||||
flags |= FlagUtil.toBinaryFlag(AttachmentPointer.Flags.GIF.getValue());
|
||||
flags |= AttachmentPointer.Flags.GIF.getValue();
|
||||
}
|
||||
|
||||
builder.flags(flags);
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package org.whispersystems.util;
|
||||
|
||||
public final class FlagUtil {
|
||||
|
||||
private FlagUtil() {}
|
||||
|
||||
/**
|
||||
* Left shift 1 by 'flag' - 1 spaces.
|
||||
*
|
||||
* Examples:
|
||||
* 1 -> 0001
|
||||
* 2 -> 0010
|
||||
* 3 -> 0100
|
||||
* 4 -> 1000
|
||||
*/
|
||||
public static int toBinaryFlag(int flag) {
|
||||
return 1 << (flag - 1);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package org.whispersystems.util
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class FlagUtilTest {
|
||||
@Test
|
||||
fun given1_whenIConvertToBinaryFlag_thenIExpect1() {
|
||||
assertEquals(1, FlagUtil.toBinaryFlag(1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun given2_whenIConvertToBinaryFlag_thenIExpect2() {
|
||||
assertEquals(2, FlagUtil.toBinaryFlag(2))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun given3_whenIConvertToBinaryFlag_thenIExpect4() {
|
||||
assertEquals(4, FlagUtil.toBinaryFlag(3))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user