Squashed commit of the following:
commit 0a80206abb8fae7785a59aab88043b2b1974756b Author: Jason McBrayer <jmcbray@carcosa.net> Date: Tue Nov 5 19:22:00 2019 -0500 Fix oxford comma in bundled notifications, remove unused dependency commit e96bd22bdce996734aaaf1d5625e08add3c8fcf7 Author: Jason McBrayer <jmcbray@carcosa.net> Date: Tue Nov 5 19:19:42 2019 -0500 Now template works with bundled or un-bundled notifications commit 6f46bef7fdd0defe2f02e09e28558de882ce4456 Author: Jason McBrayer <jmcbray@carcosa.net> Date: Tue Nov 5 19:02:51 2019 -0500 Bundled toots work; now fix unbundled case commit 07d9de49f943d019d04a5a5203081e57dc0741d8 Author: Jason McBrayer <jmcbray@carcosa.net> Date: Tue Nov 5 14:09:14 2019 -0500 Notifications are now sorted by groups, but not collapsed commit f62666929f12cf0c7db4c68a1468f7e138318a5c Author: Jason McBrayer <jmcbray@carcosa.net> Date: Tue Nov 5 13:58:41 2019 -0500 Fix saving of bundle_notifications setting commit 335d5f985c968bb84e4b459dabf77d1d7ecad646 Author: Jason McBrayer <jmcbray@carcosa.net> Date: Mon Nov 4 18:57:54 2019 -0500 Forgot to include migration for bundle notifications preference commit 0e8232591c4f1bb972e9694433c546c9f66b5419 Author: Jason McBrayer <jmcbray@carcosa.net> Date: Mon Nov 4 18:57:35 2019 -0500 Bundle notifications setting front-end commit 6e945f1ceb2ff19470e164a946a6a48de4142812 Author: Jason McBrayer <jmcbray@carcosa.net> Date: Mon Nov 4 18:54:49 2019 -0500 Backend code to group notifications
This commit is contained in:
parent
61f8d19879
commit
cf13ad3790
1
Pipfile
1
Pipfile
|
@ -27,4 +27,3 @@ inscriptis = "*"
|
||||||
lxml = "*"
|
lxml = "*"
|
||||||
|
|
||||||
[dev-packages]
|
[dev-packages]
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ class PreferencesForm(forms.ModelForm):
|
||||||
"click_to_load",
|
"click_to_load",
|
||||||
"lightbox",
|
"lightbox",
|
||||||
"filter_notifications",
|
"filter_notifications",
|
||||||
|
"bundle_notifications",
|
||||||
"poll_frequency",
|
"poll_frequency",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.7 on 2019-11-04 23:53
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('brutaldon', '0022_auto_20190506_0938'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='preference',
|
||||||
|
name='bundle_notifications',
|
||||||
|
field=models.BooleanField(default=False, help_text='Collapse together boosts or likes of the same toot in the notifications page.'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -65,6 +65,12 @@ class Preference(models.Model):
|
||||||
default=False,
|
default=False,
|
||||||
help_text=_("""Exclude boosts and favs from your notifications."""),
|
help_text=_("""Exclude boosts and favs from your notifications."""),
|
||||||
)
|
)
|
||||||
|
bundle_notifications = models.BooleanField(
|
||||||
|
default=False,
|
||||||
|
help_text=_(
|
||||||
|
"""Collapse together boosts or likes of the same toot in the notifications page."""
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Account(models.Model):
|
class Account(models.Model):
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
{% if not forloop.first %}
|
||||||
|
{% if forloop.last %}, and
|
||||||
|
{% else %},
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
|
@ -3,7 +3,7 @@
|
||||||
{% load taglinks %}
|
{% load taglinks %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
Brutaldon ({{ own_acct.username }}) - Notifications timelime
|
Brutaldon ({{ own_acct.username }}) - Notifications timelime
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% comment %}
|
{% comment %}
|
||||||
|
@ -21,73 +21,99 @@ mastodon.notifications()[0]
|
||||||
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1 class="title">Your notifications timeline</h1>
|
<h1 class="title">Your notifications timeline</h1>
|
||||||
{% for note in notes %}
|
{% for group in groups %}
|
||||||
{% if note.type == 'mention' %}
|
{% if bundle_notifications and group.0.type in bundleable %}
|
||||||
<p>
|
{% if group.0.type == 'favourite' %}
|
||||||
<strong>{{ note.account.display_name }}</strong>
|
<p>
|
||||||
(<a href="{{ note.account.url | localuser }}">{{ note.account.acct }}</a>)
|
{% for account in group.accounts %}
|
||||||
mentioned you.
|
{% include "comma.html" %}{{ account.display_name }}
|
||||||
</p>
|
(<a href="{{ account.url | localuser}}">{{ account.acct }}</a>)
|
||||||
<br>
|
{% endfor %}
|
||||||
{% include "main/toot_partial.html" with toot=note.status reblog=False %}
|
favorited your toot.
|
||||||
<hr class="is-hidden">
|
</p>
|
||||||
{% elif note.type == 'reblog' %}
|
{% include "main/toot_partial.html" with toot=group.0.status %}
|
||||||
<p>
|
<hr class="is-hidden">
|
||||||
{{ note.account.display_name }}
|
{% elif group.0.type == 'reblog' %}
|
||||||
(<a href="{{ note.account.url | localuser }}">{{ note.account.acct }}</a>)
|
<p>
|
||||||
boosted your toot.
|
{% for account in group.accounts %}
|
||||||
(<span>
|
{% include "comma.html" %}{{ account.display_name }}
|
||||||
<small>{{ note.created_at |humane_time }}</small>
|
(<a href="{{ account.url | localuser }}">{{ account.acct }}</a>)
|
||||||
</span>)
|
{% endfor %}
|
||||||
</p>
|
boosted your toot.
|
||||||
{% include "main/toot_partial.html" with toot=note.status reblog=True reblog_by=note.account.acct reblog_icon=note.account.avatar_static %}
|
</p>
|
||||||
<hr class="is-hidden">
|
{% include "main/toot_partial.html" with toot=group.0.status reblog=True reblog_by=group.0.account.acct reblog_icon=group.0.account.avatar_static %}
|
||||||
{% elif note.type == 'favourite' %}
|
<hr class="is-hidden">
|
||||||
<p>
|
{% endif %}
|
||||||
{{ note.account.display_name }}
|
{% else %}
|
||||||
(<a href="{{ note.account.url | localuser}}">{{ note.account.acct }}</a>)
|
{% for note in group %}
|
||||||
favorited your toot.
|
{% if note.type == 'mention' %}
|
||||||
(<span>
|
<p>
|
||||||
<small>{{ note.created_at |humane_time }}</small>
|
<strong>{{ note.account.display_name }}</strong>
|
||||||
</span>)
|
(<a href="{{ note.account.url | localuser }}">{{ note.account.acct }}</a>)
|
||||||
</p>
|
mentioned you.
|
||||||
{% include "main/toot_partial.html" with toot=note.status %}
|
</p>
|
||||||
<hr class="is-hidden">
|
<br>
|
||||||
{% elif note.type == 'follow' %}
|
{% include "main/toot_partial.html" with toot=note.status reblog=False %}
|
||||||
<article class="media">
|
<hr class="is-hidden">
|
||||||
<figure class="media-left">
|
{% elif note.type == 'reblog' %}
|
||||||
<p class="image is-64x64">
|
<p>
|
||||||
<img src="{{ note.account.avatar_static }}" alt="">
|
{{ note.account.display_name }}
|
||||||
</p>
|
(<a href="{{ note.account.url | localuser }}">{{ note.account.acct }}</a>)
|
||||||
</figure>
|
boosted your toot.
|
||||||
<div class="media-content" >
|
(<span>
|
||||||
<div class="content">
|
<small>{{ note.created_at |humane_time }}</small>
|
||||||
<strong>{{ note.account.display_name }}</strong>
|
</span>)
|
||||||
(<a href="{{ note.account.url |localuser }}">{{ note.account.acct }}</a>)
|
</p>
|
||||||
followed you.
|
{% include "main/toot_partial.html" with toot=note.status reblog=True reblog_by=note.account.acct reblog_icon=note.account.avatar_static %}
|
||||||
(<a href="{{ note.url }}">
|
<hr class="is-hidden">
|
||||||
<small>{{ note.created_at |humane_time }}</small>
|
{% elif note.type == 'favourite' %}
|
||||||
</a>)
|
<p>
|
||||||
</div>
|
{{ note.account.display_name }}
|
||||||
</div>
|
(<a href="{{ note.account.url | localuser}}">{{ note.account.acct }}</a>)
|
||||||
</article>
|
favorited your toot.
|
||||||
<hr class="is-hidden">
|
(<span>
|
||||||
{% elif note.type == 'poll' %}
|
<small>{{ note.created_at |humane_time }}</small>
|
||||||
<p>A poll you created or voted in has ended.</p>
|
</span>)
|
||||||
{% include "main/toot_partial.html" with toot=note.status %}
|
</p>
|
||||||
<hr class="is-hidden">
|
{% include "main/toot_partial.html" with toot=note.status %}
|
||||||
{% endif %}
|
<hr class="is-hidden">
|
||||||
{% endfor %}
|
{% elif note.type == 'follow' %}
|
||||||
|
<article class="media">
|
||||||
|
<figure class="media-left">
|
||||||
|
<p class="image is-64x64">
|
||||||
|
<img src="{{ note.account.avatar_static }}" alt="">
|
||||||
|
</p>
|
||||||
|
</figure>
|
||||||
|
<div class="media-content" >
|
||||||
|
<div class="content">
|
||||||
|
<strong>{{ note.account.display_name }}</strong>
|
||||||
|
(<a href="{{ note.account.url |localuser }}">{{ note.account.acct }}</a>)
|
||||||
|
followed you.
|
||||||
|
(<a href="{{ note.url }}">
|
||||||
|
<small>{{ note.created_at |humane_time }}</small>
|
||||||
|
</a>)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
<hr class="is-hidden">
|
||||||
|
{% elif note.type == 'poll' %}
|
||||||
|
<p>A poll you created or voted in has ended.</p>
|
||||||
|
{% include "main/toot_partial.html" with toot=note.status %}
|
||||||
|
<hr class="is-hidden">
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
<nav class="pagination is-centered" role="navigation" aria-label="pagination">
|
<nav class="pagination is-centered" role="navigation" aria-label="pagination">
|
||||||
{% if prev %}
|
{% if prev %}
|
||||||
<a class="pagination-next" href="{% url 'note_prev' prev.min_id %}">Newer</a>
|
<a class="pagination-next" href="{% url 'note_prev' prev.min_id %}">Newer</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if next %}
|
{% if next %}
|
||||||
<a class="pagination-previous" href="{% url 'note_next' next.max_id %}">Older</a>
|
<a class="pagination-previous" href="{% url 'note_next' next.max_id %}">Older</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -125,6 +125,23 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column is-quarter">
|
||||||
|
<label class="label checkbox" for="id_bundle_notifications">
|
||||||
|
{% render_field form.bundle_notifications class+="checkbox" %}
|
||||||
|
{{ form.bundle_notifications.label }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="column is-quarter">
|
||||||
|
<p class="notification is-info preferences-help">
|
||||||
|
{{ form.bundle_notifications.help_text }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="column is-half">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column is-quarter">
|
<div class="column is-quarter">
|
||||||
<label class="label" for="id_poll_frequency">
|
<label class="label" for="id_poll_frequency">
|
||||||
|
|
|
@ -24,6 +24,7 @@ from mastodon import (
|
||||||
)
|
)
|
||||||
from urllib import parse
|
from urllib import parse
|
||||||
from pdb import set_trace
|
from pdb import set_trace
|
||||||
|
from itertools import groupby
|
||||||
from inscriptis import get_text
|
from inscriptis import get_text
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from requests import Session
|
from requests import Session
|
||||||
|
@ -32,7 +33,19 @@ import re
|
||||||
|
|
||||||
class NotLoggedInException(Exception):
|
class NotLoggedInException(Exception):
|
||||||
pass
|
pass
|
||||||
|
class LabeledList(list):
|
||||||
|
"""A subclass of list that can accept additional attributes"""
|
||||||
|
def __new__(self, *args, **kwargs):
|
||||||
|
return super(LabeledList, self).__new__(self, args, kwargs)
|
||||||
|
def __init(self, *args, **kwargs):
|
||||||
|
if len(args) == 1 and hasattr(args[0], '__iter__'):
|
||||||
|
list.__init__(self, args[0])
|
||||||
|
else:
|
||||||
|
list.__init__(self, args)
|
||||||
|
self.__dict__.update(kwargs)
|
||||||
|
def __call(self, **kwargs):
|
||||||
|
self.__dict__.update(kwargs)
|
||||||
|
return self
|
||||||
|
|
||||||
global sessons_cache
|
global sessons_cache
|
||||||
sessions_cache = {}
|
sessions_cache = {}
|
||||||
|
@ -612,17 +625,34 @@ def note(request, next=None, prev=None):
|
||||||
next = notes[-1]._pagination_next
|
next = notes[-1]._pagination_next
|
||||||
except (IndexError, AttributeError, KeyError):
|
except (IndexError, AttributeError, KeyError):
|
||||||
next = None
|
next = None
|
||||||
|
|
||||||
|
# Now group notes into lists based on type and status
|
||||||
|
groups = []
|
||||||
|
if account.preferences.bundle_notifications:
|
||||||
|
def bundle_key(note):
|
||||||
|
return str(note.status.id) + note.type
|
||||||
|
sorted_notes = sorted(notes, key=bundle_key, reverse=True)
|
||||||
|
for _, group in groupby(sorted_notes, bundle_key):
|
||||||
|
group = LabeledList(group)
|
||||||
|
group.accounts = [x.account for x in group]
|
||||||
|
groups.append(group)
|
||||||
|
else:
|
||||||
|
groups.append(notes)
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"main/notifications.html",
|
"main/notifications.html",
|
||||||
{
|
{
|
||||||
"notes": notes,
|
"notes": notes,
|
||||||
|
"groups": groups,
|
||||||
"timeline": "Notifications",
|
"timeline": "Notifications",
|
||||||
"timeline_name": "Notifications",
|
"timeline_name": "Notifications",
|
||||||
"own_acct": request.session["active_user"],
|
"own_acct": request.session["active_user"],
|
||||||
"preferences": account.preferences,
|
"preferences": account.preferences,
|
||||||
"prev": prev,
|
"prev": prev,
|
||||||
"next": next,
|
"next": next,
|
||||||
|
"bundleable": ["favourite", "reblog"],
|
||||||
|
"bundle_notifications": account.preferences.bundle_notifications,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -735,6 +765,9 @@ def settings(request):
|
||||||
account.preferences.filter_notifications = form.cleaned_data[
|
account.preferences.filter_notifications = form.cleaned_data[
|
||||||
"filter_notifications"
|
"filter_notifications"
|
||||||
]
|
]
|
||||||
|
account.preferences.bundle_notifications = form.cleaned_data[
|
||||||
|
"bundle_notifications"
|
||||||
|
]
|
||||||
account.preferences.poll_frequency = form.cleaned_data["poll_frequency"]
|
account.preferences.poll_frequency = form.cleaned_data["poll_frequency"]
|
||||||
request.session["timezone"] = account.preferences.timezone
|
request.session["timezone"] = account.preferences.timezone
|
||||||
account.preferences.save()
|
account.preferences.save()
|
||||||
|
|
Loading…
Reference in New Issue