Fix GIF attachment flags.

This commit is contained in:
Greyson Parrelli
2025-02-18 12:13:12 -05:00
parent f7bd6bc9ed
commit 7f4e96d619
3 changed files with 6 additions and 47 deletions

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -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))
}
}