Search in sources :

Example 1 with StickerPackRecordReader

use of org.thoughtcrime.securesms.database.StickerDatabase.StickerPackRecordReader in project Signal-Android by WhisperSystems.

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 2 with StickerPackRecordReader

use of org.thoughtcrime.securesms.database.StickerDatabase.StickerPackRecordReader in project Signal-Android by WhisperSystems.

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)

Example 3 with StickerPackRecordReader

use of org.thoughtcrime.securesms.database.StickerDatabase.StickerPackRecordReader 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 4 with StickerPackRecordReader

use of org.thoughtcrime.securesms.database.StickerDatabase.StickerPackRecordReader 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

StickerPackRecordReader (org.thoughtcrime.securesms.database.StickerDatabase.StickerPackRecordReader)4 StickerPackRecord (org.thoughtcrime.securesms.database.model.StickerPackRecord)4 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 NotPushRegisteredException (org.thoughtcrime.securesms.net.NotPushRegisteredException)2 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)2 StickerPackOperationMessage (org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage)2