From 52e83814b64e15a0fdd26a60cba0b8a97f053cc0 Mon Sep 17 00:00:00 2001 From: Jason McBrayer Date: Sun, 24 Jun 2018 14:19:35 -0400 Subject: [PATCH] Add paging to notifications. Untested --- brutaldon/templates/main/notifications.html | 10 ++++++++++ brutaldon/urls.py | 4 +++- brutaldon/views.py | 20 +++++++++++++++++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/brutaldon/templates/main/notifications.html b/brutaldon/templates/main/notifications.html index b9c7e7b..f468573 100644 --- a/brutaldon/templates/main/notifications.html +++ b/brutaldon/templates/main/notifications.html @@ -75,5 +75,15 @@ mastodon.notifications()[0] {% endif %} {% endfor %} +{% block pagination %} + +{% endblock %} {% endblock %} diff --git a/brutaldon/urls.py b/brutaldon/urls.py index ecc0f2e..ed11256 100644 --- a/brutaldon/urls.py +++ b/brutaldon/urls.py @@ -29,13 +29,15 @@ urlpatterns = [ path('logout', views.logout, name='logout'), path('oauth_callback', views.oauth_callback, name="oauth_callback"), path('error', views.error, name='error'), - path('note', views.note, name='note'), path('local', views.local, name='local'), path('local/next/', views.local, name='local_next'), path('local/prev/', views.local, name='local_prev'), path('fed', views.fed, name='fed'), path('fed/next/', views.fed, name='fed_next'), path('fed/prev/', views.fed, name='fed_prev'), + path('note', views.note, name='note'), + path('note/next', views.note, name='note_next'), + path('note/prev/', views.note, name='note_prev'), path('settings', views.settings, name='settings'), path('thread/', views.thread, name='thread'), path('tags/', views.tag, name='tag'), diff --git a/brutaldon/views.py b/brutaldon/views.py index c6b8224..2d19775 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -244,11 +244,25 @@ def logout(request): def error(request): return render(request, 'error.html', { 'error': "Not logged in yet."}) -def note(request): - mastodon = get_mastodon(request) - notes = mastodon.notifications() +def note(request, next=None, prev=None): + try: + mastodon = get_mastodon(request) + except NotLoggedInException: + return redirect(about) + notes = mastodon.notifications(limit=100, max_id=next, since_id=prev) + try: + prev = notes[0]._pagination_prev + if len(mastodon.timeline(since_id=prev['since_id'])) == 0: + prev = None + except IndexError: + prev = None + try: + next = notes[-1]._pagination_next + except IndexError: + next = None return render(request, 'main/notifications.html', {'notes': notes,'timeline': 'Notifications', + 'timeline_name': 'Notifications', 'own_username': request.session['user'].acct, 'fullbrutalism': fullbrutalism_p(request)})