Search in sources :

Example 1 with GroupChangeException

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

the class MessageRequestRepository method blockAndReportSpamMessageRequest.

void blockAndReportSpamMessageRequest(@NonNull LiveRecipient liveRecipient, long threadId, @NonNull Runnable onMessageRequestBlocked, @NonNull GroupChangeErrorCallback error) {
    executor.execute(() -> {
        Recipient recipient = liveRecipient.resolve();
        try {
            RecipientUtil.block(context, recipient);
        } catch (GroupChangeException | IOException e) {
            Log.w(TAG, e);
            error.onError(GroupChangeFailureReason.fromException(e));
            return;
        }
        liveRecipient.refresh();
        ApplicationDependencies.getJobManager().add(new ReportSpamJob(threadId, System.currentTimeMillis()));
        if (TextSecurePreferences.isMultiDevice(context)) {
            ApplicationDependencies.getJobManager().add(MultiDeviceMessageRequestResponseJob.forBlockAndReportSpam(liveRecipient.getId()));
        }
        onMessageRequestBlocked.run();
    });
}
Also used : ReportSpamJob(org.thoughtcrime.securesms.jobs.ReportSpamJob) GroupChangeException(org.thoughtcrime.securesms.groups.GroupChangeException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) IOException(java.io.IOException)

Example 2 with GroupChangeException

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

the class MessageRequestRepository method acceptMessageRequest.

void acceptMessageRequest(@NonNull LiveRecipient liveRecipient, long threadId, @NonNull Runnable onMessageRequestAccepted, @NonNull GroupChangeErrorCallback error) {
    executor.execute(() -> {
        if (liveRecipient.get().isPushV2Group()) {
            try {
                Log.i(TAG, "GV2 accepting invite");
                GroupManager.acceptInvite(context, liveRecipient.get().requireGroupId().requireV2());
                RecipientDatabase recipientDatabase = SignalDatabase.recipients();
                recipientDatabase.setProfileSharing(liveRecipient.getId(), true);
                onMessageRequestAccepted.run();
            } catch (GroupChangeException | IOException e) {
                Log.w(TAG, e);
                error.onError(GroupChangeFailureReason.fromException(e));
            }
        } else {
            RecipientDatabase recipientDatabase = SignalDatabase.recipients();
            recipientDatabase.setProfileSharing(liveRecipient.getId(), true);
            MessageSender.sendProfileKey(context, threadId);
            List<MessageDatabase.MarkedMessageInfo> messageIds = SignalDatabase.threads().setEntireThreadRead(threadId);
            ApplicationDependencies.getMessageNotifier().updateNotification(context);
            MarkReadReceiver.process(context, messageIds);
            List<MessageDatabase.MarkedMessageInfo> viewedInfos = SignalDatabase.mms().getViewedIncomingMessages(threadId);
            SendViewedReceiptJob.enqueue(threadId, liveRecipient.getId(), viewedInfos);
            if (TextSecurePreferences.isMultiDevice(context)) {
                ApplicationDependencies.getJobManager().add(MultiDeviceMessageRequestResponseJob.forAccept(liveRecipient.getId()));
            }
            onMessageRequestAccepted.run();
        }
    });
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) GroupChangeException(org.thoughtcrime.securesms.groups.GroupChangeException) IOException(java.io.IOException)

Example 3 with GroupChangeException

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

the class MessageRequestRepository method deleteMessageRequest.

void deleteMessageRequest(@NonNull LiveRecipient recipient, long threadId, @NonNull Runnable onMessageRequestDeleted, @NonNull GroupChangeErrorCallback error) {
    executor.execute(() -> {
        Recipient resolved = recipient.resolve();
        if (resolved.isGroup() && resolved.requireGroupId().isPush()) {
            try {
                GroupManager.leaveGroupFromBlockOrMessageRequest(context, resolved.requireGroupId().requirePush());
            } catch (GroupChangeException | GroupPatchNotAcceptedException e) {
                if (SignalDatabase.groups().isCurrentMember(resolved.requireGroupId().requirePush(), Recipient.self().getId())) {
                    Log.w(TAG, "Failed to leave group, and we're still a member.", e);
                    error.onError(GroupChangeFailureReason.fromException(e));
                    return;
                } else {
                    Log.w(TAG, "Failed to leave group, but we're not a member, so ignoring.");
                }
            } catch (IOException e) {
                Log.w(TAG, e);
                error.onError(GroupChangeFailureReason.fromException(e));
                return;
            }
        }
        if (TextSecurePreferences.isMultiDevice(context)) {
            ApplicationDependencies.getJobManager().add(MultiDeviceMessageRequestResponseJob.forDelete(recipient.getId()));
        }
        ThreadDatabase threadDatabase = SignalDatabase.threads();
        threadDatabase.deleteConversation(threadId);
        onMessageRequestDeleted.run();
    });
}
Also used : GroupPatchNotAcceptedException(org.whispersystems.signalservice.internal.push.exceptions.GroupPatchNotAcceptedException) GroupChangeException(org.thoughtcrime.securesms.groups.GroupChangeException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) IOException(java.io.IOException) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase)

Example 4 with GroupChangeException

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

the class MessageRequestRepository method blockMessageRequest.

void blockMessageRequest(@NonNull LiveRecipient liveRecipient, @NonNull Runnable onMessageRequestBlocked, @NonNull GroupChangeErrorCallback error) {
    executor.execute(() -> {
        Recipient recipient = liveRecipient.resolve();
        try {
            RecipientUtil.block(context, recipient);
        } catch (GroupChangeException | IOException e) {
            Log.w(TAG, e);
            error.onError(GroupChangeFailureReason.fromException(e));
            return;
        }
        liveRecipient.refresh();
        if (TextSecurePreferences.isMultiDevice(context)) {
            ApplicationDependencies.getJobManager().add(MultiDeviceMessageRequestResponseJob.forBlock(liveRecipient.getId()));
        }
        onMessageRequestBlocked.run();
    });
}
Also used : GroupChangeException(org.thoughtcrime.securesms.groups.GroupChangeException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)4 GroupChangeException (org.thoughtcrime.securesms.groups.GroupChangeException)4 LiveRecipient (org.thoughtcrime.securesms.recipients.LiveRecipient)3 Recipient (org.thoughtcrime.securesms.recipients.Recipient)3 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)1 ThreadDatabase (org.thoughtcrime.securesms.database.ThreadDatabase)1 ReportSpamJob (org.thoughtcrime.securesms.jobs.ReportSpamJob)1 GroupPatchNotAcceptedException (org.whispersystems.signalservice.internal.push.exceptions.GroupPatchNotAcceptedException)1