cwtch address in profile

main
Bob Mottram 2021-06-27 12:48:03 +01:00
parent a21fa28587
commit 29cb994b31
4 changed files with 126 additions and 2 deletions

92
cwtch.py 100644
View File

@ -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)

View File

@ -44,6 +44,8 @@ from briar import getBriarAddress
from briar import setBriarAddress from briar import setBriarAddress
from jami import getJamiAddress from jami import getJamiAddress
from jami import setJamiAddress from jami import setJamiAddress
from cwtch import getCwtchAddress
from cwtch import setCwtchAddress
from matrix import getMatrixAddress from matrix import getMatrixAddress
from matrix import setMatrixAddress from matrix import setMatrixAddress
from donate import getDonationUrl from donate import getDonationUrl
@ -4517,6 +4519,18 @@ class PubServer(BaseHTTPRequestHandler):
setJamiAddress(actorJson, '') setJamiAddress(actorJson, '')
actorChanged = True 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 # change PGP public key
currentPGPpubKey = getPGPpubKey(actorJson) currentPGPpubKey = getPGPpubKey(actorJson)
if fields.get('pgp'): if fields.get('pgp'):
@ -5811,6 +5825,7 @@ class PubServer(BaseHTTPRequestHandler):
toxAddress = None toxAddress = None
briarAddress = None briarAddress = None
jamiAddress = None jamiAddress = None
cwtchAddress = None
ssbAddress = None ssbAddress = None
emailAddress = None emailAddress = None
lockedAccount = False lockedAccount = False
@ -5832,6 +5847,7 @@ class PubServer(BaseHTTPRequestHandler):
toxAddress = getToxAddress(actorJson) toxAddress = getToxAddress(actorJson)
briarAddress = getBriarAddress(actorJson) briarAddress = getBriarAddress(actorJson)
jamiAddress = getJamiAddress(actorJson) jamiAddress = getJamiAddress(actorJson)
cwtchAddress = getCwtchAddress(actorJson)
emailAddress = getEmailAddress(actorJson) emailAddress = getEmailAddress(actorJson)
PGPpubKey = getPGPpubKey(actorJson) PGPpubKey = getPGPpubKey(actorJson)
PGPfingerprint = getPGPfingerprint(actorJson) PGPfingerprint = getPGPfingerprint(actorJson)
@ -5866,7 +5882,7 @@ class PubServer(BaseHTTPRequestHandler):
xmppAddress, matrixAddress, xmppAddress, matrixAddress,
ssbAddress, blogAddress, ssbAddress, blogAddress,
toxAddress, briarAddress, toxAddress, briarAddress,
jamiAddress, jamiAddress, cwtchAddress,
PGPpubKey, PGPfingerprint, PGPpubKey, PGPfingerprint,
emailAddress, emailAddress,
self.server.dormantMonths, self.server.dormantMonths,

View File

@ -45,6 +45,7 @@ def htmlPersonOptions(defaultTimeline: str,
toxAddress: str, toxAddress: str,
briarAddress: str, briarAddress: str,
jamiAddress: str, jamiAddress: str,
cwtchAddress: str,
PGPpubKey: str, PGPpubKey: str,
PGPfingerprint: str, PGPfingerprint: str,
emailAddress: str, emailAddress: str,
@ -214,6 +215,9 @@ def htmlPersonOptions(defaultTimeline: str,
if jamiAddress: if jamiAddress:
optionsStr += \ optionsStr += \
'<p class="imText">Jami: ' + removeHtml(jamiAddress) + '</p>\n' '<p class="imText">Jami: ' + removeHtml(jamiAddress) + '</p>\n'
if cwtchAddress:
optionsStr += \
'<p class="imText">Cwtch: ' + removeHtml(cwtchAddress) + '</p>\n'
if PGPfingerprint: if PGPfingerprint:
optionsStr += '<p class="pgp">PGP: ' + \ optionsStr += '<p class="pgp">PGP: ' + \
removeHtml(PGPfingerprint).replace('\n', '<br>') + '</p>\n' removeHtml(PGPfingerprint).replace('\n', '<br>') + '</p>\n'

View File

@ -40,6 +40,7 @@ from pgp import getPGPpubKey
from tox import getToxAddress from tox import getToxAddress
from briar import getBriarAddress from briar import getBriarAddress
from jami import getJamiAddress from jami import getJamiAddress
from cwtch import getCwtchAddress
from filters import isFiltered from filters import isFiltered
from follow import isFollowerOfPerson from follow import isFollowerOfPerson
from webapp_frontscreen import htmlFrontScreen from webapp_frontscreen import htmlFrontScreen
@ -517,9 +518,10 @@ def htmlProfile(rssIconAtTop: bool,
toxAddress = getToxAddress(profileJson) toxAddress = getToxAddress(profileJson)
briarAddress = getBriarAddress(profileJson) briarAddress = getBriarAddress(profileJson)
jamiAddress = getJamiAddress(profileJson) jamiAddress = getJamiAddress(profileJson)
cwtchAddress = getCwtchAddress(profileJson)
if donateUrl or xmppAddress or matrixAddress or \ if donateUrl or xmppAddress or matrixAddress or \
ssbAddress or toxAddress or briarAddress or \ ssbAddress or toxAddress or briarAddress or \
jamiAddress or PGPpubKey or \ jamiAddress or cwtchAddress or PGPpubKey or \
PGPfingerprint or emailAddress: PGPfingerprint or emailAddress:
donateSection = '<div class="container">\n' donateSection = '<div class="container">\n'
donateSection += ' <center>\n' donateSection += ' <center>\n'
@ -560,6 +562,10 @@ def htmlProfile(rssIconAtTop: bool,
donateSection += \ donateSection += \
'<p>Jami: <label class="toxaddr">' + \ '<p>Jami: <label class="toxaddr">' + \
jamiAddress + '</label></p>\n' jamiAddress + '</label></p>\n'
if cwtchAddress:
donateSection += \
'<p>Cwtch: <label class="toxaddr">' + \
cwtchAddress + '</label></p>\n'
if PGPfingerprint: if PGPfingerprint:
donateSection += \ donateSection += \
'<p class="pgp">PGP: ' + \ '<p class="pgp">PGP: ' + \
@ -1063,6 +1069,7 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
toxAddress = getToxAddress(actorJson) toxAddress = getToxAddress(actorJson)
briarAddress = getBriarAddress(actorJson) briarAddress = getBriarAddress(actorJson)
jamiAddress = getJamiAddress(actorJson) jamiAddress = getJamiAddress(actorJson)
cwtchAddress = getCwtchAddress(actorJson)
emailAddress = getEmailAddress(actorJson) emailAddress = getEmailAddress(actorJson)
PGPpubKey = getPGPpubKey(actorJson) PGPpubKey = getPGPpubKey(actorJson)
PGPfingerprint = getPGPfingerprint(actorJson) PGPfingerprint = getPGPfingerprint(actorJson)
@ -1698,6 +1705,11 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
' <input type="text" name="jamiAddress" value="' + \ ' <input type="text" name="jamiAddress" value="' + \
jamiAddress + '">\n' jamiAddress + '">\n'
editProfileForm += '<label class="labels">Cwtch</label><br>\n'
editProfileForm += \
' <input type="text" name="cwtchAddress" value="' + \
cwtchAddress + '">\n'
editProfileForm += \ editProfileForm += \
'<label class="labels">' + \ '<label class="labels">' + \
translate['PGP Fingerprint'] + '</label><br>\n' translate['PGP Fingerprint'] + '</label><br>\n'