Search in sources :

Example 1 with LiveRecipient

use of org.thoughtcrime.securesms.recipients.LiveRecipient in project Signal-Android by WhisperSystems.

the class SharedContactView method setContact.

public void setContact(@NonNull Contact contact, @NonNull GlideRequests glideRequests, @NonNull Locale locale) {
    this.glideRequests = glideRequests;
    this.locale = locale;
    this.contact = contact;
    Stream.of(activeRecipients.values()).forEach(recipient -> recipient.removeForeverObserver(this));
    this.activeRecipients.clear();
    presentContact(contact);
    presentAvatar(contact.getAvatarAttachment() != null ? contact.getAvatarAttachment().getUri() : null);
    presentActionButtons(ContactUtil.getRecipients(getContext(), contact));
    for (LiveRecipient recipient : activeRecipients.values()) {
        recipient.observeForever(this);
    }
}
Also used : LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient)

Example 2 with LiveRecipient

use of org.thoughtcrime.securesms.recipients.LiveRecipient in project Signal-Android by WhisperSystems.

the class SharedContactView method presentActionButtons.

private void presentActionButtons(@NonNull List<RecipientId> recipients) {
    for (RecipientId recipientId : recipients) {
        activeRecipients.put(recipientId, Recipient.live(recipientId));
    }
    List<Recipient> pushUsers = new ArrayList<>(recipients.size());
    List<Recipient> systemUsers = new ArrayList<>(recipients.size());
    for (LiveRecipient recipient : activeRecipients.values()) {
        if (recipient.get().getRegistered() == RecipientDatabase.RegisteredState.REGISTERED) {
            pushUsers.add(recipient.get());
        } else if (recipient.get().isSystemContact()) {
            systemUsers.add(recipient.get());
        }
    }
    if (!pushUsers.isEmpty()) {
        actionButtonView.setText(R.string.SharedContactView_message);
        actionButtonView.setOnClickListener(v -> {
            if (eventListener != null) {
                eventListener.onMessageClicked(pushUsers);
            }
        });
    } else if (!systemUsers.isEmpty()) {
        actionButtonView.setText(R.string.SharedContactView_invite_to_signal);
        actionButtonView.setOnClickListener(v -> {
            if (eventListener != null) {
                eventListener.onInviteClicked(systemUsers);
            }
        });
    } else {
        actionButtonView.setText(R.string.SharedContactView_add_to_contacts);
        actionButtonView.setOnClickListener(v -> {
            if (eventListener != null && contact != null) {
                eventListener.onAddToContactsClicked(contact);
            }
        });
    }
}
Also used : RequiresApi(androidx.annotation.RequiresApi) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) ImageView(android.widget.ImageView) HashMap(java.util.HashMap) R(org.thoughtcrime.securesms.R) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) TypedArray(android.content.res.TypedArray) ArrayList(java.util.ArrayList) AttributeSet(android.util.AttributeSet) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Locale(java.util.Locale) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Map(java.util.Map) View(android.view.View) Canvas(android.graphics.Canvas) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Build(android.os.Build) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) Contact(org.thoughtcrime.securesms.contactshare.Contact) RecipientForeverObserver(org.thoughtcrime.securesms.recipients.RecipientForeverObserver) ContactUtil(org.thoughtcrime.securesms.contactshare.ContactUtil) Color(android.graphics.Color) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) DecryptableUri(org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri) GlideRequests(org.thoughtcrime.securesms.mms.GlideRequests) Collections(java.util.Collections) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) ArrayList(java.util.ArrayList) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient)

Example 3 with LiveRecipient

use of org.thoughtcrime.securesms.recipients.LiveRecipient 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 4 with LiveRecipient

use of org.thoughtcrime.securesms.recipients.LiveRecipient 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 5 with LiveRecipient

use of org.thoughtcrime.securesms.recipients.LiveRecipient in project Signal-Android by WhisperSystems.

the class MessageRequestRepository method unblockAndAccept.

void unblockAndAccept(@NonNull LiveRecipient liveRecipient, long threadId, @NonNull Runnable onMessageRequestUnblocked) {
    executor.execute(() -> {
        Recipient recipient = liveRecipient.resolve();
        RecipientUtil.unblock(context, recipient);
        if (TextSecurePreferences.isMultiDevice(context)) {
            ApplicationDependencies.getJobManager().add(MultiDeviceMessageRequestResponseJob.forAccept(liveRecipient.getId()));
        }
        onMessageRequestUnblocked.run();
    });
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient)

Aggregations

LiveRecipient (org.thoughtcrime.securesms.recipients.LiveRecipient)8 Recipient (org.thoughtcrime.securesms.recipients.Recipient)6 IOException (java.io.IOException)3 GroupChangeException (org.thoughtcrime.securesms.groups.GroupChangeException)3 Context (android.content.Context)2 Uri (android.net.Uri)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 DiskCacheStrategy (com.bumptech.glide.load.engine.DiskCacheStrategy)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 R (org.thoughtcrime.securesms.R)2 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)2 DecryptableUri (org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri)2