Search in sources :

Example 11 with GroupId

use of org.thoughtcrime.securesms.groups.GroupId in project Signal-Android by WhisperSystems.

the class MessageContentProcessor method shouldIgnore.

private boolean shouldIgnore(@NonNull SignalServiceContent content, @NonNull Recipient sender, @NonNull Recipient conversation) throws BadGroupIdException {
    if (content.getDataMessage().isPresent()) {
        SignalServiceDataMessage message = content.getDataMessage().get();
        if (conversation.isGroup() && conversation.isBlocked()) {
            return true;
        } else if (conversation.isGroup()) {
            GroupDatabase groupDatabase = SignalDatabase.groups();
            Optional<GroupId> groupId = GroupUtil.idFromGroupContext(message.getGroupContext());
            if (groupId.isPresent() && groupId.get().isV1() && message.isGroupV1Update() && groupDatabase.groupExists(groupId.get().requireV1().deriveV2MigrationGroupId())) {
                warn(String.valueOf(content.getTimestamp()), "Ignoring V1 update for a group we've already migrated to V2.");
                return true;
            }
            if (groupId.isPresent() && groupDatabase.isUnknownGroup(groupId.get())) {
                return sender.isBlocked();
            }
            boolean isTextMessage = message.getBody().isPresent();
            boolean isMediaMessage = message.getAttachments().isPresent() || message.getQuote().isPresent() || message.getSharedContacts().isPresent() || message.getSticker().isPresent();
            boolean isExpireMessage = message.isExpirationUpdate();
            boolean isGv2Update = message.isGroupV2Update();
            boolean isContentMessage = !message.isGroupV1Update() && !isGv2Update && !isExpireMessage && (isTextMessage || isMediaMessage);
            boolean isGroupActive = groupId.isPresent() && groupDatabase.isActive(groupId.get());
            boolean isLeaveMessage = message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1Type() == SignalServiceGroup.Type.QUIT;
            return (isContentMessage && !isGroupActive) || (sender.isBlocked() && !isLeaveMessage && !isGv2Update);
        } else {
            return sender.isBlocked();
        }
    } else if (content.getCallMessage().isPresent()) {
        return sender.isBlocked();
    } else if (content.getTypingMessage().isPresent()) {
        if (sender.isBlocked()) {
            return true;
        }
        if (content.getTypingMessage().get().getGroupId().isPresent()) {
            GroupId groupId = GroupId.push(content.getTypingMessage().get().getGroupId().get());
            Recipient groupRecipient = Recipient.externalPossiblyMigratedGroup(context, groupId);
            if (groupRecipient.isBlocked() || !groupRecipient.isActiveGroup()) {
                return true;
            } else {
                Optional<GroupRecord> groupRecord = SignalDatabase.groups().getGroup(groupId);
                return groupRecord.isPresent() && groupRecord.get().isAnnouncementGroup() && !groupRecord.get().getAdmins().contains(sender);
            }
        }
    }
    return false;
}
Also used : SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) Optional(org.whispersystems.libsignal.util.guava.Optional) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) GroupId(org.thoughtcrime.securesms.groups.GroupId)

Example 12 with GroupId

use of org.thoughtcrime.securesms.groups.GroupId in project Signal-Android by WhisperSystems.

the class MessageContentProcessor method handleTypingMessage.

