use of org.thoughtcrime.securesms.database.model.StickerRecord in project Signal-Android by WhisperSystems.
the class StickerDownloadJob method onRun.
@Override
protected void onRun() throws Exception {
StickerDatabase db = SignalDatabase.stickers();
StickerRecord stickerRecord = db.getSticker(sticker.getPackId(), sticker.getStickerId(), sticker.isCover());
if (stickerRecord != null) {
try (InputStream stream = PartAuthority.getAttachmentStream(context, stickerRecord.getUri())) {
if (stream != null) {
Log.w(TAG, "Sticker already downloaded.");
return;
}
} catch (FileNotFoundException e) {
Log.w(TAG, "Sticker file no longer exists, downloading again.");
}
}
if (!db.isPackInstalled(sticker.getPackId()) && !sticker.isCover()) {
Log.w(TAG, "Pack is no longer installed.");
return;
}
SignalServiceMessageReceiver receiver = ApplicationDependencies.getSignalServiceMessageReceiver();
byte[] packIdBytes = Hex.fromStringCondensed(sticker.getPackId());
byte[] packKeyBytes = Hex.fromStringCondensed(sticker.getPackKey());
InputStream stream = receiver.retrieveSticker(packIdBytes, packKeyBytes, sticker.getStickerId());
db.insertSticker(sticker, stream, notify);
}
use of org.thoughtcrime.securesms.database.model.StickerRecord in project Signal-Android by WhisperSystems.
the class StickerSearchRepository method searchByEmoji.
public void searchByEmoji(@NonNull String emoji, @NonNull Callback<List<StickerRecord>> callback) {
SignalExecutors.BOUNDED.execute(() -> {
String searchEmoji = EmojiUtil.getCanonicalRepresentation(emoji);
List<StickerRecord> out = new ArrayList<>();
Set<String> possible = EmojiUtil.getAllRepresentations(searchEmoji);
for (String candidate : possible) {
try (StickerRecordReader reader = new StickerRecordReader(stickerDatabase.getStickersByEmoji(candidate))) {
StickerRecord record = null;
while ((record = reader.getNext()) != null) {
out.add(record);
}
}
}
callback.onResult(out);
});
}
use of org.thoughtcrime.securesms.database.model.StickerRecord in project Signal-Android by signalapp.
the class StickerDownloadJob method onRun.
@Override
protected void onRun() throws Exception {
StickerDatabase db = SignalDatabase.stickers();
StickerRecord stickerRecord = db.getSticker(sticker.getPackId(), sticker.getStickerId(), sticker.isCover());
if (stickerRecord != null) {
try (InputStream stream = PartAuthority.getAttachmentStream(context, stickerRecord.getUri())) {
if (stream != null) {
Log.w(TAG, "Sticker already downloaded.");
return;
}
} catch (FileNotFoundException e) {
Log.w(TAG, "Sticker file no longer exists, downloading again.");
}
}
if (!db.isPackInstalled(sticker.getPackId()) && !sticker.isCover()) {
Log.w(TAG, "Pack is no longer installed.");
return;
}
SignalServiceMessageReceiver receiver = ApplicationDependencies.getSignalServiceMessageReceiver();
byte[] packIdBytes = Hex.fromStringCondensed(sticker.getPackId());
byte[] packKeyBytes = Hex.fromStringCondensed(sticker.getPackKey());
InputStream stream = receiver.retrieveSticker(packIdBytes, packKeyBytes, sticker.getStickerId());
db.insertSticker(sticker, stream, notify);
}
use of org.thoughtcrime.securesms.database.model.StickerRecord in project Signal-Android by signalapp.
the class StickerSearchRepository method searchByEmoji.
public void searchByEmoji(@NonNull String emoji, @NonNull Callback<List<StickerRecord>> callback) {
SignalExecutors.BOUNDED.execute(() -> {
String searchEmoji = EmojiUtil.getCanonicalRepresentation(emoji);
List<StickerRecord> out = new ArrayList<>();
Set<String> possible = EmojiUtil.getAllRepresentations(searchEmoji);
for (String candidate : possible) {
try (StickerRecordReader reader = new StickerRecordReader(stickerDatabase.getStickersByEmoji(candidate))) {
StickerRecord record = null;
while ((record = reader.getNext()) != null) {
out.add(record);
}
}
}
callback.onResult(out);
});
}
use of org.thoughtcrime.securesms.database.model.StickerRecord in project Signal-Android by signalapp.
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();
}
}
Aggregations