Search in sources :

Example 36 with SignalServiceAddress

use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project libsignal-service-java by signalapp.

the class SignalServiceMessageSender method createGroupContent.

private GroupContext createGroupContent(SignalServiceGroup group) throws IOException {
    GroupContext.Builder builder = GroupContext.newBuilder();
    builder.setId(ByteString.copyFrom(group.getGroupId()));
    if (group.getType() != SignalServiceGroup.Type.DELIVER) {
        if (group.getType() == SignalServiceGroup.Type.UPDATE)
            builder.setType(GroupContext.Type.UPDATE);
        else if (group.getType() == SignalServiceGroup.Type.QUIT)
            builder.setType(GroupContext.Type.QUIT);
        else if (group.getType() == SignalServiceGroup.Type.REQUEST_INFO)
            builder.setType(GroupContext.Type.REQUEST_INFO);
        else
            throw new AssertionError("Unknown type: " + group.getType());
        if (group.getName().isPresent()) {
            builder.setName(group.getName().get());
        }
        if (group.getMembers().isPresent()) {
            for (SignalServiceAddress address : group.getMembers().get()) {
                if (address.getNumber().isPresent()) {
                    builder.addMembersE164(address.getNumber().get());
                }
                GroupContext.Member.Builder memberBuilder = GroupContext.Member.newBuilder();
                if (address.getUuid().isPresent()) {
                    memberBuilder.setUuid(address.getUuid().get().toString());
                }
                if (address.getNumber().isPresent()) {
                    memberBuilder.setE164(address.getNumber().get());
                }
                builder.addMembers(memberBuilder.build());
            }
        }
        if (group.getAvatar().isPresent()) {
            if (group.getAvatar().get().isStream()) {
                builder.setAvatar(createAttachmentPointer(group.getAvatar().get().asStream()));
            } else {
                builder.setAvatar(createAttachmentPointer(group.getAvatar().get().asPointer()));
            }
        }
    } else {
        builder.setType(GroupContext.Type.DELIVER);
    }
    return builder.build();
}
Also used : SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)

Example 37 with SignalServiceAddress

use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project libsignal-service-java by signalapp.

the class SignalServiceMessageReceiver method retrieveMessages.

public List<SignalServiceEnvelope> retrieveMessages(MessageReceivedCallback callback) throws IOException {
    List<SignalServiceEnvelope> results = new LinkedList<>();
    List<SignalServiceEnvelopeEntity> entities = socket.getMessages();
    for (SignalServiceEnvelopeEntity entity : entities) {
        SignalServiceEnvelope envelope;
        if (entity.hasSource() && entity.getSourceDevice() > 0) {
            SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrNull(entity.getSourceUuid()), entity.getSourceE164());
            envelope = new SignalServiceEnvelope(entity.getType(), Optional.of(address), entity.getSourceDevice(), entity.getTimestamp(), entity.getMessage(), entity.getContent(), entity.getServerTimestamp(), entity.getServerUuid());
        } else {
            envelope = new SignalServiceEnvelope(entity.getType(), entity.getTimestamp(), entity.getMessage(), entity.getContent(), entity.getServerTimestamp(), entity.getServerUuid());
        }
        callback.onMessage(envelope);
        results.add(envelope);
        if (envelope.hasUuid())
            socket.acknowledgeMessage(envelope.getUuid());
        else
            socket.acknowledgeMessage(entity.getSourceE164(), entity.getTimestamp());
    }
    return results;
}
Also used : SignalServiceEnvelopeEntity(org.whispersystems.signalservice.internal.push.SignalServiceEnvelopeEntity) SignalServiceEnvelope(org.whispersystems.signalservice.api.messages.SignalServiceEnvelope) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) LinkedList(java.util.LinkedList)

Example 38 with SignalServiceAddress

use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by signalapp.

the class GroupV1MessageProcessor method handleGroupCreate.

