Merge remote-tracking branch 'megalodon_main/main' into m3-merger
# Conflicts: # README.md # build.gradle # mastodon/build.gradle # mastodon/src/main/AndroidManifest.xml # mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java # mastodon/src/main/java/org/joinmastodon/android/MainActivity.java # mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java # mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SetAccountMuted.java # mastodon/src/main/java/org/joinmastodon/android/fragments/AccountTimelineFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/EditTimelinesFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/PinnableStatusListFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileAboutFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BaseAccountListFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/CustomWelcomeFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceRulesFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/OnboardingFollowSuggestionsFragment.java # mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java # mastodon/src/main/java/org/joinmastodon/android/model/Attachment.java # mastodon/src/main/java/org/joinmastodon/android/model/Status.java # mastodon/src/main/java/org/joinmastodon/android/ui/CustomEmojiPopupKeyboard.java # mastodon/src/main/java/org/joinmastodon/android/ui/M3AlertDialogBuilder.java # mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/AudioStatusDisplayItem.java # mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java # mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java # mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollOptionStatusDisplayItem.java # mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java # mastodon/src/main/java/org/joinmastodon/android/ui/utils/InsetStatusItemDecoration.java # mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java # mastodon/src/main/res/color/button_bg_secondary_dark_on_light.xml # mastodon/src/main/res/color/button_text_primary_light_on_dark.xml # mastodon/src/main/res/drawable/bg_image_alt_text_overlay.xml # mastodon/src/main/res/drawable/bg_rect_4dp_ripple.xml # mastodon/src/main/res/drawable/bg_search_field.xml # mastodon/src/main/res/drawable/ic_fluent_save_24_regular.xml # mastodon/src/main/res/layout/compose_action.xml # mastodon/src/main/res/layout/compose_media_thumb.xml # mastodon/src/main/res/layout/compose_poll_option.xml # mastodon/src/main/res/layout/display_item_footer.xml # mastodon/src/main/res/layout/display_item_header.xml # mastodon/src/main/res/layout/display_item_text.xml # mastodon/src/main/res/layout/fragment_compose.xml # mastodon/src/main/res/layout/fragment_profile.xml # mastodon/src/main/res/layout/item_instance_category.xml # mastodon/src/main/res/layout/item_report_choice.xml # mastodon/src/main/res/layout/item_settings_footer.xml # mastodon/src/main/res/layout/item_settings_switch.xml # mastodon/src/main/res/layout/item_settings_theme.xml # mastodon/src/main/res/layout/item_settings_theme_subitem.xml # mastodon/src/main/res/layout/item_settings_update.xml # mastodon/src/main/res/layout/tab_bar.xml # mastodon/src/main/res/menu/mute_duration.xml # mastodon/src/main/res/values-de-rDE/strings_sk.xml # mastodon/src/main/res/values-es-rES/strings_sk.xml # mastodon/src/main/res/values-fa/strings_sk.xml # mastodon/src/main/res/values-night/colors.xml # mastodon/src/main/res/values-nl-rNL/strings_sk.xml # mastodon/src/main/res/values-uk-rUA/strings_sk.xml # mastodon/src/main/res/values-zh-rCN/strings_sk.xml # mastodon/src/main/res/values/attrs.xml # mastodon/src/main/res/values/ids.xml # mastodon/src/main/res/values/styles.xml # metadata/es/changelogs/83.txt
This commit is contained in:
@@ -17,6 +17,7 @@ import android.graphics.drawable.Drawable;
|
||||
import android.opengl.Visibility;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -29,7 +30,6 @@ import org.joinmastodon.android.api.requests.statuses.SetStatusFavorited;
|
||||
import org.joinmastodon.android.api.requests.statuses.SetStatusReblogged;
|
||||
import org.joinmastodon.android.api.session.AccountSession;
|
||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||
import org.joinmastodon.android.events.NotificationReceivedEvent;
|
||||
import org.joinmastodon.android.model.Account;
|
||||
import org.joinmastodon.android.model.Mention;
|
||||
import org.joinmastodon.android.model.NotificationAction;
|
||||
@@ -38,12 +38,15 @@ import org.joinmastodon.android.model.PushNotification;
|
||||
import org.joinmastodon.android.model.Status;
|
||||
import org.joinmastodon.android.model.StatusPrivacy;
|
||||
import org.joinmastodon.android.model.StatusPrivacy;
|
||||
import org.joinmastodon.android.ui.text.HtmlParser;
|
||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||
import org.parceler.Parcels;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -62,6 +65,7 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
||||
|
||||
private static final int SUMMARY_ID = 791;
|
||||
private static int notificationId = 0;
|
||||
private static final Map<String, Integer> notificationIdsForAccounts = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent){
|
||||
@@ -93,9 +97,12 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
||||
Log.w(TAG, "onReceive: account for id '"+pushAccountID+"' not found");
|
||||
return;
|
||||
}
|
||||
if(account.getLocalPreferences().getNotificationsPauseEndTime()>System.currentTimeMillis()){
|
||||
Log.i(TAG, "onReceive: dropping notification because user has paused notifications for this account");
|
||||
return;
|
||||
}
|
||||
String accountID=account.getID();
|
||||
PushNotification pn=AccountSessionManager.getInstance().getAccount(accountID).getPushSubscriptionManager().decryptNotification(k, p, s);
|
||||
E.post(new NotificationReceivedEvent(accountID, pn.notificationId+""));
|
||||
new GetNotificationByID(pn.notificationId+"")
|
||||
.setCallback(new Callback<>(){
|
||||
@Override
|
||||
@@ -128,24 +135,16 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
||||
|
||||
if(intent.hasExtra("notification")){
|
||||
org.joinmastodon.android.model.Notification notification=Parcels.unwrap(intent.getParcelableExtra("notification"));
|
||||
String statusID = null;
|
||||
String targetAccountID = null;
|
||||
|
||||
if(notification.status != null){
|
||||
statusID = notification.status.id;
|
||||
}
|
||||
if(notification.account != null){
|
||||
targetAccountID = notification.account.id;
|
||||
}
|
||||
if (statusID != null || targetAccountID != null) {
|
||||
String statusID=notification.status.id;
|
||||
if (statusID != 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 REBLOG -> new SetStatusReblogged(notification.status.id, true, preferences.postingDefaultVisibility).exec(accountID);
|
||||
case UNDO_REBLOG -> new SetStatusReblogged(notification.status.id, 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");
|
||||
@@ -157,10 +156,15 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyUnifiedPush(Context context, String accountID, 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
|
||||
PushNotificationReceiver.this.notify(context, PushNotification.fromNotification(context, notification), accountID, notification);
|
||||
}
|
||||
|
||||
private void notify(Context context, PushNotification pn, String accountID, org.joinmastodon.android.model.Notification notification){
|
||||
NotificationManager nm=context.getSystemService(NotificationManager.class);
|
||||
notificationId=getPrefs().getInt("latestNotificationId", 0);
|
||||
Account self=AccountSessionManager.getInstance().getAccount(accountID).self;
|
||||
AccountSession session=AccountSessionManager.get(accountID);
|
||||
Account self=session.self;
|
||||
String accountName="@"+self.username+"@"+AccountSessionManager.getInstance().getAccount(accountID).domain;
|
||||
Notification.Builder builder;
|
||||
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
|
||||
@@ -230,8 +234,21 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
||||
builder.setSubText(accountName);
|
||||
}
|
||||
|
||||
int id = GlobalUserPreferences.keepOnlyLatestNotification ? NOTIFICATION_ID : notificationId++;
|
||||
getPrefs().edit().putInt("latestNotificationId", notificationId).apply();
|
||||
int id;
|
||||
if(session.getLocalPreferences().keepOnlyLatestNotification){
|
||||
if(notificationIdsForAccounts.containsKey(accountID)){
|
||||
// we overwrite the existing notification
|
||||
id=notificationIdsForAccounts.get(accountID);
|
||||
}else{
|
||||
// there's no existing notification, so we increment
|
||||
id=notificationId++;
|
||||
// and store the notification id for this account
|
||||
notificationIdsForAccounts.put(accountID, id);
|
||||
}
|
||||
}else{
|
||||
// we don't want to overwrite anything, therefore incrementing
|
||||
id=notificationId++;
|
||||
}
|
||||
|
||||
if (notification != null){
|
||||
switch (pn.notificationType){
|
||||
|
||||
Reference in New Issue
Block a user