From 25e654fbabd53bb53fc666088d93756b2cc80dbc Mon Sep 17 00:00:00 2001 From: FineFindus Date: Wed, 19 Jun 2024 16:28:27 +0200 Subject: [PATCH] fix(Notification): check if either status or account is null Account related notifications do not contain a status, leading to their actions never being executed. --- .../android/PushNotificationReceiver.java | 12 ++++++++---- .../api/requests/accounts/RemoveFromFollowers.java | 11 +++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/RemoveFromFollowers.java diff --git a/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java b/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java index b26ba5fa7..317bda2f3 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java +++ b/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java @@ -133,20 +133,24 @@ public class PushNotificationReceiver extends BroadcastReceiver{ if(intent.hasExtra("notification")){ org.joinmastodon.android.model.Notification notification=Parcels.unwrap(intent.getParcelableExtra("notification")); + if(notification==null){ + Log.e(TAG, "onReceive: Failed to notification"); + return; + } String statusID = null; - if(notification != null && notification.status != null) + if(notification.status != null) statusID=notification.status.id; - if (statusID != null) { + if (statusID!=null || notification.account!=null) { AccountSessionManager accountSessionManager = AccountSessionManager.getInstance(); Preferences preferences = accountSessionManager.getAccount(accountID).preferences; switch (NotificationAction.values()[intent.getIntExtra("notificationAction", 0)]) { case FAVORITE -> new SetStatusFavorited(statusID, true).exec(accountID); case BOOKMARK -> new SetStatusBookmarked(statusID, true).exec(accountID); - case BOOST -> new SetStatusReblogged(notification.status.id, true, preferences.postingDefaultVisibility).exec(accountID); - case UNBOOST -> new SetStatusReblogged(notification.status.id, false, preferences.postingDefaultVisibility).exec(accountID); + case BOOST -> new SetStatusReblogged(statusID, true, preferences.postingDefaultVisibility).exec(accountID); + case UNBOOST -> new SetStatusReblogged(statusID, false, preferences.postingDefaultVisibility).exec(accountID); case REPLY -> handleReplyAction(context, accountID, intent, notification, notificationId, preferences); case FOLLOW_BACK -> new SetAccountFollowed(notification.account.id, true, true, false).exec(accountID); default -> Log.w(TAG, "onReceive: Failed to get NotificationAction"); diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/RemoveFromFollowers.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/RemoveFromFollowers.java new file mode 100644 index 000000000..f6b61333e --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/RemoveFromFollowers.java @@ -0,0 +1,11 @@ +package org.joinmastodon.android.api.requests.accounts; + +import org.joinmastodon.android.api.MastodonAPIRequest; +import org.joinmastodon.android.model.Relationship; + +public class RemoveFromFollowers extends MastodonAPIRequest{ + public RemoveFromFollowers(String id){ + super(HttpMethod.POST, "/follow_requests/"+id+"/reject", Relationship.class); + setRequestBody(new Object()); + } +}