Switching to person options screen

master
Bob Mottram 2019-08-25 00:00:03 +01:00
parent eefacc4171
commit ab0ff77f0d
2 changed files with 125 additions and 103 deletions

160
daemon.py
View File

@ -76,6 +76,7 @@ from roles import setRole
from roles import clearModeratorStatus from roles import clearModeratorStatus
from skills import outboxSkills from skills import outboxSkills
from availability import outboxAvailability from availability import outboxAvailability
from webinterface import htmlUnblockConfirm
from webinterface import htmlPersonOptions from webinterface import htmlPersonOptions
from webinterface import htmlIndividualPost from webinterface import htmlIndividualPost
from webinterface import htmlProfile from webinterface import htmlProfile
@ -514,32 +515,24 @@ class PubServer(BaseHTTPRequestHandler):
self.path=='/users/'+self.server.domain: self.path=='/users/'+self.server.domain:
self.path='/inbox' self.path='/inbox'
# Unfollow a person from the web interface by selecting Unfollow on the dropdown
if htmlGET and '/users/' in self.path and '?unfollow=' in self.path:
followStr=self.path.split('?unfollow=')[1]
originPathStr=self.path.split('?unfollow=')[0]
if ';' in followStr:
followActor=followStr.split(';')[0]
followProfileUrl=followStr.split(';')[1]
# show the confirm follow screen
msg=htmlUnfollowConfirm(self.server.baseDir,originPathStr,followActor,followProfileUrl).encode()
self._set_headers('text/html',len(msg),cookie)
self.wfile.write(msg)
self.server.GETbusy=False
return
self._redirect_headers(originPathStr,cookie)
self.server.GETbusy=False
return
# show the person options screen with view/follow/block/report # show the person options screen with view/follow/block/report
if htmlGET and '/users/' in self.path: if htmlGET and '/users/' in self.path:
if '?options=' in self.path: if '?options=' in self.path:
optionsStr=self.path.split('?options=')[1] optionsStr=self.path.split('?options=')[1]
originPathStr=self.path.split('?options=')[0] originPathStr=self.path.split('?options=')[0]
if ';' in optionsStr: if ';' in optionsStr:
optionsActor=optionsStr.split(';')[0] optionsList=optionsStr.split(';')
optionsProfileUrl=optionsStr.split(';')[1] optionsActor=optionsList[0]
msg=htmlPersonOptions(self.server.baseDir,originPathStr,optionsActor,optionsProfileUrl).encode() optionsProfileUrl=optionsList[1]
optionsLink=None
if len(optionsList)>2:
optionsLink=optionsList[2]
msg=htmlPersonOptions(self.server.baseDir, \
self.server.domain, \
originPathStr, \
optionsActor, \
optionsProfileUrl,
optionsLink).encode()
self._set_headers('text/html',len(msg),cookie) self._set_headers('text/html',len(msg),cookie)
self.wfile.write(msg) self.wfile.write(msg)
self.server.GETbusy=False self.server.GETbusy=False
@ -790,42 +783,6 @@ class PubServer(BaseHTTPRequestHandler):
self.server.GETbusy=False self.server.GETbusy=False
return return
# follow a person from the web interface by selecting Follow on the dropdown
if '/users/' in self.path:
if '?follow=' in self.path:
followStr=self.path.split('?follow=')[1]
originPathStr=self.path.split('?follow=')[0]
if ';' in followStr:
followActor=followStr.split(';')[0]
followProfileUrl=followStr.split(';')[1]
# show the confirm follow screen
msg=htmlFollowConfirm(self.server.baseDir,originPathStr,followActor,followProfileUrl).encode()
self._set_headers('text/html',len(msg),cookie)
self.wfile.write(msg)
self.server.GETbusy=False
return
self._redirect_headers(originPathStr,cookie)
self.server.GETbusy=False
return
# block a person from the web interface by selecting Block on the dropdown
if '/users/' in self.path:
if '?block=' in self.path:
blockStr=self.path.split('?block=')[1]
originPathStr=self.path.split('?block=')[0]
if ';' in blockStr:
blockActor=blockStr.split(';')[0]
blockProfileUrl=blockStr.split(';')[1]
# show the confirm block screen
msg=htmlBlockConfirm(self.server.baseDir,originPathStr,blockActor,blockProfileUrl).encode()
self._set_headers('text/html',len(msg),cookie)
self.wfile.write(msg)
self.server.GETbusy=False
return
self._redirect_headers(originPathStr,cookie)
self.server.GETbusy=False
return
# hashtag search # hashtag search
if self.path.startswith('/tags/'): if self.path.startswith('/tags/'):
pageNumber=1 pageNumber=1
@ -879,24 +836,6 @@ class PubServer(BaseHTTPRequestHandler):
self.server.GETbusy=False self.server.GETbusy=False
return return
# Unblock a person from the web interface by selecting Unblock on the dropdown
if htmlGET and '/users/' in self.path:
if '?unblock=' in self.path:
blockStr=self.path.split('?unblock=')[1]
originPathStr=self.path.split('?unblock=')[0]
if ';' in blockStr:
blockActor=blockStr.split(';')[0]
blockProfileUrl=blockStr.split(';')[1]
# show the confirm unblock screen
msg=htmlUnblockConfirm(self.server.baseDir,originPathStr,blockActor,blockProfileUrl).encode()
self._set_headers('text/html',len(msg),cookie)
self.wfile.write(msg)
self.server.GETbusy=False
return
self._redirect_headers(originPathStr,cookie)
self.server.GETbusy=False
return
# announce/repeat from the web interface # announce/repeat from the web interface
if htmlGET and '?repeat=' in self.path: if htmlGET and '?repeat=' in self.path:
repeatUrl=self.path.split('?repeat=')[1] repeatUrl=self.path.split('?repeat=')[1]
@ -1117,7 +1056,6 @@ class PubServer(BaseHTTPRequestHandler):
self.path.endswith('/newfollowers') or \ self.path.endswith('/newfollowers') or \
self.path.endswith('/newdm') or \ self.path.endswith('/newdm') or \
self.path.endswith('/newreport') or \ self.path.endswith('/newreport') or \
'/newreport?' in self.path or \
self.path.endswith('/newshare')): self.path.endswith('/newshare')):
msg=htmlNewPost(self.server.baseDir,self.path,inReplyToUrl,replyToList).encode() msg=htmlNewPost(self.server.baseDir,self.path,inReplyToUrl,replyToList).encode()
self._set_headers('text/html',len(msg),cookie) self._set_headers('text/html',len(msg),cookie)
@ -2661,6 +2599,78 @@ class PubServer(BaseHTTPRequestHandler):
self.server.POSTbusy=False self.server.POSTbusy=False
return return
# an option was chosen from person options screen
# view/follow/block/report
if authorized and self.path.endswith('/personoptions'):
originPathStr=self.path.split('/personoptions')[0]
chooserNickname=getNicknameFromActor(originPathStr)
length = int(self.headers['Content-length'])
optionsConfirmParams=self.rfile.read(length).decode('utf-8').replace('%3A',':').replace('%2F','/')
optionsActor=optionsConfirmParams.split('actor=')[1]
optionsAvatarUrl=optionsConfirmParams.split('avatarUrl=')[1]
if '&' in optionsActor:
optionsActor=optionsActor.split('&')[0]
optionsNickname=getNicknameFromActor(optionsActor)
optionsDomain,optionsPort=getDomainFromActor(optionsActor)
optionsDomainFull=optionsDomain
if optionsPort:
if optionsPort!=80 and optionsPort!=443:
if ':' not in optionsDomain:
optionsDomainFull=optionsDomain+':'+str(optionsPort)
if chooserNickname==optionsNickname and \
optionsDomain==self.server.domain and \
optionsPort==self.server.port:
if self.server.debug:
print('You cannot perform an option action on yourself')
if '&submitView=' in optionsConfirmParams:
if self.server.debug:
print('Viewing '+optionsActor)
self._redirect_headers(optionsActor,cookie)
self.server.POSTbusy=False
return
if '&submitBlock=' in optionsConfirmParams:
if self.server.debug:
print('Adding block by '+chooserNickname+' of '+optionsActor)
addBlock(self.server.baseDir,chooserNickname,self.server.domain, \
optionsNickname,optionsDomainFull)
if '&submitUnblock=' in optionsConfirmParams:
if self.server.debug:
print('Unblocking '+optionsActor)
msg=htmlUnblockConfirm(self.server.baseDir,originPathStr,optionsActor,optionsAvatarUrl).encode()
self._set_headers('text/html',len(msg),cookie)
self.wfile.write(msg)
self.server.POSTbusy=False
return
if '&submitFollow=' in optionsConfirmParams:
if self.server.debug:
print('Following '+optionsActor)
msg=htmlFollowConfirm(self.server.baseDir,originPathStr,optionsActor,optionsAvatarUrl).encode()
self._set_headers('text/html',len(msg),cookie)
self.wfile.write(msg)
self.server.POSTbusy=False
return
if '&submitUnfollow=' in optionsConfirmParams:
if self.server.debug:
print('Unfollowing '+optionsActor)
msg=htmlUnfollowConfirm(self.server.baseDir,originPathStr,optionsActor,optionsAvatarUrl).encode()
self._set_headers('text/html',len(msg),cookie)
self.wfile.write(msg)
self.server.POSTbusy=False
return
if '&submitReport=' in optionsConfirmParams:
if self.server.debug:
print('Reporting '+optionsActor)
msg=htmlNewPost(self.server.baseDir,self.path,None,[]).encode()
self._set_headers('text/html',len(msg),cookie)
self.wfile.write(msg)
self.server.POSTbusy=False
return
self._redirect_headers(originPathStr,cookie)
self.server.POSTbusy=False
return
postState=self._receiveNewPost(authorized,'newpost') postState=self._receiveNewPost(authorized,'newpost')
if postState!=0: if postState!=0:
nickname=self.path.split('/users/')[1] nickname=self.path.split('/users/')[1]

