diff --git a/daemon.py b/daemon.py index c39de2985..50f671180 100644 --- a/daemon.py +++ b/daemon.py @@ -40,6 +40,8 @@ from ssb import getSSBAddress from ssb import setSSBAddress from tox import getToxAddress from tox import setToxAddress +from jami import getJamiAddress +from jami import setJamiAddress from matrix import getMatrixAddress from matrix import setMatrixAddress from donate import getDonationUrl @@ -3787,6 +3789,18 @@ class PubServer(BaseHTTPRequestHandler): setToxAddress(actorJson, '') actorChanged = True + # change jami address + currentJamiAddress = getJamiAddress(actorJson) + if fields.get('jamiAddress'): + if fields['jamiAddress'] != currentJamiAddress: + setJamiAddress(actorJson, + fields['jamiAddress']) + actorChanged = True + else: + if currentJamiAddress: + setJamiAddress(actorJson, '') + actorChanged = True + # change PGP public key currentPGPpubKey = getPGPpubKey(actorJson) if fields.get('pgp'): @@ -4747,6 +4761,7 @@ class PubServer(BaseHTTPRequestHandler): matrixAddress = None blogAddress = None toxAddress = None + jamiAddress = None ssbAddress = None emailAddress = None actorJson = getPersonFromCache(baseDir, @@ -4760,6 +4775,7 @@ class PubServer(BaseHTTPRequestHandler): ssbAddress = getSSBAddress(actorJson) blogAddress = getBlogAddress(actorJson) toxAddress = getToxAddress(actorJson) + jamiAddress = getJamiAddress(actorJson) emailAddress = getEmailAddress(actorJson) PGPpubKey = getPGPpubKey(actorJson) PGPfingerprint = getPGPfingerprint(actorJson) @@ -4775,7 +4791,7 @@ class PubServer(BaseHTTPRequestHandler): pageNumber, donateUrl, xmppAddress, matrixAddress, ssbAddress, blogAddress, - toxAddress, + toxAddress, jamiAddress, PGPpubKey, PGPfingerprint, emailAddress).encode('utf-8') self._set_headers('text/html', len(msg), diff --git a/jami.py b/jami.py new file mode 100644 index 000000000..6cc3fe3ca --- /dev/null +++ b/jami.py @@ -0,0 +1,93 @@ +__filename__ = "jami.py" +__author__ = "Bob Mottram" +__license__ = "AGPL3+" +__version__ = "1.1.0" +__maintainer__ = "Bob Mottram" +__email__ = "bob@freedombone.net" +__status__ = "Production" + + +def getJamiAddress(actorJson: {}) -> str: + """Returns jami 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('jami'): + continue + if not propertyValue.get('type'): + continue + if not propertyValue.get('value'): + continue + if propertyValue['type'] != 'PropertyValue': + continue + propertyValue['value'] = propertyValue['value'].strip() + if len(propertyValue['value']) < 2: + continue + if '"' in propertyValue['value']: + continue + if ' ' in propertyValue['value']: + continue + if ',' in propertyValue['value']: + continue + if '.' in propertyValue['value']: + continue + return propertyValue['value'] + return '' + + +def setJamiAddress(actorJson: {}, jamiAddress: str) -> None: + """Sets an jami address for the given actor + """ + notJamiAddress = False + + if len(jamiAddress) < 2: + notJamiAddress = True + if '"' in jamiAddress: + notJamiAddress = True + if ' ' in jamiAddress: + notJamiAddress = True + if '.' in jamiAddress: + notJamiAddress = True + if ',' in jamiAddress: + notJamiAddress = True + + 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('jami'): + continue + propertyFound = propertyValue + break + if propertyFound: + actorJson['attachment'].remove(propertyFound) + if notJamiAddress: + return + + for propertyValue in actorJson['attachment']: + if not propertyValue.get('name'): + continue + if not propertyValue.get('type'): + continue + if not propertyValue['name'].lower().startswith('jami'): + continue + if propertyValue['type'] != 'PropertyValue': + continue + propertyValue['value'] = jamiAddress + return + + newJamiAddress = { + "name": "Jami", + "type": "PropertyValue", + "value": jamiAddress + } + actorJson['attachment'].append(newJamiAddress) diff --git a/webapp_person_options.py b/webapp_person_options.py index 564974146..d6c7c506f 100644 --- a/webapp_person_options.py +++ b/webapp_person_options.py @@ -34,6 +34,7 @@ def htmlPersonOptions(defaultTimeline: str, ssbAddress: str, blogAddress: str, toxAddress: str, + jamiAddress: str, PGPpubKey: str, PGPfingerprint: str, emailAddress) -> str: @@ -131,6 +132,9 @@ def htmlPersonOptions(defaultTimeline: str, if toxAddress: optionsStr += \ '
Tox: ' + toxAddress + '
\n' + if jamiAddress: + optionsStr += \ + 'Jami: ' + jamiAddress + '
\n' if PGPfingerprint: optionsStr += 'PGP: ' + \
PGPfingerprint.replace('\n', '
') + '
Tox:
\n' + if jamiAddress: + donateSection += \ + 'Jami:
\n' if PGPfingerprint: donateSection += \ 'PGP: ' + \
@@ -863,6 +869,7 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
ssbAddress = getSSBAddress(actorJson)
blogAddress = getBlogAddress(actorJson)
toxAddress = getToxAddress(actorJson)
+ jamiAddress = getJamiAddress(actorJson)
emailAddress = getEmailAddress(actorJson)
PGPpubKey = getPGPpubKey(actorJson)
PGPfingerprint = getPGPfingerprint(actorJson)
@@ -1194,6 +1201,12 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
editProfileForm += \
' \n'
+
+ editProfileForm += '
\n'
+ editProfileForm += \
+ ' \n'
+
editProfileForm += '
\n'
editProfileForm += \