From 55d5692856dfeb8d53281bc2da2015c4d17bbdd5 Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 16 Sep 2019 10:51:59 +0100 Subject: refactor AP Note stringifying out to ap_utils.py --- modules/fediverse/ap_utils.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'modules/fediverse/ap_utils.py') 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 -- cgit v1.3.1-10-gc9f91