mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Implement listStickerPacks command
This commit is contained in:
parent
404063a080
commit
e70463d7b8
10 changed files with 167 additions and 3 deletions
|
@ -1,8 +1,15 @@
|
|||
package org.asamk.signal.manager;
|
||||
|
||||
import org.asamk.signal.manager.api.StickerPack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record JsonStickerPack(String title, String author, JsonSticker cover, List<JsonSticker> stickers) {
|
||||
|
||||
public record JsonSticker(String emoji, String file, String contentType) {}
|
||||
public record JsonSticker(Integer id, String emoji, String file, String contentType) {
|
||||
|
||||
public StickerPack.Sticker toApi() {
|
||||
return new StickerPack.Sticker(id == null ? Integer.parseInt(file) : id, emoji, contentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.asamk.signal.manager.api.Pair;
|
|||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||
import org.asamk.signal.manager.api.SendGroupMessageResults;
|
||||
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;
|
||||
|
@ -221,6 +222,8 @@ public interface Manager extends Closeable {
|
|||
*/
|
||||
URI uploadStickerPack(File path) throws IOException, StickerPackInvalidException;
|
||||
|
||||
List<StickerPack> getStickerPacks();
|
||||
|
||||
void requestAllSyncData() throws IOException;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package org.asamk.signal.manager.api;
|
||||
|
||||
import org.asamk.signal.manager.storage.stickers.StickerPackId;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public record StickerPack(
|
||||
StickerPackId packId,
|
||||
byte[] packKey,
|
||||
boolean installed,
|
||||
String title,
|
||||
String author,
|
||||
Optional<Sticker> cover,
|
||||
List<Sticker> stickers
|
||||
) {
|
||||
|
||||
public StickerPack(final StickerPackId packId, final byte[] packKey, final boolean installed) {
|
||||
this(packId, packKey, installed, "", "", Optional.empty(), List.of());
|
||||
}
|
||||
|
||||
public record Sticker(int id, String emoji, String contentType) {}
|
||||
}
|
|
@ -54,13 +54,15 @@ public class RetrieveStickerPackJob implements Job {
|
|||
final var jsonManifest = new JsonStickerPack(manifest.getTitle().orNull(),
|
||||
manifest.getAuthor().orNull(),
|
||||
manifest.getCover()
|
||||
.transform(c -> new JsonStickerPack.JsonSticker(c.getEmoji(),
|
||||
.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.getEmoji(),
|
||||
.map(c -> new JsonStickerPack.JsonSticker(c.getId(),
|
||||
c.getEmoji(),
|
||||
String.valueOf(c.getId()),
|
||||
c.getContentType()))
|
||||
.toList());
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.asamk.signal.manager.storage.stickers;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -41,6 +42,10 @@ public class StickerStore {
|
|||
return new StickerStore(stickers, saver);
|
||||
}
|
||||
|
||||
public Collection<Sticker> getStickerPacks() {
|
||||
return stickers.values();
|
||||
}
|
||||
|
||||
public Sticker getStickerPack(StickerPackId packId) {
|
||||
synchronized (stickers) {
|
||||
return stickers.get(packId);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue