]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java
Implement listStickerPacks command
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / ManagerImpl.java
index 708b0226ddd513e50d68bbdc5533de62fc8dc03f..fdb289295651790a8bb18c8ac4407a36d6d3f1cd 100644 (file)
@@ -29,6 +29,7 @@ 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.TypingAction;
 import org.asamk.signal.manager.api.UnregisteredRecipientException;
 import org.asamk.signal.manager.api.UpdateGroup;
@@ -682,6 +683,29 @@ public class ManagerImpl implements Manager {
         }
     }
 
+    @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(),
+                            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
     public void requestAllSyncData() throws IOException {
         context.getSyncHelper().requestAllSyncData();