Add sticker pack url to list output

This commit is contained in:
AsamK 2022-01-03 18:50:27 +01:00
parent 99eef05084
commit 8a5f98dac6
10 changed files with 133 additions and 44 deletions

View file

@ -35,21 +35,29 @@ public class ListStickerPacksCommand implements JsonRpcLocalCommand {
jsonWriter.write(jsonStickerPacks);
} else if (outputWriter instanceof PlainTextWriter plainTextWriter) {
for (final var sticker : stickerPacks) {
plainTextWriter.println("Pack {}: “{}” by “{}” has {} stickers",
plainTextWriter.println("Pack {}: “{}” by “{}” has {} stickers. {}",
Hex.toStringCondensed(sticker.packId().serialize()),
sticker.title(),
sticker.author(),
sticker.stickers().size());
sticker.stickers().size(),
sticker.url().getUrl());
}
}
}
private record JsonStickerPack(
String packId, boolean installed, String title, String author, JsonSticker cover, List<JsonSticker> stickers
String packId,
String url,
boolean installed,
String title,
String author,
JsonSticker cover,
List<JsonSticker> stickers
) {
JsonStickerPack(StickerPack stickerPack) {
this(Hex.toStringCondensed(stickerPack.packId().serialize()),
stickerPack.url().getUrl().toString(),
stickerPack.installed(),
stickerPack.title(),
stickerPack.author(),

View file

@ -43,10 +43,10 @@ public class UploadStickerPackCommand implements JsonRpcLocalCommand {
try {
var url = m.uploadStickerPack(path);
if (outputWriter instanceof PlainTextWriter writer) {
writer.println("{}", url);
writer.println("{}", url.getUrl());
} else {
final var writer = (JsonWriter) outputWriter;
writer.write(Map.of("url", url));
writer.write(Map.of("url", url.getUrl()));
}
} catch (IOException e) {
throw new IOErrorException("Upload error (maybe image size too large):" + e.getMessage(), e);

View file

@ -19,6 +19,7 @@ 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.StickerPackUrl;
import org.asamk.signal.manager.api.TypingAction;
import org.asamk.signal.manager.api.UpdateGroup;
import org.asamk.signal.manager.groups.GroupId;
@ -436,10 +437,10 @@ public class DbusManagerImpl implements Manager {
}
@Override
public URI uploadStickerPack(final File path) throws IOException, StickerPackInvalidException {
public StickerPackUrl uploadStickerPack(final File path) throws IOException, StickerPackInvalidException {
try {
return new URI(signal.uploadStickerPack(path.getPath()));
} catch (URISyntaxException e) {
return StickerPackUrl.fromUri(new URI(signal.uploadStickerPack(path.getPath())));
} catch (URISyntaxException | StickerPackUrl.InvalidStickerPackLinkException e) {
throw new AssertionError(e);
}
}