mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07: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.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
import android.text.SpannableStringBuilder;
|
|
||||||
import org.session.libsession.messaging.contacts.Contact;
|
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.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.loki.activities.HomeActivity;
|
import org.thoughtcrime.securesms.loki.activities.HomeActivity;
|
||||||
import org.thoughtcrime.securesms.loki.database.SessionContactDatabase;
|
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.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -50,14 +53,7 @@ public class MultipleRecipientNotificationBuilder extends AbstractNotificationBu
|
|||||||
public void setMostRecentSender(Recipient recipient, Recipient threadRecipient) {
|
public void setMostRecentSender(Recipient recipient, Recipient threadRecipient) {
|
||||||
String displayName = recipient.toShortString();
|
String displayName = recipient.toShortString();
|
||||||
if (threadRecipient.isOpenGroupRecipient()) {
|
if (threadRecipient.isOpenGroupRecipient()) {
|
||||||
SessionContactDatabase contactDB = DatabaseFactory.getSessionContactDatabase(context);
|
displayName = getOpenGroupDisplayName(recipient);
|
||||||
String sessionID = recipient.getAddress().serialize();
|
|
||||||
Contact contact = contactDB.getContactWithSessionID(sessionID);
|
|
||||||
if (contact != null) {
|
|
||||||
displayName = contact.displayName(Contact.ContactContext.OPEN_GROUP);
|
|
||||||
} else {
|
|
||||||
displayName = sessionID;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (privacy.isDisplayContact()) {
|
if (privacy.isDisplayContact()) {
|
||||||
setContentText(context.getString(R.string.MessageNotifier_most_recent_from_s, displayName));
|
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) {
|
public void addMessageBody(@NonNull Recipient sender, Recipient threadRecipient, @Nullable CharSequence body) {
|
||||||
String displayName = sender.toShortString();
|
String displayName = sender.toShortString();
|
||||||
if (threadRecipient.isOpenGroupRecipient()) {
|
if (threadRecipient.isOpenGroupRecipient()) {
|
||||||
SessionContactDatabase contactDB = DatabaseFactory.getSessionContactDatabase(context);
|
displayName = getOpenGroupDisplayName(sender);
|
||||||
String sessionID = sender.getAddress().serialize();
|
|
||||||
Contact contact = contactDB.getContactWithSessionID(sessionID);
|
|
||||||
if (contact != null) {
|
|
||||||
displayName = contact.displayName(Contact.ContactContext.OPEN_GROUP);
|
|
||||||
} else {
|
|
||||||
displayName = sessionID;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (privacy.isDisplayMessage()) {
|
if (privacy.isDisplayMessage()) {
|
||||||
SpannableStringBuilder builder = new SpannableStringBuilder();
|
SpannableStringBuilder builder = new SpannableStringBuilder();
|
||||||
@ -118,4 +107,17 @@ public class MultipleRecipientNotificationBuilder extends AbstractNotificationBu
|
|||||||
|
|
||||||
return super.build();
|
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,19 +119,9 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
|
|||||||
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
||||||
|
|
||||||
if (privacy.isDisplayContact() && threadRecipients.isOpenGroupRecipient()) {
|
if (privacy.isDisplayContact() && threadRecipients.isOpenGroupRecipient()) {
|
||||||
String displayName;
|
String displayName = getOpenGroupDisplayName(individualRecipient);
|
||||||
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 + ": "));
|
stringBuilder.append(Util.getBoldedString(displayName + ": "));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (privacy.isDisplayMessage()) {
|
if (privacy.isDisplayMessage()) {
|
||||||
setContentText(stringBuilder.append(message));
|
setContentText(stringBuilder.append(message));
|
||||||
@ -215,19 +205,9 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
|
|||||||
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
||||||
|
|
||||||
if (privacy.isDisplayContact() && threadRecipient.isOpenGroupRecipient()) {
|
if (privacy.isDisplayContact() && threadRecipient.isOpenGroupRecipient()) {
|
||||||
String displayName;
|
String displayName = getOpenGroupDisplayName(individualRecipient);
|
||||||
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 + ": "));
|
stringBuilder.append(Util.getBoldedString(displayName + ": "));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (privacy.isDisplayMessage()) {
|
if (privacy.isDisplayMessage()) {
|
||||||
messageBodies.add(stringBuilder.append(messageBody == null ? "" : messageBody));
|
messageBodies.add(stringBuilder.append(messageBody == null ? "" : messageBody));
|
||||||
@ -342,4 +322,17 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
|
|||||||
String displayName = recipient.getName();
|
String displayName = recipient.getName();
|
||||||
return AvatarPlaceholderGenerator.generate(context, 128, publicKey, displayName);
|
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
|
@JvmStatic
|
||||||
fun getBoldedString(value: String?): CharSequence {
|
fun getBoldedString(value: String?): CharSequence {
|
||||||
|
if (value.isNullOrEmpty()) { return "" }
|
||||||
val spanned = SpannableString(value)
|
val spanned = SpannableString(value)
|
||||||
spanned.setSpan(StyleSpan(Typeface.BOLD), 0,
|
spanned.setSpan(StyleSpan(Typeface.BOLD), 0,
|
||||||
spanned.length,
|
spanned.length,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user