SSB profile field

main
Bob Mottram 2020-02-26 14:35:17 +00:00
parent 963f8226f8
commit c59cf2fe1a
3 changed files with 114 additions and 1 deletions

View File

@ -32,6 +32,8 @@ from pgp import getPGPpubKey
from pgp import setPGPpubKey
from xmpp import getXmppAddress
from xmpp import setXmppAddress
from ssb import getSSBAddress
from ssb import setSSBAddress
from matrix import getMatrixAddress
from matrix import setMatrixAddress
from donate import getDonationUrl
@ -1078,12 +1080,14 @@ class PubServer(BaseHTTPRequestHandler):
PGPpubKey=None
xmppAddress=None
matrixAddress=None
ssbAddress=None
emailAddress=None
actorJson=getPersonFromCache(self.server.baseDir,optionsActor,self.server.personCache)
if actorJson:
donateUrl=getDonationUrl(actorJson)
xmppAddress=getXmppAddress(actorJson)
matrixAddress=getMatrixAddress(actorJson)
ssbAddress=getSSBAddress(actorJson)
emailAddress=getEmailAddress(actorJson)
PGPpubKey=getPGPpubKey(actorJson)
msg=htmlPersonOptions(self.server.translate, \
@ -1095,6 +1099,7 @@ class PubServer(BaseHTTPRequestHandler):
optionsLink, \
pageNumber,donateUrl, \
xmppAddress,matrixAddress, \
ssbAddress, \
PGPpubKey,emailAddress).encode()
self._set_headers('text/html',len(msg),cookie)
self._write(msg)
@ -4423,6 +4428,15 @@ class PubServer(BaseHTTPRequestHandler):
if currentMatrixAddress:
setMatrixAddress(actorJson,'')
actorChanged=True
currentSSBAddress=getSSBAddress(actorJson)
if fields.get('ssbAddress'):
if fields['ssbAddress']!=currentSSBAddress:
setSSBAddress(actorJson,fields['ssbAddress'])
actorChanged=True
else:
if currentSSBAddress:
setSSBAddress(actorJson,'')
actorChanged=True
currentPGPpubKey=getPGPpubKey(actorJson)
if fields.get('pgp'):
if fields['pgp']!=currentPGPpubKey:

86
ssb.py 100644
View File

@ -0,0 +1,86 @@
__filename__ = "ssb.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.1.0"
__maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net"
__status__ = "Production"
import json
def getSSBAddress(actorJson: {}) -> str:
"""Returns ssb address for the given actor
"""
if not actorJson.get('attachment'):
return ''
for propertyValue in actorJson['attachment']:
if not propertyValue.get('name'):
continue
if not propertyValue['name'].lower().startswith('ssb'):
continue
if not propertyValue.get('type'):
continue
if not propertyValue.get('value'):
continue
if propertyValue['type']!='PropertyValue':
continue
if '@' not in propertyValue['value']:
continue
if not propertyValue['value'].startswith('@'):
continue
if ':' not in propertyValue['value']:
continue
if '"' in propertyValue['value']:
continue
return propertyValue['value']
return ''
def setSSBAddress(actorJson: {},ssbAddress: str) -> None:
"""Sets an ssb address for the given actor
"""
if not actorJson.get('attachment'):
actorJson['attachment']=[]
# remove any existing value
propertyFound=None
for propertyValue in actorJson['attachment']:
if not propertyValue.get('name'):
continue
if not propertyValue.get('type'):
continue
if not propertyValue['name'].lower().startswith('ssb'):
continue
propertyFound=propertyValue
break
if propertyFound:
actorJson['attachment'].remove(propertyFound)
if '@' not in ssbAddress:
return
if not ssbAddress.startswith('@'):
return
if '.' not in ssbAddress:
return
if '"' in ssbAddress:
return
if ':' not in ssbAddress:
return
for propertyValue in actorJson['attachment']:
if not propertyValue.get('name'):
continue
if not propertyValue.get('type'):
continue
if not propertyValue['name'].lower().startswith('ssb'):
continue
if propertyValue['type']!='PropertyValue':
continue
propertyValue['value']=ssbAddress
return
newSSBAddress={
"name": "SSB",
"type": "PropertyValue",
"value": ssbAddress
}
actorJson['attachment'].append(newSSBAddress)

