mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-07-13 23:20:29 +03:00
Fix issue #1220 - Limits number of fetch for filters
This commit is contained in:
parent
e69c46661d
commit
7e6d0a5c6e
2 changed files with 6 additions and 2 deletions
|
@ -212,6 +212,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
public static List<Filter> mainFilters;
|
||||
public static List<app.fedilab.android.mastodon.client.entities.api.Account> filteredAccounts;
|
||||
public static boolean filterFetched;
|
||||
public static int filterFetchedRetry = 0;
|
||||
public static boolean show_boosts, show_replies, show_dms, show_art_nsfw, show_self_boosts, show_self_replies, show_my_messages;
|
||||
public static String regex_home, regex_local, regex_public;
|
||||
public static iconLauncher mLauncher = iconLauncher.BUBBLES;
|
||||
|
@ -1358,6 +1359,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
filteredAccounts = new ArrayList<>();
|
||||
|
||||
filterFetched = false;
|
||||
filterFetchedRetry = 0;
|
||||
networkStateReceiver = new NetworkStateReceiver();
|
||||
networkStateReceiver.addListener(this);
|
||||
registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
|
||||
|
|
|
@ -76,7 +76,7 @@ public class TimelineHelper {
|
|||
*/
|
||||
public static List<Status> filterStatus(Context context, List<Status> statuses, Timeline.TimeLineEnum filterTimeLineType) {
|
||||
//A security to make sure filters have been fetched before displaying messages
|
||||
if (!BaseMainActivity.filterFetched) {
|
||||
if (!BaseMainActivity.filterFetched && BaseMainActivity.filterFetchedRetry < 3) {
|
||||
MastodonFiltersService mastodonFiltersService = initv2(context);
|
||||
List<Filter> filterList;
|
||||
Call<List<Filter>> getFiltersCall = mastodonFiltersService.getFilters(BaseMainActivity.currentToken);
|
||||
|
@ -92,6 +92,7 @@ public class TimelineHelper {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
BaseMainActivity.filterFetchedRetry++;
|
||||
}
|
||||
|
||||
//If there are filters:
|
||||
|
@ -222,7 +223,7 @@ public class TimelineHelper {
|
|||
public static List<Notification> filterNotification(Context context, List<Notification> notifications) {
|
||||
//A security to make sure filters have been fetched before displaying messages
|
||||
List<Notification> notificationToRemove = new ArrayList<>();
|
||||
if (!BaseMainActivity.filterFetched) {
|
||||
if (!BaseMainActivity.filterFetched && BaseMainActivity.filterFetchedRetry < 3) {
|
||||
try {
|
||||
FiltersVM filtersVM = new ViewModelProvider((ViewModelStoreOwner) context).get(FiltersVM.class);
|
||||
filtersVM.getFilters(BaseMainActivity.currentInstance, BaseMainActivity.currentToken).observe((LifecycleOwner) context, filters -> {
|
||||
|
@ -232,6 +233,7 @@ public class TimelineHelper {
|
|||
} catch (Exception e) {
|
||||
return notifications;
|
||||
}
|
||||
BaseMainActivity.filterFetchedRetry++;
|
||||
}
|
||||
//If there are filters:
|
||||
if (BaseMainActivity.mainFilters != null && !BaseMainActivity.mainFilters.isEmpty() && notifications != null && !notifications.isEmpty()) {
|
||||
|
|
Loading…
Reference in a new issue