mirror of https://gitlab.com/bashrc2/epicyon
Include mentions in new posts
parent
e5803ae454
commit
19ae236665
15
content.py
15
content.py
|
@ -62,3 +62,18 @@ def addMentions(baseDir: str,httpPrefix: str, \
|
|||
content=content.replace('\n','</p><p>')
|
||||
return '<p>'+content+'</p>'
|
||||
|
||||
def getMentionsFromHtml(htmlText: str,matchStr="<span class=\"h-card\"><a href=\"") -> []:
|
||||
"""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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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='<a href="'+pathBase+'/newshare"><img src="/icons/scope_share.png"/><b>Share</b><br>Describe a shared item</a>'
|
||||
|
||||
mentionsStr=''
|
||||
for m in mentions:
|
||||
mentionNickname=getNicknameFromActor(m)
|
||||
if not mentionNickname:
|
||||
continue
|
||||
mentionDomain,mentionPort=getDomainFromActor(m)
|
||||
if not mentionDomain:
|
||||
continue
|
||||
if mentionPort:
|
||||
mentionsStr+='@'+mentionNickname+'@'+mentionDomain+':'+str(mentionPort)+' '
|
||||
else:
|
||||
mentionsStr+='@'+mentionNickname+'@'+mentionDomain+' '
|
||||
|
||||
newPostForm+= \
|
||||
'<form enctype="multipart/form-data" method="POST" action="'+path+'?'+endpoint+'">' \
|
||||
' <div class="vertical-center">' \
|
||||
|
@ -258,7 +273,7 @@ def htmlNewPost(baseDir: str,path: str,inReplyTo: str) -> str:
|
|||
replyStr+ \
|
||||
' <input type="text" placeholder="'+placeholderSubject+'" name="subject">' \
|
||||
'' \
|
||||
' <textarea id="message" name="message" placeholder="'+placeholderMessage+'" style="height:200px"></textarea>' \
|
||||
' <textarea id="message" name="message" placeholder="'+placeholderMessage+'" style="height:200px" autofocus>'+mentionsStr+'</textarea>' \
|
||||
''+extraFields+ \
|
||||
' <div class="container">' \
|
||||
' <input type="text" placeholder="Image description" name="imageDescription">' \
|
||||
|
@ -700,8 +715,20 @@ def individualPostAsHtml(baseDir: str, \
|
|||
'<img src="/icons/delete.png"/></a>'
|
||||
|
||||
if showIcons:
|
||||
replyToLink=postJsonObject['object']['id']
|
||||
if postJsonObject['object'].get('attributedTo'):
|
||||
replyToLink+='?mention='+postJsonObject['object']['attributedTo']
|
||||
if postJsonObject['object'].get('content'):
|
||||
mentionedActors=getMentionsFromHtml(postJsonObject['object']['content'])
|
||||
if mentionedActors:
|
||||
for actorUrl in mentionedActors:
|
||||
if '?mention='+actorUrl not in replyToLink:
|
||||
replyToLink+='?mention='+actorUrl
|
||||
if len(replyToLink)>500:
|
||||
break
|
||||
|
||||
footerStr='<div class="'+containerClassIcons+'">'
|
||||
footerStr+='<a href="/users/'+nickname+'?replyto='+postJsonObject['object']['id']+'" title="Reply to this post">'
|
||||
footerStr+='<a href="/users/'+nickname+'?replyto='+replyToLink+'" title="Reply to this post">'
|
||||
footerStr+='<img src="/icons/reply.png"/></a>'
|
||||
footerStr+=announceStr+likeStr+deleteStr
|
||||
footerStr+='<span class="'+timeClass+'">'+publishedStr+'</span>'
|
||||
|
|
Loading…
Reference in New Issue