Matrix address in profile

main
Bob Mottram 2019-12-17 15:25:34 +00:00
parent a3950c3be0
commit 4562fec1ca
3 changed files with 95 additions and 3 deletions

View File

@ -27,6 +27,8 @@ from metadata import metaDataNodeInfo
from metadata import metaDataInstance
from xmpp import getXmppAddress
from xmpp import setXmppAddress
from matrix import getMatrixAddress
from matrix import setMatrixAddress
from donate import getDonationUrl
from donate import setDonationUrl
from person import activateAccount
@ -1169,10 +1171,12 @@ class PubServer(BaseHTTPRequestHandler):
optionsLink=optionsList[3]
donateUrl=None
xmppAddress=None
matrixAddress=None
actorJson=getPersonFromCache(self.server.baseDir,optionsActor,self.server.personCache)
if actorJson:
donateUrl=getDonationUrl(actorJson)
xmppAddress=getXmppAddress(actorJson)
matrixAddress=getMatrixAddress(actorJson)
msg=htmlPersonOptions(self.server.translate, \
self.server.baseDir, \
self.server.domain, \
@ -1181,7 +1185,7 @@ class PubServer(BaseHTTPRequestHandler):
optionsProfileUrl, \
optionsLink, \
pageNumber,donateUrl, \
xmppAddress).encode()
xmppAddress,matrixAddress).encode()
self._set_headers('text/html',len(msg),cookie)
self._write(msg)
return
@ -4280,6 +4284,11 @@ class PubServer(BaseHTTPRequestHandler):
if fields['xmppAddress']!=currentXmppAddress:
setXmppAddress(actorJson,fields['xmppAddress'])
actorChanged=True
if fields.get('matrixAddress'):
currentMatrixAddress=getMatrixAddress(actorJson)
if fields['matrixAddress']!=currentMatrixAddress:
setMatrixAddress(actorJson,fields['matrixAddress'])
actorChanged=True
if fields.get('donateUrl'):
currentDonateUrl=getDonationUrl(actorJson)
if fields['donateUrl']!=currentDonateUrl:

72
matrix.py 100644
View File

@ -0,0 +1,72 @@
__filename__ = "matrix.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.1.0"
__maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net"
__status__ = "Production"
import json
def getMatrixAddress(actorJson: {}) -> str:
"""Returns matrix 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('matrix'):
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 setMatrixAddress(actorJson: {},matrixAddress: str) -> None:
"""Sets an matrix address for the given actor
"""
if not actorJson.get('attachment'):
actorJson['attachment']=[]
if '@' not in matrixAddress:
return
if not matrixAddress.startswith('@'):
return
if '.' not in matrixAddress:
return
if '"' in matrixAddress:
return
if ':' not in matrixAddress:
return
for propertyValue in actorJson['attachment']:
if not propertyValue.get('name'):
continue
if not propertyValue.get('type'):
continue
if not propertyValue['name'].lower().startswith('matrix'):
continue
if propertyValue['type']!='PropertyValue':
continue
propertyValue['value']=matrixAddress
return
newMatrixAddress={
"name": "Matrix",
"type": "PropertyValue",
"value": matrixAddress
}
actorJson['attachment'].append(newMatrixAddress)

View File

@ -19,6 +19,7 @@ from pprint import pprint
from person import personBoxJson
from person import isPersonSnoozed
from xmpp import getXmppAddress
from matrix import getMatrixAddress
from donate import getDonationUrl
from utils import updateRecentPostsCache
from utils import getNicknameFromActor
@ -588,11 +589,13 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int,h
bioStr=''
donateUrl=''
xmppAddress=''
matrixAddress=''
manuallyApprovesFollowers=''
actorJson=loadJson(actorFilename)
if actorJson:
donateUrl=getDonationUrl(actorJson)
xmppAddress=getXmppAddress(actorJson)
matrixAddress=getMatrixAddress(actorJson)
if actorJson.get('name'):
displayNickname=actorJson['name']
if actorJson.get('summary'):
@ -716,6 +719,8 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int,h
editProfileForm+=' <input type="text" placeholder="https://..." name="donateUrl" value="'+donateUrl+'">'
editProfileForm+='<label class="labels">XMPP</label><br>'
editProfileForm+=' <input type="text" name="xmppAddress" value="'+xmppAddress+'">'
editProfileForm+='<label class="labels">Matrix</label><br>'
editProfileForm+=' <input type="text" name="matrixAddress" value="'+matrixAddress+'">'
editProfileForm+=' </div>'
editProfileForm+=' <div class="container">'
editProfileForm+=' <label class="labels">'+translate['The files attached below should be no larger than 10MB in total uploaded at once.']+'</label><br><br>'
@ -1522,13 +1527,16 @@ def htmlProfile(defaultTimeline: str, \
donateSection=''
donateUrl=getDonationUrl(profileJson)
xmppAddress=getXmppAddress(profileJson)
if donateUrl or xmppAddress:
matrixAddress=getMatrixAddress(profileJson)
if donateUrl or xmppAddress or matrixAddress:
donateSection='<div class="container">\n'
donateSection+=' <center>\n'
if donateUrl:
donateSection+=' <p><a href="'+donateUrl+'"><button class="donateButton">'+translate['Donate']+'</button></a></p>\n'
if xmppAddress:
donateSection+='<p>XMPP: '+xmppAddress+'</p>\n'
if matrixAddress:
donateSection+='<p>Matrix: '+matrixAddress+'</p>\n'
donateSection+=' </center>\n'
donateSection+='</div>\n'
@ -3331,7 +3339,8 @@ def htmlPersonOptions(translate: {},baseDir: str, \
optionsLink: str, \
pageNumber: int, \
donateUrl: str, \
xmppAddress: str) -> str:
xmppAddress: str, \
matrixAddress: str) -> str:
"""Show options for a person: view/follow/block/report
"""
optionsDomain,optionsPort=getDomainFromActor(optionsActor)
@ -3390,6 +3399,8 @@ def htmlPersonOptions(translate: {},baseDir: str, \
optionsStr+=' <p class="optionsText">'+translate['Options for']+' @'+getNicknameFromActor(optionsActor)+'@'+optionsDomain+'</p>'
if xmppAddress:
optionsStr+='<p>XMPP: '+xmppAddress+'</p>'
if matrixAddress:
optionsStr+='<p>Matrix: '+matrixAddress+'</p>'
optionsStr+=' <form method="POST" action="'+originPathStr+'/personoptions">'
optionsStr+=' <input type="hidden" name="pageNumber" value="'+str(pageNumber)+'">'
optionsStr+=' <input type="hidden" name="actor" value="'+optionsActor+'">'