From 766b60c09c8ff955049f508eeb7a56f924866ea5 Mon Sep 17 00:00:00 2001 From: io Date: Mon, 27 Sep 2021 11:15:18 +0000 Subject: [PATCH] accept pleroma-style empty string CWs (fix #3) --- pleroma.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pleroma.py b/pleroma.py index dda9cd0..91ed8e6 100644 --- a/pleroma.py +++ b/pleroma.py @@ -86,7 +86,10 @@ class Pleroma: data['in_reply_to_id'] = in_reply_to_id if visibility is not None: data['visibility'] = visibility - if cw is not None: + # normally, this would be a check against None. + # however, apparently Pleroma serializes posts without CWs as posts with an empty string + # as a CW, so per the robustness principle we'll accept that too. + if cw: data['spoiler_text'] = cw return await self.request('POST', '/api/v1/statuses', data=data) @@ -103,7 +106,7 @@ class Pleroma: content = ''.join('@' + x + ' ' for x in mentioned_accounts.values()) + content visibility = 'unlisted' if to_status['visibility'] == 'public' else to_status['visibility'] - if cw is None and 'spoiler_text' in to_status and to_status['spoiler_text']: + if not cw and 'spoiler_text' in to_status and to_status['spoiler_text']: cw = 're: ' + to_status['spoiler_text'] return await self.post(content, in_reply_to_id=to_status['id'], cw=cw, visibility=visibility)