From e5b988aa3ca220dc7a5280211c53f6d62d950c8d Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 19 Aug 2019 21:01:29 +0100 Subject: [PATCH] Dedicated emoji search screen --- daemon.py | 20 +++++++++++++++++++- webinterface.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/daemon.py b/daemon.py index 9ae23f3c..a5fd725d 100644 --- a/daemon.py +++ b/daemon.py @@ -88,6 +88,7 @@ from webinterface import htmlNewPost from webinterface import htmlFollowConfirm from webinterface import htmlSearch from webinterface import htmlSearchEmoji +from webinterface import htmlSearchEmojiTextEntry from webinterface import htmlUnfollowConfirm from webinterface import htmlProfileAfterSearch from webinterface import htmlEditProfile @@ -799,7 +800,7 @@ class PubServer(BaseHTTPRequestHandler): self.server.GETbusy=False return - # search for a fediverse address from the web interface by selecting search icon + # search for a fediverse address, shared item or emoji from the web interface by selecting search icon if htmlGET and '/users/' in self.path: if self.path.endswith('/search'): # show the search screen @@ -809,6 +810,16 @@ class PubServer(BaseHTTPRequestHandler): self.server.GETbusy=False return + # search for emoji by name + if htmlGET and '/users/' in self.path: + if self.path.endswith('/searchemoji'): + # show the search screen + msg=htmlSearchEmojiTextEntry(self.server.baseDir,self.path).encode() + self._set_headers('text/html',len(msg),cookie) + self.wfile.write(msg) + self.server.GETbusy=False + return + # Unfollow a person from the web interface by selecting Unfollow on the dropdown if htmlGET and '/users/' in self.path: if '?unfollow=' in self.path: @@ -2345,6 +2356,11 @@ class PubServer(BaseHTTPRequestHandler): self.server.POSTbusy=False return + searchForEmoji=False + if authorized and self.path.endswith('/searchhandleemoji': + searchForEmoji=True + self.path=self.path.replace('/searchhandleemoji','/searchhandle') + # a search was made if authorized and \ (self.path.endswith('/searchhandle') or '/searchhandle?page=' in self.path): @@ -2364,6 +2380,8 @@ class PubServer(BaseHTTPRequestHandler): if '&' in searchStr: searchStr=searchStr.split('&')[0] searchStr=searchStr.replace('+',' ').replace('%40','@').replace('%3A',':').replace('%23','#').strip() + if searchForEmoji: + searchStr=':'+searchStr+':' if searchStr.startswith('#'): # hashtag search hashtagStr= \ diff --git a/webinterface.py b/webinterface.py index 2e1c0b86..ad4ba8c2 100644 --- a/webinterface.py +++ b/webinterface.py @@ -1535,6 +1535,37 @@ def htmlUnblockConfirm(baseDir: str,originPathStr: str,blockActor: str,blockProf blockStr+=htmlFooter() return blockStr +def htmlSearchEmojiTextEntry(baseDir: str,path: str) -> str: + """Search for an emoji by name + """ + actor=path.replace('/search','') + nickname=getNicknameFromActor(actor) + domain,port=getDomainFromActor(actor) + + if os.path.isfile(baseDir+'/img/search-background.png'): + if not os.path.isfile(baseDir+'/accounts/search-background.png'): + copyfile(baseDir+'/img/search-background.png',baseDir+'/accounts/search-background.png') + + with open(baseDir+'/epicyon-follow.css', 'r') as cssFile: + profileStyle = cssFile.read() + emojiStr=htmlHeader(profileStyle) + emojiStr+='
' + emojiStr+='
' + emojiStr+='
' + emojiStr+='

Enter an emoji name to search for

' + emojiStr+= \ + '
' \ + ' ' \ + '
' \ + ' ' \ + ' ' \ + '
' + emojiStr+='
' + emojiStr+='
' + emojiStr+='
' + emojiStr+=htmlFooter() + return emojiStr + def htmlSearch(baseDir: str,path: str) -> str: """Search called from the timeline icon """