Compare commits

...

4 Commits

7 changed files with 43 additions and 10 deletions

View File

@@ -92,10 +92,10 @@ $ pip install -r requirements.txt
4. run dev server: 4. run dev server:
```bash ```bash
$ python -m app.run $ python -m app.run -d
``` ```
the server will run on localhost:8080. when run for the first time, it will create an admin account and print its credentials to the terminal, so make sure to run this in an interactive session. the server will run on localhost:8080 (and will be available on the local network as well; if this is not desired, drop the `-d` flag). when run for the first time, it will create an admin account and print its credentials to the terminal, so make sure to run this in an interactive session.
press <kbd>Ctrl</kbd>+<kbd>C</kbd> to stop the server. press <kbd>Ctrl</kbd>+<kbd>C</kbd> to stop the server.
@@ -110,4 +110,3 @@ when you want to run the server again, make sure to activate the venv first:
$ source .venv/bin/activate $ source .venv/bin/activate
$ python -m app.run $ python -m app.run
``` ```

View File

@@ -14,9 +14,11 @@ from ..auth import (
login_required, revoke_session, get_active_user, login_required, revoke_session, get_active_user,
parse_display_name, revoke_all_sessions, csrf_verified parse_display_name, revoke_all_sessions, csrf_verified
) )
from ..models import Users, Posts, Reactions, Threads, Avatars, PostHistory, Mentions from ..models import Users, Posts, Reactions, Threads, Avatars, PostHistory, Mentions, BookmarkCollections
from ..constants import PermissionLevel, InfoboxKind from ..constants import PermissionLevel, InfoboxKind
from ..util import get_form_checkbox from ..util import get_form_checkbox
from ..lib.babycode import babycode_to_html
from ..db import db
import math import math
import os import os
import time import time
@@ -202,6 +204,8 @@ def sign_up_post():
'created_at': int(time.time()), 'created_at': int(time.time()),
}) })
BookmarkCollections.create_default(user.id)
if username_pair[0] != username_pair[1]: if username_pair[0] != username_pair[1]:
user.update({ user.update({
'display_name': parse_display_name(username_pair[1]) 'display_name': parse_display_name(username_pair[1])
@@ -386,11 +390,28 @@ def set_personalization(username):
session['sort_by'] = request.form.get('sort_by', 'activity') session['sort_by'] = request.form.get('sort_by', 'activity')
session['dont_subscribe_by_default'] = not get_form_checkbox('subscribe_by_default') session['dont_subscribe_by_default'] = not get_form_checkbox('subscribe_by_default')
old_display_name = user.display_name
new_display_name = parse_display_name(request.form.get('display_name', ''))
user.update({ user.update({
'status': request.form.get('status', '')[:100], 'status': request.form.get('status', '')[:100],
'display_name': parse_display_name(request.form.get('display_name', '')) 'display_name': new_display_name
}) })
if old_display_name != new_display_name:
# re-parse posts with mentions
q = """SELECT DISTINCT m.revision_id FROM mentions m
JOIN post_history ph ON m.revision_id = ph.id
JOIN posts p ON p.current_revision_id = ph.id
WHERE m.mentioned_user_id = ?"""
mentions = db.query(q, int(user.id))
with db.transaction():
for mention in mentions:
rev = PostHistory.find({'id': int(mention['revision_id'])})
parsed_content = babycode_to_html(rev.original_markup).result
rev.update({'content': parsed_content})
flash('Personalization settings updated.', InfoboxKind.INFO) flash('Personalization settings updated.', InfoboxKind.INFO)
return redirect(url_for('.settings', username=username)) return redirect(url_for('.settings', username=username))

View File

@@ -1,10 +1,15 @@
from app import create_app from app import create_app
import os import os
import sys
app = create_app() app = create_app()
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == '-d':
hostname = '0.0.0.0'
else:
hostname = '127.0.0.1'
app.run( app.run(
host = "127.0.0.1", host = hostname,
port = 8080 port = 8080
) )

View File

@@ -112,7 +112,7 @@
<span class="flex-last js-only" data-r="enhance babycodeEditorCharCount">stub: char count</span> <span class="flex-last js-only" data-r="enhance babycodeEditorCharCount">stub: char count</span>
</span> </span>
<input type="hidden" name="babycode_banned_tags" id="{{id}}-banned-tags" value="{{banned_tags | unique | list | tojson | forceescape}}"> <input type="hidden" name="babycode_banned_tags" id="{{id}}-banned-tags" value="{{banned_tags | unique | list | tojson | forceescape}}">
<textarea name="babycode_content" id="{{id}}" class="babycode-editor" placeholder="{{placeholder}}" {{'required' if required else ''}} autocomplete="off" maxlength="5000" data-r="insertBabycode babycodePreviewInit babycodeEditorCharCountInit" data-listeners="input" data-s="babycodeEditorCharCount" data-banned-tags="{{banned_tags | unique | list | tojson | forceescape}}">{{ prefill }}</textarea> <textarea name="babycode_content" id="{{id}}" class="babycode-editor" placeholder="{{placeholder}}" {{'required' if required else ''}} autocomplete="off" maxlength="5000" data-r="insertBabycode babycodePreviewInit babycodeEditorCharCountInit babycodeEditorQuote" data-listeners="input" data-s="babycodeEditorCharCount" data-banned-tags="{{banned_tags | unique | list | tojson | forceescape}}">{{ prefill }}</textarea>
{%- if banned_tags -%} {%- if banned_tags -%}
<div> <div>
<span>Forbidden tags:</span> <span>Forbidden tags:</span>
@@ -186,7 +186,7 @@
<a class="linkbutton" href="{{url_for('posts.edit', post_id=post.id, _anchor='babycode-content')}}">Edit</a> <a class="linkbutton" href="{{url_for('posts.edit', post_id=post.id, _anchor='babycode-content')}}">Edit</a>
{%- endif -%} {%- endif -%}
{%- if can_reply -%} {%- if can_reply -%}
<button data-r="enhance" disabled title="This feature requires JavaScript to be enabled.">Quote</button> <button data-r="enhance" data-s="babycodeEditorQuote" disabled title="This feature requires JavaScript to be enabled." data-quote="{{post.original_markup}}" data-poster-name="{{ post.display_name if post.display_name else post.username }}">Quote</button>
{%- endif -%} {%- endif -%}
{%- if can_delete -%} {%- if can_delete -%}
<a class="linkbutton critical" href="{{url_for('posts.delete', post_id=post.id)}}">Delete</a> <a class="linkbutton critical" href="{{url_for('posts.delete', post_id=post.id)}}">Delete</a>

View File

@@ -29,7 +29,7 @@
<input type="hidden" name="last_post_id" value="{{last_post.id}}"> <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'}}"> <input type="submit" value="{{'Subscribe' if not get_active_user().is_subscribed(thread.id) else 'Unsubscribe'}}">
</form> </form>
<button disabled title="This feature requires JavaScript to be enabled.">{{icn_bookmark(24)}}Bookmark&hellip;</button> <button data-r="enhance" disabled title="This feature requires JavaScript to be enabled.">{{icn_bookmark(24)}}Bookmark&hellip;</button>
{%- endif -%} {%- endif -%}
<a href="{{url_for('threads.feed', thread_id=thread.id)}}" class="linkbutton rss">Subscribe via RSS</a> <a href="{{url_for('threads.feed', thread_id=thread.id)}}" class="linkbutton rss">Subscribe via RSS</a>
</fieldset> </fieldset>

View File

@@ -848,7 +848,7 @@ a.mention {
padding: var(--base-padding); padding: var(--base-padding);
background-color: var(--mention-color); background-color: var(--mention-color);
color: black; color: black;
border: 1px dashed; border: 1px solid hsl(from var(--mention-color) h s 55%);
&:hover { &:hover {
background-color: var(--hover-color); background-color: var(--hover-color);

View File

@@ -162,3 +162,11 @@ export function showBabycodePreview(payload, _, el) {
el.innerHTML = payload.html; el.innerHTML = payload.html;
} }
} }
export function babycodeEditorQuote(ev, sender, el) {
console.log(sender.dataset.quote);
const newline = el.value.length === 0 ? '' : '\n'
el.value += `${newline}[quote=${sender.dataset.posterName}]\n${sender.dataset.quote}\n[/quote]\n\n`
b.send({ sender: el }, 'babycodeEditorCharCount');
el.focus();
}