Search in sources :

Example 6 with StickerPackOperationMessage

use of org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage 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 7 with StickerPackOperationMessage

use of org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage in project Signal-Android by WhisperSystems.

the class MultiDeviceStickerPackOperationJob method onRun.

@Override
protected void onRun() throws Exception {
    if (!TextSecurePreferences.isMultiDevice(context)) {
        Log.i(TAG, "Not multi device, aborting...");
        return;
    }
    byte[] packIdBytes = Hex.fromStringCondensed(packId);
    byte[] packKeyBytes = Hex.fromStringCondensed(packKey);
    StickerPackOperationMessage.Type remoteType;
    switch(type) {
        case INSTALL:
            remoteType = StickerPackOperationMessage.Type.INSTALL;
            break;
        case REMOVE:
            remoteType = StickerPackOperationMessage.Type.REMOVE;
            break;
        default:
            throw new AssertionError("No matching type?");
    }
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    StickerPackOperationMessage stickerPackOperation = new StickerPackOperationMessage(packIdBytes, packKeyBytes, remoteType);
    messageSender.sendSyncMessage(SignalServiceSyncMessage.forStickerPackOperations(Collections.singletonList(stickerPackOperation)), UnidentifiedAccessUtil.getAccessForSync(context));
}
Also used : StickerPackOperationMessage(org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender)

Example 8 with StickerPackOperationMessage

use of org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage in project Signal-Android by WhisperSystems.

the class SignalServiceMessageSender method createMultiDeviceStickerPackOperationContent.

private Content createMultiDeviceStickerPackOperationContent(List<StickerPackOperationMessage> stickerPackOperations) {
    Content.Builder container = Content.newBuilder();
    SyncMessage.Builder syncMessage = createSyncMessageBuilder();
    for (StickerPackOperationMessage stickerPackOperation : stickerPackOperations) {
        SyncMessage.StickerPackOperation.Builder builder = SyncMessage.StickerPackOperation.newBuilder();
        if (stickerPackOperation.getPackId().isPresent()) {
            builder.setPackId(ByteString.copyFrom(stickerPackOperation.getPackId().get()));
        }
        if (stickerPackOperation.getPackKey().isPresent()) {
            builder.setPackKey(ByteString.copyFrom(stickerPackOperation.getPackKey().get()));
        }
        if (stickerPackOperation.getType().isPresent()) {
            switch(stickerPackOperation.getType().get()) {
                case INSTALL:
                    builder.setType(SyncMessage.StickerPackOperation.Type.INSTALL);
                    break;
                case REMOVE:
                    builder.setType(SyncMessage.StickerPackOperation.Type.REMOVE);
                    break;
            }
        }
        syncMessage.addStickerPackOperation(builder);
    }
    return container.setSyncMessage(syncMessage).build();
}
Also used : SyncMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.SyncMessage) SignalServiceSyncMessage(org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage) EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent) PlaintextContent(org.whispersystems.libsignal.protocol.PlaintextContent) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) StickerPackOperationMessage(org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage)

Example 9 with StickerPackOperationMessage

use of org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage in project Signal-Android by signalapp.

the class SignalServiceMessageSender method createMultiDeviceStickerPackOperationContent.

private Content createMultiDeviceStickerPackOperationContent(List<StickerPackOperationMessage> stickerPackOperations) {
    Content.Builder container = Content.newBuilder();
    SyncMessage.Builder syncMessage = createSyncMessageBuilder();
    for (StickerPackOperationMessage stickerPackOperation : stickerPackOperations) {
        SyncMessage.StickerPackOperation.Builder builder = SyncMessage.StickerPackOperation.newBuilder();
        if (stickerPackOperation.getPackId().isPresent()) {
            builder.setPackId(ByteString.copyFrom(stickerPackOperation.getPackId().get()));
        }
        if (stickerPackOperation.getPackKey().isPresent()) {
            builder.setPackKey(ByteString.copyFrom(stickerPackOperation.getPackKey().get()));
        }
        if (stickerPackOperation.getType().isPresent()) {
            switch(stickerPackOperation.getType().get()) {
                case INSTALL:
                    builder.setType(SyncMessage.StickerPackOperation.Type.INSTALL);
                    break;
                case REMOVE:
                    builder.setType(SyncMessage.StickerPackOperation.Type.REMOVE);
                    break;
            }
        }
        syncMessage.addStickerPackOperation(builder);
    }
    return container.setSyncMessage(syncMessage).build();
}
Also used : SyncMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.SyncMessage) SignalServiceSyncMessage(org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage) EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent) PlaintextContent(org.whispersystems.libsignal.protocol.PlaintextContent) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) StickerPackOperationMessage(org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage)

Example 10 with StickerPackOperationMessage

use of org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage 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

StickerPackOperationMessage (org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage)12 SignalServiceSyncMessage (org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage)6 LinkedList (java.util.LinkedList)5 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)4 SyncMessage (org.whispersystems.signalservice.internal.push.SignalServiceProtos.SyncMessage)4 ByteString (com.google.protobuf.ByteString)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ProtocolInvalidKeyException (org.signal.libsignal.metadata.ProtocolInvalidKeyException)3 IdentityKey (org.whispersystems.libsignal.IdentityKey)3 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)3 BlockedListMessage (org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage)3 ConfigurationMessage (org.whispersystems.signalservice.api.messages.multidevice.ConfigurationMessage)3 ReadMessage (org.whispersystems.signalservice.api.messages.multidevice.ReadMessage)3 RequestMessage (org.whispersystems.signalservice.api.messages.multidevice.RequestMessage)3 SentTranscriptMessage (org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage)3 VerifiedMessage (org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage)3 ViewOnceOpenMessage (org.whispersystems.signalservice.api.messages.multidevice.ViewOnceOpenMessage)3 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)3 Content (org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content)3