aboutsummaryrefslogtreecommitdiff
path: root/modules/fediverse/ap_utils.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-09-16 10:51:59 +0100
committerGravatar jesopo2019-09-16 10:51:59 +0100
commit55d5692856dfeb8d53281bc2da2015c4d17bbdd5 (patch)
treeb7ec725225a92922b03c5da3d64f956644176657 /modules/fediverse/ap_utils.py
parent[:1] -> [:-1] (diff)
signature
refactor AP Note stringifying out to ap_utils.py
Diffstat (limited to 'modules/fediverse/ap_utils.py')
-rw-r--r--modules/fediverse/ap_utils.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/modules/fediverse/ap_utils.py b/modules/fediverse/ap_utils.py
index 61a59888..42fa2caf 100644
--- a/modules/fediverse/ap_utils.py
+++ b/modules/fediverse/ap_utils.py
@@ -54,3 +54,25 @@ def find_actor(username, instance):
if link["type"] == ACTIVITY_TYPE:
return link["href"]
+def format_note(actor, note):
+ if note["type"] == "Announce":
+ retoot_url = note["object"]
+ retoot_instance = urllib.parse.urlparse(retoot_url).hostname
+ retoot = activity_request(retoot_url)
+
+ original_tooter = ap_actor.Actor(retoot.data["attributedTo"])
+ original_tooter.load()
+ original_tooter = activity_request(original_tooter_url)
+ retooted_user = "@%s@%s" % (original_tooter.username, retoot_instance)
+ retoot_content = utils.http.strip_html(retoot.data["content"])
+
+ return "%s (boost %s): %s - %s" % (
+ actor.username, retooted_user, retoot_content), retoot_url
+
+ elif note["type"] == "Create":
+ content = utils.http.strip_html(note["object"]["content"])
+ url = note["object"]["id"]
+
+ return "%s: %s" % (actor.username, content), url
+
+ return None, None