From 19ae236665df2a1cb827d6983722f08720624491 Mon Sep 17 00:00:00 2001
From: Bob Mottram
') return '
'+content+'
' +def getMentionsFromHtml(htmlText: str,matchStr=" []: + """Extracts mentioned actors from the given html content string + """ + mentions=[] + if matchStr not in htmlText: + return mentions + mentionsList=htmlStr.split(matchStr) + for mentionStr in mentionsList: + if '"' not in mentionStr: + continue + actorStr=mentionStr.split('"')[0] + if actorStr.startswith('http') or \ + actorStr.startswith('dat:'): + mentions.append(actorStr) + return mentions diff --git a/daemon.py b/daemon.py index 99b9c5fd..718a4644 100644 --- a/daemon.py +++ b/daemon.py @@ -823,8 +823,15 @@ class PubServer(BaseHTTPRequestHandler): # reply from the web interface icon inReplyToUrl=None + replyToList=[] if authorized and '?replyto=' in self.path: inReplyToUrl=self.path.split('?replyto=')[1] + if '?' in inReplyToUrl: + mentionsList=inReplyToUrl.split('?') + for m in mentionsList: + if m.startswith('mention='): + replyToList.append(m.replace('mention=','')) + inReplyToUrl=mentionsList[0] self.path=self.path.split('?replyto=')[0]+'/newpost' # edit profile in web interface @@ -842,7 +849,7 @@ class PubServer(BaseHTTPRequestHandler): self.path.endswith('/newdm') or \ self.path.endswith('/newshare')): self._set_headers('text/html',cookie) - self.wfile.write(htmlNewPost(self.server.baseDir,self.path,inReplyToUrl).encode()) + self.wfile.write(htmlNewPost(self.server.baseDir,self.path,inReplyToUrl,replyToList).encode()) self.server.GETbusy=False return diff --git a/webinterface.py b/webinterface.py index d33090e5..2919aeae 100644 --- a/webinterface.py +++ b/webinterface.py @@ -28,6 +28,7 @@ from auth import createPassword from like import likedByPerson from announce import announcedByPerson from blocking import isBlocked +from content import getMentionsFromHtml def htmlEditProfile(baseDir: str,path: str,domain: str,port: int) -> str: """Shows the edit profile screen @@ -179,7 +180,7 @@ def htmlLogin(baseDir: str) -> str: loginForm+=htmlFooter() return loginForm -def htmlNewPost(baseDir: str,path: str,inReplyTo: str) -> str: +def htmlNewPost(baseDir: str,path: str,inReplyTo: str,mentions: []) -> str: replyStr='' if not path.endswith('/newshare'): if not inReplyTo: @@ -237,6 +238,20 @@ def htmlNewPost(baseDir: str,path: str,inReplyTo: str) -> str: shareOptionOnDropdown='' if not replyStr: shareOptionOnDropdown='