@Nullable
private static Long handleGroupCreate(@NonNull Context context, @NonNull SignalServiceContent content, @NonNull SignalServiceGroup group, boolean outgoing) {
    GroupDatabase database = SignalDatabase.groups();
    GroupId.V1 id = GroupId.v1orThrow(group.getGroupId());
    GroupContext.Builder builder = createGroupContext(group);
    builder.setType(GroupContext.Type.UPDATE);
    SignalServiceAttachment avatar = group.getAvatar().orNull();
    List<RecipientId> members = new LinkedList<>();
    if (group.getMembers().isPresent()) {
        for (SignalServiceAddress member : group.getMembers().get()) {
            members.add(Recipient.externalGV1Member(member).getId());
        }
    }
    database.create(id, group.getName().orNull(), members, avatar != null && avatar.isPointer() ? avatar.asPointer() : null, null);
    Recipient sender = Recipient.externalHighTrustPush(context, content.getSender());
    if (sender.isSystemContact() || sender.isProfileSharing()) {
        Log.i(TAG, "Auto-enabling profile sharing because 'adder' is trusted. contact: " + sender.isSystemContact() + ", profileSharing: " + sender.isProfileSharing());
        SignalDatabase.recipients().setProfileSharing(Recipient.externalGroupExact(context, id).getId(), true);
    }
    return storeMessage(context, content, group, builder.build(), outgoing);
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext) SignalServiceGroupContext(org.whispersystems.signalservice.api.messages.SignalServiceGroupContext) LinkedList(java.util.LinkedList) Nullable(androidx.annotation.Nullable)

Example 39 with SignalServiceAddress

use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by signalapp.

the class SendRetryReceiptJob method onRun.

@Override
protected void onRun() throws Exception {
    Recipient recipient = Recipient.resolved(recipientId);
    if (recipient.isUnregistered()) {
        Log.w(TAG, recipient.getId() + " not registered!");
        return;
    }
    SignalServiceAddress address = RecipientUtil.toSignalServiceAddress(context, recipient);
    Optional<UnidentifiedAccessPair> access = UnidentifiedAccessUtil.getAccessFor(context, recipient);
    Optional<byte[]> group = groupId.transform(GroupId::getDecodedId);
    Log.i(TAG, "Sending retry receipt for " + errorMessage.getTimestamp() + " to " + recipientId + ", device: " + errorMessage.getDeviceId());
    ApplicationDependencies.getSignalServiceMessageSender().sendRetryReceipt(address, access, group, errorMessage);
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) UnidentifiedAccessPair(org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair) GroupId(org.thoughtcrime.securesms.groups.GroupId)

Example 40 with SignalServiceAddress

use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by signalapp.

the class SendViewedReceiptJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    if (!TextSecurePreferences.isReadReceiptsEnabled(context)) {
        Log.w(TAG, "Read receipts not enabled!");
        return;
    }
    if (messageSentTimestamps.isEmpty()) {
        Log.w(TAG, "No sync timestamps!");
        return;
    }
    if (!RecipientUtil.isMessageRequestAccepted(context, threadId)) {
        Log.w(TAG, "Refusing to send receipts to untrusted recipient");
        return;
    }
    Recipient recipient = Recipient.resolved(recipientId);
    if (recipient.isSelf()) {
        Log.i(TAG, "Not sending view receipt to self.");
        return;
    }
    if (recipient.isBlocked()) {
        Log.w(TAG, "Refusing to send receipts to blocked recipient");
        return;
    }
    if (recipient.isGroup()) {
        Log.w(TAG, "Refusing to send receipts to group");
        return;
    }
    if (recipient.isUnregistered()) {
        Log.w(TAG, recipient.getId() + " not registered!");
        return;
    }
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    SignalServiceAddress remoteAddress = RecipientUtil.toSignalServiceAddress(context, recipient);
    SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.VIEWED, messageSentTimestamps, timestamp);
    SendMessageResult result = messageSender.sendReceipt(remoteAddress, UnidentifiedAccessUtil.getAccessFor(context, Recipient.resolved(recipientId)), receiptMessage);
    if (Util.hasItems(messageIds)) {
        SignalDatabase.messageLog().insertIfPossible(recipientId, timestamp, result, ContentHint.IMPLICIT, messageIds);
    }
}
Also used : NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceReceiptMessage(org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult)

Aggregations

SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)113 Recipient (org.thoughtcrime.securesms.recipients.Recipient)44 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)32 SendMessageResult (org.whispersystems.signalservice.api.messages.SendMessageResult)28 LinkedList (java.util.LinkedList)27 Optional (org.whispersystems.libsignal.util.guava.Optional)23 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)21 NotPushRegisteredException (org.thoughtcrime.securesms.net.NotPushRegisteredException)20 UnidentifiedAccessPair (org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair)20 NonNull (androidx.annotation.NonNull)18 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)18 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)16 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)15 List (java.util.List)14 ByteString (com.google.protobuf.ByteString)13 Nullable (androidx.annotation.Nullable)12 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)12 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)10