Search in sources :

Example 6 with StickerPackRecord

use of org.thoughtcrime.securesms.database.model.StickerPackRecord in project Signal-Android by signalapp.

the class StickerManagementRepository method getStickerPacks.

void getStickerPacks(@NonNull Callback<PackResult> callback) {
    SignalExecutors.SERIAL.execute(() -> {
        List<StickerPackRecord> installedPacks = new ArrayList<>();
        List<StickerPackRecord> availablePacks = new ArrayList<>();
        List<StickerPackRecord> blessedPacks = new ArrayList<>();
        try (StickerPackRecordReader reader = new StickerPackRecordReader(stickerDatabase.getAllStickerPacks())) {
            StickerPackRecord record;
            while ((record = reader.getNext()) != null) {
                if (record.isInstalled()) {
                    installedPacks.add(record);
                } else if (BlessedPacks.contains(record.getPackId())) {
                    blessedPacks.add(record);
                } else {
                    availablePacks.add(record);
                }
            }
        }
        callback.onComplete(new PackResult(installedPacks, availablePacks, blessedPacks));
    });
}
Also used : StickerPackRecordReader(org.thoughtcrime.securesms.database.StickerDatabase.StickerPackRecordReader) ArrayList(java.util.ArrayList) StickerPackRecord(org.thoughtcrime.securesms.database.model.StickerPackRecord)

Example 7 with StickerPackRecord

use of org.thoughtcrime.securesms.database.model.StickerPackRecord in project Signal-Android by signalapp.

the class StickerPackPreviewRepository method getManifestFromDatabase.

@WorkerThread
private Optional<StickerManifestResult> getManifestFromDatabase(@NonNull String packId) {
    StickerPackRecord record = stickerDatabase.getStickerPack(packId);
    if (record != null && record.isInstalled()) {
        StickerManifest.Sticker cover = toSticker(record.getCover());
        List<StickerManifest.Sticker> stickers = getStickersFromDatabase(packId);
        StickerManifest manifest = new StickerManifest(record.getPackId(), record.getPackKey(), record.getTitle(), record.getAuthor(), Optional.of(cover), stickers);
        return Optional.of(new StickerManifestResult(manifest, record.isInstalled()));
    }
    return Optional.absent();
}
Also used : StickerPackRecord(org.thoughtcrime.securesms.database.model.StickerPackRecord) SignalServiceStickerManifest(org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest) WorkerThread(androidx.annotation.WorkerThread)

Example 8 with StickerPackRecord

use of org.thoughtcrime.securesms.database.model.StickerPackRecord in project Signal-Android by signalapp.

the class MultiDeviceStickerPackSyncJob method onRun.

@Override
protected void onRun() throws Exception {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    if (!TextSecurePreferences.isMultiDevice(context)) {
        Log.i(TAG, "Not multi device, aborting...");
        return;
    }
    List<StickerPackOperationMessage> operations = new LinkedList<>();
    try (StickerPackRecordReader reader = new StickerPackRecordReader(SignalDatabase.stickers().getInstalledStickerPacks())) {
        StickerPackRecord pack;
        while ((pack = reader.getNext()) != null) {
            byte[] packIdBytes = Hex.fromStringCondensed(pack.getPackId());
            byte[] packKeyBytes = Hex.fromStringCondensed(pack.getPackKey());
            operations.add(new StickerPackOperationMessage(packIdBytes, packKeyBytes, StickerPackOperationMessage.Type.INSTALL));
        }
    }
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    messageSender.sendSyncMessage(SignalServiceSyncMessage.forStickerPackOperations(operations), UnidentifiedAccessUtil.getAccessForSync(context));
}
Also used : StickerPackRecordReader(org.thoughtcrime.securesms.database.StickerDatabase.StickerPackRecordReader) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) StickerPackOperationMessage(org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) StickerPackRecord(org.thoughtcrime.securesms.database.model.StickerPackRecord) LinkedList(java.util.LinkedList)

Aggregations

StickerPackRecord (org.thoughtcrime.securesms.database.model.StickerPackRecord)8 StickerPackRecordReader (org.thoughtcrime.securesms.database.StickerDatabase.StickerPackRecordReader)4 ContentValues (android.content.ContentValues)2 WorkerThread (androidx.annotation.WorkerThread)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 NotPushRegisteredException (org.thoughtcrime.securesms.net.NotPushRegisteredException)2 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)2 SignalServiceStickerManifest (org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest)2 StickerPackOperationMessage (org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage)2