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.
This commit is contained in:
FineFindus 2024-06-19 16:28:27 +02:00
parent edb4b7152b
commit 25e654fbab
No known key found for this signature in database
GPG Key ID: 64873EE210FF8E6B
2 changed files with 19 additions and 4 deletions

View File

@ -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");

View File

@ -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<Relationship>{
public RemoveFromFollowers(String id){
super(HttpMethod.POST, "/follow_requests/"+id+"/reject", Relationship.class);
setRequestBody(new Object());
}
}