Fediverse: Show attachment URLs.

This commit is contained in:
Valentin Lorentz 2020-05-15 18:51:19 +02:00
parent 3d1e88cb68
commit 376917b1b8
3 changed files with 60 additions and 7 deletions

View File

@ -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:

View File

@ -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 <https://example.org/foo.jpg>",
)
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 "
+ "<https://example.net/system/media_attachments/image.png>",
)
# 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 "
+ "<https://example.net/system/media_attachments/image.png>",
)
def testStatusUrlSnarferDisabled(self):

View File

@ -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": [