Add vcard to message

This commit is contained in:
moezbhatti
2018-12-25 22:44:47 -05:00
parent f6e07d9bc3
commit 14b2d2ef8b
11 changed files with 177 additions and 36 deletions
@@ -235,10 +235,9 @@ class MessageRepositoryImpl @Inject constructor(
parts += MMSPart("text", ContentType.TEXT_PLAIN, body.toByteArray())
}
// Add the GIFs as attachments. The app currently can't compress them, which may result
// in a lot of these messages failing to send
// TODO Add support for GIF compression
// Add the GIFs as attachments
parts += attachments
.mapNotNull { attachment -> attachment as? Attachment.Image }
.filter { attachment -> attachment.isGif(context) }
.mapNotNull { attachment -> attachment.getUri() }
.map { uri -> ImageUtils.compressGif(context, uri, prefs.mmsSize.get() * 1024) }
@@ -247,6 +246,7 @@ class MessageRepositoryImpl @Inject constructor(
// Compress the images and add them as attachments
var totalImageBytes = 0
parts += attachments
.mapNotNull { attachment -> attachment as? Attachment.Image }
.filter { attachment -> !attachment.isGif(context) }
.mapNotNull { attachment -> attachment.getUri() }
.mapNotNull { uri -> tryOrNull { imageRepository.loadImage(uri) } }
@@ -257,6 +257,11 @@ class MessageRepositoryImpl @Inject constructor(
}
.map { bitmap -> MMSPart("image", ContentType.IMAGE_JPEG, bitmap) }
// Send contacts
parts += attachments
.mapNotNull { attachment -> attachment as? Attachment.Contact }
.map { attachment -> attachment.vCard.toByteArray() }
.map { vCard -> MMSPart("contact", ContentType.TEXT_VCARD, vCard) }
val transaction = Transaction(context)
transaction.sendNewMessage(subId, threadId, addresses.map(PhoneNumberUtils::stripSeparators), parts, null)