From a52e7fa91bc46ab3ea253c0d4055706a616fd9d3 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 10 May 2020 13:04:01 +0200 Subject: [PATCH] Fediverse: Show content warnings. --- plugins/Fediverse/plugin.py | 19 ++++++++++++++----- plugins/Fediverse/test.py | 26 ++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/plugins/Fediverse/plugin.py b/plugins/Fediverse/plugin.py index 4c569dfc6..bcac70432 100644 --- a/plugins/Fediverse/plugin.py +++ b/plugins/Fediverse/plugin.py @@ -172,11 +172,20 @@ class Fediverse(callbacks.PluginRegexp): elif status["type"] == "Note": author_url = status["attributedTo"] author = self._get_actor(irc, author_url) - return _("\x02%s (%s)\x02: %s") % ( - author["name"], - self._format_actor_username(author), - utils.web.htmlToText(status["content"]), - ) + cw = status.get("summary") + if cw: + return _("\x02%s (%s)\x02: [CW %s] %s") % ( + author["name"], + self._format_actor_username(author), + cw, + utils.web.htmlToText(status["content"]), + ) + else: + return _("\x02%s (%s)\x02: %s") % ( + author["name"], + self._format_actor_username(author), + utils.web.htmlToText(status["content"]), + ) elif status["type"] == "Announce": # aka boost; let's go fetch the original status try: diff --git a/plugins/Fediverse/test.py b/plugins/Fediverse/test.py index 8893bd3eb..4e252a7a5 100644 --- a/plugins/Fediverse/test.py +++ b/plugins/Fediverse/test.py @@ -189,7 +189,7 @@ OUTBOX_FIRSTPAGE_VALUE = { "partOf": "https://example.org/users/someuser/outbox", "orderedItems": [ { - "id": "https://example.org/users/someuser/statuses/104135036335976677/activity", + "id": "https://example.org/users/someuser/statuses/1234/activity", "type": "Create", "actor": "https://example.org/users/someuser", "published": "2020-05-08T01:23:45Z", @@ -239,6 +239,25 @@ OUTBOX_FIRSTPAGE_VALUE = { }, }, }, + { + "id": "https://example.org/users/someuser/statuses/1234/activity", + "type": "Create", + "actor": "https://example.org/users/someuser", + "published": "2020-05-08T01:23:45Z", + "to": ["https://example.org/users/someuser/followers"], + "cc": [ + "https://www.w3.org/ns/activitystreams#Public", + "https://example.com/users/FirstAuthor", + ], + "object": { + "id": "https://example.org/users/someuser/statuses/1234", + "type": "Note", + "summary": "This is a content warning", + "attributedTo": "https://example.org/users/someuser", + "inReplyTo": None, + "content": "

This is a status with a content warning

", + }, + }, { "id": "https://example.org/users/someuser/statuses/12345/activity", "type": "Announce", @@ -551,7 +570,10 @@ class FediverseTestCase(ChannelPluginTestCase): self.assertResponse( "statuses @someuser@example.org", "\x02someuser (@someuser@example.org)\x02: " - + "@ FirstAuthor I am replying to you and " + + "@ FirstAuthor I am replying to you, " + + "\x02someuser (@someuser@example.org)\x02: " + + "[CW This is a content warning] " + + "This is a status with a content warning, and " + "\x02Boosted User (@BoostedUser@example.net)\x02: " + "Status Content", )