tags path including nickname

main
Bob Mottram 2019-12-13 10:33:33 +00:00
parent 08b98516f9
commit cc99ebf527
2 changed files with 30 additions and 12 deletions

View File

@ -1619,7 +1619,8 @@ class PubServer(BaseHTTPRequestHandler):
self._benchmarkGETtimings(GETstartTime,GETtimings,27) self._benchmarkGETtimings(GETstartTime,GETtimings,27)
# hashtag search # hashtag search
if self.path.startswith('/tags/'): if self.path.startswith('/tags/') or \
(authorized and '/tags/' in self.path):
pageNumber=1 pageNumber=1
if '?page=' in self.path: if '?page=' in self.path:
pageNumberStr=self.path.split('?page=')[1] pageNumberStr=self.path.split('?page=')[1]
@ -1634,8 +1635,14 @@ class PubServer(BaseHTTPRequestHandler):
self._write(msg) self._write(msg)
self.server.GETbusy=False self.server.GETbusy=False
return return
nickname=None
if '/users/' in self.path:
actor=self.server.httpPrefix+'://'+self.server.domainFull+self.path
nickname= \
getNicknameFromActor(actor)
hashtagStr= \ hashtagStr= \
htmlHashtagSearch(self.server.domain,self.server.port, \ htmlHashtagSearch(nickname, \
self.server.domain,self.server.port, \
self.server.recentPostsCache, \ self.server.recentPostsCache, \
self.server.maxRecentPosts, \ self.server.maxRecentPosts, \
self.server.translate, \ self.server.translate, \
@ -4647,9 +4654,11 @@ class PubServer(BaseHTTPRequestHandler):
if searchForEmoji: if searchForEmoji:
searchStr=':'+searchStr+':' searchStr=':'+searchStr+':'
if searchStr.startswith('#'): if searchStr.startswith('#'):
nickname=getNicknameFromActor(actorStr)
# hashtag search # hashtag search
hashtagStr= \ hashtagStr= \
htmlHashtagSearch(self.server.domain,self.server.port, \ htmlHashtagSearch(nickname, \
self.server.domain,self.server.port, \
self.server.recentPostsCache, \ self.server.recentPostsCache, \
self.server.maxRecentPosts, \ self.server.maxRecentPosts, \
self.server.translate, \ self.server.translate, \
@ -4683,7 +4692,7 @@ class PubServer(BaseHTTPRequestHandler):
return return
elif '@' in searchStr: elif '@' in searchStr:
# profile search # profile search
nickname=getNicknameFromActor(self.path) nickname=getNicknameFromActor(actorStr)
if not self.server.session: if not self.server.session:
self.server.session= \ self.server.session= \
createSession(self.server.useTor) createSession(self.server.useTor)

View File

@ -346,7 +346,7 @@ def htmlModerationInfo(translate: {},baseDir: str,httpPrefix: str) -> str:
infoForm+=htmlFooter() infoForm+=htmlFooter()
return infoForm return infoForm
def htmlHashtagSearch(domain: str,port: int, \ def htmlHashtagSearch(nickname: str,domain: str,port: int, \
recentPostsCache: {},maxRecentPosts: int, \ recentPostsCache: {},maxRecentPosts: int, \
translate: {}, \ translate: {}, \
baseDir: str,hashtag: str,pageNumber: int, \ baseDir: str,hashtag: str,pageNumber: int, \
@ -362,6 +362,11 @@ def htmlHashtagSearch(domain: str,port: int, \
if not os.path.isfile(hashtagIndexFile): if not os.path.isfile(hashtagIndexFile):
return None return None
# check that the directory for the nickname exists
if nickname:
if not os.path.isdir(baseDir+'/accounts/'+nickname+'@'+domain):
nickname=None
# read the index # read the index
with open(hashtagIndexFile, "r") as f: with open(hashtagIndexFile, "r") as f:
lines = f.readlines() lines = f.readlines()
@ -414,15 +419,19 @@ def htmlHashtagSearch(domain: str,port: int, \
if postJsonObject: if postJsonObject:
if not isPublicPost(postJsonObject): if not isPublicPost(postJsonObject):
index-=1 index-=1
continue continue
showIndividualPostIcons=False
if nickname:
showIndividualPostIcons=True
allowDeletion=False
hashtagSearchForm+= \ hashtagSearchForm+= \
individualPostAsHtml(recentPostsCache,maxRecentPosts, \ individualPostAsHtml(recentPostsCache,maxRecentPosts, \
iconsDir,translate,None, \ iconsDir,translate,None, \
baseDir,session,wfRequest,personCache, \ baseDir,session,wfRequest,personCache, \
nickname,domain,port,postJsonObject, \ nickname,domain,port,postJsonObject, \
None,True,False, \ None,True,allowDeletion, \
httpPrefix,projectVersion,'inbox', \ httpPrefix,projectVersion,'inbox', \
False,False,False,False,False) False,showIndividualPostIcons,False,False,False)
index-=1 index-=1
if endIndex>0: if endIndex>0:
@ -3746,12 +3755,12 @@ def htmlCalendar(translate: {}, \
calendarStr+=htmlFooter() calendarStr+=htmlFooter()
return calendarStr return calendarStr
def htmlHashTagCloud(baseDir: str,path: str) -> str: def htmlHashTagCloud(baseDir: str,actor: str) -> str:
"""Returns a tag cloud of today's hashtags """Returns a tag cloud of today's hashtags
""" """
daysSinceEpoch=(datetime.utcnow() - datetime(1970,1,1)).days daysSinceEpoch=(datetime.utcnow() - datetime(1970,1,1)).days
daysSinceEpochStr=str(daysSinceEpoch)+' ' daysSinceEpochStr=str(daysSinceEpoch)+' '
nickname=getNicknameFromActor(path) nickname=getNicknameFromActor(actor)
tagCloud=[] tagCloud=[]
for subdir, dirs, files in os.walk(baseDir+'/tags'): for subdir, dirs, files in os.walk(baseDir+'/tags'):
for f in files: for f in files:
@ -3782,7 +3791,7 @@ def htmlHashTagCloud(baseDir: str,path: str) -> str:
tagCloud.sort() tagCloud.sort()
tagCloudStr='' tagCloudStr=''
for tagName in tagCloud: for tagName in tagCloud:
tagCloudStr+='<a href="/tags/'+tagName+'" class="hashtagcloud">'+tagName+'</a> ' tagCloudStr+='<a href="'+actor+'/tags/'+tagName+'" class="hashtagcloud">'+tagName+'</a> '
tagCloudHtml=tagCloudStr.strip()+'\n' tagCloudHtml=tagCloudStr.strip()+'\n'
return tagCloudHtml return tagCloudHtml
@ -3813,7 +3822,7 @@ def htmlSearch(translate: {}, \
followStr+=' <input type="text" name="searchtext" autofocus><br>' followStr+=' <input type="text" name="searchtext" autofocus><br>'
followStr+=' <button type="submit" class="button" name="submitSearch">'+translate['Submit']+'</button>' followStr+=' <button type="submit" class="button" name="submitSearch">'+translate['Submit']+'</button>'
followStr+=' </form>' followStr+=' </form>'
followStr+=' <p class="hashtagcloud">'+htmlHashTagCloud(baseDir,path)+'</p>' followStr+=' <p class="hashtagcloud">'+htmlHashTagCloud(baseDir,actor)+'</p>'
followStr+=' </center>' followStr+=' </center>'
followStr+=' </div>' followStr+=' </div>'
followStr+='</div>' followStr+='</div>'