View File

@ -1231,28 +1231,15 @@ def individualPostAsHtml(baseDir: str, \
' <img src="'+avatarUrl+'" title="Show profile" alt="Avatar"'+avatarPosition+'/></a>' ' <img src="'+avatarUrl+'" title="Show profile" alt="Avatar"'+avatarPosition+'/></a>'
if showAvatarDropdown and fullDomain+'/users/'+nickname not in postJsonObject['actor']: if showAvatarDropdown and fullDomain+'/users/'+nickname not in postJsonObject['actor']:
# if not following then show "Follow" in the dropdown
followUnfollowStr='<a href="/users/'+nickname+'?follow='+postJsonObject['actor']+';'+avatarUrl+'">Follow</a>'
# if following then show "Unfollow" in the dropdown
if isFollowingActor(baseDir,nickname,domain,postJsonObject['actor']):
followUnfollowStr='<a href="/users/'+nickname+'?unfollow='+postJsonObject['actor']+';'+avatarUrl+'">Unfollow</a>'
blockUnblockStr='<a href="/users/'+nickname+'?block='+postJsonObject['actor']+';'+avatarUrl+'">Block</a>'
# if blocking then show "Unblock" in the dropdown
actorDomainFull=actorDomain
if actorPort:
if actorPort!=80 and actorPort!=443:
if ':' not in actorDomain:
actorDomainFull=actorDomain+':'+str(actorPort)
if isBlocked(baseDir,nickname,domain,actorNickname,actorDomainFull):
blockUnblockStr='<a href="/users/'+nickname+'?unblock='+postJsonObject['actor']+';'+avatarUrl+'">Unblock</a>'
reportStr=''
if messageId: if messageId:
reportStr='<a href="/users/'+nickname+'/newreport?url='+messageId+';'+avatarUrl+'">Report</a>'
avatarDropdown= \ avatarDropdown= \
' <div onclick="dropdown()" class="dropdown-timeline">' \ ' <div class="dropdown-timeline">' \
' <a href="/users/'+nickname+'?options='+postJsonObject['actor']+';'+avatarUrl+';'+messageId+'">' \
' <img title="Show options for this person" src="'+avatarUrl+'" '+avatarPosition+'/></a>' \
' </div>'
else:
avatarDropdown= \
' <div class="dropdown-timeline">' \
' <a href="/users/'+nickname+'?options='+postJsonObject['actor']+';'+avatarUrl+'">' \ ' <a href="/users/'+nickname+'?options='+postJsonObject['actor']+';'+avatarUrl+'">' \
' <img title="Show options for this person" src="'+avatarUrl+'" '+avatarPosition+'/></a>' \ ' <img title="Show options for this person" src="'+avatarUrl+'" '+avatarPosition+'/></a>' \
' </div>' ' </div>'
@ -1605,15 +1592,38 @@ def htmlUnfollowConfirm(baseDir: str,originPathStr: str,followActor: str,followP
followStr+=htmlFooter() followStr+=htmlFooter()
return followStr return followStr
def htmlPersonOptions(baseDir: str,originPathStr: str,optionsActor: str,optionsProfileUrl: str) -> str: def htmlPersonOptions(baseDir: str,domain: str,originPathStr: str,optionsActor: str,optionsProfileUrl: str,optionsLink: str) -> str:
"""Show options for a person: view/follow/block/report """Show options for a person: view/follow/block/report
""" """
optionsDomain,port=getDomainFromActor(optionsActor) optionsDomain,optionsPort=getDomainFromActor(optionsActor)
if os.path.isfile(baseDir+'/img/options-background.png'): if os.path.isfile(baseDir+'/img/options-background.png'):
if not os.path.isfile(baseDir+'/accounts/options-background.png'): if not os.path.isfile(baseDir+'/accounts/options-background.png'):
copyfile(baseDir+'/img/options-background.png',baseDir+'/accounts/options-background.png') copyfile(baseDir+'/img/options-background.png',baseDir+'/accounts/options-background.png')
followStr='Follow'
blockStr='Block'
if originPathStr.startswith('/users/'):
nickname=originPathStr.split('/users/')[1]
if '/' in nickname:
nickname=nickname.split('/')[0]
if '?' in nickname:
nickname=nickname.split('?')[0]
followerDomain,followerPort=getDomainFromActor(optionsActor)
if isFollowingActor(baseDir,nickname,domain,optionsActor):
followStr='Unfollow'
optionsNickname=getNicknameFromActor(optionsActor)
optionsDomainFull=optionsDomain
if optionsPort:
if optionsPort!=80 and optionsPort!=443:
optionsDomainFull=optionsDomain+':'+str(optionsPort)
if isBlocked(baseDir,nickname,domain,optionsNickname,optionsDomainFull):
blockStr='Block'
optionsLinkStr=''
if optionsLink:
optionsLinkStr=' <input type="hidden" name="postUrl" value="'+optionsLink+'">'
with open(baseDir+'/epicyon-follow.css', 'r') as cssFile: with open(baseDir+'/epicyon-follow.css', 'r') as cssFile:
profileStyle = cssFile.read() profileStyle = cssFile.read()
optionsStr=htmlHeader(profileStyle) optionsStr=htmlHeader(profileStyle)
@ -1626,9 +1636,11 @@ def htmlPersonOptions(baseDir: str,originPathStr: str,optionsActor: str,optionsP
optionsStr+= \ optionsStr+= \
' <form method="POST" action="'+originPathStr+'/personoptions">' \ ' <form method="POST" action="'+originPathStr+'/personoptions">' \
' <input type="hidden" name="actor" value="'+optionsActor+'">' \ ' <input type="hidden" name="actor" value="'+optionsActor+'">' \
' <input type="hidden" name="avatarUrl" value="'+optionsProfileUrl+'">'+ \
optionsLinkStr+ \
' <button type="submit" class="button" name="submitView">View</button>' \ ' <button type="submit" class="button" name="submitView">View</button>' \
' <button type="submit" class="button" name="submitFollow">Follow</button>' \ ' <button type="submit" class="button" name="submit'+followStr+'">'+followStr+'</button>' \
' <button type="submit" class="button" name="submitBlock">Block</button>' \ ' <button type="submit" class="button" name="submit'+blockStr+'">'+blockStr+'</button>' \
' <button type="submit" class="button" name="submitReport">Report</button>' \ ' <button type="submit" class="button" name="submitReport">Report</button>' \
' </form>' ' </form>'
optionsStr+='</center>' optionsStr+='</center>'