mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-05-13 18:07:25 +02:00
Fediverse: Show attachment URLs.
This commit is contained in:
parent
3d1e88cb68
commit
376917b1b8
@ -216,20 +216,24 @@ class Fediverse(callbacks.PluginRegexp):
|
|||||||
irc.network,
|
irc.network,
|
||||||
):
|
):
|
||||||
# show CW and content
|
# show CW and content
|
||||||
return _("%s: \x02[CW %s]\x02 %s") % (
|
res = [_("%s: \x02[CW %s]\x02 %s") % (
|
||||||
author_fullname,
|
author_fullname,
|
||||||
cw,
|
cw,
|
||||||
utils.web.htmlToText(status["content"]),
|
utils.web.htmlToText(status["content"]),
|
||||||
)
|
)]
|
||||||
else:
|
else:
|
||||||
# show CW but not content
|
# show CW but not content
|
||||||
return _("%s: CW %s") % (author_fullname, cw)
|
res = [_("%s: CW %s") % (author_fullname, cw)]
|
||||||
else:
|
else:
|
||||||
# no CW, show content
|
# no CW, show content
|
||||||
return _("%s: %s") % (
|
res = [_("%s: %s") % (
|
||||||
author_fullname,
|
author_fullname,
|
||||||
utils.web.htmlToText(status["content"]),
|
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":
|
elif status["type"] == "Announce":
|
||||||
# aka boost; let's go fetch the original status
|
# aka boost; let's go fetch the original status
|
||||||
try:
|
try:
|
||||||
|
@ -50,6 +50,8 @@ from .test_data import (
|
|||||||
OUTBOX_DATA,
|
OUTBOX_DATA,
|
||||||
STATUS_URL,
|
STATUS_URL,
|
||||||
STATUS_DATA,
|
STATUS_DATA,
|
||||||
|
STATUS_WITH_PHOTO_URL,
|
||||||
|
STATUS_WITH_PHOTO_DATA,
|
||||||
OUTBOX_FIRSTPAGE_URL,
|
OUTBOX_FIRSTPAGE_URL,
|
||||||
OUTBOX_FIRSTPAGE_DATA,
|
OUTBOX_FIRSTPAGE_DATA,
|
||||||
BOOSTED_URL,
|
BOOSTED_URL,
|
||||||
@ -347,6 +349,19 @@ class NetworklessFediverseTestCase(BaseFediverseTestCase):
|
|||||||
+ "@ FirstAuthor I am replying to you",
|
+ "@ 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):
|
def testStatusError(self):
|
||||||
expected_requests = [(STATUS_URL, utils.web.Error("blah"))]
|
expected_requests = [(STATUS_URL, utils.web.Error("blah"))]
|
||||||
|
|
||||||
@ -387,7 +402,8 @@ class NetworklessFediverseTestCase(BaseFediverseTestCase):
|
|||||||
+ "\x02[CW This is a content warning]\x02 "
|
+ "\x02[CW This is a content warning]\x02 "
|
||||||
+ "This is a status with a content warning, and "
|
+ "This is a status with a content warning, and "
|
||||||
+ "\x02Boosted User\x02 (@BoostedUser@example.net): "
|
+ "\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
|
# The actors are cached from the previous request
|
||||||
@ -408,7 +424,8 @@ class NetworklessFediverseTestCase(BaseFediverseTestCase):
|
|||||||
+ "\x02someuser\x02 (@someuser@example.org): "
|
+ "\x02someuser\x02 (@someuser@example.org): "
|
||||||
+ "CW This is a content warning, and "
|
+ "CW This is a content warning, and "
|
||||||
+ "\x02Boosted User\x02 (@BoostedUser@example.net): "
|
+ "\x02Boosted User\x02 (@BoostedUser@example.net): "
|
||||||
+ "Status Content",
|
+ "Status Content "
|
||||||
|
+ "<https://example.net/system/media_attachments/image.png>",
|
||||||
)
|
)
|
||||||
|
|
||||||
def testStatusUrlSnarferDisabled(self):
|
def testStatusUrlSnarferDisabled(self):
|
||||||
|
@ -214,6 +214,38 @@ STATUS_VALUE = {
|
|||||||
}
|
}
|
||||||
STATUS_DATA = json.dumps(STATUS_VALUE).encode()
|
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_URL = "https://example.org/users/someuser/outbox?page=true"
|
||||||
OUTBOX_FIRSTPAGE_VALUE = {
|
OUTBOX_FIRSTPAGE_VALUE = {
|
||||||
"@context": [
|
"@context": [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user