From 3a9f2b52e081d7a906b6f02be9fc2063614f61da Mon Sep 17 00:00:00 2001 From: Jason McBrayer Date: Sun, 3 Mar 2019 20:04:52 -0500 Subject: [PATCH] Fix mentions in redrafts The obvious failure modes should be taken care of; there may be spacing changes. --- brutaldon/views.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/brutaldon/views.py b/brutaldon/views.py index 30049a6..64f7bee 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -584,9 +584,16 @@ def redraft(request, id): if request.method == 'GET': account, mastodon = get_usercontext(request) toot = mastodon.status(id) - toot_content = get_text(toot.content) - toot_content = re.sub("(^\n)|(\n$)", '', re.sub("\n\n", "\n", toot_content)) - form = PostForm({'status': toot_content, + toot_content = get_text(toot.content) # convert to plain text + # fix up white space + toot_content = re.sub("(^\n)|(\n$)", '', + re.sub("\n\n", "\n", toot_content)) + # Fix up references + for mention in toot.mentions: + menchie_re = re.compile( r"\s?@" + mention.username + r"\s", re.I) + toot_content = menchie_re.sub(" @" + mention.acct + " ", + toot_content, count=1) + form = PostForm({'status': toot_content.strip(), 'visibility': toot.visibility, 'spoiler_text': toot.spoiler_text, 'media_text_1': safe_get_attachment(toot, 0).description,