Search in sources :

Example 1 with SignalServiceGroupV2

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

the class PushGroupSilentUpdateSendJob method deliver.

@NonNull
private List<Recipient> deliver(@NonNull List<Recipient> destinations, @NonNull GroupId.V2 groupId) throws IOException, UntrustedIdentityException {
    SignalServiceGroupV2 group = SignalServiceGroupV2.fromProtobuf(groupContextV2);
    SignalServiceDataMessage groupDataMessage = SignalServiceDataMessage.newBuilder().withTimestamp(timestamp).asGroupMessage(group).build();
    List<SendMessageResult> results = GroupSendUtil.sendUnresendableDataMessage(context, groupId, destinations, false, ContentHint.IMPLICIT, groupDataMessage);
    return GroupSendJobHelper.getCompletedSends(destinations, results);
}
Also used : SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) SignalServiceGroupV2(org.whispersystems.signalservice.api.messages.SignalServiceGroupV2) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) NonNull(androidx.annotation.NonNull)

Example 2 with SignalServiceGroupV2

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

the class PushGroupSendJob method deliver.

private List<SendMessageResult> deliver(OutgoingMediaMessage message, @NonNull Recipient groupRecipient, @NonNull List<Recipient> destinations) throws IOException, UntrustedIdentityException, UndeliverableMessageException {
    try {
        rotateSenderCertificateIfNecessary();
        GroupId.Push groupId = groupRecipient.requireGroupId().requirePush();
        Optional<byte[]> profileKey = getProfileKey(groupRecipient);
        Optional<Quote> quote = getQuoteFor(message);
        Optional<SignalServiceDataMessage.Sticker> sticker = getStickerFor(message);
        List<SharedContact> sharedContacts = getSharedContactsFor(message);
        List<Preview> previews = getPreviewsFor(message);
        List<SignalServiceDataMessage.Mention> mentions = getMentionsFor(message.getMentions());
        List<Attachment> attachments = Stream.of(message.getAttachments()).filterNot(Attachment::isSticker).toList();
        List<SignalServiceAttachment> attachmentPointers = getAttachmentPointersFor(attachments);
        boolean isRecipientUpdate = Stream.of(SignalDatabase.groupReceipts().getGroupReceiptInfo(messageId)).anyMatch(info -> info.getStatus() > GroupReceiptDatabase.STATUS_UNDELIVERED);
        if (message.isGroup()) {
            OutgoingGroupUpdateMessage groupMessage = (OutgoingGroupUpdateMessage) message;
            if (groupMessage.isV2Group()) {
                MessageGroupContext.GroupV2Properties properties = groupMessage.requireGroupV2Properties();
                GroupContextV2 groupContext = properties.getGroupContext();
                SignalServiceGroupV2.Builder builder = SignalServiceGroupV2.newBuilder(properties.getGroupMasterKey()).withRevision(groupContext.getRevision());
                ByteString groupChange = groupContext.getGroupChange();
                if (groupChange != null) {
                    builder.withSignedGroupChange(groupChange.toByteArray());
                }
                SignalServiceGroupV2 group = builder.build();
                SignalServiceDataMessage groupDataMessage = SignalServiceDataMessage.newBuilder().withTimestamp(message.getSentTimeMillis()).withExpiration(groupRecipient.getExpiresInSeconds()).asGroupMessage(group).build();
                return GroupSendUtil.sendResendableDataMessage(context, groupRecipient.requireGroupId().requireV2(), destinations, isRecipientUpdate, ContentHint.IMPLICIT, new MessageId(messageId, true), groupDataMessage);
            } else {
                throw new UndeliverableMessageException("Messages can no longer be sent to V1 groups!");
            }
        } else {
            Optional<GroupDatabase.GroupRecord> groupRecord = SignalDatabase.groups().getGroup(groupRecipient.requireGroupId());
            if (groupRecord.isPresent() && groupRecord.get().isAnnouncementGroup() && !groupRecord.get().isAdmin(Recipient.self())) {
                throw new UndeliverableMessageException("Non-admins cannot send messages in announcement groups!");
            }
            SignalServiceDataMessage.Builder builder = SignalServiceDataMessage.newBuilder().withTimestamp(message.getSentTimeMillis());
            GroupUtil.setDataMessageGroupContext(context, builder, groupId);
            SignalServiceDataMessage groupMessage = builder.withAttachments(attachmentPointers).withBody(message.getBody()).withExpiration((int) (message.getExpiresIn() / 1000)).withViewOnce(message.isViewOnce()).asExpirationUpdate(message.isExpirationUpdate()).withProfileKey(profileKey.orNull()).withQuote(quote.orNull()).withSticker(sticker.orNull()).withSharedContacts(sharedContacts).withPreviews(previews).withMentions(mentions).build();
            Log.i(TAG, JobLogger.format(this, "Beginning message send."));
            return GroupSendUtil.sendResendableDataMessage(context, groupRecipient.getGroupId().transform(GroupId::requireV2).orNull(), destinations, isRecipientUpdate, ContentHint.RESENDABLE, new MessageId(messageId, true), groupMessage);
        }
    } catch (ServerRejectedException e) {
        throw new UndeliverableMessageException(e);
    }
}
Also used : ByteString(com.google.protobuf.ByteString) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) OutgoingGroupUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingGroupUpdateMessage) GroupContextV2(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContextV2) MessageGroupContext(org.thoughtcrime.securesms.mms.MessageGroupContext) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) Preview(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage.Preview) ServerRejectedException(org.whispersystems.signalservice.api.push.exceptions.ServerRejectedException) SignalServiceGroupV2(org.whispersystems.signalservice.api.messages.SignalServiceGroupV2) GroupId(org.thoughtcrime.securesms.groups.GroupId) Quote(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage.Quote) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) SharedContact(org.whispersystems.signalservice.api.messages.shared.SharedContact) MessageId(org.thoughtcrime.securesms.database.model.MessageId)

Example 3 with SignalServiceGroupV2

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

the class MessageContentProcessor method handleSynchronizeSentGv2Update.

private void handleSynchronizeSentGv2Update(@NonNull SignalServiceContent content, @NonNull SentTranscriptMessage message) throws IOException, GroupChangeBusyException {
    log(content.getTimestamp(), "Synchronize sent GV2 update for message with timestamp " + message.getTimestamp());
    SignalServiceGroupV2 signalServiceGroupV2 = message.getMessage().getGroupContext().get().getGroupV2().get();
    GroupId.V2 groupIdV2 = GroupId.v2(signalServiceGroupV2.getMasterKey());
    if (!updateGv2GroupFromServerOrP2PChange(content, signalServiceGroupV2)) {
        log(String.valueOf(content.getTimestamp()), "Ignoring GV2 message for group we are not currently in " + groupIdV2);
    }
}
Also used : SignalServiceGroupV2(org.whispersystems.signalservice.api.messages.SignalServiceGroupV2) GroupId(org.thoughtcrime.securesms.groups.GroupId)

Example 4 with SignalServiceGroupV2

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

the class GroupUtil method setDataMessageGroupContext.

@WorkerThread
public static void setDataMessageGroupContext(@NonNull Context context, @NonNull SignalServiceDataMessage.Builder dataMessageBuilder, @NonNull GroupId.Push groupId) {
    if (groupId.isV2()) {
        GroupDatabase groupDatabase = SignalDatabase.groups();
        GroupDatabase.GroupRecord groupRecord = groupDatabase.requireGroup(groupId);
        GroupDatabase.V2GroupProperties v2GroupProperties = groupRecord.requireV2GroupProperties();
        SignalServiceGroupV2 group = SignalServiceGroupV2.newBuilder(v2GroupProperties.getGroupMasterKey()).withRevision(v2GroupProperties.getGroupRevision()).build();
        dataMessageBuilder.asGroupMessage(group);
    } else {
        dataMessageBuilder.asGroupMessage(new SignalServiceGroup(groupId.getDecodedId()));
    }
}
Also used : GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) SignalServiceGroupV2(org.whispersystems.signalservice.api.messages.SignalServiceGroupV2) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

SignalServiceGroupV2 (org.whispersystems.signalservice.api.messages.SignalServiceGroupV2)4 GroupId (org.thoughtcrime.securesms.groups.GroupId)2 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)2 NonNull (androidx.annotation.NonNull)1 WorkerThread (androidx.annotation.WorkerThread)1 ByteString (com.google.protobuf.ByteString)1 Attachment (org.thoughtcrime.securesms.attachments.Attachment)1 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)1 MessageId (org.thoughtcrime.securesms.database.model.MessageId)1 MessageGroupContext (org.thoughtcrime.securesms.mms.MessageGroupContext)1 OutgoingGroupUpdateMessage (org.thoughtcrime.securesms.mms.OutgoingGroupUpdateMessage)1 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)1 SendMessageResult (org.whispersystems.signalservice.api.messages.SendMessageResult)1 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)1 Preview (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage.Preview)1 Quote (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage.Quote)1 SignalServiceGroup (org.whispersystems.signalservice.api.messages.SignalServiceGroup)1 SharedContact (org.whispersystems.signalservice.api.messages.shared.SharedContact)1 ServerRejectedException (org.whispersystems.signalservice.api.push.exceptions.ServerRejectedException)1 GroupContextV2 (org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContextV2)1