Add vCard support for received MMS.

This commit is contained in:
Dan
2020-09-14 16:57:26 -04:00
committed by Greyson Parrelli
parent edaf17bdd4
commit 1116502bc0
7 changed files with 219 additions and 148 deletions

View File

@@ -48,7 +48,8 @@ public class IncomingMediaMessage {
long expiresIn,
boolean expirationUpdate,
boolean viewOnce,
boolean unidentified)
boolean unidentified,
Optional<List<Contact>> sharedContacts)
{
this.from = from;
this.groupId = groupId.orNull();
@@ -64,6 +65,8 @@ public class IncomingMediaMessage {
this.unidentified = unidentified;
this.attachments.addAll(attachments);
this.sharedContacts.addAll(sharedContacts.or(Collections.emptyList()));
}
public IncomingMediaMessage(@NonNull RecipientId from,

View File

@@ -9,17 +9,20 @@ import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.util.Util;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.List;
public class PartParser {
private static final String TAG = Log.tag(PartParser.class);
private static final String TAG = Log.tag(PartParser.class);
private static final List<String> DOCUMENT_TYPES = Arrays.asList("text/vcard", "text/x-vcard");
public static String getMessageText(PduBody body) {
String bodyText = null;
for (int i=0;i<body.getPartsNum();i++) {
if (ContentType.isTextType(Util.toIsoString(body.getPart(i).getContentType()))) {
if (isText(body.getPart(i)) && !isDocument(body.getPart(i))) {
String partText;
try {
@@ -49,7 +52,7 @@ public class PartParser {
PduBody stripped = new PduBody();
for (int i=0;i<body.getPartsNum();i++) {
if (isDisplayableMedia(body.getPart(i))) {
if (isDisplayableMedia(body.getPart(i)) || isDocument(body.getPart(i))) {
stripped.addPart(body.getPart(i));
}
}
@@ -61,7 +64,7 @@ public class PartParser {
int partCount = 0;
for (int i=0;i<body.getPartsNum();i++) {
if (isDisplayableMedia(body.getPart(i))) {
if (isDisplayableMedia(body.getPart(i)) || isDocument(body.getPart(i))) {
partCount++;
}
}
@@ -88,4 +91,8 @@ public class PartParser {
public static boolean isDisplayableMedia(PduPart part) {
return isImage(part) || isAudio(part) || isVideo(part);
}
public static boolean isDocument(PduPart part) {
return DOCUMENT_TYPES.contains(Util.toIsoString(part.getContentType()).toLowerCase());
}
}

View File

@@ -204,7 +204,10 @@ public abstract class Slide {
Optional<String> fileName = getFileName();
if (fileName.isPresent()) {
return Optional.of(getFileType(fileName));
String fileType = getFileType(fileName);
if (!fileType.isEmpty()) {
return Optional.of(fileType);
}
}
return Optional.fromNullable(MediaUtil.getExtension(context, getUri()));