mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-07-14 07:30: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<Filter> mainFilters;
|
||||||
public static List<app.fedilab.android.mastodon.client.entities.api.Account> filteredAccounts;
|
public static List<app.fedilab.android.mastodon.client.entities.api.Account> filteredAccounts;
|
||||||
public static boolean filterFetched;
|
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 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 String regex_home, regex_local, regex_public;
|
||||||
public static iconLauncher mLauncher = iconLauncher.BUBBLES;
|
public static iconLauncher mLauncher = iconLauncher.BUBBLES;
|
||||||
|
@ -1358,6 +1359,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
||||||
filteredAccounts = new ArrayList<>();
|
filteredAccounts = new ArrayList<>();
|
||||||
|
|
||||||
filterFetched = false;
|
filterFetched = false;
|
||||||
|
filterFetchedRetry = 0;
|
||||||
networkStateReceiver = new NetworkStateReceiver();
|
networkStateReceiver = new NetworkStateReceiver();
|
||||||
networkStateReceiver.addListener(this);
|
networkStateReceiver.addListener(this);
|
||||||
registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
|
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) {
|
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
|
//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);
|
MastodonFiltersService mastodonFiltersService = initv2(context);
|
||||||
List<Filter> filterList;
|
List<Filter> filterList;
|
||||||
Call<List<Filter>> getFiltersCall = mastodonFiltersService.getFilters(BaseMainActivity.currentToken);
|
Call<List<Filter>> getFiltersCall = mastodonFiltersService.getFilters(BaseMainActivity.currentToken);
|
||||||
|
@ -92,6 +92,7 @@ public class TimelineHelper {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BaseMainActivity.filterFetchedRetry++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//If there are filters:
|
//If there are filters:
|
||||||
|
@ -222,7 +223,7 @@ public class TimelineHelper {
|
||||||
public static List<Notification> filterNotification(Context context, List<Notification> notifications) {
|
public static List<Notification> filterNotification(Context context, List<Notification> notifications) {
|
||||||
//A security to make sure filters have been fetched before displaying messages
|
//A security to make sure filters have been fetched before displaying messages
|
||||||
List<Notification> notificationToRemove = new ArrayList<>();
|
List<Notification> notificationToRemove = new ArrayList<>();
|
||||||
if (!BaseMainActivity.filterFetched) {
|
if (!BaseMainActivity.filterFetched && BaseMainActivity.filterFetchedRetry < 3) {
|
||||||
try {
|
try {
|
||||||
FiltersVM filtersVM = new ViewModelProvider((ViewModelStoreOwner) context).get(FiltersVM.class);
|
FiltersVM filtersVM = new ViewModelProvider((ViewModelStoreOwner) context).get(FiltersVM.class);
|
||||||
filtersVM.getFilters(BaseMainActivity.currentInstance, BaseMainActivity.currentToken).observe((LifecycleOwner) context, filters -> {
|
filtersVM.getFilters(BaseMainActivity.currentInstance, BaseMainActivity.currentToken).observe((LifecycleOwner) context, filters -> {
|
||||||
|
@ -232,6 +233,7 @@ public class TimelineHelper {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return notifications;
|
return notifications;
|
||||||
}
|
}
|
||||||
|
BaseMainActivity.filterFetchedRetry++;
|
||||||
}
|
}
|
||||||
//If there are filters:
|
//If there are filters:
|
||||||
if (BaseMainActivity.mainFilters != null && !BaseMainActivity.mainFilters.isEmpty() && notifications != null && !notifications.isEmpty()) {
|
if (BaseMainActivity.mainFilters != null && !BaseMainActivity.mainFilters.isEmpty() && notifications != null && !notifications.isEmpty()) {
|
||||||
|
|
Loading…
Reference in a new issue