Skip to content

Commit 51a9c7c

Browse files
committed
Merge branch 'fix/double_push'
2 parents 8e00b04 + c8604ad commit 51a9c7c

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ public void onError(ErrorResponse error){
154154
}
155155
}
156156

157-
public void notifyUnifiedPush(Context context, String accountID, org.joinmastodon.android.model.Notification notification) {
157+
public void notifyUnifiedPush(Context context, AccountSession account, org.joinmastodon.android.model.Notification notification) {
158158
// push notifications are only created from the official push notification, so we create a fake from by transforming the notification
159-
PushNotificationReceiver.this.notify(context, PushNotification.fromNotification(context, notification), accountID, notification);
159+
PushNotificationReceiver.this.notify(context, PushNotification.fromNotification(context, account, notification), account.getID(), notification);
160160
}
161161

162162
private void notify(Context context, PushNotification pn, String accountID, org.joinmastodon.android.model.Notification notification){

mastodon/src/main/java/org/joinmastodon/android/UnifiedPushNotificationReceiver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void onSuccess(PaginatedResponse<List<Notification>> result){
7272
result.items
7373
.stream()
7474
.findFirst()
75-
.ifPresent(value->MastodonAPIController.runInBackground(()->new PushNotificationReceiver().notifyUnifiedPush(context, instance, value)));
75+
.ifPresent(value->MastodonAPIController.runInBackground(()->new PushNotificationReceiver().notifyUnifiedPush(context, account, value)));
7676
}
7777

7878
@Override

mastodon/src/main/java/org/joinmastodon/android/model/PushNotification.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import org.joinmastodon.android.R;
88
import org.joinmastodon.android.api.RequiredField;
9+
import org.joinmastodon.android.api.session.AccountSession;
910
import org.joinmastodon.android.ui.utils.UiUtils;
1011

1112
import androidx.annotation.StringRes;
@@ -23,7 +24,7 @@ public class PushNotification extends BaseModel{
2324
@RequiredField
2425
public String body;
2526

26-
public static PushNotification fromNotification(Context context, Notification notification){
27+
public static PushNotification fromNotification(Context context, AccountSession account, Notification notification){
2728
PushNotification pushNotification = new PushNotification();
2829
pushNotification.notificationType = switch(notification.type) {
2930
case FOLLOW -> PushNotification.Type.FOLLOW;
@@ -53,8 +54,12 @@ public static PushNotification fromNotification(Context context, Notification no
5354
});
5455

5556
pushNotification.title = UiUtils.generateFormattedString(notificationTitle, notification.account.displayName).toString();
56-
pushNotification.icon = notification.status.account.avatarStatic;
57-
pushNotification.body = notification.status.getStrippedText();
57+
if (notification.status != null) {
58+
pushNotification.icon = notification.status.account.avatarStatic;
59+
pushNotification.body = notification.status.getStrippedText();
60+
} else {
61+
pushNotification.icon = account.getDefaultAvatarUrl();
62+
}
5863
return pushNotification;
5964
}
6065

0 commit comments

Comments
 (0)