use of org.thoughtcrime.securesms.contactshare.Contact in project Signal-Android by signalapp.
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.contactshare.Contact in project Signal-Android by signalapp.
the class MediaMmsMessageRecord method withAttachments.
@NonNull
public MediaMmsMessageRecord withAttachments(@NonNull Context context, @NonNull List<DatabaseAttachment> attachments) {
Map<AttachmentId, DatabaseAttachment> attachmentIdMap = new HashMap<>();
for (DatabaseAttachment attachment : attachments) {
attachmentIdMap.put(attachment.getAttachmentId(), attachment);
}
List<Contact> contacts = updateContacts(getSharedContacts(), attachmentIdMap);
Set<Attachment> contactAttachments = contacts.stream().map(Contact::getAvatarAttachment).filter(Objects::nonNull).collect(Collectors.toSet());
List<LinkPreview> linkPreviews = updateLinkPreviews(getLinkPreviews(), attachmentIdMap);
Set<Attachment> linkPreviewAttachments = linkPreviews.stream().map(LinkPreview::getThumbnail).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toSet());
Quote quote = updateQuote(context, getQuote(), attachments);
List<DatabaseAttachment> slideAttachments = attachments.stream().filter(a -> !contactAttachments.contains(a)).filter(a -> !linkPreviewAttachments.contains(a)).collect(Collectors.toList());
SlideDeck slideDeck = MmsDatabase.Reader.buildSlideDeck(context, slideAttachments);
return new MediaMmsMessageRecord(getId(), getRecipient(), getIndividualRecipient(), getRecipientDeviceId(), getDateSent(), getDateReceived(), getServerTimestamp(), getDeliveryReceiptCount(), getThreadId(), getBody(), slideDeck, getPartCount(), getType(), getIdentityKeyMismatches(), getNetworkFailures(), getSubscriptionId(), getExpiresIn(), getExpireStarted(), isViewOnce(), getReadReceiptCount(), quote, contacts, linkPreviews, isUnidentified(), getReactions(), isRemoteDelete(), mentionsSelf, getNotifiedTimestamp(), getViewedReceiptCount(), getReceiptTimestamp(), getMessageRanges());
}
use of org.thoughtcrime.securesms.contactshare.Contact in project Signal-Android by signalapp.
the class SendJob method markAttachmentsUploaded.
protected void markAttachmentsUploaded(long messageId, @NonNull OutgoingMediaMessage message) {
List<Attachment> attachments = new LinkedList<>();
attachments.addAll(message.getAttachments());
attachments.addAll(Stream.of(message.getLinkPreviews()).map(lp -> lp.getThumbnail().orNull()).withoutNulls().toList());
attachments.addAll(Stream.of(message.getSharedContacts()).map(Contact::getAvatarAttachment).withoutNulls().toList());
if (message.getOutgoingQuote() != null) {
attachments.addAll(message.getOutgoingQuote().getAttachments());
}
AttachmentDatabase database = SignalDatabase.attachments();
for (Attachment attachment : attachments) {
database.markAttachmentUploaded(messageId, attachment);
}
}
use of org.thoughtcrime.securesms.contactshare.Contact in project Signal-Android by signalapp.
the class MessageSender method sendLocalMediaSelf.
private static void sendLocalMediaSelf(Context context, long messageId) {
try {
ExpiringMessageManager expirationManager = ApplicationDependencies.getExpiringMessageManager();
MessageDatabase mmsDatabase = SignalDatabase.mms();
MmsSmsDatabase mmsSmsDatabase = SignalDatabase.mmsSms();
OutgoingMediaMessage message = mmsDatabase.getOutgoingMessage(messageId);
SyncMessageId syncId = new SyncMessageId(Recipient.self().getId(), message.getSentTimeMillis());
List<Attachment> attachments = new LinkedList<>();
attachments.addAll(message.getAttachments());
attachments.addAll(Stream.of(message.getLinkPreviews()).map(LinkPreview::getThumbnail).filter(Optional::isPresent).map(Optional::get).toList());
attachments.addAll(Stream.of(message.getSharedContacts()).map(Contact::getAvatar).withoutNulls().map(Contact.Avatar::getAttachment).withoutNulls().toList());
List<AttachmentCompressionJob> compressionJobs = Stream.of(attachments).map(a -> AttachmentCompressionJob.fromAttachment((DatabaseAttachment) a, false, -1)).toList();
List<AttachmentMarkUploadedJob> fakeUploadJobs = Stream.of(attachments).map(a -> new AttachmentMarkUploadedJob(messageId, ((DatabaseAttachment) a).getAttachmentId())).toList();
ApplicationDependencies.getJobManager().startChain(compressionJobs).then(fakeUploadJobs).enqueue();
mmsDatabase.markAsSent(messageId, true);
mmsDatabase.markUnidentified(messageId, true);
mmsSmsDatabase.incrementDeliveryReceiptCount(syncId, System.currentTimeMillis());
mmsSmsDatabase.incrementReadReceiptCount(syncId, System.currentTimeMillis());
mmsSmsDatabase.incrementViewedReceiptCount(syncId, System.currentTimeMillis());
if (message.getExpiresIn() > 0 && !message.isExpirationUpdate()) {
mmsDatabase.markExpireStarted(messageId);
expirationManager.scheduleDeletion(messageId, true, message.getExpiresIn());
}
} catch (NoSuchMessageException | MmsException e) {
Log.w(TAG, "Failed to update self-sent message.", e);
}
}
use of org.thoughtcrime.securesms.contactshare.Contact in project Signal-Android by WhisperSystems.
the class MmsDownloadJob method storeRetrievedMms.
private void storeRetrievedMms(String contentLocation, long messageId, long threadId, RetrieveConf retrieved, int subscriptionId, @Nullable RecipientId notificationFrom) throws MmsException {
MessageDatabase database = SignalDatabase.mms();
Optional<GroupId> group = Optional.absent();
Set<RecipientId> members = new HashSet<>();
String body = null;
List<Attachment> attachments = new LinkedList<>();
List<Contact> sharedContacts = new LinkedList<>();
RecipientId from = null;
if (retrieved.getFrom() != null) {
from = Recipient.external(context, Util.toIsoString(retrieved.getFrom().getTextString())).getId();
} else if (notificationFrom != null) {
from = notificationFrom;
}
if (retrieved.getTo() != null) {
for (EncodedStringValue toValue : retrieved.getTo()) {
members.add(Recipient.external(context, Util.toIsoString(toValue.getTextString())).getId());
}
}
if (retrieved.getCc() != null) {
for (EncodedStringValue ccValue : retrieved.getCc()) {
members.add(Recipient.external(context, Util.toIsoString(ccValue.getTextString())).getId());
}
}
if (from != null) {
members.add(from);
}
members.add(Recipient.self().getId());
if (retrieved.getBody() != null) {
body = PartParser.getMessageText(retrieved.getBody());
PduBody media = PartParser.getSupportedMediaParts(retrieved.getBody());
for (int i = 0; i < media.getPartsNum(); i++) {
PduPart part = media.getPart(i);
if (part.getData() != null) {
if (Util.toIsoString(part.getContentType()).toLowerCase().equals(MediaUtil.VCARD)) {
sharedContacts.addAll(VCardUtil.parseContacts(new String(part.getData())));
} else {
Uri uri = BlobProvider.getInstance().forData(part.getData()).createForSingleUseInMemory();
String name = null;
if (part.getName() != null)
name = Util.toIsoString(part.getName());
attachments.add(new UriAttachment(uri, Util.toIsoString(part.getContentType()), AttachmentDatabase.TRANSFER_PROGRESS_DONE, part.getData().length, name, false, false, false, false, null, null, null, null, null));
}
}
}
}
if (members.size() > 2) {
List<RecipientId> recipients = new ArrayList<>(members);
group = Optional.of(SignalDatabase.groups().getOrCreateMmsGroupForMembers(recipients));
}
IncomingMediaMessage message = new IncomingMediaMessage(from, group, body, TimeUnit.SECONDS.toMillis(retrieved.getDate()), -1, System.currentTimeMillis(), attachments, subscriptionId, 0, false, false, false, Optional.of(sharedContacts));
Optional<InsertResult> insertResult = database.insertMessageInbox(message, contentLocation, threadId);
if (insertResult.isPresent()) {
database.deleteMessage(messageId);
ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
}
}
Aggregations