mirror of https://gitlab.com/bashrc2/epicyon
LXMF address within profile
parent
f1d9fc2ed7
commit
dec6c57394
|
|
@ -1199,6 +1199,10 @@ def remove_long_words(content: str, max_word_length: int,
|
|||
if word_str.upper() == word_str:
|
||||
# tox address
|
||||
continue
|
||||
if len(word_str) == 32:
|
||||
if word_str.lower() == word_str:
|
||||
# LXMF address
|
||||
continue
|
||||
if '=\"' in word_str:
|
||||
continue
|
||||
if '@' in word_str:
|
||||
|
|
|
|||
|
|
@ -120,6 +120,8 @@ from posts import set_max_profile_posts
|
|||
from posts import get_max_profile_posts
|
||||
from tox import get_tox_address
|
||||
from tox import set_tox_address
|
||||
from lxmf import get_lxmf_address
|
||||
from lxmf import set_lxmf_address
|
||||
from briar import get_briar_address
|
||||
from briar import set_briar_address
|
||||
from cwtch import get_cwtch_address
|
||||
|
|
@ -1969,6 +1971,23 @@ def _profile_post_tox_address(fields: {}, actor_json: {},
|
|||
return actor_changed
|
||||
|
||||
|
||||
def _profile_post_lxmf_address(fields: {}, actor_json: {},
|
||||
actor_changed: bool) -> bool:
|
||||
""" HTTP POST change LXMF address
|
||||
"""
|
||||
current_lxmf_address = get_lxmf_address(actor_json)
|
||||
if fields.get('lxmfAddress'):
|
||||
if fields['lxmfAddress'] != current_lxmf_address:
|
||||
set_lxmf_address(actor_json,
|
||||
fields['lxmfAddress'])
|
||||
actor_changed = True
|
||||
else:
|
||||
if current_lxmf_address:
|
||||
set_lxmf_address(actor_json, '')
|
||||
actor_changed = True
|
||||
return actor_changed
|
||||
|
||||
|
||||
def _profile_post_birthday(fields: {}, actor_json: {},
|
||||
actor_changed: bool) -> bool:
|
||||
""" HTTP POST birthday on edit profile screen
|
||||
|
|
@ -3203,6 +3222,10 @@ def profile_edit(self, calling_domain: str, cookie: str,
|
|||
_profile_post_tox_address(fields, actor_json,
|
||||
actor_changed)
|
||||
|
||||
actor_changed = \
|
||||
_profile_post_lxmf_address(fields, actor_json,
|
||||
actor_changed)
|
||||
|
||||
actor_changed = \
|
||||
_profile_post_briar_address(fields, actor_json,
|
||||
actor_changed)
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ from matrix import get_matrix_address
|
|||
from ssb import get_ssb_address
|
||||
from blog import get_blog_address
|
||||
from tox import get_tox_address
|
||||
from lxmf import get_lxmf_address
|
||||
from briar import get_briar_address
|
||||
from cwtch import get_cwtch_address
|
||||
from pgp import get_pgp_fingerprint
|
||||
|
|
@ -669,6 +670,7 @@ def show_person_options(self, calling_domain: str, path: str,
|
|||
matrix_address = None
|
||||
blog_address = None
|
||||
tox_address = None
|
||||
lxmf_address = None
|
||||
briar_address = None
|
||||
cwtch_address = None
|
||||
ssb_address = None
|
||||
|
|
@ -716,6 +718,7 @@ def show_person_options(self, calling_domain: str, path: str,
|
|||
ssb_address = get_ssb_address(actor_json)
|
||||
blog_address = get_blog_address(actor_json)
|
||||
tox_address = get_tox_address(actor_json)
|
||||
lxmf_address = get_lxmf_address(actor_json)
|
||||
briar_address = get_briar_address(actor_json)
|
||||
cwtch_address = get_cwtch_address(actor_json)
|
||||
email_address = get_email_address(actor_json)
|
||||
|
|
@ -774,7 +777,8 @@ def show_person_options(self, calling_domain: str, path: str,
|
|||
gemini_link, pronouns,
|
||||
xmpp_address, matrix_address,
|
||||
ssb_address, blog_address,
|
||||
tox_address, briar_address,
|
||||
tox_address, lxmf_address,
|
||||
briar_address,
|
||||
cwtch_address,
|
||||
enigma_pub_key,
|
||||
pgp_pub_key, pgp_fingerprint,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,138 @@
|
|||
__filename__ = "lxmf.py"
|
||||
__author__ = "Bob Mottram"
|
||||
__license__ = "AGPL3+"
|
||||
__version__ = "1.7.0"
|
||||
__maintainer__ = "Bob Mottram"
|
||||
__email__ = "bob@libreserver.org"
|
||||
__status__ = "Production"
|
||||
__module_group__ = "Profile Metadata"
|
||||
|
||||
|
||||
from utils import get_attachment_property_value
|
||||
from utils import remove_html
|
||||
|
||||
VALID_LXMF_CHARS = set('0123456789abcdefghijklmnopqrstuvwxyz')
|
||||
|
||||
|
||||
def get_lxmf_address(actor_json: {}) -> str:
|
||||
"""Returns lxmf address for the given actor
|
||||
"""
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
if not isinstance(actor_json['attachment'], list):
|
||||
return ''
|
||||
for property_value in actor_json['attachment']:
|
||||
if not isinstance(property_value, dict):
|
||||
print("WARN: actor attachment is not dict: " + str(property_value))
|
||||
continue
|
||||
name_value = None
|
||||
if property_value.get('name'):
|
||||
name_value = property_value['name']
|
||||
elif property_value.get('schema:name'):
|
||||
name_value = property_value['schema:name']
|
||||
if not name_value:
|
||||
continue
|
||||
if not name_value.lower().startswith('lxmf'):
|
||||
continue
|
||||
if not property_value.get('type'):
|
||||
continue
|
||||
prop_value_name, _ = \
|
||||
get_attachment_property_value(property_value)
|
||||
if not prop_value_name:
|
||||
continue
|
||||
if not property_value['type'].endswith('PropertyValue'):
|
||||
continue
|
||||
property_value[prop_value_name] = \
|
||||
property_value[prop_value_name].strip()
|
||||
if len(property_value[prop_value_name]) != 76:
|
||||
continue
|
||||
if property_value[prop_value_name].upper() != \
|
||||
property_value[prop_value_name]:
|
||||
continue
|
||||
if '"' in property_value[prop_value_name]:
|
||||
continue
|
||||
if ' ' in property_value[prop_value_name]:
|
||||
continue
|
||||
if ',' in property_value[prop_value_name]:
|
||||
continue
|
||||
if '.' in property_value[prop_value_name]:
|
||||
continue
|
||||
return remove_html(property_value[prop_value_name])
|
||||
return ''
|
||||
|
||||
|
||||
def _is_valid_lxmf_address(lxmf_address: str) -> bool:
|
||||
"""Is the given LXMF address valid?
|
||||
"""
|
||||
if len(lxmf_address) != 32:
|
||||
return False
|
||||
if lxmf_address.lower() != lxmf_address:
|
||||
return False
|
||||
if not set(lxmf_address).issubset(VALID_LXMF_CHARS):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def set_lxmf_address(actor_json: {}, lxmf_address: str) -> None:
|
||||
"""Sets an lxmf address for the given actor
|
||||
"""
|
||||
lxmf_address = lxmf_address.strip()
|
||||
is_lxmfaddress = _is_valid_lxmf_address(lxmf_address)
|
||||
|
||||
if not actor_json.get('attachment'):
|
||||
actor_json['attachment']: list[dict] = []
|
||||
|
||||
# remove any existing value
|
||||
property_found = None
|
||||
for property_value in actor_json['attachment']:
|
||||
if not isinstance(property_value, dict):
|
||||
print("WARN: actor attachment is not dict: " + str(property_value))
|
||||
continue
|
||||
name_value = None
|
||||
if property_value.get('name'):
|
||||
name_value = property_value['name']
|
||||
elif property_value.get('schema:name'):
|
||||
name_value = property_value['schema:name']
|
||||
if not name_value:
|
||||
continue
|
||||
if not property_value.get('type'):
|
||||
continue
|
||||
if not name_value.lower().startswith('lxmf'):
|
||||
continue
|
||||
property_found = property_value
|
||||
break
|
||||
if property_found:
|
||||
actor_json['attachment'].remove(property_found)
|
||||
if not is_lxmfaddress:
|
||||
return
|
||||
|
||||
for property_value in actor_json['attachment']:
|
||||
if not isinstance(property_value, dict):
|
||||
print("WARN: actor attachment is not dict: " + str(property_value))
|
||||
continue
|
||||
name_value = None
|
||||
if property_value.get('name'):
|
||||
name_value = property_value['name']
|
||||
elif property_value.get('schema:name'):
|
||||
name_value = property_value['schema:name']
|
||||
if not name_value:
|
||||
continue
|
||||
if not property_value.get('type'):
|
||||
continue
|
||||
if not name_value.lower().startswith('lxmf'):
|
||||
continue
|
||||
if not property_value['type'].endswith('PropertyValue'):
|
||||
continue
|
||||
prop_value_name, _ = \
|
||||
get_attachment_property_value(property_value)
|
||||
if not prop_value_name:
|
||||
continue
|
||||
property_value[prop_value_name] = lxmf_address
|
||||
return
|
||||
|
||||
new_lxmf_address = {
|
||||
"name": "LXMF",
|
||||
"type": "PropertyValue",
|
||||
"value": lxmf_address
|
||||
}
|
||||
actor_json['attachment'].append(new_lxmf_address)
|
||||
|
|
@ -155,6 +155,7 @@ def html_person_options(default_timeline: str,
|
|||
ssb_address: str,
|
||||
blog_address: str,
|
||||
tox_address: str,
|
||||
lxmf_address: str,
|
||||
briar_address: str,
|
||||
cwtch_address: str,
|
||||
enigma_pub_key: str,
|
||||
|
|
@ -496,6 +497,9 @@ def html_person_options(default_timeline: str,
|
|||
if tox_address:
|
||||
options_str += \
|
||||
' <p class="imText">Tox: ' + remove_html(tox_address) + '</p>\n'
|
||||
if lxmf_address:
|
||||
options_str += \
|
||||
' <p class="imText">LXMF: ' + remove_html(lxmf_address) + '</p>\n'
|
||||
if briar_address:
|
||||
if briar_address.startswith('briar://'):
|
||||
options_str += \
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ from pgp import get_pgp_fingerprint
|
|||
from pgp import get_pgp_pub_key
|
||||
from enigma import get_enigma_pub_key
|
||||
from tox import get_tox_address
|
||||
from lxmf import get_lxmf_address
|
||||
from briar import get_briar_address
|
||||
from cwtch import get_cwtch_address
|
||||
from filters import is_filtered
|
||||
|
|
@ -1294,6 +1295,7 @@ def html_profile(signing_priv_key_pem: str,
|
|||
matrix_address = get_matrix_address(profile_json)
|
||||
ssb_address = get_ssb_address(profile_json)
|
||||
tox_address = get_tox_address(profile_json)
|
||||
lxmf_address = get_lxmf_address(profile_json)
|
||||
briar_address = get_briar_address(profile_json)
|
||||
cwtch_address = get_cwtch_address(profile_json)
|
||||
verified_site_checkmark = '✔'
|
||||
|
|
@ -1301,9 +1303,9 @@ def html_profile(signing_priv_key_pem: str,
|
|||
if donate_url or website_url or repo_url or pronouns or discord or \
|
||||
art_site_url or music_site_url or youtube or peertube or pixelfed or \
|
||||
xmpp_address or matrix_address or \
|
||||
ssb_address or tox_address or briar_address or cwtch_address or \
|
||||
pgp_pub_key or enigma_pub_key or pgp_fingerprint or email_address or \
|
||||
deltachat_invite:
|
||||
ssb_address or tox_address or lxmf_address or briar_address or \
|
||||
cwtch_address or pgp_pub_key or enigma_pub_key or pgp_fingerprint or \
|
||||
email_address or deltachat_invite:
|
||||
donate_section = '<div class="container">\n'
|
||||
donate_section += ' <center>\n'
|
||||
if donate_url and not is_system_account(nickname):
|
||||
|
|
@ -1411,6 +1413,10 @@ def html_profile(signing_priv_key_pem: str,
|
|||
donate_section += \
|
||||
'<p>Tox: <label class="toxaddr">' + \
|
||||
tox_address + '</label></p>\n'
|
||||
if lxmf_address:
|
||||
donate_section += \
|
||||
'<p>LXMF: <label class="toxaddr">' + \
|
||||
lxmf_address + '</label></p>\n'
|
||||
if briar_address:
|
||||
if briar_address.startswith('briar://'):
|
||||
donate_section += \
|
||||
|
|
@ -3038,6 +3044,7 @@ def _html_edit_profile_contact_info(email_address: str,
|
|||
matrix_address: str,
|
||||
ssb_address: str,
|
||||
tox_address: str,
|
||||
lxmf_address: str,
|
||||
briar_address: str,
|
||||
cwtch_address: str,
|
||||
translate: {},
|
||||
|
|
@ -3060,6 +3067,7 @@ def _html_edit_profile_contact_info(email_address: str,
|
|||
'matrixAddress', matrix_address)
|
||||
edit_profile_form += edit_text_field('SSB', 'ssbAddress', ssb_address)
|
||||
edit_profile_form += edit_text_field('Tox', 'toxAddress', tox_address)
|
||||
edit_profile_form += edit_text_field('LXMF', 'lxmfAddress', lxmf_address)
|
||||
edit_profile_form += edit_text_field('Briar', 'briarAddress',
|
||||
briar_address)
|
||||
edit_profile_form += edit_text_field('Cwtch', 'cwtchAddress',
|
||||
|
|
@ -3546,7 +3554,8 @@ def html_edit_profile(server, translate: {},
|
|||
email_address = deltachat_invite = featured_hashtags = ''
|
||||
pgp_pub_key = enigma_pub_key = ''
|
||||
pgp_fingerprint = pronouns = peertube = youtube = pixelfed = ''
|
||||
ssb_address = blog_address = matrix_address = tox_address = ''
|
||||
ssb_address = blog_address = matrix_address = ''
|
||||
tox_address = lxmf_address = ''
|
||||
cwtch_address = briar_address = xmpp_address = ''
|
||||
discord = music_site_url = art_site_url = ''
|
||||
manually_approves_followers = reject_spam_actors = ''
|
||||
|
|
@ -3575,6 +3584,7 @@ def html_edit_profile(server, translate: {},
|
|||
ssb_address = get_ssb_address(actor_json)
|
||||
blog_address = get_blog_address(actor_json)
|
||||
tox_address = get_tox_address(actor_json)
|
||||
lxmf_address = get_lxmf_address(actor_json)
|
||||
briar_address = get_briar_address(actor_json)
|
||||
cwtch_address = get_cwtch_address(actor_json)
|
||||
email_address = get_email_address(actor_json)
|
||||
|
|
@ -3802,6 +3812,7 @@ def html_edit_profile(server, translate: {},
|
|||
deltachat_invite,
|
||||
xmpp_address, matrix_address,
|
||||
ssb_address, tox_address,
|
||||
lxmf_address,
|
||||
briar_address,
|
||||
cwtch_address, translate,
|
||||
youtube, peertube, pixelfed,
|
||||
|
|
|
|||
Loading…
Reference in New Issue