WIP: show attachment in conversation preview as iOS

This commit is contained in:
Ryan ZHAO 2020-09-02 16:59:52 +10:00
parent 8e6920f37e
commit c0d5c22a21
3 changed files with 39 additions and 4 deletions

View File

@ -1855,4 +1855,8 @@
<string name="view_reset_secure_session_done_message">Secure session reset done</string>
<!-- Attachment message -->
<string name="attachment">Attachment</string>
<string name="attachment_type_voice_message">Voice Message</string>
</resources>

View File

@ -618,9 +618,13 @@ public class ThreadDatabase extends Database {
}
private @NonNull String getFormattedBodyFor(@NonNull MessageRecord messageRecord) {
if (messageRecord.isMms() && ((MmsMessageRecord) messageRecord).getSharedContacts().size() > 0) {
Contact contact = ((MmsMessageRecord) messageRecord).getSharedContacts().get(0);
return ContactUtil.getStringSummary(context, contact).toString();
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();
}
}
return messageRecord.getBody();

View File

@ -22,6 +22,7 @@ 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;
@ -33,6 +34,8 @@ import org.whispersystems.libsignal.util.guava.Optional;
import java.security.SecureRandom;
import network.loki.messenger.R;
public abstract class Slide {
protected final Attachment attachment;
@ -59,7 +62,31 @@ public abstract class Slide {
@NonNull
public Optional<String> getBody() {
return Optional.absent();
String attachmentString = context.getString(R.string.attachment);
if (MimeTypes.isAudio(attachment.getContentType())) {
// 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()) {
attachmentString = context.getString(R.string.attachment_type_voice_message);
return Optional.fromNullable("🎤 " + attachmentString);
}
}
return Optional.fromNullable(emojiForMimeType(attachment.getContentType()) + attachmentString);
}
private String emojiForMimeType(String contentType) {
if (MimeTypes.isVideo(contentType)) {
return "📷 ";
} else if (MimeTypes.isVideo(contentType)) {
return "🎥 ";
} else if (MimeTypes.isAudio(contentType)) {
return "🎧 ";
} else if (MimeTypes.is) {
return "🎡 ";
} else {
return "📎 ";
}
}
@NonNull