use of org.thoughtcrime.securesms.database.StickerDatabase in project Signal-Android by WhisperSystems.
the class StickerPackDownloadJob method onRun.
@Override
protected void onRun() throws IOException, InvalidMessageException {
if (isReferencePack && !SignalDatabase.attachments().containsStickerPackId(packId) && !BlessedPacks.contains(packId)) {
Log.w(TAG, "There are no attachments with the requested packId present for this reference pack. Skipping.");
return;
}
if (isReferencePack && SignalDatabase.stickers().isPackAvailableAsReference(packId)) {
Log.i(TAG, "Sticker pack already available for reference. Skipping.");
return;
}
SignalServiceMessageReceiver receiver = ApplicationDependencies.getSignalServiceMessageReceiver();
JobManager jobManager = ApplicationDependencies.getJobManager();
StickerDatabase stickerDatabase = SignalDatabase.stickers();
byte[] packIdBytes = Hex.fromStringCondensed(packId);
byte[] packKeyBytes = Hex.fromStringCondensed(packKey);
SignalServiceStickerManifest manifest = receiver.retrieveStickerManifest(packIdBytes, packKeyBytes);
if (manifest.getStickers().isEmpty()) {
Log.w(TAG, "No stickers in pack!");
return;
}
if (!isReferencePack && stickerDatabase.isPackAvailableAsReference(packId)) {
stickerDatabase.markPackAsInstalled(packId, notify);
}
StickerInfo cover = manifest.getCover().or(manifest.getStickers().get(0));
JobManager.Chain chain = jobManager.startChain(new StickerDownloadJob(new IncomingSticker(packId, packKey, manifest.getTitle().or(""), manifest.getAuthor().or(""), cover.getId(), "", cover.getContentType(), true, !isReferencePack), notify));
if (!isReferencePack) {
List<Job> jobs = new ArrayList<>(manifest.getStickers().size());
for (StickerInfo stickerInfo : manifest.getStickers()) {
jobs.add(new StickerDownloadJob(new IncomingSticker(packId, packKey, manifest.getTitle().or(""), manifest.getAuthor().or(""), stickerInfo.getId(), stickerInfo.getEmoji(), stickerInfo.getContentType(), false, true), notify));
}
chain.then(jobs);
}
chain.enqueue();
}
use of org.thoughtcrime.securesms.database.StickerDatabase 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.StickerDatabase in project Signal-Android by WhisperSystems.
the class StickerLaunchMigrationJob method installPack.
private static void installPack(@NonNull Context context, @NonNull BlessedPacks.Pack pack) {
JobManager jobManager = ApplicationDependencies.getJobManager();
StickerDatabase stickerDatabase = SignalDatabase.stickers();
if (stickerDatabase.isPackAvailableAsReference(pack.getPackId())) {
stickerDatabase.markPackAsInstalled(pack.getPackId(), false);
}
jobManager.add(StickerPackDownloadJob.forInstall(pack.getPackId(), pack.getPackKey(), false));
if (TextSecurePreferences.isMultiDevice(context)) {
jobManager.add(new MultiDeviceStickerPackOperationJob(pack.getPackId(), pack.getPackKey(), MultiDeviceStickerPackOperationJob.Type.INSTALL));
}
}
use of org.thoughtcrime.securesms.database.StickerDatabase 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);
}
Aggregations