mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
parent
d486563099
commit
7cf3a989bf
13 changed files with 296 additions and 3 deletions
|
@ -34,6 +34,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.StickerPackId;
|
||||
import org.asamk.signal.manager.api.StickerPackInvalidException;
|
||||
import org.asamk.signal.manager.api.StickerPackUrl;
|
||||
import org.asamk.signal.manager.api.TypingAction;
|
||||
|
@ -307,6 +308,14 @@ public interface Manager extends Closeable {
|
|||
|
||||
InputStream retrieveAttachment(final String id) throws IOException;
|
||||
|
||||
InputStream retrieveContactAvatar(final RecipientIdentifier.Single recipient) throws IOException, UnregisteredRecipientException;
|
||||
|
||||
InputStream retrieveProfileAvatar(final RecipientIdentifier.Single recipient) throws IOException, UnregisteredRecipientException;
|
||||
|
||||
InputStream retrieveGroupAvatar(final GroupId groupId) throws IOException;
|
||||
|
||||
InputStream retrieveSticker(final StickerPackId stickerPackId, final int stickerId) throws IOException;
|
||||
|
||||
@Override
|
||||
void close();
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package org.asamk.signal.manager.api;
|
||||
|
||||
import org.whispersystems.signalservice.internal.util.Hex;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
|
||||
public class StickerPackId {
|
||||
|
||||
|
@ -36,6 +37,6 @@ public class StickerPackId {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StickerPackId{" + Base64.getUrlEncoder().encodeToString(id) + '}';
|
||||
return "StickerPackId{" + Hex.toStringCondensed(id) + '}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@ import org.whispersystems.signalservice.internal.util.Util;
|
|||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -1337,6 +1338,58 @@ public class ManagerImpl implements Manager {
|
|||
return context.getAttachmentHelper().retrieveAttachment(id).getStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream retrieveContactAvatar(final RecipientIdentifier.Single recipient) throws IOException, UnregisteredRecipientException {
|
||||
final var recipientId = context.getRecipientHelper().resolveRecipient(recipient);
|
||||
final var address = account.getRecipientStore().resolveRecipientAddress(recipientId);
|
||||
final var streamDetails = context.getAvatarStore().retrieveContactAvatar(address);
|
||||
if (streamDetails == null) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
return streamDetails.getStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream retrieveProfileAvatar(final RecipientIdentifier.Single recipient) throws IOException, UnregisteredRecipientException {
|
||||
final var recipientId = context.getRecipientHelper().resolveRecipient(recipient);
|
||||
context.getProfileHelper().getRecipientProfile(recipientId);
|
||||
final var address = account.getRecipientStore().resolveRecipientAddress(recipientId);
|
||||
final var streamDetails = context.getAvatarStore().retrieveProfileAvatar(address);
|
||||
if (streamDetails == null) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
return streamDetails.getStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream retrieveGroupAvatar(final GroupId groupId) throws IOException {
|
||||
final var streamDetails = context.getAvatarStore().retrieveGroupAvatar(groupId);
|
||||
context.getGroupHelper().getGroup(groupId);
|
||||
if (streamDetails == null) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
return streamDetails.getStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream retrieveSticker(final StickerPackId stickerPackId, final int stickerId) throws IOException {
|
||||
var streamDetails = context.getStickerPackStore().retrieveSticker(stickerPackId, stickerId);
|
||||
if (streamDetails == null) {
|
||||
final var pack = account.getStickerStore().getStickerPack(stickerPackId);
|
||||
if (pack != null) {
|
||||
try {
|
||||
context.getStickerHelper().retrieveStickerPack(stickerPackId, pack.packKey());
|
||||
} catch (InvalidMessageException e) {
|
||||
logger.warn("Failed to download sticker pack");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (streamDetails == null) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
return streamDetails.getStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
Thread thread;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue