mirror of https://gitlab.com/brutaldon/brutaldon
Non-working implementation of ajax notification badge
This commit is contained in:
parent
1523e3f229
commit
86ec6aed95
|
@ -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),
|
||||||
|
),
|
||||||
|
]
|
|
@ -38,4 +38,5 @@ class Account(models.Model):
|
||||||
access_token = models.CharField(null=True, blank=True, max_length=2048)
|
access_token = models.CharField(null=True, blank=True, max_length=2048)
|
||||||
client= models.ForeignKey(Client, models.SET_NULL, null=True)
|
client= models.ForeignKey(Client, models.SET_NULL, null=True)
|
||||||
preferences = models.ForeignKey(Preference, models.SET_NULL, null=True)
|
preferences = models.ForeignKey(Preference, models.SET_NULL, null=True)
|
||||||
|
note_seen = models.IntegerField(null=True)
|
||||||
|
|
||||||
|
|
|
@ -100,9 +100,12 @@
|
||||||
ic-on-success="afterPage('{{ own_acct.username }}', 'Notifications');"
|
ic-on-success="afterPage('{{ own_acct.username }}', 'Notifications');"
|
||||||
ic-indicator="#page-load-indicator">
|
ic-indicator="#page-load-indicator">
|
||||||
<span class="fa fa-bell-o"></span>
|
<span class="fa fa-bell-o"></span>
|
||||||
{% if notifications and not preferences.theme.is_brutalist %}
|
{% if not preferences.theme.is_brutalist %}
|
||||||
<span class="badge"
|
<span class="badge"
|
||||||
data-badge="{{ notifications }}">
|
data-badge="{{ notifications }}"
|
||||||
|
ic-src="{% url 'notes_count' %}"
|
||||||
|
ic-poll="60s"
|
||||||
|
ic-push-url="false">
|
||||||
Notifications
|
Notifications
|
||||||
</span>
|
</span>
|
||||||
{% elif notifications %}
|
{% elif notifications %}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<span class="badge"
|
||||||
|
data-badge="{{ notifications }}"
|
||||||
|
ic-src="{% url 'notes_count' %}"
|
||||||
|
ic-poll="60s"
|
||||||
|
ic-push-url="false">
|
||||||
|
Notifications
|
||||||
|
</span>
|
|
@ -38,6 +38,7 @@ urlpatterns = [
|
||||||
path('note', views.note, name='note'),
|
path('note', views.note, name='note'),
|
||||||
path('note/next<int:next>', views.note, name='note_next'),
|
path('note/next<int:next>', views.note, name='note_next'),
|
||||||
path('note/prev/<int:prev>', views.note, name='note_prev'),
|
path('note/prev/<int:prev>', views.note, name='note_prev'),
|
||||||
|
path('notes_count', views.notes_count, name='notes_count'),
|
||||||
path('settings', views.settings, name='settings'),
|
path('settings', views.settings, name='settings'),
|
||||||
path('thread/<int:id>', views.thread, name='thread'),
|
path('thread/<int:id>', views.thread, name='thread'),
|
||||||
path('tags/<tag>', views.tag, name='tag'),
|
path('tags/<tag>', views.tag, name='tag'),
|
||||||
|
|
|
@ -38,6 +38,19 @@ def get_usercontext(request):
|
||||||
def is_logged_in(request):
|
def is_logged_in(request):
|
||||||
return request.session.has_key('user')
|
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):
|
def br_login_required(function=None, home_url=None, redirect_field_name=None):
|
||||||
"""Check that the user is logged in to a Mastodon instance.
|
"""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:
|
else:
|
||||||
return _dec(function)
|
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):
|
def timeline(request, timeline='home', timeline_name='Home', max_id=None, since_id=None):
|
||||||
account, mastodon = get_usercontext(request)
|
account, mastodon = get_usercontext(request)
|
||||||
data = mastodon.timeline(timeline, limit=100, max_id=max_id, since_id=since_id)
|
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)
|
account, mastodon = get_usercontext(request)
|
||||||
except NotLoggedInException:
|
except NotLoggedInException:
|
||||||
return redirect(about)
|
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)
|
notes = mastodon.notifications(limit=100, max_id=next, since_id=prev)
|
||||||
try:
|
try:
|
||||||
prev = notes[0]._pagination_prev
|
prev = notes[0]._pagination_prev
|
||||||
|
|
Loading…
Reference in New Issue