]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/jobs/RetrieveStickerPackJob.java
Make JobExecutor execute jobs asynchronously
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / jobs / RetrieveStickerPackJob.java
index 4a3ac3069da230d5250f94a40841f02625d158ee..1eeed9dc02e2692a678c1bdf9f9c5c3d55897016 100644 (file)
@@ -1,20 +1,17 @@
 package org.asamk.signal.manager.jobs;
 
-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.storage.stickers.StickerPackId;
-import org.asamk.signal.manager.util.IOUtils;
+import org.signal.libsignal.protocol.InvalidMessageException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.whispersystems.libsignal.InvalidMessageException;
 import org.whispersystems.signalservice.internal.util.Hex;
 
 import java.io.IOException;
-import java.util.HashSet;
 
 public class RetrieveStickerPackJob implements Job {
 
-    private final static Logger logger = LoggerFactory.getLogger(RetrieveStickerPackJob.class);
+    private static final Logger logger = LoggerFactory.getLogger(RetrieveStickerPackJob.class);
 
     private final StickerPackId packId;
     private final byte[] packKey;
@@ -26,47 +23,9 @@ public class RetrieveStickerPackJob implements Job {
 
     @Override
     public void run(Context context) {
-        if (context.getStickerPackStore().existsStickerPack(packId)) {
-            logger.debug("Sticker pack {} already downloaded.", Hex.toStringCondensed(packId.serialize()));
-            return;
-        }
-        logger.debug("Retrieving sticker pack {}.", Hex.toStringCondensed(packId.serialize()));
+        logger.trace("Downloading sticker pack {}", packId);
         try {
-            final var manifest = context.getDependencies()
-                    .getMessageReceiver()
-                    .retrieveStickerManifest(packId.serialize(), packKey);
-
-            final var stickerIds = new HashSet<Integer>();
-            if (manifest.getCover().isPresent()) {
-                stickerIds.add(manifest.getCover().get().getId());
-            }
-            for (var sticker : manifest.getStickers()) {
-                stickerIds.add(sticker.getId());
-            }
-
-            for (var id : stickerIds) {
-                final var inputStream = context.getDependencies()
-                        .getMessageReceiver()
-                        .retrieveSticker(packId.serialize(), packKey, id);
-                context.getStickerPackStore().storeSticker(packId, id, o -> IOUtils.copyStream(inputStream, o));
-            }
-
-            final var jsonManifest = new JsonStickerPack(manifest.getTitle().orNull(),
-                    manifest.getAuthor().orNull(),
-                    manifest.getCover()
-                            .transform(c -> new JsonStickerPack.JsonSticker(c.getId(),
-                                    c.getEmoji(),
-                                    String.valueOf(c.getId()),
-                                    c.getContentType()))
-                            .orNull(),
-                    manifest.getStickers()
-                            .stream()
-                            .map(c -> new JsonStickerPack.JsonSticker(c.getId(),
-                                    c.getEmoji(),
-                                    String.valueOf(c.getId()),
-                                    c.getContentType()))
-                            .toList());
-            context.getStickerPackStore().storeManifest(packId, jsonManifest);
+            context.getStickerHelper().retrieveStickerPack(packId, packKey);
         } catch (IOException e) {
             logger.warn("Failed to retrieve sticker pack {}: {}",
                     Hex.toStringCondensed(packId.serialize()),