From a19e61c90da264a37a97466fb9dec26d878ff194 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 12 Dec 2019 18:56:30 +0000 Subject: [PATCH] Add nickname to tag url --- daemon.py | 6 ++++-- inbox.py | 8 ++++---- webinterface.py | 34 ++++++++++++++++++++++------------ 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/daemon.py b/daemon.py index 7c0f9f4a8..0d4fd65cd 100644 --- a/daemon.py +++ b/daemon.py @@ -1635,7 +1635,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.GETbusy=False return hashtagStr= \ - htmlHashtagSearch(self.server.recentPostsCache, \ + htmlHashtagSearch(self.server.domain, \ + self.server.recentPostsCache, \ self.server.maxRecentPosts, \ self.server.translate, \ self.server.baseDir,hashtag,pageNumber, \ @@ -4648,7 +4649,8 @@ class PubServer(BaseHTTPRequestHandler): if searchStr.startswith('#'): # hashtag search hashtagStr= \ - htmlHashtagSearch(self.server.recentPostsCache, \ + htmlHashtagSearch(self.server.domain, \ + self.server.recentPostsCache, \ self.server.maxRecentPosts, \ self.server.translate, \ self.server.baseDir,searchStr[1:],1, \ diff --git a/inbox.py b/inbox.py index 59d4ab9c3..1977115b3 100644 --- a/inbox.py +++ b/inbox.py @@ -60,7 +60,7 @@ from webinterface import individualPostAsHtml from webinterface import getIconsDir from question import questionUpdateVotes -def storeHashTags(baseDir: str,postJsonObject: {}) -> None: +def storeHashTags(baseDir: str,nickname: str,postJsonObject: {}) -> None: """Extracts hashtags from an incoming post and updates the relevant tags files. """ @@ -90,7 +90,7 @@ def storeHashTags(baseDir: str,postJsonObject: {}) -> None: if not os.path.isfile(tagsFilename): tagsFile=open(tagsFilename, "w+") if tagsFile: - tagsFile.write(postUrl+'\n') + tagsFile.write(nickname+' '+postUrl+'\n') tagsFile.close() else: if postUrl not in open(tagsFilename).read(): @@ -98,7 +98,7 @@ def storeHashTags(baseDir: str,postJsonObject: {}) -> None: with open(tagsFilename, 'r+') as tagsFile: content = tagsFile.read() tagsFile.seek(0, 0) - tagsFile.write(postUrl+'\n'+content) + tagsFile.write(nickname+' '+postUrl+'\n'+content) except Exception as e: print('WARN: Failed to write entry to tags file '+ \ tagsFilename+' '+str(e)) @@ -1920,7 +1920,7 @@ def inboxAfterCapabilities(recentPostsCache: {},maxRecentPosts: int, \ inboxUpdateCalendar(baseDir,handle,postJsonObject) - storeHashTags(baseDir,postJsonObject) + storeHashTags(baseDir,handle.split('@')[0],postJsonObject) if not unitTest: if debug: diff --git a/webinterface.py b/webinterface.py index 8b6448485..f4b83f39f 100644 --- a/webinterface.py +++ b/webinterface.py @@ -345,9 +345,11 @@ def htmlModerationInfo(translate: {},baseDir: str,httpPrefix: str) -> str: infoForm+=htmlFooter() return infoForm -def htmlHashtagSearch(recentPostsCache: {},maxRecentPosts: int, \ +def htmlHashtagSearch(domain: str, \ + recentPostsCache: {},maxRecentPosts: int, \ translate: {}, \ - baseDir: str,hashtag: str,pageNumber: int,postsPerPage: int, \ + baseDir: str,hashtag: str,pageNumber: int, \ + postsPerPage: int, \ session,wfRequest: {},personCache: {}, \ httpPrefix: str,projectVersion: str) -> str: """Show a page containing search results for a hashtag @@ -381,18 +383,22 @@ def htmlHashtagSearch(recentPostsCache: {},maxRecentPosts: int, \ hashtagSearchForm+='

#'+hashtag+'

' if startIndex!=len(lines)-1: # previous page link - hashtagSearchForm+='
'+translate['Page up']+'
' + hashtagSearchForm+= \ + '
'+translate['Page up']+'
' index=startIndex while index>=endIndex: postId=lines[index].strip('\n') - nickname=getNicknameFromActor(postId) - if not nickname: - index-=1 - continue - domain,port=getDomainFromActor(postId) - if not domain: - index-=1 - continue + if ' ' not in postId: + nickname=getNicknameFromActor(postId) + if not nickname: + index-=1 + continue + else: + nickname=postId.split(' ')[0] + postId=postId.split(' ')[1] postFilename=locatePost(baseDir,nickname,domain,postId) if not postFilename: index-=1 @@ -414,7 +420,11 @@ def htmlHashtagSearch(recentPostsCache: {},maxRecentPosts: int, \ if endIndex>0: # next page link - hashtagSearchForm+='
'+translate['Page down']+'
' + hashtagSearchForm+= \ + '
'+translate['Page down']+'
' hashtagSearchForm+=htmlFooter() return hashtagSearchForm