show attachment emoji in conversation previews

This commit is contained in:
Ryan ZHAO 2020-09-03 14:41:00 +10:00
parent 4a740780ca
commit f42855f43e
3 changed files with 18 additions and 18 deletions

View File

@ -620,13 +620,18 @@ public class ThreadDatabase extends Database {
private @NonNull String getFormattedBodyFor(@NonNull MessageRecord messageRecord) {
if (messageRecord.isMms()) {
MmsMessageRecord record = (MmsMessageRecord) messageRecord;
if (record.getSlideDeck().getBody())
if (record.getSharedContacts().size() > 0) {
Contact contact = ((MmsMessageRecord) messageRecord).getSharedContacts().get(0);
return ContactUtil.getStringSummary(context, contact).toString();
}
String attachmentString = record.getSlideDeck().getBody();
if (!attachmentString.isEmpty()) {
if (!messageRecord.getBody().isEmpty()) {
attachmentString = attachmentString + ": " + messageRecord.getBody();
}
return attachmentString;
}
}
return messageRecord.getBody();
}

View File

@ -146,13 +146,10 @@ public class OutgoingMediaMessage {
}
private static String buildMessage(SlideDeck slideDeck, String message) {
if (!TextUtils.isEmpty(message) && !TextUtils.isEmpty(slideDeck.getBody())) {
return slideDeck.getBody() + "\n\n" + message;
} else if (!TextUtils.isEmpty(message)) {
if (!TextUtils.isEmpty(message)) {
return message;
} else {
return slideDeck.getBody();
}
return "";
}
}

View File

@ -22,8 +22,6 @@ import android.net.Uri;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.util.MimeTypes;
import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.attachments.UriAttachment;
import org.thoughtcrime.securesms.database.AttachmentDatabase;
@ -64,7 +62,7 @@ public abstract class Slide {
public Optional<String> getBody() {
String attachmentString = context.getString(R.string.attachment);
if (MimeTypes.isAudio(attachment.getContentType())) {
if (MediaUtil.isAudio(attachment)) {
// a missing filename is the legacy way to determine if an audio attachment is
// a voice note vs. other arbitrary audio attachments.
if (attachment.isVoiceNote() || !attachment.getFileName().isEmpty()) {
@ -72,20 +70,20 @@ public abstract class Slide {
return Optional.fromNullable("🎤 " + attachmentString);
}
}
return Optional.fromNullable(emojiForMimeType(attachment.getContentType()) + attachmentString);
return Optional.fromNullable(emojiForMimeType() + attachmentString);
}
private String emojiForMimeType(String contentType) {
if (MimeTypes.isVideo(contentType)) {
private String emojiForMimeType() {
if (MediaUtil.isImage(attachment)) {
return "📷 ";
} else if (MimeTypes.isVideo(contentType)) {
} else if (MediaUtil.isVideo(attachment)) {
return "🎥 ";
} else if (MimeTypes.isAudio(contentType)) {
} else if (MediaUtil.isAudio(attachment)) {
return "🎧 ";
} else if (MimeTypes.is) {
return "🎡 ";
} else {
} else if (MediaUtil.isFile(attachment)) {
return "📎 ";
} else {
return "🎡 ";
}
}