From c7fb38b57c4225742ffb9e2e8d39239accb8046a Mon Sep 17 00:00:00 2001 From: Jason McBrayer Date: Mon, 14 Jan 2019 09:08:36 -0500 Subject: [PATCH] Add 'filter notifications" option This reduces the number of notifications in both your tab bar and your notifications page, by showing only mentions and new subscribers (i.e., things that are actionable by you). --- brutaldon/forms.py | 3 ++- .../0018_preference_filter_notifications.py | 18 ++++++++++++++++++ brutaldon/models.py | 2 ++ brutaldon/templates/setup/settings.html | 10 ++++++++++ brutaldon/views.py | 8 ++++++-- 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 brutaldon/migrations/0018_preference_filter_notifications.py diff --git a/brutaldon/forms.py b/brutaldon/forms.py index 14c731a..a61c0a3 100644 --- a/brutaldon/forms.py +++ b/brutaldon/forms.py @@ -26,7 +26,8 @@ class PreferencesForm(forms.ModelForm): class Meta: model = Preference fields = ['theme', 'filter_replies', 'filter_boosts', 'timezone', - 'no_javascript', 'notifications', 'click_to_load', 'lightbox', 'poll_frequency'] + 'no_javascript', 'notifications', 'click_to_load', 'lightbox', + 'filter_notifications', 'poll_frequency'] class PostForm(forms.Form): """def status_post(self, status, in_reply_to_id=None, media_ids=None, diff --git a/brutaldon/migrations/0018_preference_filter_notifications.py b/brutaldon/migrations/0018_preference_filter_notifications.py new file mode 100644 index 0000000..741515d --- /dev/null +++ b/brutaldon/migrations/0018_preference_filter_notifications.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.5 on 2019-01-14 13:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('brutaldon', '0017_preference_poll_frequency'), + ] + + operations = [ + migrations.AddField( + model_name='preference', + name='filter_notifications', + field=models.BooleanField(default=False, help_text='Exclude boosts and favs from your notifications.'), + ), + ] diff --git a/brutaldon/models.py b/brutaldon/models.py index 074a144..9ccc06d 100644 --- a/brutaldon/models.py +++ b/brutaldon/models.py @@ -41,6 +41,8 @@ class Preference(models.Model): help_text=_("""Use a JavaScript lightbox to display media.""")) poll_frequency = models.IntegerField(default=300, help_text=_("""Number of seconds to wait between checking notifications. Default: 300""")) + filter_notifications = models.BooleanField(default=False, + help_text=_("""Exclude boosts and favs from your notifications.""")) class Account(models.Model): username = models.EmailField(unique=True) diff --git a/brutaldon/templates/setup/settings.html b/brutaldon/templates/setup/settings.html index 19797b3..9449d2c 100644 --- a/brutaldon/templates/setup/settings.html +++ b/brutaldon/templates/setup/settings.html @@ -85,6 +85,16 @@

+
+ +

+ {{ form.filter_notifications.help_text }} +

+
+
diff --git a/brutaldon/views.py b/brutaldon/views.py index d9e111e..05a0ea9 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -43,8 +43,10 @@ def _notes_count(account, mastodon): if not mastodon: return "" notes = mastodon.notifications(limit=40) + if account.preferences.filter_notifications: + notes = [ note for note in notes if note.type == 'mention' or note.type == 'follow'] for index, item in enumerate(notes): - if item.id == account.note_seen: + if item.id <= account.note_seen: break else: index = "40+" @@ -325,6 +327,8 @@ def note(request, next=None, prev=None): account.save() notes = mastodon.notifications(limit=100, max_id=next, since_id=prev) + if account.preferences.filter_notifications: + notes = [ note for note in notes if note.type == 'mention' or note.type == 'follow'] try: prev = notes[0]._pagination_prev if len(mastodon.notifications(since_id=prev['since_id'])) == 0: @@ -402,6 +406,7 @@ def settings(request): account.preferences.notifications = form.cleaned_data['notifications'] account.preferences.click_to_load = form.cleaned_data['click_to_load'] account.preferences.lightbox = form.cleaned_data['lightbox'] + account.preferences.filter_notifications = form.cleaned_data['filter_notifications'] request.session['timezone'] = account.preferences.timezone account.preferences.save() account.save() @@ -838,4 +843,3 @@ def emoji_reference(request): "emojos": sorted(emojos, key=lambda x: x['shortcode']), "notifications": notifications, 'own_acct' : request.session['user']}) -