View File

@ -21,6 +21,7 @@ from person import isPersonSnoozed
from pgp import getEmailAddress
from pgp import getPGPpubKey
from xmpp import getXmppAddress
from ssb import getSSBAddress
from matrix import getMatrixAddress
from donate import getDonationUrl
from utils import isBlogPost
@ -677,12 +678,14 @@ def htmlEditProfile(translate: {},baseDir: str,path: str, \
PGPpubKey=''
xmppAddress=''
matrixAddress=''
ssbAddress=''
manuallyApprovesFollowers=''
actorJson=loadJson(actorFilename)
if actorJson:
donateUrl=getDonationUrl(actorJson)
xmppAddress=getXmppAddress(actorJson)
matrixAddress=getMatrixAddress(actorJson)
ssbAddress=getSSBAddress(actorJson)
emailAddress=getEmailAddress(actorJson)
PGPpubKey=getPGPpubKey(actorJson)
if actorJson.get('name'):
@ -857,6 +860,8 @@ def htmlEditProfile(translate: {},baseDir: str,path: str, \
editProfileForm+=' <input type="text" name="xmppAddress" value="'+xmppAddress+'">'
editProfileForm+='<label class="labels">'+translate['Matrix']+'</label><br>'
editProfileForm+=' <input type="text" name="matrixAddress" value="'+matrixAddress+'">'
editProfileForm+='<label class="labels">SSB</label><br>'
editProfileForm+=' <input type="text" name="ssbAddress" value="'+ssbAddress+'">'
editProfileForm+='<label class="labels">'+translate['Email']+'</label><br>'
editProfileForm+=' <input type="text" name="email" value="'+emailAddress+'">'
editProfileForm+='<label class="labels">'+translate['PGP']+'</label><br>'
@ -1847,8 +1852,9 @@ def htmlProfile(defaultTimeline: str, \
emailAddress=getEmailAddress(profileJson)
xmppAddress=getXmppAddress(profileJson)
matrixAddress=getMatrixAddress(profileJson)
ssbAddress=getSSBAddress(profileJson)
if donateUrl or xmppAddress or matrixAddress or \
PGPpubKey or emailAddress:
ssbAddress or PGPpubKey or emailAddress:
donateSection='<div class="container">\n'
donateSection+=' <center>\n'
if donateUrl:
@ -1867,6 +1873,9 @@ def htmlProfile(defaultTimeline: str, \
if matrixAddress:
donateSection+= \
'<p>'+translate['Matrix']+': '+matrixAddress+'</p>\n'
if ssbAddress:
donateSection+= \
'<p>'+translate['SSB']+': '+ssbAddress+'</p>\n'
if PGPpubKey:
donateSection+= \
'<p class="pgp">'+PGPpubKey.replace('\n','<br>')+'</p>\n'
@ -4279,6 +4288,7 @@ def htmlPersonOptions(translate: {},baseDir: str, \
donateUrl: str, \
xmppAddress: str, \
matrixAddress: str, \
ssbAddress: str, \
PGPpubKey: str, \
emailAddress) -> str:
"""Show options for a person: view/follow/block/report
@ -4352,6 +4362,9 @@ def htmlPersonOptions(translate: {},baseDir: str, \
if matrixAddress:
optionsStr+= \
'<p class="imText">'+translate['Matrix']+': '+matrixAddress+'</p>'
if ssbAddress:
optionsStr+= \
'<p class="imText">SSB: '+ssbAddress+'</p>'
if PGPpubKey:
optionsStr+='<p class="pgp">'+PGPpubKey.replace('\n','<br>')+'</p>'
optionsStr+=' <form method="POST" action="'+originPathStr+'/personoptions">'