use of org.thoughtcrime.securesms.contactshare.Contact in project Signal-Android by WhisperSystems.
the class PushSendJob method getSharedContactsFor.
List<SharedContact> getSharedContactsFor(OutgoingMediaMessage mediaMessage) {
List<SharedContact> sharedContacts = new LinkedList<>();
for (Contact contact : mediaMessage.getSharedContacts()) {
SharedContact.Builder builder = ContactModelMapper.localToRemoteBuilder(contact);
SharedContact.Avatar avatar = null;
if (contact.getAvatar() != null && contact.getAvatar().getAttachment() != null) {
avatar = SharedContact.Avatar.newBuilder().withAttachment(getAttachmentFor(contact.getAvatarAttachment())).withProfileFlag(contact.getAvatar().isProfile()).build();
}
builder.setAvatar(avatar);
sharedContacts.add(builder.build());
}
return sharedContacts;
}
use of org.thoughtcrime.securesms.contactshare.Contact in project Signal-Android by WhisperSystems.
the class MmsDatabase method insertMediaMessage.
private long insertMediaMessage(long threadId, @Nullable String body, @NonNull List<Attachment> attachments, @NonNull List<Attachment> quoteAttachments, @NonNull List<Contact> sharedContacts, @NonNull List<LinkPreview> linkPreviews, @NonNull List<Mention> mentions, @Nullable BodyRangeList messageRanges, @NonNull ContentValues contentValues, @Nullable InsertListener insertListener, boolean updateThread) throws MmsException {
SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
AttachmentDatabase partsDatabase = SignalDatabase.attachments();
MentionDatabase mentionDatabase = SignalDatabase.mentions();
boolean mentionsSelf = Stream.of(mentions).filter(m -> Recipient.resolved(m.getRecipientId()).isSelf()).findFirst().isPresent();
List<Attachment> allAttachments = new LinkedList<>();
List<Attachment> contactAttachments = Stream.of(sharedContacts).map(Contact::getAvatarAttachment).filter(a -> a != null).toList();
List<Attachment> previewAttachments = Stream.of(linkPreviews).filter(lp -> lp.getThumbnail().isPresent()).map(lp -> lp.getThumbnail().get()).toList();
allAttachments.addAll(attachments);
allAttachments.addAll(contactAttachments);
allAttachments.addAll(previewAttachments);
contentValues.put(BODY, body);
contentValues.put(PART_COUNT, allAttachments.size());
contentValues.put(MENTIONS_SELF, mentionsSelf ? 1 : 0);
if (messageRanges != null) {
contentValues.put(MESSAGE_RANGES, messageRanges.toByteArray());
}
db.beginTransaction();
try {
long messageId = db.insert(TABLE_NAME, null, contentValues);
mentionDatabase.insert(threadId, messageId, mentions);
Map<Attachment, AttachmentId> insertedAttachments = partsDatabase.insertAttachmentsForMessage(messageId, allAttachments, quoteAttachments);
String serializedContacts = getSerializedSharedContacts(insertedAttachments, sharedContacts);
String serializedPreviews = getSerializedLinkPreviews(insertedAttachments, linkPreviews);
if (!TextUtils.isEmpty(serializedContacts)) {
ContentValues contactValues = new ContentValues();
contactValues.put(SHARED_CONTACTS, serializedContacts);
SQLiteDatabase database = databaseHelper.getSignalReadableDatabase();
int rows = database.update(TABLE_NAME, contactValues, ID + " = ?", new String[] { String.valueOf(messageId) });
if (rows <= 0) {
Log.w(TAG, "Failed to update message with shared contact data.");
}
}
if (!TextUtils.isEmpty(serializedPreviews)) {
ContentValues contactValues = new ContentValues();
contactValues.put(LINK_PREVIEWS, serializedPreviews);
SQLiteDatabase database = databaseHelper.getSignalReadableDatabase();
int rows = database.update(TABLE_NAME, contactValues, ID + " = ?", new String[] { String.valueOf(messageId) });
if (rows <= 0) {
Log.w(TAG, "Failed to update message with link preview data.");
}
}
db.setTransactionSuccessful();
return messageId;
} finally {
db.endTransaction();
if (insertListener != null) {
insertListener.onComplete();
}
long contentValuesThreadId = contentValues.getAsLong(THREAD_ID);
if (updateThread) {
SignalDatabase.threads().setLastScrolled(contentValuesThreadId, 0);
SignalDatabase.threads().update(threadId, true);
}
}
}
use of org.thoughtcrime.securesms.contactshare.Contact in project Signal-Android by WhisperSystems.
the class MmsDatabase method getSharedContacts.
private static List<Contact> getSharedContacts(@NonNull Cursor cursor, @NonNull List<DatabaseAttachment> attachments) {
String serializedContacts = cursor.getString(cursor.getColumnIndexOrThrow(SHARED_CONTACTS));
if (TextUtils.isEmpty(serializedContacts)) {
return Collections.emptyList();
}
Map<AttachmentId, DatabaseAttachment> attachmentIdMap = new HashMap<>();
for (DatabaseAttachment attachment : attachments) {
attachmentIdMap.put(attachment.getAttachmentId(), attachment);
}
try {
List<Contact> contacts = new LinkedList<>();
JSONArray jsonContacts = new JSONArray(serializedContacts);
for (int i = 0; i < jsonContacts.length(); i++) {
Contact contact = Contact.deserialize(jsonContacts.getJSONObject(i).toString());
if (contact.getAvatar() != null && contact.getAvatar().getAttachmentId() != null) {
DatabaseAttachment attachment = attachmentIdMap.get(contact.getAvatar().getAttachmentId());
Avatar updatedAvatar = new Avatar(contact.getAvatar().getAttachmentId(), attachment, contact.getAvatar().isProfile());
contacts.add(new Contact(contact, updatedAvatar));
} else {
contacts.add(contact);
}
}
return contacts;
} catch (JSONException | IOException e) {
Log.w(TAG, "Failed to parse shared contacts.", e);
}
return Collections.emptyList();
}
use of org.thoughtcrime.securesms.contactshare.Contact in project Signal-Android by signalapp.
the class ThreadBodyUtil method getFormattedBodyForMms.
@NonNull
private static String getFormattedBodyForMms(@NonNull Context context, @NonNull MmsMessageRecord record) {
if (record.getSharedContacts().size() > 0) {
Contact contact = record.getSharedContacts().get(0);
return ContactUtil.getStringSummary(context, contact).toString();
} else if (record.getSlideDeck().getDocumentSlide() != null) {
return format(context, record, EmojiStrings.FILE, R.string.ThreadRecord_file);
} else if (record.getSlideDeck().getAudioSlide() != null) {
return format(context, record, EmojiStrings.AUDIO, R.string.ThreadRecord_voice_message);
} else if (MessageRecordUtil.hasSticker(record)) {
String emoji = getStickerEmoji(record);
return format(context, record, emoji, R.string.ThreadRecord_sticker);
}
boolean hasImage = false;
boolean hasVideo = false;
boolean hasGif = false;
for (Slide slide : record.getSlideDeck().getSlides()) {
hasVideo |= slide.hasVideo();
hasImage |= slide.hasImage();
hasGif |= slide instanceof GifSlide || slide.isVideoGif();
}
if (hasGif) {
return format(context, record, EmojiStrings.GIF, R.string.ThreadRecord_gif);
} else if (hasVideo) {
return format(context, record, EmojiStrings.VIDEO, R.string.ThreadRecord_video);
} else if (hasImage) {
return format(context, record, EmojiStrings.PHOTO, R.string.ThreadRecord_photo);
} else if (TextUtils.isEmpty(record.getBody())) {
return context.getString(R.string.ThreadRecord_media_message);
} else {
return getBody(context, record);
}
}
use of org.thoughtcrime.securesms.contactshare.Contact in project Signal-Android by signalapp.
the class MmsDatabase method getSharedContacts.
private static List<Contact> getSharedContacts(@NonNull Cursor cursor, @NonNull List<DatabaseAttachment> attachments) {
String serializedContacts = cursor.getString(cursor.getColumnIndexOrThrow(SHARED_CONTACTS));
if (TextUtils.isEmpty(serializedContacts)) {
return Collections.emptyList();
}
Map<AttachmentId, DatabaseAttachment> attachmentIdMap = new HashMap<>();
for (DatabaseAttachment attachment : attachments) {
attachmentIdMap.put(attachment.getAttachmentId(), attachment);
}
try {
List<Contact> contacts = new LinkedList<>();
JSONArray jsonContacts = new JSONArray(serializedContacts);
for (int i = 0; i < jsonContacts.length(); i++) {
Contact contact = Contact.deserialize(jsonContacts.getJSONObject(i).toString());
if (contact.getAvatar() != null && contact.getAvatar().getAttachmentId() != null) {
DatabaseAttachment attachment = attachmentIdMap.get(contact.getAvatar().getAttachmentId());
Avatar updatedAvatar = new Avatar(contact.getAvatar().getAttachmentId(), attachment, contact.getAvatar().isProfile());
contacts.add(new Contact(contact, updatedAvatar));
} else {
contacts.add(contact);
}
}
return contacts;
} catch (JSONException | IOException e) {
Log.w(TAG, "Failed to parse shared contacts.", e);
}
return Collections.emptyList();
}
Aggregations