Fix NullPointerException with double push
This commit is contained in:
@@ -148,9 +148,9 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notifyUnifiedPush(Context context, String accountID, org.joinmastodon.android.model.Notification notification) {
|
public void notifyUnifiedPush(Context context, AccountSession account, org.joinmastodon.android.model.Notification notification) {
|
||||||
// push notifications are only created from the official push notification, so we create a fake from by transforming the notification
|
// push notifications are only created from the official push notification, so we create a fake from by transforming the notification
|
||||||
PushNotificationReceiver.this.notify(context, PushNotification.fromNotification(context, notification), accountID, notification);
|
PushNotificationReceiver.this.notify(context, PushNotification.fromNotification(context, account, notification), account.getID(), notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notify(Context context, PushNotification pn, String accountID, org.joinmastodon.android.model.Notification notification){
|
private void notify(Context context, PushNotification pn, String accountID, org.joinmastodon.android.model.Notification notification){
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class UnifiedPushNotificationReceiver extends MessagingReceiver{
|
|||||||
result.items
|
result.items
|
||||||
.stream()
|
.stream()
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.ifPresent(value->MastodonAPIController.runInBackground(()->new PushNotificationReceiver().notifyUnifiedPush(context, instance, value)));
|
.ifPresent(value->MastodonAPIController.runInBackground(()->new PushNotificationReceiver().notifyUnifiedPush(context, account, value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.google.gson.annotations.SerializedName;
|
|||||||
|
|
||||||
import org.joinmastodon.android.R;
|
import org.joinmastodon.android.R;
|
||||||
import org.joinmastodon.android.api.RequiredField;
|
import org.joinmastodon.android.api.RequiredField;
|
||||||
|
import org.joinmastodon.android.api.session.AccountSession;
|
||||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||||
|
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
@@ -23,7 +24,7 @@ public class PushNotification extends BaseModel{
|
|||||||
@RequiredField
|
@RequiredField
|
||||||
public String body;
|
public String body;
|
||||||
|
|
||||||
public static PushNotification fromNotification(Context context, Notification notification){
|
public static PushNotification fromNotification(Context context, AccountSession account, Notification notification){
|
||||||
PushNotification pushNotification = new PushNotification();
|
PushNotification pushNotification = new PushNotification();
|
||||||
pushNotification.notificationType = switch(notification.type) {
|
pushNotification.notificationType = switch(notification.type) {
|
||||||
case FOLLOW -> PushNotification.Type.FOLLOW;
|
case FOLLOW -> PushNotification.Type.FOLLOW;
|
||||||
@@ -52,8 +53,12 @@ public class PushNotification extends BaseModel{
|
|||||||
});
|
});
|
||||||
|
|
||||||
pushNotification.title = UiUtils.generateFormattedString(notificationTitle, notification.account.displayName).toString();
|
pushNotification.title = UiUtils.generateFormattedString(notificationTitle, notification.account.displayName).toString();
|
||||||
pushNotification.icon = notification.status.account.avatarStatic;
|
if (notification.status != null) {
|
||||||
pushNotification.body = notification.status.getStrippedText();
|
pushNotification.icon = notification.status.account.avatarStatic;
|
||||||
|
pushNotification.body = notification.status.getStrippedText();
|
||||||
|
} else {
|
||||||
|
pushNotification.icon = account.getDefaultAvatarUrl();
|
||||||
|
}
|
||||||
return pushNotification;
|
return pushNotification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user