mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Fix conversation snippet for contact shares.
Previously, contact shares would be displayed as "Media Message". Now it'll show the same as it does in a notification, namely "{contact-emoji} {contact-name}".
This commit is contained in:
parent
933be54035
commit
dae655fd01
@ -18,12 +18,15 @@ import com.google.i18n.phonenumbers.NumberParseException;
|
|||||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||||
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
|
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.R;
|
||||||
|
import org.thoughtcrime.securesms.components.emoji.EmojiStrings;
|
||||||
import org.thoughtcrime.securesms.contactshare.Contact.Email;
|
import org.thoughtcrime.securesms.contactshare.Contact.Email;
|
||||||
import org.thoughtcrime.securesms.contactshare.Contact.Phone;
|
import org.thoughtcrime.securesms.contactshare.Contact.Phone;
|
||||||
import org.thoughtcrime.securesms.contactshare.Contact.PostalAddress;
|
import org.thoughtcrime.securesms.contactshare.Contact.PostalAddress;
|
||||||
import org.thoughtcrime.securesms.database.Address;
|
import org.thoughtcrime.securesms.database.Address;
|
||||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
|
import org.thoughtcrime.securesms.util.SpanUtil;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -43,6 +46,16 @@ public final class ContactUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static @NonNull CharSequence getStringSummary(@NonNull Context context, @NonNull Contact contact) {
|
||||||
|
String contactName = ContactUtil.getDisplayName(contact);
|
||||||
|
|
||||||
|
if (!TextUtils.isEmpty(contactName)) {
|
||||||
|
return context.getString(R.string.MessageNotifier_contact_message, EmojiStrings.BUST_IN_SILHOUETTE, contactName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SpanUtil.italic(context.getString(R.string.MessageNotifier_unknown_contact_message));
|
||||||
|
}
|
||||||
|
|
||||||
public static @NonNull String getDisplayName(@Nullable Contact contact) {
|
public static @NonNull String getDisplayName(@Nullable Contact contact) {
|
||||||
if (contact == null) {
|
if (contact == null) {
|
||||||
return "";
|
return "";
|
||||||
|
@ -30,6 +30,8 @@ import com.annimon.stream.Stream;
|
|||||||
|
|
||||||
import net.sqlcipher.database.SQLiteDatabase;
|
import net.sqlcipher.database.SQLiteDatabase;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.contactshare.Contact;
|
||||||
|
import org.thoughtcrime.securesms.contactshare.ContactUtil;
|
||||||
import org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord;
|
import org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord;
|
||||||
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
|
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
|
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
|
||||||
@ -567,7 +569,7 @@ public class ThreadDatabase extends Database {
|
|||||||
MessageRecord record;
|
MessageRecord record;
|
||||||
|
|
||||||
if (reader != null && (record = reader.getNext()) != null) {
|
if (reader != null && (record = reader.getNext()) != null) {
|
||||||
updateThread(threadId, count, record.getBody(), getAttachmentUriFor(record),
|
updateThread(threadId, count, getFormattedBodyFor(record), getAttachmentUriFor(record),
|
||||||
record.getTimestamp(), record.getDeliveryStatus(), record.getDeliveryReceiptCount(),
|
record.getTimestamp(), record.getDeliveryStatus(), record.getDeliveryReceiptCount(),
|
||||||
record.getType(), unarchive, record.getExpiresIn(), record.getReadReceiptCount());
|
record.getType(), unarchive, record.getExpiresIn(), record.getReadReceiptCount());
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
@ -583,6 +585,15 @@ public class ThreadDatabase extends Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private @NonNull String getFormattedBodyFor(@NonNull MessageRecord messageRecord) {
|
||||||
|
if (messageRecord.isMms() && ((MediaMmsMessageRecord) messageRecord).getSharedContacts().size() > 0) {
|
||||||
|
Contact contact = ((MediaMmsMessageRecord) messageRecord).getSharedContacts().get(0);
|
||||||
|
return ContactUtil.getStringSummary(context, contact).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return messageRecord.getBody();
|
||||||
|
}
|
||||||
|
|
||||||
private @Nullable Uri getAttachmentUriFor(MessageRecord record) {
|
private @Nullable Uri getAttachmentUriFor(MessageRecord record) {
|
||||||
if (!record.isMms() || record.isMmsNotification() || record.isGroupAction()) return null;
|
if (!record.isMms() || record.isMmsNotification() || record.isGroupAction()) return null;
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@ import android.util.Log;
|
|||||||
|
|
||||||
import org.thoughtcrime.securesms.ConversationActivity;
|
import org.thoughtcrime.securesms.ConversationActivity;
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.components.emoji.EmojiStrings;
|
|
||||||
import org.thoughtcrime.securesms.contactshare.ContactUtil;
|
import org.thoughtcrime.securesms.contactshare.ContactUtil;
|
||||||
import org.thoughtcrime.securesms.contactshare.Contact;
|
import org.thoughtcrime.securesms.contactshare.Contact;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
@ -433,14 +432,8 @@ public class MessageNotifier {
|
|||||||
if (KeyCachingService.isLocked(context)) {
|
if (KeyCachingService.isLocked(context)) {
|
||||||
body = SpanUtil.italic(context.getString(R.string.MessageNotifier_locked_message));
|
body = SpanUtil.italic(context.getString(R.string.MessageNotifier_locked_message));
|
||||||
} else if (record.isMms() && !((MmsMessageRecord) record).getSharedContacts().isEmpty()) {
|
} else if (record.isMms() && !((MmsMessageRecord) record).getSharedContacts().isEmpty()) {
|
||||||
Contact contact = ((MmsMessageRecord) record).getSharedContacts().get(0);
|
Contact contact = ((MmsMessageRecord) record).getSharedContacts().get(0);
|
||||||
String contactName = ContactUtil.getDisplayName(contact);
|
body = ContactUtil.getStringSummary(context, contact);
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(contactName)) {
|
|
||||||
body = context.getString(R.string.MessageNotifier_contact_message, EmojiStrings.BUST_IN_SILHOUETTE, contactName);
|
|
||||||
} else {
|
|
||||||
body = SpanUtil.italic(context.getString(R.string.MessageNotifier_unknown_contact_message));
|
|
||||||
}
|
|
||||||
} else if (record.isMms() && TextUtils.isEmpty(body) && !((MmsMessageRecord) record).getSlideDeck().getSlides().isEmpty()) {
|
} else if (record.isMms() && TextUtils.isEmpty(body) && !((MmsMessageRecord) record).getSlideDeck().getSlides().isEmpty()) {
|
||||||
body = SpanUtil.italic(context.getString(R.string.MessageNotifier_media_message));
|
body = SpanUtil.italic(context.getString(R.string.MessageNotifier_media_message));
|
||||||
slideDeck = ((MediaMmsMessageRecord)record).getSlideDeck();
|
slideDeck = ((MediaMmsMessageRecord)record).getSlideDeck();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user