Make notifications work on brutalist themes

This commit is contained in:
McBrayer 2018-10-19 12:35:31 -04:00
parent e799c097cc
commit 733d8bb453
3 changed files with 30 additions and 22 deletions

View File

@ -92,7 +92,11 @@
&nbsp; Notifications</span> &nbsp; Notifications</span>
</span> </span>
{% elif notifications and preferences.notifications %} {% elif notifications and preferences.notifications %}
<span >&nbsp; Notifications ({{ notifications }})</span> <span ic-src="{% url 'notes_count' %}"
ic-poll="60s"
ic-target="this">
<span >&nbsp; Notifications ({{ notifications }})</span>
</span>
{% else %} {% else %}
<span >&nbsp; Notifications</span> <span >&nbsp; Notifications</span>
{% endif %} {% endif %}

View File

@ -1,7 +1,11 @@
<span {% if not preferences.theme.is_brutalist %}
{% if notifications and notifications != '0' %} <span
class="badge" {% if notifications and notifications != '0' %}
{% endif %} class="badge"
data-badge="{{ notifications }}"> {% endif %}
&nbsp; Notifications</span> data-badge="{{ notifications }}">
</span> &nbsp; Notifications</span>
</span>
{% else %}
<span >&nbsp; Notifications ({{ notifications }})</span>
{% endif %}

View File

@ -38,10 +38,8 @@ 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): def _notes_count(account, mastodon):
try: if not mastodon:
account, mastodon = get_usercontext(request)
except NotLoggedInException:
return "" return ""
notes = mastodon.notifications(limit=40) notes = mastodon.notifications(limit=40)
for index, item in enumerate(notes): for index, item in enumerate(notes):
@ -89,9 +87,11 @@ def br_login_required(function=None, home_url=None, redirect_field_name=None):
return _dec(function) return _dec(function)
def notes_count(request): def notes_count(request):
count = _notes_count(request) account, mastodon = get_usercontext(request)
count = _notes_count(account, mastodon)
return render(request, 'intercooler/notes.html', return render(request, 'intercooler/notes.html',
{'notifications': count,}) {'notifications': count,
'preferences': account.preferences })
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)
@ -108,7 +108,7 @@ def timeline(request, timeline='home', timeline_name='Home', max_id=None, since_
except (IndexError, AttributeError): except (IndexError, AttributeError):
next = None next = None
notifications = _notes_count(request) notifications = _notes_count(account, mastodon)
# This filtering has to be done *after* getting next/prev links # This filtering has to be done *after* getting next/prev links
if account.preferences.filter_replies: if account.preferences.filter_replies:
@ -142,7 +142,7 @@ def tag(request, tag):
except NotLoggedInException: except NotLoggedInException:
return redirect(login) return redirect(login)
data = mastodon.timeline_hashtag(tag) data = mastodon.timeline_hashtag(tag)
notifications = _notes_count(request) notifications = _notes_count(account, mastodon)
return render(request, 'main/timeline.html', return render(request, 'main/timeline.html',
{'toots': data, 'timeline_name': '#'+tag, {'toots': data, 'timeline_name': '#'+tag,
'own_acct': request.session['user'], 'own_acct': request.session['user'],
@ -346,7 +346,7 @@ def thread(request, id):
account, mastodon = get_usercontext(request) account, mastodon = get_usercontext(request)
context = mastodon.status_context(id) context = mastodon.status_context(id)
toot = mastodon.status(id) toot = mastodon.status(id)
notifications = _notes_count(request) notifications = _notes_count(account, mastodon)
return render(request, 'main/thread.html', return render(request, 'main/thread.html',
{'context': context, 'toot': toot, {'context': context, 'toot': toot,
'own_acct': request.session['user'], 'own_acct': request.session['user'],
@ -365,7 +365,7 @@ def user(request, username, prev=None, next=None):
raise Http404("The user %s could not be found." % username) raise Http404("The user %s could not be found." % username)
data = mastodon.account_statuses(user_dict.id, max_id=next, since_id=prev) data = mastodon.account_statuses(user_dict.id, max_id=next, since_id=prev)
relationship = mastodon.account_relationships(user_dict.id)[0] relationship = mastodon.account_relationships(user_dict.id)[0]
notifications = _notes_count(request) notifications = _notes_count(account, mastodon)
try: try:
prev = data[0]._pagination_prev prev = data[0]._pagination_prev
if len(mastodon.account_statuses(user_dict.id, if len(mastodon.account_statuses(user_dict.id,
@ -548,7 +548,7 @@ def reply(request, id):
account, mastodon = get_usercontext(request) account, mastodon = get_usercontext(request)
toot = mastodon.status(id) toot = mastodon.status(id)
context = mastodon.status_context(id) context = mastodon.status_context(id)
notifications = _notes_count(request) notifications = _notes_count(account, mastodon)
if toot.account.acct != request.session['user'].acct: if toot.account.acct != request.session['user'].acct:
initial_text = '@' + toot.account.acct + " " initial_text = '@' + toot.account.acct + " "
else: else:
@ -570,7 +570,7 @@ def reply(request, id):
account, mastodon = get_usercontext(request) account, mastodon = get_usercontext(request)
toot = mastodon.status(id) toot = mastodon.status(id)
context = mastodon.status_context(id) context = mastodon.status_context(id)
notifications = _notes_count(request) notifications = _notes_count(account, mastodon)
if form.is_valid(): if form.is_valid():
# create media objects # create media objects
media_objects = [] media_objects = []
@ -787,7 +787,7 @@ def search_results(request):
query = '' query = ''
account, mastodon = get_usercontext(request) account, mastodon = get_usercontext(request)
results = mastodon.search(query) results = mastodon.search(query)
notifications = _notes_count(request) notifications = _notes_count(account, mastodon)
return render(request, 'main/search_results.html', return render(request, 'main/search_results.html',
{"results": results, {"results": results,
'own_acct': request.session['user'], 'own_acct': request.session['user'],
@ -821,7 +821,7 @@ def privacy(request):
def emoji_reference(request): def emoji_reference(request):
account, mastodon = get_usercontext(request) account, mastodon = get_usercontext(request)
emojos = mastodon.custom_emojis() emojos = mastodon.custom_emojis()
notifications = _notes_count(request) notifications = _notes_count(account, mastodon)
return render(request, 'main/emoji.html', return render(request, 'main/emoji.html',
{"preferences": account.preferences, {"preferences": account.preferences,
"emojos": sorted(emojos, key=lambda x: x['shortcode']), "emojos": sorted(emojos, key=lambda x: x['shortcode']),