From 52162d1b9b760baf85b427d4caf41b00d4e337d5 Mon Sep 17 00:00:00 2001
From: Bob Mottram
') return '
'+content+'
' diff --git a/daemon.py b/daemon.py index 8552bb9c..c4837af1 100644 --- a/daemon.py +++ b/daemon.py @@ -1838,7 +1838,7 @@ class PubServer(BaseHTTPRequestHandler): addHtmlTags(self.server.baseDir, \ self.server.httpPrefix, \ nickname, \ - self.server.domain,fields['bio'],[]) + self.server.domain,fields['bio'],[],{}) actorChanged=True approveFollowers=False if fields.get('approveFollowers'): diff --git a/posts.py b/posts.py index 8f6aa2e9..c55b53a1 100644 --- a/posts.py +++ b/posts.py @@ -371,6 +371,22 @@ def savePostToBox(baseDir: str,httpPrefix: str,postId: str, \ commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False) return filename +def updateHashtagsIndex(baseDir: str,tag: {},newPostId: str) -> None: + """Writes the post url for hashtags to a file + This allows posts for a hashtag to be quickly looked up + """ + # create hashtags directory + tagsDir=baseDir+'/tags' + if not os.path.isdir(tagsDir): + os.mkdir(tagsDir) + tagName=tag['name'] + tagsFilename=tagsDir+'/'+tagName[1:]+'.txt' + tagFile=open(tagsFilename, "a+") + if not tagFile: + return + tagFile.write(newPostId+'\n') + tagFile.close() + def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \ toUrl: str, ccUrl: str, httpPrefix: str, content: str, \ followersOnly: bool, saveToFile: bool, clientToServer: bool, @@ -379,11 +395,15 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \ """Creates a message """ mentionedRecipients=[] + tags=[] + hashtagsDict={} if not clientToServer: # convert content to html - content=addHtmlTags(baseDir,httpPrefix, \ - nickname,domain,content, \ - mentionedRecipients) + content= \ + addHtmlTags(baseDir,httpPrefix, \ + nickname,domain,content, \ + mentionedRecipients, \ + hashtagsDict) if port!=80 and port!=443: if ':' not in domain: @@ -407,7 +427,13 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \ # who to send to toRecipients=[toUrl] + mentionedRecipients - + + # create a list of hashtags + if hashtagsDict: + for tagName,tag in hashtagsDict.items(): + tags.append(tag) + updateHashtagsIndex(baseDir,tag,newPostId) + if not clientToServer: actorUrl=httpPrefix+'://'+domain+'/users/'+nickname @@ -449,7 +475,7 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \ 'en': content }, 'attachment': [], - 'tag': [], + 'tag': tags, 'replies': { 'id': 'https://'+domain+'/users/'+nickname+'/statuses/'+statusNumber+'/replies', 'type': 'Collection', @@ -486,7 +512,7 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \ 'en': content }, 'attachment': [], - 'tag': [], + 'tag': tags, 'replies': { 'id': 'https://'+domain+'/users/'+nickname+'/statuses/'+statusNumber+'/replies', 'type': 'Collection', diff --git a/tests.py b/tests.py index 9a614b32..b145f5f6 100644 --- a/tests.py +++ b/tests.py @@ -353,7 +353,7 @@ def testPostMessageBetweenServers(): sendResult = \ sendPost(sessionAlice,aliceDir,'alice', aliceDomain, alicePort, \ 'bob', bobDomain, bobPort, ccUrl, httpPrefix, \ - 'Why is a mouse when it spins?', followersOnly, \ + 'Why is a mouse when it spins? #sillyquestion', followersOnly, \ saveToFile, clientToServer,attachedImageFilename, \ attachedImageDescription,useBlurhash, federationList, \ aliceSendThreads, alicePostLog, aliceCachedWebfingers, \