use of org.thoughtcrime.securesms.database.model.StickerRecord in project Signal-Android by WhisperSystems.
the class StickerPackPreviewRepository method getStickersFromDatabase.
@WorkerThread
private List<StickerManifest.Sticker> getStickersFromDatabase(@NonNull String packId) {
List<StickerManifest.Sticker> stickers = new ArrayList<>();
try (Cursor cursor = stickerDatabase.getStickersForPack(packId)) {
StickerDatabase.StickerRecordReader reader = new StickerDatabase.StickerRecordReader(cursor);
StickerRecord record;
while ((record = reader.getNext()) != null) {
stickers.add(toSticker(record));
}
}
return stickers;
}
use of org.thoughtcrime.securesms.database.model.StickerRecord in project Signal-Android by WhisperSystems.
the class PushSendJob method getStickerFor.
protected Optional<SignalServiceDataMessage.Sticker> getStickerFor(OutgoingMediaMessage message) {
Attachment stickerAttachment = Stream.of(message.getAttachments()).filter(Attachment::isSticker).findFirst().orElse(null);
if (stickerAttachment == null) {
return Optional.absent();
}
try {
byte[] packId = Hex.fromStringCondensed(stickerAttachment.getSticker().getPackId());
byte[] packKey = Hex.fromStringCondensed(stickerAttachment.getSticker().getPackKey());
int stickerId = stickerAttachment.getSticker().getStickerId();
StickerRecord record = SignalDatabase.stickers().getSticker(stickerAttachment.getSticker().getPackId(), stickerId, false);
String emoji = record != null ? record.getEmoji() : null;
SignalServiceAttachment attachment = getAttachmentPointerFor(stickerAttachment);
return Optional.of(new SignalServiceDataMessage.Sticker(packId, packKey, stickerId, emoji, attachment));
} catch (IOException e) {
Log.w(TAG, "Failed to decode sticker id/key", e);
return Optional.absent();
}
}
use of org.thoughtcrime.securesms.database.model.StickerRecord in project Signal-Android by WhisperSystems.
the class MessageContentProcessor method getStickerAttachment.
private Optional<Attachment> getStickerAttachment(Optional<SignalServiceDataMessage.Sticker> sticker) {
if (!sticker.isPresent()) {
return Optional.absent();
}
if (sticker.get().getPackId() == null || sticker.get().getPackKey() == null || sticker.get().getAttachment() == null) {
warn("Malformed sticker!");
return Optional.absent();
}
String packId = Hex.toStringCondensed(sticker.get().getPackId());
String packKey = Hex.toStringCondensed(sticker.get().getPackKey());
int stickerId = sticker.get().getStickerId();
String emoji = sticker.get().getEmoji();
StickerLocator stickerLocator = new StickerLocator(packId, packKey, stickerId, emoji);
StickerDatabase stickerDatabase = SignalDatabase.stickers();
StickerRecord stickerRecord = stickerDatabase.getSticker(stickerLocator.getPackId(), stickerLocator.getStickerId(), false);
if (stickerRecord != null) {
return Optional.of(new UriAttachment(stickerRecord.getUri(), stickerRecord.getContentType(), AttachmentDatabase.TRANSFER_PROGRESS_DONE, stickerRecord.getSize(), StickerSlide.WIDTH, StickerSlide.HEIGHT, null, String.valueOf(new SecureRandom().nextLong()), false, false, false, false, null, stickerLocator, null, null, null));
} else {
return Optional.of(PointerAttachment.forPointer(Optional.of(sticker.get().getAttachment()), stickerLocator).get());
}
}
use of org.thoughtcrime.securesms.database.model.StickerRecord in project Signal-Android by signalapp.
the class StickerPackPreviewRepository method getStickersFromDatabase.
@WorkerThread
private List<StickerManifest.Sticker> getStickersFromDatabase(@NonNull String packId) {
List<StickerManifest.Sticker> stickers = new ArrayList<>();
try (Cursor cursor = stickerDatabase.getStickersForPack(packId)) {
StickerDatabase.StickerRecordReader reader = new StickerDatabase.StickerRecordReader(cursor);
StickerRecord record;
while ((record = reader.getNext()) != null) {
stickers.add(toSticker(record));
}
}
return stickers;
}
use of org.thoughtcrime.securesms.database.model.StickerRecord in project Signal-Android by signalapp.
the class MessageContentProcessor method getStickerAttachment.
private Optional<Attachment> getStickerAttachment(Optional<SignalServiceDataMessage.Sticker> sticker) {
if (!sticker.isPresent()) {
return Optional.absent();
}
if (sticker.get().getPackId() == null || sticker.get().getPackKey() == null || sticker.get().getAttachment() == null) {
warn("Malformed sticker!");
return Optional.absent();
}
String packId = Hex.toStringCondensed(sticker.get().getPackId());
String packKey = Hex.toStringCondensed(sticker.get().getPackKey());
int stickerId = sticker.get().getStickerId();
String emoji = sticker.get().getEmoji();
StickerLocator stickerLocator = new StickerLocator(packId, packKey, stickerId, emoji);
StickerDatabase stickerDatabase = SignalDatabase.stickers();
StickerRecord stickerRecord = stickerDatabase.getSticker(stickerLocator.getPackId(), stickerLocator.getStickerId(), false);
if (stickerRecord != null) {
return Optional.of(new UriAttachment(stickerRecord.getUri(), stickerRecord.getContentType(), AttachmentDatabase.TRANSFER_PROGRESS_DONE, stickerRecord.getSize(), StickerSlide.WIDTH, StickerSlide.HEIGHT, null, String.valueOf(new SecureRandom().nextLong()), false, false, false, false, null, stickerLocator, null, null, null));
} else {
return Optional.of(PointerAttachment.forPointer(Optional.of(sticker.get().getAttachment()), stickerLocator).get());
}
}
Aggregations