Change stickerId to hex everywhere

Remove packKey from output
This commit is contained in:
AsamK 2022-01-03 17:51:04 +01:00
parent e70463d7b8
commit beb3adcc72
12 changed files with 23 additions and 20 deletions

View file

@ -30,6 +30,7 @@ import org.asamk.signal.manager.api.SendGroupMessageResults;
import org.asamk.signal.manager.api.SendMessageResult; import org.asamk.signal.manager.api.SendMessageResult;
import org.asamk.signal.manager.api.SendMessageResults; import org.asamk.signal.manager.api.SendMessageResults;
import org.asamk.signal.manager.api.StickerPack; import org.asamk.signal.manager.api.StickerPack;
import org.asamk.signal.manager.api.StickerPackId;
import org.asamk.signal.manager.api.TypingAction; import org.asamk.signal.manager.api.TypingAction;
import org.asamk.signal.manager.api.UnregisteredRecipientException; import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.api.UpdateGroup; import org.asamk.signal.manager.api.UpdateGroup;
@ -49,7 +50,6 @@ import org.asamk.signal.manager.storage.recipients.Profile;
import org.asamk.signal.manager.storage.recipients.RecipientAddress; import org.asamk.signal.manager.storage.recipients.RecipientAddress;
import org.asamk.signal.manager.storage.recipients.RecipientId; import org.asamk.signal.manager.storage.recipients.RecipientId;
import org.asamk.signal.manager.storage.stickers.Sticker; import org.asamk.signal.manager.storage.stickers.Sticker;
import org.asamk.signal.manager.storage.stickers.StickerPackId;
import org.asamk.signal.manager.util.AttachmentUtils; import org.asamk.signal.manager.util.AttachmentUtils;
import org.asamk.signal.manager.util.KeyUtils; import org.asamk.signal.manager.util.KeyUtils;
import org.asamk.signal.manager.util.StickerUtils; import org.asamk.signal.manager.util.StickerUtils;

View file

@ -2,7 +2,7 @@ package org.asamk.signal.manager;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.asamk.signal.manager.storage.stickers.StickerPackId; import org.asamk.signal.manager.api.StickerPackId;
import org.asamk.signal.manager.util.IOUtils; import org.asamk.signal.manager.util.IOUtils;
import org.asamk.signal.manager.util.Utils; import org.asamk.signal.manager.util.Utils;
import org.whispersystems.signalservice.api.util.StreamDetails; import org.whispersystems.signalservice.api.util.StreamDetails;

View file

@ -322,10 +322,12 @@ public record MessageEnvelope(
} }
} }
public record Sticker(byte[] packId, byte[] packKey, int stickerId) { public record Sticker(StickerPackId packId, byte[] packKey, int stickerId) {
static Sticker from(SignalServiceDataMessage.Sticker sticker) { static Sticker from(SignalServiceDataMessage.Sticker sticker) {
return new Sticker(sticker.getPackId(), sticker.getPackKey(), sticker.getStickerId()); return new Sticker(StickerPackId.deserialize(sticker.getPackId()),
sticker.getPackKey(),
sticker.getStickerId());
} }
} }

View file

@ -1,7 +1,5 @@
package org.asamk.signal.manager.api; package org.asamk.signal.manager.api;
import org.asamk.signal.manager.storage.stickers.StickerPackId;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;

View file

@ -1,4 +1,4 @@
package org.asamk.signal.manager.storage.stickers; package org.asamk.signal.manager.api;
import java.util.Arrays; import java.util.Arrays;

View file

@ -20,6 +20,7 @@ import org.asamk.signal.manager.actions.SendSyncGroupsAction;
import org.asamk.signal.manager.actions.SendSyncKeysAction; import org.asamk.signal.manager.actions.SendSyncKeysAction;
import org.asamk.signal.manager.api.MessageEnvelope; import org.asamk.signal.manager.api.MessageEnvelope;
import org.asamk.signal.manager.api.Pair; import org.asamk.signal.manager.api.Pair;
import org.asamk.signal.manager.api.StickerPackId;
import org.asamk.signal.manager.groups.GroupId; import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.groups.GroupNotFoundException; import org.asamk.signal.manager.groups.GroupNotFoundException;
import org.asamk.signal.manager.groups.GroupUtils; import org.asamk.signal.manager.groups.GroupUtils;
@ -29,7 +30,6 @@ import org.asamk.signal.manager.storage.groups.GroupInfoV1;
import org.asamk.signal.manager.storage.recipients.Profile; import org.asamk.signal.manager.storage.recipients.Profile;
import org.asamk.signal.manager.storage.recipients.RecipientId; import org.asamk.signal.manager.storage.recipients.RecipientId;
import org.asamk.signal.manager.storage.stickers.Sticker; import org.asamk.signal.manager.storage.stickers.Sticker;
import org.asamk.signal.manager.storage.stickers.StickerPackId;
import org.signal.libsignal.metadata.ProtocolInvalidKeyException; import org.signal.libsignal.metadata.ProtocolInvalidKeyException;
import org.signal.libsignal.metadata.ProtocolInvalidKeyIdException; import org.signal.libsignal.metadata.ProtocolInvalidKeyIdException;
import org.signal.libsignal.metadata.ProtocolInvalidMessageException; import org.signal.libsignal.metadata.ProtocolInvalidMessageException;

