]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java
Update year
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / ManagerImpl.java
index 708b0226ddd513e50d68bbdc5533de62fc8dc03f..aab5d2304105d12fc4979f7172cdb47d1109dfc0 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2015-2021 AsamK and contributors
+  Copyright (C) 2015-2022 AsamK and contributors
 
   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -29,6 +29,9 @@ import org.asamk.signal.manager.api.RecipientIdentifier;
 import org.asamk.signal.manager.api.SendGroupMessageResults;
 import org.asamk.signal.manager.api.SendMessageResult;
 import org.asamk.signal.manager.api.SendMessageResults;
+import org.asamk.signal.manager.api.StickerPack;
+import org.asamk.signal.manager.api.StickerPackId;
+import org.asamk.signal.manager.api.StickerPackUrl;
 import org.asamk.signal.manager.api.TypingAction;
 import org.asamk.signal.manager.api.UnregisteredRecipientException;
 import org.asamk.signal.manager.api.UpdateGroup;
@@ -48,7 +51,6 @@ import org.asamk.signal.manager.storage.recipients.Profile;
 import org.asamk.signal.manager.storage.recipients.RecipientAddress;
 import org.asamk.signal.manager.storage.recipients.RecipientId;
 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.KeyUtils;
 import org.asamk.signal.manager.util.StickerUtils;
@@ -69,9 +71,6 @@ import org.whispersystems.signalservice.internal.util.Util;
 import java.io.File;
 import java.io.IOException;
 import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
 import java.time.Duration;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -518,10 +517,10 @@ public class ManagerImpl implements Manager {
             final var stickerId = sticker.stickerId();
 
             final var stickerPack = context.getAccount().getStickerStore().getStickerPack(packId);
-            if (stickerPack == null || !context.getStickerPackStore().existsStickerPack(packId)) {
+            if (stickerPack == null) {
                 throw new InvalidStickerException("Sticker pack not found");
             }
-            final var manifest = context.getStickerPackStore().retrieveManifest(packId);
+            final var manifest = context.getStickerHelper().getOrRetrieveStickerPack(packId, stickerPack.getPackKey());
             if (manifest.stickers().size() <= stickerId) {
                 throw new InvalidStickerException("Sticker id not part of this pack");
             }
@@ -657,7 +656,7 @@ public class ManagerImpl implements Manager {
     }
 
     @Override
-    public URI uploadStickerPack(File path) throws IOException, StickerPackInvalidException {
+    public StickerPackUrl uploadStickerPack(File path) throws IOException, StickerPackInvalidException {
         var manifest = StickerUtils.getSignalServiceStickerManifestUpload(path);
 
         var messageSender = dependencies.getMessageSender();
@@ -669,17 +668,30 @@ public class ManagerImpl implements Manager {
         var sticker = new Sticker(packId, packKey);
         account.getStickerStore().updateSticker(sticker);
 
-        try {
-            return new URI("https",
-                    "signal.art",
-                    "/addstickers/",
-                    "pack_id="
-                            + URLEncoder.encode(Hex.toStringCondensed(packId.serialize()), StandardCharsets.UTF_8)
-                            + "&pack_key="
-                            + URLEncoder.encode(Hex.toStringCondensed(packKey), StandardCharsets.UTF_8));
-        } catch (URISyntaxException e) {
-            throw new AssertionError(e);
-        }
+        return new StickerPackUrl(packId, packKey);
+    }
+
+    @Override
+    public List<StickerPack> getStickerPacks() {
+        final var stickerPackStore = context.getStickerPackStore();
+        return account.getStickerStore().getStickerPacks().stream().map(pack -> {
+            if (stickerPackStore.existsStickerPack(pack.getPackId())) {
+                try {
+                    final var manifest = stickerPackStore.retrieveManifest(pack.getPackId());
+                    return new StickerPack(pack.getPackId(),
+                            new StickerPackUrl(pack.getPackId(), pack.getPackKey()),
+                            pack.isInstalled(),
+                            manifest.title(),
+                            manifest.author(),
+                            java.util.Optional.ofNullable(manifest.cover() == null ? null : manifest.cover().toApi()),
+                            manifest.stickers().stream().map(JsonStickerPack.JsonSticker::toApi).toList());
+                } catch (Exception e) {
+                    logger.warn("Failed to read local sticker pack manifest: {}", e.getMessage(), e);
+                }
+            }
+
+            return new StickerPack(pack.getPackId(), pack.getPackKey(), pack.isInstalled());
+        }).toList();
     }
 
     @Override