From c5f3729636ab28198c2b5e4db002f90584805e29 Mon Sep 17 00:00:00 2001 From: hiromi-mi Date: Wed, 27 May 2020 19:46:44 +0900 Subject: [PATCH] Support Posting Unlisted/Followers-only Question Though I chose Unlisted or Followers-only when posting question, the question are sent to public. This is probably because api_new_question() in blueprints/api.py does not look up visibility api argument. Tihs patch fixes by adding visibility argument check at api_new_question(). --- blueprints/api.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/blueprints/api.py b/blueprints/api.py index d17c12a..1b3aaac 100644 --- a/blueprints/api.py +++ b/blueprints/api.py @@ -621,10 +621,25 @@ def api_new_question() -> _Response: if not source: raise ValueError("missing content") + visibility = ap.Visibility[ + _user_api_arg("visibility", default=ap.Visibility.PUBLIC.name) + ] + content, tags = parse_markdown(source) tags = tags + emojis.tags(content) - cc = [ID + "/followers"] + to: List[str] = [] + cc: List[str] = [] + + if visibility == ap.Visibility.PUBLIC: + to = [ap.AS_PUBLIC] + 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 = [] for tag in tags: if tag["type"] == "Mention": @@ -658,7 +673,7 @@ def api_new_question() -> _Response: raw_question = dict( attributedTo=MY_PERSON.id, cc=list(set(cc)), - to=[ap.AS_PUBLIC], + to=list(set(to)), context=new_context(), content=content, tag=tags,