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);
}
}
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);
}
});
}
}
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();
});
}
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();
});
}
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();
});
}
Aggregations