mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 00:37:47 +00:00
Fix crash
This commit is contained in:
parent
f872c2b9be
commit
e1f3362c2a
@ -4,18 +4,21 @@ import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.SpannableStringBuilder;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import android.text.SpannableStringBuilder;
|
||||
|
||||
import org.session.libsession.messaging.contacts.Contact;
|
||||
import org.session.libsession.utilities.NotificationPrivacyPreference;
|
||||
import org.session.libsession.utilities.TextSecurePreferences;
|
||||
import org.session.libsession.utilities.Util;
|
||||
import org.session.libsession.utilities.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.loki.activities.HomeActivity;
|
||||
import org.thoughtcrime.securesms.loki.database.SessionContactDatabase;
|
||||
import org.session.libsession.utilities.NotificationPrivacyPreference;
|
||||
import org.session.libsession.utilities.recipients.Recipient;
|
||||
import org.session.libsession.utilities.TextSecurePreferences;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@ -50,14 +53,7 @@ public class MultipleRecipientNotificationBuilder extends AbstractNotificationBu
|
||||
public void setMostRecentSender(Recipient recipient, Recipient threadRecipient) {
|
||||
String displayName = recipient.toShortString();
|
||||
if (threadRecipient.isOpenGroupRecipient()) {
|
||||
SessionContactDatabase contactDB = DatabaseFactory.getSessionContactDatabase(context);
|
||||
String sessionID = recipient.getAddress().serialize();
|
||||
Contact contact = contactDB.getContactWithSessionID(sessionID);
|
||||
if (contact != null) {
|
||||
displayName = contact.displayName(Contact.ContactContext.OPEN_GROUP);
|
||||
} else {
|
||||
displayName = sessionID;
|
||||
}
|
||||
displayName = getOpenGroupDisplayName(recipient);
|
||||
}
|
||||
if (privacy.isDisplayContact()) {
|
||||
setContentText(context.getString(R.string.MessageNotifier_most_recent_from_s, displayName));
|
||||
@ -79,14 +75,7 @@ public class MultipleRecipientNotificationBuilder extends AbstractNotificationBu
|
||||
public void addMessageBody(@NonNull Recipient sender, Recipient threadRecipient, @Nullable CharSequence body) {
|
||||
String displayName = sender.toShortString();
|
||||
if (threadRecipient.isOpenGroupRecipient()) {
|
||||
SessionContactDatabase contactDB = DatabaseFactory.getSessionContactDatabase(context);
|
||||
String sessionID = sender.getAddress().serialize();
|
||||
Contact contact = contactDB.getContactWithSessionID(sessionID);
|
||||
if (contact != null) {
|
||||
displayName = contact.displayName(Contact.ContactContext.OPEN_GROUP);
|
||||
} else {
|
||||
displayName = sessionID;
|
||||
}
|
||||
displayName = getOpenGroupDisplayName(sender);
|
||||
}
|
||||
if (privacy.isDisplayMessage()) {
|
||||
SpannableStringBuilder builder = new SpannableStringBuilder();
|
||||
@ -118,4 +107,17 @@ public class MultipleRecipientNotificationBuilder extends AbstractNotificationBu
|
||||
|
||||
return super.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param recipient the * individual * recipient for which to get the open group display name.
|
||||
*/
|
||||
private String getOpenGroupDisplayName(Recipient recipient) {
|
||||
SessionContactDatabase contactDB = DatabaseFactory.getSessionContactDatabase(context);
|
||||
String sessionID = recipient.getAddress().serialize();
|
||||
Contact contact = contactDB.getContactWithSessionID(sessionID);
|
||||
if (contact == null) { return sessionID; }
|
||||
String displayName = contact.displayName(Contact.ContactContext.OPEN_GROUP);
|
||||
if (displayName == null) { return sessionID; }
|
||||
return displayName;
|
||||
}
|
||||
}
|
||||
|
@ -119,18 +119,8 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
|
||||
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
||||
|
||||
if (privacy.isDisplayContact() && threadRecipients.isOpenGroupRecipient()) {
|
||||
String displayName;
|
||||
SessionContactDatabase contactDB = DatabaseFactory.getSessionContactDatabase(context);
|
||||
String sessionID = individualRecipient.getAddress().serialize();
|
||||
Contact contact = contactDB.getContactWithSessionID(sessionID);
|
||||
if (contact != null) {
|
||||
displayName = contact.displayName(Contact.ContactContext.OPEN_GROUP);
|
||||
} else {
|
||||
displayName = sessionID;
|
||||
}
|
||||
if (displayName != null) {
|
||||
stringBuilder.append(Util.getBoldedString(displayName + ": "));
|
||||
}
|
||||
String displayName = getOpenGroupDisplayName(individualRecipient);
|
||||
stringBuilder.append(Util.getBoldedString(displayName + ": "));
|
||||
}
|
||||
|
||||
if (privacy.isDisplayMessage()) {
|
||||
@ -215,18 +205,8 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
|
||||
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
||||
|
||||
if (privacy.isDisplayContact() && threadRecipient.isOpenGroupRecipient()) {
|
||||
String displayName;
|
||||
SessionContactDatabase contactDB = DatabaseFactory.getSessionContactDatabase(context);
|
||||
String sessionID = individualRecipient.getAddress().serialize();
|
||||
Contact contact = contactDB.getContactWithSessionID(sessionID);
|
||||
if (contact != null) {
|
||||
displayName = contact.displayName(Contact.ContactContext.OPEN_GROUP);
|
||||
} else {
|
||||
displayName = sessionID;
|
||||
}
|
||||
if (displayName != null) {
|
||||
stringBuilder.append(Util.getBoldedString(displayName + ": "));
|
||||
}
|
||||
String displayName = getOpenGroupDisplayName(individualRecipient);
|
||||
stringBuilder.append(Util.getBoldedString(displayName + ": "));
|
||||
}
|
||||
|
||||
if (privacy.isDisplayMessage()) {
|
||||
@ -342,4 +322,17 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
|
||||
String displayName = recipient.getName();
|
||||
return AvatarPlaceholderGenerator.generate(context, 128, publicKey, displayName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param recipient the * individual * recipient for which to get the open group display name.
|
||||
*/
|
||||
private String getOpenGroupDisplayName(Recipient recipient) {
|
||||
SessionContactDatabase contactDB = DatabaseFactory.getSessionContactDatabase(context);
|
||||
String sessionID = recipient.getAddress().serialize();
|
||||
Contact contact = contactDB.getContactWithSessionID(sessionID);
|
||||
if (contact == null) { return sessionID; }
|
||||
String displayName = contact.displayName(Contact.ContactContext.OPEN_GROUP);
|
||||
if (displayName == null) { return sessionID; }
|
||||
return displayName;
|
||||
}
|
||||
}
|
||||
|
@ -321,6 +321,7 @@ object Util {
|
||||
|
||||
@JvmStatic
|
||||
fun getBoldedString(value: String?): CharSequence {
|
||||
if (value.isNullOrEmpty()) { return "" }
|
||||
val spanned = SpannableString(value)
|
||||
spanned.setSpan(StyleSpan(Typeface.BOLD), 0,
|
||||
spanned.length,
|
||||
|
Loading…
x
Reference in New Issue
Block a user