Start working on post visibility

This commit is contained in:
Thomas Sileo 2019-07-13 00:28:14 +02:00
parent 5effab8b90
commit 6ab59d2e41
2 changed files with 30 additions and 5 deletions

24
app.py
View file

@ -1532,6 +1532,7 @@ def admin_new():
reply=reply_id, reply=reply_id,
content=content, content=content,
thread=thread, thread=thread,
visibility=ap.Visibility,
emojis=EMOJIS.split(" "), emojis=EMOJIS.split(" "),
) )
@ -1995,22 +1996,41 @@ def api_new_note():
except ValueError: except ValueError:
pass pass
visibility = ap.Visibility[
_user_api_arg("visibility", default=ap.Visibility.PUBLIC.name)
]
content, tags = parse_markdown(source) content, tags = parse_markdown(source)
to = request.args.get("to")
to, cc = [], []
if visibility == ap.Visibility.PUBLIC:
to = [ap.AS_PUBLIC]
cc = [ID + "/followers"] cc = [ID + "/followers"]
elif visibility == ap.Visibility.UNLISTED:
to = [ID + "/followers"]
cc = [ap.AS_PUBLIC]
elif visibility == ap.Visibility.FOLLOWERS_ONLY:
to = [ID + "/followers"]
cc = []
if _reply: if _reply:
reply = ap.fetch_remote_activity(_reply) reply = ap.fetch_remote_activity(_reply)
if visibility == ap.Visibility.DIRECT:
to.append(reply.attributedTo)
else:
cc.append(reply.attributedTo) cc.append(reply.attributedTo)
for tag in tags: for tag in tags:
if tag["type"] == "Mention": if tag["type"] == "Mention":
if visibility == ap.Visibility.DIRECT:
to.append(tag["href"])
else:
cc.append(tag["href"]) cc.append(tag["href"])
raw_note = dict( raw_note = dict(
attributedTo=MY_PERSON.id, attributedTo=MY_PERSON.id,
cc=list(set(cc)), cc=list(set(cc)),
to=[to if to else ap.AS_PUBLIC], to=list(set(to)),
content=content, content=content,
tag=tags, tag=tags,
source={"mediaType": "text/markdown", "content": source}, source={"mediaType": "text/markdown", "content": source},

View file

@ -21,6 +21,11 @@
<form action="/api/new_{% if request.args.get("question") == "1" %}question{%else%}note{%endif%}" method="POST" enctype="multipart/form-data"> <form action="/api/new_{% if request.args.get("question") == "1" %}question{%else%}note{%endif%}" method="POST" enctype="multipart/form-data">
<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() }}">
<select name="visibility">
{% for v in visibility %}
<option value="{{v.name}}">{{ v.value }}</option>
{% endfor %}
</select>
{% if reply %}<input type="hidden" name="reply" value="{{reply}}">{% endif %} {% if reply %}<input type="hidden" name="reply" value="{{reply}}">{% endif %}
<p> <p>