private void handleTypingMessage(@NonNull SignalServiceContent content, @NonNull SignalServiceTypingMessage typingMessage, @NonNull Recipient senderRecipient) throws BadGroupIdException {
    if (!TextSecurePreferences.isTypingIndicatorsEnabled(context)) {
        return;
    }
    long threadId;
    if (typingMessage.getGroupId().isPresent()) {
        GroupId.Push groupId = GroupId.push(typingMessage.getGroupId().get());
        if (!SignalDatabase.groups().isCurrentMember(groupId, senderRecipient.getId())) {
            warn(String.valueOf(content.getTimestamp()), "Seen typing indicator for non-member " + senderRecipient.getId());
            return;
        }
        Recipient groupRecipient = Recipient.externalPossiblyMigratedGroup(context, groupId);
        threadId = SignalDatabase.threads().getOrCreateThreadIdFor(groupRecipient);
    } else {
        threadId = SignalDatabase.threads().getOrCreateThreadIdFor(senderRecipient);
    }
    if (threadId <= 0) {
        warn(String.valueOf(content.getTimestamp()), "Couldn't find a matching thread for a typing message.");
        return;
    }
    if (typingMessage.isTypingStarted()) {
        Log.d(TAG, "Typing started on thread " + threadId);
        ApplicationDependencies.getTypingStatusRepository().onTypingStarted(context, threadId, senderRecipient, content.getSenderDevice());
    } else {
        Log.d(TAG, "Typing stopped on thread " + threadId);
        ApplicationDependencies.getTypingStatusRepository().onTypingStopped(context, threadId, senderRecipient, content.getSenderDevice(), false);
    }
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupId(org.thoughtcrime.securesms.groups.GroupId)

Example 13 with GroupId

use of org.thoughtcrime.securesms.groups.GroupId in project Signal-Android by WhisperSystems.

the class MessageContentProcessor method handleSynchronizeSentMessage.

private void handleSynchronizeSentMessage(@NonNull SignalServiceContent content, @NonNull SentTranscriptMessage message, @NonNull Recipient senderRecipient) throws StorageFailedException, BadGroupIdException, IOException, GroupChangeBusyException {
    log(String.valueOf(content.getTimestamp()), "Processing sent transcript for message with ID " + message.getTimestamp());
    try {
        GroupDatabase groupDatabase = SignalDatabase.groups();
        if (message.getMessage().isGroupV2Message()) {
            GroupId.V2 groupId = GroupId.v2(message.getMessage().getGroupContext().get().getGroupV2().get().getMasterKey());
            if (handleGv2PreProcessing(groupId, content, message.getMessage().getGroupContext().get().getGroupV2().get(), senderRecipient)) {
                return;
            }
        }
        long threadId = -1;
        if (message.isRecipientUpdate()) {
            handleGroupRecipientUpdate(message, content.getTimestamp());
        } else if (message.getMessage().isEndSession()) {
            threadId = handleSynchronizeSentEndSessionMessage(message, content.getTimestamp());
        } else if (message.getMessage().isGroupV1Update()) {
            Long gv1ThreadId = GroupV1MessageProcessor.process(context, content, message.getMessage(), true);
            threadId = gv1ThreadId == null ? -1 : gv1ThreadId;
        } else if (message.getMessage().isGroupV2Update()) {
            handleSynchronizeSentGv2Update(content, message);
            threadId = SignalDatabase.threads().getOrCreateThreadIdFor(getSyncMessageDestination(message));
        } else if (Build.VERSION.SDK_INT > 19 && message.getMessage().getGroupCallUpdate().isPresent()) {
            handleGroupCallUpdateMessage(content, message.getMessage(), GroupUtil.idFromGroupContext(message.getMessage().getGroupContext()), senderRecipient);
        } else if (message.getMessage().isEmptyGroupV2Message()) {
            warn(content.getTimestamp(), "Empty GV2 message! Doing nothing.");
        } else if (message.getMessage().isExpirationUpdate()) {
            threadId = handleSynchronizeSentExpirationUpdate(message);
        } else if (message.getMessage().getReaction().isPresent()) {
            handleReaction(content, message.getMessage(), senderRecipient);
            threadId = SignalDatabase.threads().getOrCreateThreadIdFor(getSyncMessageDestination(message));
        } else if (message.getMessage().getRemoteDelete().isPresent()) {
            handleRemoteDelete(content, message.getMessage(), senderRecipient);
        } else if (message.getMessage().getAttachments().isPresent() || message.getMessage().getQuote().isPresent() || message.getMessage().getPreviews().isPresent() || message.getMessage().getSticker().isPresent() || message.getMessage().isViewOnce() || message.getMessage().getMentions().isPresent()) {
            threadId = handleSynchronizeSentMediaMessage(message, content.getTimestamp());
        } else {
            threadId = handleSynchronizeSentTextMessage(message, content.getTimestamp());
        }
        if (message.getMessage().getGroupContext().isPresent() && groupDatabase.isUnknownGroup(GroupUtil.idFromGroupContext(message.getMessage().getGroupContext().get()))) {
            handleUnknownGroupMessage(content, message.getMessage().getGroupContext().get(), senderRecipient);
        }
        if (message.getMessage().getProfileKey().isPresent()) {
            Recipient recipient = getSyncMessageDestination(message);
            if (recipient != null && !recipient.isSystemContact() && !recipient.isProfileSharing()) {
                SignalDatabase.recipients().setProfileSharing(recipient.getId(), true);
            }
        }
        if (threadId != -1) {
            SignalDatabase.threads().setRead(threadId, true);
            ApplicationDependencies.getMessageNotifier().updateNotification(context);
        }
        if (SignalStore.rateLimit().needsRecaptcha()) {
            log(content.getTimestamp(), "Got a sent transcript while in reCAPTCHA mode. Assuming we're good to message again.");
            RateLimitUtil.retryAllRateLimitedMessages(context);
        }
        ApplicationDependencies.getMessageNotifier().setLastDesktopActivityTimestamp(message.getTimestamp());
    } catch (MmsException e) {
        throw new StorageFailedException(e, content.getSender().getIdentifier(), content.getSenderDevice());
    }
}
Also used : MmsException(org.thoughtcrime.securesms.mms.MmsException) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupId(org.thoughtcrime.securesms.groups.GroupId)

Example 14 with GroupId

use of org.thoughtcrime.securesms.groups.GroupId in project Signal-Android by WhisperSystems.

the class MessageDecryptionUtil method toExceptionMetadata.

private static ExceptionMetadata toExceptionMetadata(@NonNull UnsupportedDataMessageException e) throws NoSenderException {
    String sender = e.getSender();
    if (sender == null)
        throw new NoSenderException();
    GroupId groupId = null;
    if (e.getGroup().isPresent()) {
        try {
            groupId = GroupUtil.idFromGroupContext(e.getGroup().get());
        } catch (BadGroupIdException ex) {
            Log.w(TAG, "Bad group id found in unsupported data message", ex);
        }
    }
    return new ExceptionMetadata(sender, e.getSenderDevice(), groupId);
}
Also used : ExceptionMetadata(org.thoughtcrime.securesms.messages.MessageContentProcessor.ExceptionMetadata) BadGroupIdException(org.thoughtcrime.securesms.groups.BadGroupIdException) GroupId(org.thoughtcrime.securesms.groups.GroupId)

Example 15 with GroupId

use of org.thoughtcrime.securesms.groups.GroupId in project Signal-Android by WhisperSystems.

the class ReviewCardDialogFragment method getRepository.

@NonNull
private ReviewCardRepository getRepository() throws BadGroupIdException {
    RecipientId recipientId = getRecipientId();
    GroupId.V2 groupId = getGroupId();
    if (recipientId != null) {
        return new ReviewCardRepository(requireContext(), recipientId);
    } else if (groupId != null) {
        return new ReviewCardRepository(requireContext(), groupId);
    } else {
        throw new AssertionError();
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) GroupId(org.thoughtcrime.securesms.groups.GroupId) NonNull(androidx.annotation.NonNull)

Aggregations

GroupId (org.thoughtcrime.securesms.groups.GroupId)41 Recipient (org.thoughtcrime.securesms.recipients.Recipient)26 NonNull (androidx.annotation.NonNull)22 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)13 Context (android.content.Context)12 List (java.util.List)11 Log (org.signal.core.util.logging.Log)11 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)11 Collections (java.util.Collections)10 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)10 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)10 Optional (org.whispersystems.libsignal.util.guava.Optional)10 Nullable (androidx.annotation.Nullable)9 IOException (java.io.IOException)9 LinkedList (java.util.LinkedList)8 Collectors (java.util.stream.Collectors)8 SignalStore (org.thoughtcrime.securesms.keyvalue.SignalStore)8 SendMessageResult (org.whispersystems.signalservice.api.messages.SendMessageResult)8 Intent (android.content.Intent)7 Stream (com.annimon.stream.Stream)7