mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-22 21:24:28 +00:00
Emojis \o/ and fix threads
This commit is contained in:
parent
e01891d364
commit
c100796c86
5 changed files with 71 additions and 17 deletions
|
@ -473,6 +473,7 @@ class MicroblogPubBackend(Backend):
|
||||||
# It means the activity is not in the inbox, and not in the outbox, we want to save it
|
# It means the activity is not in the inbox, and not in the outbox, we want to save it
|
||||||
self.save(Box.REPLIES, reply)
|
self.save(Box.REPLIES, reply)
|
||||||
new_threads.append(reply.id)
|
new_threads.append(reply.id)
|
||||||
|
# TODO(tsileo): parses the replies collection and import the replies?
|
||||||
|
|
||||||
while reply is not None:
|
while reply is not None:
|
||||||
in_reply_to = reply.inReplyTo
|
in_reply_to = reply.inReplyTo
|
||||||
|
|
28
app.py
28
app.py
|
@ -72,6 +72,7 @@ from config import BASE_URL
|
||||||
from config import DB
|
from config import DB
|
||||||
from config import DEBUG_MODE
|
from config import DEBUG_MODE
|
||||||
from config import DOMAIN
|
from config import DOMAIN
|
||||||
|
from config import EMOJIS
|
||||||
from config import HEADERS
|
from config import HEADERS
|
||||||
from config import ICON_URL
|
from config import ICON_URL
|
||||||
from config import ID
|
from config import ID
|
||||||
|
@ -91,6 +92,7 @@ from poussetaches import PousseTaches
|
||||||
|
|
||||||
phost = "http://" + os.getenv("COMPOSE_PROJECT_NAME", "")
|
phost = "http://" + os.getenv("COMPOSE_PROJECT_NAME", "")
|
||||||
p = PousseTaches(f"{phost}_poussetaches_1:7991", f"{phost}_web_1:5005")
|
p = PousseTaches(f"{phost}_poussetaches_1:7991", f"{phost}_web_1:5005")
|
||||||
|
# p = PousseTaches("http://localhost:7991", "http://localhost:5000")
|
||||||
|
|
||||||
back = activitypub.MicroblogPubBackend()
|
back = activitypub.MicroblogPubBackend()
|
||||||
ap.use_backend(back)
|
ap.use_backend(back)
|
||||||
|
@ -831,25 +833,22 @@ def with_replies():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _build_thread(data, include_children=True):
|
def _build_thread(data, include_children=True): # noqa: C901
|
||||||
data["_requested"] = True
|
data["_requested"] = True
|
||||||
print(data)
|
|
||||||
root_id = data["meta"].get("thread_root_parent", data["activity"]["object"]["id"])
|
root_id = data["meta"].get("thread_root_parent", data["activity"]["object"]["id"])
|
||||||
|
|
||||||
query = {
|
query = {
|
||||||
"$or": [
|
"meta.thread_root_parent": root_id,
|
||||||
{"meta.thread_root_parent": root_id, "type": "Create"},
|
"meta.deleted": False,
|
||||||
{"activity.object.id": root_id},
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
if data["activity"]["object"].get("inReplyTo"):
|
replies = [data]
|
||||||
query["$or"].append(
|
for dat in DB.activities.find(query):
|
||||||
{"activity.object.id": data["activity"]["object"]["inReplyTo"]}
|
if dat["type"][0] != ActivityType.CREATE.value:
|
||||||
)
|
# Make a Note/Question/... looks like a Create
|
||||||
|
dat = {"activity": {"object": dat["activity"]}, "meta": dat["meta"], "_id": dat["_id"]}
|
||||||
# Fetch the root replies, and the children
|
replies.append(dat)
|
||||||
replies = [data] + list(DB.activities.find(query))
|
|
||||||
replies = sorted(replies, key=lambda d: d["activity"]["object"]["published"])
|
replies = sorted(replies, key=lambda d: d["activity"]["object"]["published"])
|
||||||
|
|
||||||
# Index all the IDs in order to build a tree
|
# Index all the IDs in order to build a tree
|
||||||
idx = {}
|
idx = {}
|
||||||
replies2 = []
|
replies2 = []
|
||||||
|
@ -1326,6 +1325,7 @@ def admin_lookup():
|
||||||
)
|
)
|
||||||
|
|
||||||
print(data)
|
print(data)
|
||||||
|
app.logger.debug(data.to_dict())
|
||||||
return render_template(
|
return render_template(
|
||||||
"lookup.html", data=data, meta=meta, url=request.form.get("url")
|
"lookup.html", data=data, meta=meta, url=request.form.get("url")
|
||||||
)
|
)
|
||||||
|
@ -1383,7 +1383,7 @@ def admin_new():
|
||||||
content = f"@{actor.preferredUsername}@{domain} "
|
content = f"@{actor.preferredUsername}@{domain} "
|
||||||
thread = _build_thread(data)
|
thread = _build_thread(data)
|
||||||
|
|
||||||
return render_template("new.html", reply=reply_id, content=content, thread=thread)
|
return render_template("new.html", reply=reply_id, content=content, thread=thread, emojis=EMOJIS.split(" "))
|
||||||
|
|
||||||
|
|
||||||
@app.route("/admin/notifications")
|
@app.route("/admin/notifications")
|
||||||
|
|
|
@ -106,6 +106,10 @@ def create_indexes():
|
||||||
DB.command("compact", "activities")
|
DB.command("compact", "activities")
|
||||||
DB.activities.create_index([("remote_id", pymongo.ASCENDING)])
|
DB.activities.create_index([("remote_id", pymongo.ASCENDING)])
|
||||||
DB.activities.create_index([("activity.object.id", pymongo.ASCENDING)])
|
DB.activities.create_index([("activity.object.id", pymongo.ASCENDING)])
|
||||||
|
DB.activities.create_index([("meta.thread_root_parent", pymongo.ASCENDING)])
|
||||||
|
DB.activities.create_index(
|
||||||
|
[("meta.thread_root_parent", pymongo.ASCENDING), ("meta.deleted", pymongo.ASCENDING)]
|
||||||
|
)
|
||||||
DB.activities.create_index(
|
DB.activities.create_index(
|
||||||
[("activity.object.id", pymongo.ASCENDING), ("meta.deleted", pymongo.ASCENDING)]
|
[("activity.object.id", pymongo.ASCENDING), ("meta.deleted", pymongo.ASCENDING)]
|
||||||
)
|
)
|
||||||
|
@ -195,3 +199,6 @@ ME = {
|
||||||
},
|
},
|
||||||
"publicKey": KEY.to_dict(),
|
"publicKey": KEY.to_dict(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# TODO(tsileo): read the config from the YAML if set
|
||||||
|
EMOJIS = "😺 😸 😹 😻 😼 😽 🙀 😿 😾 😺 😸 😹 😻 😼 😽 🙀 😿 😾"
|
||||||
|
|
|
@ -11,7 +11,11 @@
|
||||||
{% if not request.args.get("older_than") and not request.args.get("previous_than") %}<link rel="canonical" href="https://{{ config.DOMAIN }}{{ request.path }}">{% endif %}
|
{% if not request.args.get("older_than") and not request.args.get("previous_than") %}<link rel="canonical" href="https://{{ config.DOMAIN }}{{ request.path }}">{% endif %}
|
||||||
{% block links %}{% endblock %}
|
{% block links %}{% endblock %}
|
||||||
{% if config.THEME_COLOR %}<meta name="theme-color" content="{{ config.THEME_COLOR }}">{% endif %}
|
{% if config.THEME_COLOR %}<meta name="theme-color" content="{{ config.THEME_COLOR }}">{% endif %}
|
||||||
<style>{{ config.CSS | safe }}</style>
|
<style>{{ config.CSS | safe }}
|
||||||
|
.emoji {
|
||||||
|
width: 20px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
{% block headers %}{% endblock %}
|
{% block headers %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -39,5 +43,15 @@
|
||||||
Powered by <a href="https://microblog.pub">microblog.pub</a> <small class="microblogpub-version"><code>{{ microblogpub_version }}</code></small> (<a href="https://github.com/tsileo/microblog.pub">source code</a>) and the <a href="https://activitypub.rocks/">ActivityPub</a> protocol
|
Powered by <a href="https://microblog.pub">microblog.pub</a> <small class="microblogpub-version"><code>{{ microblogpub_version }}</code></small> (<a href="https://github.com/tsileo/microblog.pub">source code</a>) and the <a href="https://activitypub.rocks/">ActivityPub</a> protocol
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/twemoji@12.0.0/2/twemoji.min.js"></script>
|
||||||
|
<script>
|
||||||
|
window.onload = function() {
|
||||||
|
twemoji.base = "https://cdn.jsdelivr.net/npm/twemoji@12.0.0/2/";
|
||||||
|
twemoji.parse(document.body, {
|
||||||
|
folder: 'svg',
|
||||||
|
ext: '.svg'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
{% import 'utils.html' as utils %}
|
{% import 'utils.html' as utils %}
|
||||||
{% block title %}New - {{ config.NAME }}{% endblock %}
|
{% block title %}New - {{ config.NAME }}{% endblock %}
|
||||||
|
{% block headers %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div id="container">
|
<div id="container">
|
||||||
{% include "header.html" %}
|
{% include "header.html" %}
|
||||||
|
@ -15,7 +18,14 @@
|
||||||
<input type="hidden" name="redirect" value="/">
|
<input type="hidden" name="redirect" value="/">
|
||||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||||
{% if reply %}<input type="hidden" name="reply" value="{{reply}}">{% endif %}
|
{% if reply %}<input type="hidden" name="reply" value="{{reply}}">{% endif %}
|
||||||
<textarea name="content" rows="10" cols="50" autofocus="autofocus">{{ content }}</textarea>
|
|
||||||
|
<p>
|
||||||
|
{% for emoji in emojis %}
|
||||||
|
<span class="ji">{{ emoji }}</span>
|
||||||
|
{% endfor %}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<textarea name="content" rows="10" cols="50" autofocus="autofocus" designMode="on">{{ content }}</textarea>
|
||||||
<input type="file" name="file">
|
<input type="file" name="file">
|
||||||
<div style="margin-top:20px;">
|
<div style="margin-top:20px;">
|
||||||
<input type="submit" value="post">
|
<input type="submit" value="post">
|
||||||
|
@ -24,4 +34,26 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
<script>
|
||||||
|
var ta = document.getElementsByTagName("textarea")[0];
|
||||||
|
function insertAtCursor (textToInsert) {
|
||||||
|
// get current text of the input
|
||||||
|
const value = ta.value;
|
||||||
|
// save selection start and end position
|
||||||
|
const start = ta.selectionStart;
|
||||||
|
const end = ta.selectionEnd;
|
||||||
|
// update the value with our text inserted
|
||||||
|
ta.value = value.slice(0, start) + textToInsert + value.slice(end);
|
||||||
|
// update cursor to be at the end of insertion
|
||||||
|
ta.selectionStart = ta.selectionEnd = start + textToInsert.length;
|
||||||
|
}
|
||||||
|
var ji = function (ev) {
|
||||||
|
insertAtCursor(ev.target.attributes.alt.value);
|
||||||
|
ta.focus()
|
||||||
|
//console.log(document.execCommand('insertText', false /*no UI*/, ev.target.attributes.alt.value));
|
||||||
|
}
|
||||||
|
var items = document.getElementsByClassName("ji")
|
||||||
|
for (var i = 0; i < items.length; i++) {
|
||||||
|
items[i].addEventListener('click', ji);
|
||||||
|
}
|
||||||
|
</script>{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue