From af32aa08d67b378835af7ba8c5063abec49bdb05 Mon Sep 17 00:00:00 2001
From: Bob Mottram
') content='
'+content+'
' return content.replace('','') + + # read the following list so that we can detect just @nick + # in addition to @nick@domain with open(followingFilename, "r") as f: following = f.readlines() + + # extract mentions and tags from words for wordStr in words: - if wordStr.startswith('@'): - if len(wordStr)>1: - possibleHandle=wordStr[1:] - if '@' in possibleHandle: - possibleNickname=possibleHandle.split('@')[0] - possibleDomain=possibleHandle.split('@')[1] - replaceFound=False - for follow in following: - if follow.replace('\n','')==possibleHandle: - recipientActor=httpPrefix+"://"+possibleDomain+"/users/"+possibleNickname - if recipientActor not in recipients: - recipients.append(recipientActor) - replaceMentions[wordStr]="@"+possibleNickname+"" - replaceFound=True - break - if not replaceFound: - # fall back to a best effort match if an exact one is not found - for follow in following: - if follow.startswith(possibleNickname+'@'): - replaceDomain=follow.replace('\n','').split('@')[1] - recipientActor=httpPrefix+"://"+replaceDomain+"/users/"+possibleNickname - if recipientActor not in recipients: - recipients.append(recipientActor) - replaceMentions[wordStr]="@"+possibleNickname+"" - replaceFound=True - break - # do the mention replacements + if addMention(wordStr,httpPrefix,following,replaceMentions,recipients): + continue + + # replace words with their html versions for wordStr,replaceStr in replaceMentions.items(): content=content.replace(wordStr,replaceStr) content=content.replace('\n','') diff --git a/daemon.py b/daemon.py index 61163dd8..8552bb9c 100644 --- a/daemon.py +++ b/daemon.py @@ -86,7 +86,7 @@ from manualapprove import manualDenyFollowRequest from manualapprove import manualApproveFollowRequest from announce import createAnnounce from announce import outboxAnnounce -from content import addMentions +from content import addHtmlTags from media import removeMetaData import os import sys @@ -1835,7 +1835,7 @@ class PubServer(BaseHTTPRequestHandler): if fields.get('bio'): if fields['bio']!=actorJson['summary']: actorJson['summary']= \ - addMentions(self.server.baseDir, \ + addHtmlTags(self.server.baseDir, \ self.server.httpPrefix, \ nickname, \ self.server.domain,fields['bio'],[]) diff --git a/posts.py b/posts.py index fc22978f..8f6aa2e9 100644 --- a/posts.py +++ b/posts.py @@ -39,7 +39,7 @@ from utils import validNickname from capabilities import getOcapFilename from capabilities import capabilitiesUpdate from media import attachImage -from content import addMentions +from content import addHtmlTags from auth import createBasicAuthHeader try: from BeautifulSoup import BeautifulSoup @@ -381,7 +381,7 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \ mentionedRecipients=[] if not clientToServer: # convert content to html - content=addMentions(baseDir,httpPrefix, \ + content=addHtmlTags(baseDir,httpPrefix, \ nickname,domain,content, \ mentionedRecipients)