diff --git a/plugins/Fediverse/plugin.py b/plugins/Fediverse/plugin.py index 3e2617239..96d553095 100644 --- a/plugins/Fediverse/plugin.py +++ b/plugins/Fediverse/plugin.py @@ -216,20 +216,24 @@ class Fediverse(callbacks.PluginRegexp): irc.network, ): # show CW and content - return _("%s: \x02[CW %s]\x02 %s") % ( + res = [_("%s: \x02[CW %s]\x02 %s") % ( author_fullname, cw, utils.web.htmlToText(status["content"]), - ) + )] else: # show CW but not content - return _("%s: CW %s") % (author_fullname, cw) + res = [_("%s: CW %s") % (author_fullname, cw)] else: # no CW, show content - return _("%s: %s") % ( + res = [_("%s: %s") % ( author_fullname, utils.web.htmlToText(status["content"]), - ) + )] + + for attachment in status.get("attachment", []): + res.append(utils.str.url(attachment.get("url"))) + return " ".join(res) 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 7c4e6d367..36b4ca648 100644 --- a/plugins/Fediverse/test.py +++ b/plugins/Fediverse/test.py @@ -50,6 +50,8 @@ from .test_data import ( OUTBOX_DATA, STATUS_URL, STATUS_DATA, + STATUS_WITH_PHOTO_URL, + STATUS_WITH_PHOTO_DATA, OUTBOX_FIRSTPAGE_URL, OUTBOX_FIRSTPAGE_DATA, BOOSTED_URL, @@ -347,6 +349,19 @@ class NetworklessFediverseTestCase(BaseFediverseTestCase): + "@ FirstAuthor I am replying to you", ) + def testStatusAttachment(self): + expected_requests = [ + (STATUS_WITH_PHOTO_URL, STATUS_WITH_PHOTO_DATA), + (ACTOR_URL, ACTOR_DATA), + ] + + with self.mockRequests(expected_requests): + self.assertResponse( + "status https://example.org/users/someuser/statuses/123", + "\x02someuser\x02 (@someuser@example.org): " + + "Here is a picture ", + ) + def testStatusError(self): expected_requests = [(STATUS_URL, utils.web.Error("blah"))] @@ -387,7 +402,8 @@ class NetworklessFediverseTestCase(BaseFediverseTestCase): + "\x02[CW This is a content warning]\x02 " + "This is a status with a content warning, and " + "\x02Boosted User\x02 (@BoostedUser@example.net): " - + "Status Content", + + "Status Content " + + "", ) # The actors are cached from the previous request @@ -408,7 +424,8 @@ class NetworklessFediverseTestCase(BaseFediverseTestCase): + "\x02someuser\x02 (@someuser@example.org): " + "CW This is a content warning, and " + "\x02Boosted User\x02 (@BoostedUser@example.net): " - + "Status Content", + + "Status Content " + + "", ) def testStatusUrlSnarferDisabled(self): diff --git a/plugins/Fediverse/test_data.py b/plugins/Fediverse/test_data.py index bf8acec74..bb79e0a69 100644 --- a/plugins/Fediverse/test_data.py +++ b/plugins/Fediverse/test_data.py @@ -214,6 +214,38 @@ STATUS_VALUE = { } STATUS_DATA = json.dumps(STATUS_VALUE).encode() +STATUS_WITH_PHOTO_URL = "https://example.org/users/someuser/statuses/123" +STATUS_WITH_PHOTO_VALUE = { + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://example.org/schemas/litepub-0.1.jsonld", + ], + "actor": "https://example.org/users/someuser", + "attachment": [ + { + "mediaType": "image/jpeg", + "name": "IMG_foo.jpg", + "type": "Document", + "url": "https://example.org/foo.jpg" + } + ], + "attributedTo": "https://example.org/users/someuser", + "cc": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "content": "Here is a picture", + "id": "https://example.org/users/someuser/statuses/123", + "published": "2020-05-08T01:23:45Z", + "sensitive": False, + "summary": "", + "tag": [], + "to": [ + "https://example.org/users/someuser/followers" + ], + "type": "Note" +} +STATUS_WITH_PHOTO_DATA = json.dumps(STATUS_WITH_PHOTO_VALUE).encode() + OUTBOX_FIRSTPAGE_URL = "https://example.org/users/someuser/outbox?page=true" OUTBOX_FIRSTPAGE_VALUE = { "@context": [