xmpp address within profile

main
Bob Mottram 2019-12-17 14:57:16 +00:00
parent 3588e1f3aa
commit 6aa5950c2c
3 changed files with 93 additions and 5 deletions

View File

@ -25,6 +25,8 @@ from webfinger import webfingerLookup
from webfinger import webfingerHandle
from metadata import metaDataNodeInfo
from metadata import metaDataInstance
from xmpp import getXmppAddress
from xmpp import setXmppAddress
from donate import getDonationUrl
from donate import setDonationUrl
from person import activateAccount
@ -1166,9 +1168,11 @@ class PubServer(BaseHTTPRequestHandler):
if len(optionsList)>3:
optionsLink=optionsList[3]
donateUrl=None
xmppAddress=None
actorJson=getPersonFromCache(self.server.baseDir,optionsActor,self.server.personCache)
if actorJson:
donateUrl=getDonationUrl(actorJson)
xmppAddress=getXmppAddress(actorJson)
msg=htmlPersonOptions(self.server.translate, \
self.server.baseDir, \
self.server.domain, \
@ -1176,7 +1180,8 @@ class PubServer(BaseHTTPRequestHandler):
optionsActor, \
optionsProfileUrl, \
optionsLink, \
pageNumber,donateUrl).encode()
pageNumber,donateUrl, \
xmppAddress).encode()
self._set_headers('text/html',len(msg),cookie)
self._write(msg)
return
@ -4270,6 +4275,11 @@ class PubServer(BaseHTTPRequestHandler):
if fields.get('themeDropdown'):
setTheme(self.server.baseDir,fields['themeDropdown'])
#self.server.iconsCache={}
if fields.get('xmppAddress'):
currentXmppAddress=getXmppAddress(actorJson)
if fields['xmppAddress']!=currentXmppAddress:
setXmppAddress(actorJson,fields['xmppAddress'])
actorChanged=True
if fields.get('donateUrl'):
currentDonateUrl=getDonationUrl(actorJson)
if fields['donateUrl']!=currentDonateUrl:

View File

@ -18,6 +18,7 @@ from shutil import copyfileobj
from pprint import pprint
from person import personBoxJson
from person import isPersonSnoozed
from xmpp import getXmppAddress
from donate import getDonationUrl
from utils import updateRecentPostsCache
from utils import getNicknameFromActor
@ -586,10 +587,12 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int,h
displayNickname=nickname
bioStr=''
donateUrl=''
xmppAddress=''
manuallyApprovesFollowers=''
actorJson=loadJson(actorFilename)
if actorJson:
donateUrl=getDonationUrl(actorJson)
xmppAddress=getXmppAddress(actorJson)
if actorJson.get('name'):
displayNickname=actorJson['name']
if actorJson.get('summary'):
@ -711,6 +714,8 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int,h
editProfileForm+=' <textarea id="message" name="bio" style="height:200px">'+bioStr+'</textarea>'
editProfileForm+='<label class="labels">'+translate['Donations link']+'</label><br>'
editProfileForm+=' <input type="text" placeholder="https://..." name="donateUrl" value="'+donateUrl+'">'
editProfileForm+='<label class="labels">'+translate['XMPP']+'</label><br>'
editProfileForm+=' <input type="text" name="xmppAddress" value="'+xmppAddress+'">'
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>'
@ -1516,10 +1521,14 @@ def htmlProfile(defaultTimeline: str, \
donateSection=''
donateUrl=getDonationUrl(profileJson)
if donateUrl:
xmppAddress=getXmppAddress(profileJson)
if donateUrl or xmppAddress:
donateSection='<div class="container">\n'
donateSection+=' <center>\n'
if donateUrl:
donateSection+=' <a href="'+donateUrl+'"><button class="donateButton">'+translate['Donate']+'</button></a>\n'
if xmppAddress:
donateSection+='<br>XMPP: '+xmppAddress+'\n'
donateSection+=' </center>\n'
donateSection+='</div>\n'
@ -3320,8 +3329,9 @@ def htmlPersonOptions(translate: {},baseDir: str, \
optionsActor: str, \
optionsProfileUrl: str, \
optionsLink: str, \
pageNumber: int,
donateUrl: str) -> str:
pageNumber: int, \
donateUrl: str, \
xmppAddress: str) -> str:
"""Show options for a person: view/follow/block/report
"""
optionsDomain,optionsPort=getDomainFromActor(optionsActor)
@ -3378,6 +3388,8 @@ def htmlPersonOptions(translate: {},baseDir: str, \
optionsStr+=' <a href="'+optionsActor+'">'
optionsStr+=' <img loading="lazy" src="'+optionsProfileUrl+'"/></a>'
optionsStr+=' <p class="optionsText">'+translate['Options for']+' @'+getNicknameFromActor(optionsActor)+'@'+optionsDomain+'</p>'
if xmppAddress:
optionsStr+='<p>XMPP: '+xmppAddress+'</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+'">'

66
xmpp.py 100644
View File

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