View file

@ -1,8 +1,8 @@
package org.asamk.signal.manager.jobs; package org.asamk.signal.manager.jobs;
import org.asamk.signal.manager.JsonStickerPack; import org.asamk.signal.manager.JsonStickerPack;
import org.asamk.signal.manager.api.StickerPackId;
import org.asamk.signal.manager.helper.Context; import org.asamk.signal.manager.helper.Context;
import org.asamk.signal.manager.storage.stickers.StickerPackId;
import org.asamk.signal.manager.util.IOUtils; import org.asamk.signal.manager.util.IOUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;

View file

@ -1,5 +1,7 @@
package org.asamk.signal.manager.storage.stickers; package org.asamk.signal.manager.storage.stickers;
import org.asamk.signal.manager.api.StickerPackId;
public class Sticker { public class Sticker {
private final StickerPackId packId; private final StickerPackId packId;

View file

@ -1,5 +1,7 @@
package org.asamk.signal.manager.storage.stickers; package org.asamk.signal.manager.storage.stickers;
import org.asamk.signal.manager.api.StickerPackId;
import java.util.Base64; import java.util.Base64;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;

View file

@ -8,10 +8,10 @@ import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.storage.recipients.RecipientAddress; import org.asamk.signal.manager.storage.recipients.RecipientAddress;
import org.asamk.signal.output.PlainTextWriter; import org.asamk.signal.output.PlainTextWriter;
import org.asamk.signal.util.DateUtils; import org.asamk.signal.util.DateUtils;
import org.asamk.signal.util.Hex;
import org.slf4j.helpers.MessageFormatter; import org.slf4j.helpers.MessageFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Base64;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
@ -349,8 +349,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
private void printSticker( private void printSticker(
final PlainTextWriter writer, final MessageEnvelope.Data.Sticker sticker final PlainTextWriter writer, final MessageEnvelope.Data.Sticker sticker
) { ) {
writer.println("Pack id: {}", Base64.getEncoder().encodeToString(sticker.packId())); writer.println("Pack id: {}", Hex.toStringCondensed(sticker.packId().serialize()));
writer.println("Pack key: {}", Base64.getEncoder().encodeToString(sticker.packKey()));
writer.println("Sticker id: {}", sticker.stickerId()); writer.println("Sticker id: {}", sticker.stickerId());
} }

View file

@ -162,7 +162,10 @@ public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler
} }
private Map<String, Variant<? extends Serializable>> getStickerMap(final MessageEnvelope.Data.Sticker sticker) { private Map<String, Variant<? extends Serializable>> getStickerMap(final MessageEnvelope.Data.Sticker sticker) {
return Map.of("packId", new Variant<>(sticker.packId()), "stickerId", new Variant<>(sticker.stickerId())); return Map.of("packId",
new Variant<>(sticker.packId().serialize()),
"stickerId",
new Variant<>(sticker.stickerId()));
} }
private Map<String, Variant<?>> getReactionMap(final MessageEnvelope.Data.Reaction reaction) { private Map<String, Variant<?>> getReactionMap(final MessageEnvelope.Data.Reaction reaction) {

View file

@ -1,16 +1,13 @@
package org.asamk.signal.json; package org.asamk.signal.json;
import org.asamk.signal.manager.api.MessageEnvelope; import org.asamk.signal.manager.api.MessageEnvelope;
import org.asamk.signal.util.Hex;
import java.util.Base64; public record JsonSticker(String packId, int stickerId) {
public record JsonSticker(String packId, String packKey, int stickerId) {
static JsonSticker from(MessageEnvelope.Data.Sticker sticker) { static JsonSticker from(MessageEnvelope.Data.Sticker sticker) {
final var encoder = Base64.getEncoder(); final var packId = Hex.toStringCondensed(sticker.packId().serialize());
final var packId = encoder.encodeToString(sticker.packId());
final var packKey = encoder.encodeToString(sticker.packKey());
final var stickerId = sticker.stickerId(); final var stickerId = sticker.stickerId();
return new JsonSticker(packId, packKey, stickerId); return new JsonSticker(packId, stickerId);
} }
} }