diff --git a/brutaldon/migrations/0014_account_note_seen.py b/brutaldon/migrations/0014_account_note_seen.py
new file mode 100644
index 0000000..10e8670
--- /dev/null
+++ b/brutaldon/migrations/0014_account_note_seen.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.1.1 on 2018-09-08 11:47
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('brutaldon', '0013_auto_20180826_1935'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='account',
+ name='note_seen',
+ field=models.IntegerField(null=True),
+ ),
+ ]
diff --git a/brutaldon/models.py b/brutaldon/models.py
index e0ff6e8..b73c48c 100644
--- a/brutaldon/models.py
+++ b/brutaldon/models.py
@@ -38,4 +38,5 @@ class Account(models.Model):
access_token = models.CharField(null=True, blank=True, max_length=2048)
client= models.ForeignKey(Client, models.SET_NULL, null=True)
preferences = models.ForeignKey(Preference, models.SET_NULL, null=True)
+ note_seen = models.IntegerField(null=True)
diff --git a/brutaldon/templates/base.html b/brutaldon/templates/base.html
index 3a23ece..7c7c842 100644
--- a/brutaldon/templates/base.html
+++ b/brutaldon/templates/base.html
@@ -100,9 +100,12 @@
ic-on-success="afterPage('{{ own_acct.username }}', 'Notifications');"
ic-indicator="#page-load-indicator">
- {% if notifications and not preferences.theme.is_brutalist %}
+ {% if not preferences.theme.is_brutalist %}
+ data-badge="{{ notifications }}"
+ ic-src="{% url 'notes_count' %}"
+ ic-poll="60s"
+ ic-push-url="false">
Notifications
{% elif notifications %}
diff --git a/brutaldon/templates/intercooler/notes.html b/brutaldon/templates/intercooler/notes.html
new file mode 100644
index 0000000..1506e5e
--- /dev/null
+++ b/brutaldon/templates/intercooler/notes.html
@@ -0,0 +1,7 @@
+
+ Notifications
+
diff --git a/brutaldon/urls.py b/brutaldon/urls.py
index a1d0e67..eae2bb5 100644
--- a/brutaldon/urls.py
+++ b/brutaldon/urls.py
@@ -38,6 +38,7 @@ urlpatterns = [
path('note', views.note, name='note'),
path('note/next', views.note, name='note_next'),
path('note/prev/', views.note, name='note_prev'),
+ path('notes_count', views.notes_count, name='notes_count'),
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 2e5d5dc..1eefea9 100644
--- a/brutaldon/views.py
+++ b/brutaldon/views.py
@@ -38,6 +38,19 @@ def get_usercontext(request):
def is_logged_in(request):
return request.session.has_key('user')
+def _notes_count(request):
+ try:
+ account, mastodon = get_usercontext(request)
+ except NotLoggedInException:
+ return ""
+ notes = mastodon.notifications(limit=40)
+ for index, item in enumerate(notes):
+ if item.id == account.note_seen:
+ break
+ else:
+ index = "40+"
+ return str(index)
+
def br_login_required(function=None, home_url=None, redirect_field_name=None):
"""Check that the user is logged in to a Mastodon instance.
@@ -75,6 +88,11 @@ def br_login_required(function=None, home_url=None, redirect_field_name=None):
else:
return _dec(function)
+def notes_count(request):
+ count = _notes_count(request)
+ return render(request, 'intercooler/notes.html',
+ {'notifications': count,})
+
def timeline(request, timeline='home', timeline_name='Home', max_id=None, since_id=None):
account, mastodon = get_usercontext(request)
data = mastodon.timeline(timeline, limit=100, max_id=max_id, since_id=since_id)
@@ -296,6 +314,10 @@ def note(request, next=None, prev=None):
account, mastodon = get_usercontext(request)
except NotLoggedInException:
return redirect(about)
+ last_seen = mastodon.notifications(limit=1)[0]
+ account.note_seen = last_seen.id
+ account.save()
+
notes = mastodon.notifications(limit=100, max_id=next, since_id=prev)
try:
prev = notes[0]._pagination_prev