Compare commits

...

6 Commits

13 changed files with 173 additions and 17 deletions

View File

@@ -6,7 +6,7 @@ from pygments.lexers import get_lexer_by_name
from pygments.util import ClassNotFound as PygmentsClassNotFound
import re
BABYCODE_VERSION = 11
BABYCODE_VERSION = 13
class BabycodeError(Exception):
@@ -406,6 +406,13 @@ def tag_quote(children, attr):
return f'<fieldset class="plank minimal no-shadow secondary-bg"><legend>{quotee}</legend><blockquote>{children}</blockquote></fieldset>'
def tag_quote_rss(children, attr):
if attr:
quotee = f'Quoting: {attr.strip()}'
return f'<figure><blockquote>{children}</blockquote><figcaption>{quotee}</figcaption></figure>'
else:
return f'<blockquote>{children}</blockquote>'
TAGS = {
"b": lambda children, attr: f"<strong>{children}</strong>",
"i": lambda children, attr: f"<em>{children}</em>",
@@ -462,6 +469,7 @@ RSS_TAGS = {
'url': tag_url_rss,
'spoiler': lambda children, attr: f'<details><summary>{attr or "Spoiler"} (click to reveal)</summary>{children}</details>',
'code': tag_code_rss,
'quote': tag_quote_rss,
'big': lambda children, attr: f'<span style="font-size: 1.2em">{children}</span>',
'small': lambda children, attr: f'<small>{children}</small>'

View File

@@ -1,7 +1,10 @@
from flask import Blueprint, redirect, url_for, render_template, request, abort
from flask import Blueprint, redirect, url_for, render_template, request, abort, current_app
from functools import wraps
from app import cache
from ..auth import login_required, get_active_user, is_logged_in
from ..db import db
from ..models import Threads, Posts, Topics, Users, Reactions, Subscriptions
from ..lib.render_atom import render_atom_template
from ..util import get_form_checkbox, time_now
import math
@@ -69,9 +72,23 @@ def thread(thread_id, slug):
posts=posts, page=page,
page_count=page_count, topic=topic,
started_by=started_by, topics=Topics.get_list(),
Reactions=Reactions, last_post=last_post
Reactions=Reactions, last_post=last_post,
__feedlink=url_for('.feed', thread_id=thread_id, _external=True),
__feedtitle=f'replies to {thread.title}',
)
@bp.get('/<int:thread_id>/feed.atom/')
@cache.cached(timeout=5 * 60, unless=lambda: current_app.config['DEBUG'])
def feed(thread_id):
thread = Threads.find({'id': thread_id})
if not thread:
abort(404)
topic = Topics.find({'id': thread.topic_id})
posts = thread.get_posts_rss()
return render_atom_template('threads/thread.atom', thread=thread, topic=topic, posts=posts)
@bp.post('/<int:thread_id>/')
@login_required
def reply(thread_id):
@@ -166,9 +183,33 @@ def unsubscribe(thread_id):
subscription.delete()
return redirect(return_to)
@bp.get('/<int:thread_id>/feed.atom/')
def feed(thread_id):
return 'stub'
@bp.post('/subscriptions/unsubscribe-all/')
@login_required
def unsubscribe_all():
user = get_active_user()
subs = Subscriptions.findall({'user_id': user.id})
if not subs:
return redirect(url_for('users.inbox', username=user.username))
with db.transaction():
for sub in subs:
sub.delete()
return redirect(url_for('users.inbox', username=user.username))
@bp.post('/subscriptions/mark-read/')
@login_required
def mark_read():
# TODO: make a return_to param
user = get_active_user()
sub_ids = request.form.getlist('id[]', type=int)
now = time_now()
for sub_id in sub_ids:
sub = Subscriptions.find({'id': sub_id, 'user_id': user.id})
if not sub:
continue
sub.update({'last_seen': now})
return redirect(url_for('users.inbox', username=user.username))
@bp.get('/new/')
@login_required

View File

@@ -1,5 +1,6 @@
from flask import Blueprint, redirect, url_for, render_template, request, session, abort
from flask import Blueprint, redirect, url_for, render_template, request, session, abort, current_app
from app import cache
from ..lib.render_atom import render_atom_template
from ..models import Topics, Threads, Subscriptions
from ..auth import get_active_user
import math
@@ -42,8 +43,20 @@ def topic(topic_id, slug):
subscription = Subscriptions.find({'user_id': user.id, 'thread_id': thread['id']})
if subscription:
subscriptions[thread['id']] = subscription.get_unread_count()
return render_template('topics/topic.html', topic=topic, threads=threads, sort_by=sort_by, page=page, page_count=page_count, subscriptions=subscriptions)
return render_template(
'topics/topic.html', topic=topic,
threads=threads, sort_by=sort_by,
page=page, page_count=page_count, subscriptions=subscriptions,
__feedlink=url_for('.feed', topic_id=topic_id, _external=True),
__feedtitle=f'latest threads in {topic.name}',
)
@bp.get('/<int:topic_id>/feed.atom/')
@cache.cached(timeout=5 * 60, unless=lambda: current_app.config['DEBUG'])
def feed(topic_id):
return 'stub'
topic = Topics.find({'id': topic_id})
if not topic:
abort(404)
threads_list = topic.get_threads_with_op_rss()
return render_atom_template('topics/topic.atom', topic=topic, threads_list=threads_list)

20
app/templates/base.atom Normal file
View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
{%- if self.title() -%}
<title>{%- block title -%}{%- endblock -%}</title>
{%- else -%}
<title>{{- config.SITE_NAME -}}</title>
{%- endif -%}
{%- if self.feed_updated() -%}
<updated>{%- block feed_updated -%}{%- endblock -%}</updated>
{%- else -%}
<updated>{{- get_time_now() | iso8601 -}}</updated>
{%- endif -%}
<id>{{- __current_page -}}</id>
<link rel="self" href="{{ __current_page }}" />
<link href="{%- block canonical_link -%}{%- endblock -%}" />
{%- if self.feed_author() -%}
<author>{%- block feed_author -%}{%- endblock -%}</author>
{%- endif -%}
{%- block content -%}{%- endblock -%}
</feed>

View File

@@ -11,6 +11,9 @@
{%- else -%}
<title>{{ config.SITE_NAME }}</title>
{%- endif -%}
{%- if __feedlink -%}
<link rel="alternate" type="application/atom+xml" href="{{ __feedlink }}" title="{{ __feedtitle }}">
{%- endif -%}
</head>
<body>
<bitty-8 data-connect="/static/js/bits/progressive-enhancement.js"></bitty-8>

View File

@@ -107,7 +107,7 @@
<button type="button" title="insert ordered list" class="minimal" data-babycode-tag="ol" data-break-line data-s="insertBabycode">1.</button>
<button type="button" title="insert unordered list" class="minimal" data-babycode-tag="ul" data-break-line data-s="insertBabycode">&bullet;</button>
<button type="button" title="insert spoiler" class="minimal" data-babycode-tag="spoiler=" data-break-line data-prefill="spoiler content" data-s="insertBabycode">s</button>
<button type="button" title="insert emoji&hellip;" class="minimal"><img src="/static/emoji/angry.png" class="emoji"></button>
{#<button type="button" title="insert emoji&hellip;" class="minimal"><img src="/static/emoji/angry.png" class="emoji"></button>#}
</span>
<span class="flex-last js-only" data-r="enhance babycodeEditorCharCount">0/</span>
</span>
@@ -302,3 +302,7 @@
<div class="sortable-item-inner {{full and 'full' or ''}}">{{ caller() }}</div>
</li>
{%- endmacro %}
{% macro rss_html_content(html) -%}
<content type="html">{{ html }}</content>
{%- endmacro %}

View File

@@ -0,0 +1,20 @@
{% from 'common/macros.html' import rss_html_content %}
{%- extends 'base.atom' -%}
{%- block title -%}replies to {{thread.title}}{%- endblock -%}
{%- block canonical_link -%}{{ url_for('threads.thread_by_id', thread_id=thread.id, _external=true) }}{%- endblock -%}
{%- block content -%}
{%- for post in posts -%}
{%- set post_url = get_post_url(post.id, _anchor=true, external=true) -%}
<entry>
<title>Re: {{ thread.title | escape }}</title>
<link href="{{ post_url }}"/>
<id>{{ post_url }}</id>
<updated>{{ post.edited_at | iso8601 }}</updated>
{{ rss_html_content(post.content_rss) }}
<author>
<name>{{ post.display_name | escape }} @{{ post.username }}</name>
<uri>{{ url_for('users.user_page', username=post.username, _external=true) }}</uri>
</author>
</entry>
{%- endfor -%}
{%- endblock -%}

View File

@@ -1,4 +1,4 @@
{%- from 'common/macros.html' import subheader, timestamp, pager, babycode_editor_component -%}
{%- from 'common/macros.html' import subheader, timestamp, pager, babycode_editor_component, bookmark_button -%}
{%- from 'common/icons.html' import icn_bookmark -%}
{%- from 'common/macros.html' import full_post, bookmark_menu with context -%}
{%- extends 'base.html' -%}
@@ -31,7 +31,7 @@
<input type="hidden" name="last_post_id" value="{{last_post.id}}">
<input type="submit" value="{{'Subscribe' if not get_active_user().is_subscribed(thread.id) else 'Unsubscribe'}}">
</form>
<button disabled autocomplete='off' data-r="enhance" data-s="showBookmarkMenu" title="This feature requires JavaScript to be enabled." data-concept-kind="thread" data-concept-id="{{thread.id}}">{{icn_bookmark(24)}}Bookmark&hellip;</button>
{{- bookmark_button('thread', thread.id) -}}
{%- endif -%}
<a href="{{url_for('threads.feed', thread_id=thread.id)}}" class="linkbutton rss">Subscribe via RSS</a>
</fieldset>

View File

@@ -0,0 +1,21 @@
{% from 'common/macros.html' import rss_html_content %}
{%- extends 'base.atom' -%}
{%- block title -%}latest threads in {{topic.name | escape}}{%- endblock -%}
{%- block canonical_link -%}{{ url_for('topics.topic_by_id', topic_id=topic.id, _external=true) }}{%- endblock -%}
{%- block content -%}
<subtitle>{{ topic.description | escape }}</subtitle>
{%- for thread in threads_list -%}
<entry>
<title>{{ thread.title | escape }}</title>
<link href="{{ url_for('threads.thread_by_id', thread_id=thread.id, _external=true) }}"/>
<link rel="replies" type="application/atom+xml" href="{{ url_for('threads.feed', thread_id=thread.id, _external=true) }}"/>
<id>{{ url_for('threads.thread_by_id', thread_id=thread.id, _external=true) }}</id>
{{ rss_html_content(thread.original_post_content) }}
<updated>{{ thread.created_at | iso8601 }}</updated>
<author>
<name>{{ thread.started_by_display_name | escape }} @{{ thread.started_by }}</name>
<uri>{{ url_for('users.user_page', username=thread.started_by, _external=true) }}</uri>
</author>
</entry>
{%- endfor -%}
{%- endblock -%}

View File

@@ -43,10 +43,10 @@
</fieldset>
{%- endif -%}
{%- endcall -%}
{{ motd(get_motds()) }}
{%- if threads | length == 0 -%}
<div class="plank"><p>There are no threads in this topic yet.{%- if is_logged_in() and get_active_user().can_post_to_thread_or_topic(topic) %} Be the first to start a discussion!{%- endif -%}</p></div>
{%- endif -%}
{{ motd(get_motds()) }}
{%- for thread in threads -%}
<div class="topic-info plank">
<div class="title-container">

View File

@@ -12,7 +12,22 @@
You do not have any subscriptions.
{%- endif -%}
{%- endset -%}
{{ subheader('Your inbox', topline) }}
{%- call() subheader('Your inbox', topline) -%}
{%- if subscriptions -%}
<fieldset class="plank even no-shadow minimal subheader-actions">
<legend>Actions</legend>
<form method="POST" action="{{url_for('threads.mark_read')}}">
{%- for sub in subscriptions -%}
<input type="hidden" name="id[]" value="{{sub.id}}">
{%- endfor -%}
<button>Mark all as read</button>
</form>
<form method="POST" action="{{url_for('threads.unsubscribe_all')}}">
<button class="warn">Unsubscribe from all</button>
</form>
</fieldset>
{%- endif -%}
{%- endcall -%}
{%- if subscriptions | length > 0 -%}
<div class="plank">
{%- for sub in subscriptions -%}
@@ -20,11 +35,17 @@
{%- set thread = sub.get_thread() -%}
<summary class="plank secondary-bg no-shadow even">
{{thread.title}} ({{sub.get_unread_count()}} unread)
<form method="POST" action="{{url_for('threads.unsubscribe', thread_id=thread.id)}}">
<div>
<form class="inline horizontal" method="POST" action="{{url_for('threads.unsubscribe', thread_id=thread.id)}}">
<input type="hidden" name="return_to" value="{{url_for('users.inbox', username=get_active_user().username)}}">
<a href="{{url_for('threads.thread_by_id', thread_id=thread.id)}}" class="linkbutton">Go to thread</a>
<input type="submit" value="Unsubscribe" class="warn">
</form>
<form class="inline horizontal" method="POST" action="{{url_for('threads.mark_read')}}">
<input type="hidden" name="id[]" value="{{sub.id}}">
<button>Mark as read</button>
</form>
</div>
</summary>
{%- set posts = sub.get_full_posts_view() -%}

View File

@@ -335,6 +335,10 @@ form.horizontal {
flex-wrap: wrap;
}
&.inline {
display: inline flex;
}
&> fieldset {
display: flex;
gap: var(--base-padding);

View File

@@ -175,5 +175,6 @@ export function enableReactionMenuButton(_, __, el) {
}
export function enableReactionButtons(_, __, el) {
if (!el) return;
el.disabled = false;
}