diff --git a/daemon.py b/daemon.py
index 49e16cfd..a9936d22 100644
--- a/daemon.py
+++ b/daemon.py
@@ -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:
diff --git a/matrix.py b/matrix.py
new file mode 100644
index 00000000..017a85e6
--- /dev/null
+++ b/matrix.py
@@ -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)
diff --git a/webinterface.py b/webinterface.py
index c91f0aa6..f7a44b0e 100644
--- a/webinterface.py
+++ b/webinterface.py
@@ -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+=' '
editProfileForm+='
'
editProfileForm+=' '
+ editProfileForm+='
'
+ editProfileForm+=' '
editProfileForm+=' '
editProfileForm+='
XMPP: '+xmppAddress+'
\n' + if matrixAddress: + donateSection+='Matrix: '+matrixAddress+'
\n' donateSection+='XMPP: '+xmppAddress+'
' + if matrixAddress: + optionsStr+='Matrix: '+matrixAddress+'
' optionsStr+='