diff --git a/cwtch.py b/cwtch.py new file mode 100644 index 000000000..9619067f1 --- /dev/null +++ b/cwtch.py @@ -0,0 +1,92 @@ +__filename__ = "cwtch.py" +__author__ = "Bob Mottram" +__license__ = "AGPL3+" +__version__ = "1.2.0" +__maintainer__ = "Bob Mottram" +__email__ = "bob@freedombone.net" +__status__ = "Production" +__module_group__ = "Profile Metadata" + +import re + + +def getCwtchAddress(actorJson: {}) -> str: + """Returns cwtch 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('cwtch'): + 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 setCwtchAddress(actorJson: {}, cwtchAddress: str) -> None: + """Sets an cwtch address for the given actor + """ + notCwtchAddress = False + + if len(cwtchAddress) < 56: + notCwtchAddress = True + if cwtchAddress != cwtchAddress.lower(): + notCwtchAddress = True + if not re.match("^[a-z0-9]*$", cwtchAddress): + notCwtchAddress = 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('cwtch'): + continue + propertyFound = propertyValue + break + if propertyFound: + actorJson['attachment'].remove(propertyFound) + if notCwtchAddress: + return + + for propertyValue in actorJson['attachment']: + if not propertyValue.get('name'): + continue + if not propertyValue.get('type'): + continue + if not propertyValue['name'].lower().startswith('cwtch'): + continue + if propertyValue['type'] != 'PropertyValue': + continue + propertyValue['value'] = cwtchAddress + return + + newCwtchAddress = { + "name": "Cwtch", + "type": "PropertyValue", + "value": cwtchAddress + } + actorJson['attachment'].append(newCwtchAddress) diff --git a/daemon.py b/daemon.py index 69795fab2..b3904bf63 100644 --- a/daemon.py +++ b/daemon.py @@ -44,6 +44,8 @@ from briar import getBriarAddress from briar import setBriarAddress from jami import getJamiAddress from jami import setJamiAddress +from cwtch import getCwtchAddress +from cwtch import setCwtchAddress from matrix import getMatrixAddress from matrix import setMatrixAddress from donate import getDonationUrl @@ -4517,6 +4519,18 @@ class PubServer(BaseHTTPRequestHandler): setJamiAddress(actorJson, '') actorChanged = True + # change cwtch address + currentCwtchAddress = getCwtchAddress(actorJson) + if fields.get('cwtchAddress'): + if fields['cwtchAddress'] != currentCwtchAddress: + setCwtchAddress(actorJson, + fields['cwtchAddress']) + actorChanged = True + else: + if currentCwtchAddress: + setCwtchAddress(actorJson, '') + actorChanged = True + # change PGP public key currentPGPpubKey = getPGPpubKey(actorJson) if fields.get('pgp'): @@ -5811,6 +5825,7 @@ class PubServer(BaseHTTPRequestHandler): toxAddress = None briarAddress = None jamiAddress = None + cwtchAddress = None ssbAddress = None emailAddress = None lockedAccount = False @@ -5832,6 +5847,7 @@ class PubServer(BaseHTTPRequestHandler): toxAddress = getToxAddress(actorJson) briarAddress = getBriarAddress(actorJson) jamiAddress = getJamiAddress(actorJson) + cwtchAddress = getCwtchAddress(actorJson) emailAddress = getEmailAddress(actorJson) PGPpubKey = getPGPpubKey(actorJson) PGPfingerprint = getPGPfingerprint(actorJson) @@ -5866,7 +5882,7 @@ class PubServer(BaseHTTPRequestHandler): xmppAddress, matrixAddress, ssbAddress, blogAddress, toxAddress, briarAddress, - jamiAddress, + jamiAddress, cwtchAddress, PGPpubKey, PGPfingerprint, emailAddress, self.server.dormantMonths, diff --git a/webapp_person_options.py b/webapp_person_options.py index 026182d8f..35ac8708e 100644 --- a/webapp_person_options.py +++ b/webapp_person_options.py @@ -45,6 +45,7 @@ def htmlPersonOptions(defaultTimeline: str, toxAddress: str, briarAddress: str, jamiAddress: str, + cwtchAddress: str, PGPpubKey: str, PGPfingerprint: str, emailAddress: str, @@ -214,6 +215,9 @@ def htmlPersonOptions(defaultTimeline: str, if jamiAddress: optionsStr += \ '

Jami: ' + removeHtml(jamiAddress) + '

\n' + if cwtchAddress: + optionsStr += \ + '

Cwtch: ' + removeHtml(cwtchAddress) + '

\n' if PGPfingerprint: optionsStr += '

PGP: ' + \ removeHtml(PGPfingerprint).replace('\n', '
') + '

\n' diff --git a/webapp_profile.py b/webapp_profile.py index ca6d6e9fb..28247ded8 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -40,6 +40,7 @@ from pgp import getPGPpubKey from tox import getToxAddress from briar import getBriarAddress from jami import getJamiAddress +from cwtch import getCwtchAddress from filters import isFiltered from follow import isFollowerOfPerson from webapp_frontscreen import htmlFrontScreen @@ -517,9 +518,10 @@ def htmlProfile(rssIconAtTop: bool, toxAddress = getToxAddress(profileJson) briarAddress = getBriarAddress(profileJson) jamiAddress = getJamiAddress(profileJson) + cwtchAddress = getCwtchAddress(profileJson) if donateUrl or xmppAddress or matrixAddress or \ ssbAddress or toxAddress or briarAddress or \ - jamiAddress or PGPpubKey or \ + jamiAddress or cwtchAddress or PGPpubKey or \ PGPfingerprint or emailAddress: donateSection = '
\n' donateSection += '
\n' @@ -560,6 +562,10 @@ def htmlProfile(rssIconAtTop: bool, donateSection += \ '

Jami:

\n' + if cwtchAddress: + donateSection += \ + '

Cwtch:

\n' if PGPfingerprint: donateSection += \ '

PGP: ' + \ @@ -1063,6 +1069,7 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str, toxAddress = getToxAddress(actorJson) briarAddress = getBriarAddress(actorJson) jamiAddress = getJamiAddress(actorJson) + cwtchAddress = getCwtchAddress(actorJson) emailAddress = getEmailAddress(actorJson) PGPpubKey = getPGPpubKey(actorJson) PGPfingerprint = getPGPfingerprint(actorJson) @@ -1698,6 +1705,11 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str, ' \n' + editProfileForm += '
\n' + editProfileForm += \ + ' \n' + editProfileForm += \ '
\n'