Add support for DeltaChat within profile

main
Bob Mottram 2025-02-09 13:38:45 +00:00
parent 34ab976ac1
commit ee42177589
34 changed files with 201 additions and 32 deletions

View File

@ -80,6 +80,8 @@ from pgp import set_pgp_pub_key
from pgp import get_pgp_pub_key
from pgp import get_email_address
from pgp import set_email_address
from pgp import get_deltachat_invite
from pgp import set_deltachat_invite
from pgp import set_pgp_fingerprint
from pgp import get_pgp_fingerprint
from pronouns import get_pronouns
@ -2221,6 +2223,23 @@ def _profile_post_email_address(actor_json: {}, fields: {},
return actor_changed
def _profile_post_deltachat_invite(actor_json: {}, fields: {},
actor_changed: bool,
translate: {}) -> bool:
""" HTTP POST change deltachat invite link
"""
current_deltachat_invite = get_deltachat_invite(actor_json, translate)
if fields.get('deltachat'):
if fields['deltachat'] != current_deltachat_invite:
set_deltachat_invite(actor_json, fields['deltachat'], translate)
actor_changed = True
else:
if current_deltachat_invite:
set_deltachat_invite(actor_json, '', translate)
actor_changed = True
return actor_changed
def _profile_post_memorial_accounts(base_dir: str, domain: str,
person_cache: {}, fields: {}) -> None:
""" HTTP POST change memorial accounts
@ -3052,6 +3071,10 @@ def profile_edit(self, calling_domain: str, cookie: str,
_profile_post_email_address(actor_json, fields,
actor_changed)
actor_changed = \
_profile_post_deltachat_invite(actor_json, fields,
actor_changed, translate)
actor_changed = \
_profile_post_xmpp_address(actor_json, fields,
actor_changed)

View File

@ -64,6 +64,7 @@ from briar import get_briar_address
from cwtch import get_cwtch_address
from pgp import get_pgp_fingerprint
from pgp import get_email_address
from pgp import get_deltachat_invite
from pgp import get_pgp_pub_key
from enigma import get_enigma_pub_key
from git import get_repo_url
@ -650,6 +651,7 @@ def show_person_options(self, calling_domain: str, path: str,
cwtch_address = None
ssb_address = None
email_address = None
deltachat_invite = None
locked_account = False
also_known_as = None
moved_to = ''
@ -685,6 +687,8 @@ def show_person_options(self, calling_domain: str, path: str,
briar_address = get_briar_address(actor_json)
cwtch_address = get_cwtch_address(actor_json)
email_address = get_email_address(actor_json)
deltachat_invite = \
get_deltachat_invite(actor_json, self.server.translate)
enigma_pub_key = get_enigma_pub_key(actor_json)
pgp_pub_key = get_pgp_pub_key(actor_json)
pgp_fingerprint = get_pgp_fingerprint(actor_json)
@ -737,7 +741,7 @@ def show_person_options(self, calling_domain: str, path: str,
cwtch_address,
enigma_pub_key,
pgp_pub_key, pgp_fingerprint,
email_address,
email_address, deltachat_invite,
self.server.dormant_months,
back_to_path,
locked_account,

95
pgp.py
View File

@ -83,6 +83,48 @@ def get_email_address(actor_json: {}) -> str:
return ''
def _get_deltachat_strings() -> []:
return ['deltachat', 'delta chat', 'chatmail']
def get_deltachat_invite(actor_json: {}, translate: {}) -> str:
"""Returns the deltachat invite link for the given actor
"""
if not actor_json.get('attachment'):
return ''
match_strings = _get_deltachat_strings()
match_strings.append(translate['DeltaChat'].lower())
for property_value in actor_json['attachment']:
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
found = False
for possible_str in match_strings:
if possible_str in name_value.lower():
found = True
break
if not found:
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
value_str = remove_html(property_value[prop_value_name])
if 'https://' not in value_str and \
'http://' not in value_str:
continue
return value_str
return ''
def get_pgp_pub_key(actor_json: {}) -> str:
"""Returns PGP public key for the given actor
"""
@ -207,6 +249,51 @@ def set_email_address(actor_json: {}, email_address: str) -> None:
actor_json['attachment'].append(new_email_address)
def set_deltachat_invite(actor_json: {}, invite_link: str,
translate: {}) -> None:
"""Sets the deltachat invite link for the given actor
"""
invite_link = invite_link.strip()
not_url = False
if '.' not in invite_link:
not_url = True
if '://' not in invite_link:
not_url = True
if ' ' in invite_link:
not_url = True
if '<' in invite_link:
not_url = True
if not actor_json.get('attachment'):
actor_json['attachment']: list[dict] = []
match_strings = _get_deltachat_strings()
match_strings.append(translate['DeltaChat'].lower())
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
continue
if not property_value.get('type'):
continue
if property_value['name'].lower() not in match_strings:
continue
property_found = property_value
break
if property_found:
actor_json['attachment'].remove(property_found)
if not_url:
return
new_entry = {
"name": 'DeltaChat',
"type": "PropertyValue",
"value": invite_link
}
actor_json['attachment'].append(new_entry)
def set_pgp_pub_key(actor_json: {}, pgp_pub_key: str) -> None:
"""Sets a PGP public key for the given actor
"""
@ -791,6 +878,9 @@ def actor_to_vcard(actor: {}, domain: str, translate: {}) -> str:
website = get_website(actor, translate)
if website:
vcard_str += 'URL:' + website + '\n'
deltachat_invite = get_deltachat_invite(actor, translate)
if deltachat_invite:
vcard_str += 'IMPP:deltachat:' + deltachat_invite + '\n'
xmpp_address = get_xmpp_address(actor)
if xmpp_address:
vcard_str += 'IMPP:xmpp:' + xmpp_address + '\n'
@ -902,6 +992,11 @@ def actor_to_vcard_xml(actor: {}, domain: str, translate: {}) -> str:
vcard_str += ' <url>' + \
'<parameters><type><text>peertube</text></type></parameters>' + \
'<uri>' + peertube + '</uri></url>\n'
deltachat_invite = get_deltachat_invite(actor, translate)
if deltachat_invite:
vcard_str += ' <impp>' + \
'<parameters><type><text>deltachat</text></type></parameters>' + \
'<text>' + deltachat_invite + '</text></impp>\n'
xmpp_address = get_xmpp_address(actor)
if xmpp_address:
vcard_str += ' <impp>' + \

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "الدفع مقابل الخدمة أو التسجيل فقط",
"Russian State Funded Media": "وسائل الإعلام الممولة من الدولة الروسية",
"Satire": "هجاء",
"UK Right Wing Think Tank": "مركز أبحاث يميني متطرف في المملكة المتحدة"
"UK Right Wing Think Tank": "مركز أبحاث يميني متطرف في المملكة المتحدة",
"DeltaChat": "دعوة إلى DeltaChat"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "পেওয়ালড বা শুধুমাত্র নিবন্ধন",
"Russian State Funded Media": "রাশিয়ান রাষ্ট্র অর্থায়ন মিডিয়া",
"Satire": "ব্যঙ্গ",
"UK Right Wing Think Tank": "ইউকে রাইট উইং থিঙ্ক ট্যাঙ্ক"
"UK Right Wing Think Tank": "ইউকে রাইট উইং থিঙ্ক ট্যাঙ্ক",
"DeltaChat": "ডেল্টাচ্যাট আমন্ত্রণ"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Paywall o només registre",
"Russian State Funded Media": "Mitjans de comunicació finançats per l'estat rus",
"Satire": "Sàtira",
"UK Right Wing Think Tank": "Think Tank de la dreta del Regne Unit"
"UK Right Wing Think Tank": "Think Tank de la dreta del Regne Unit",
"DeltaChat": "Invitació de DeltaChat"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Paywalled neu Gofrestru yn Unig",
"Russian State Funded Media": "Cyfryngau a Ariennir gan Wladwriaeth Rwseg",
"Satire": "Dychan",
"UK Right Wing Think Tank": "Melin Drafod Adain Dde y DU"
"UK Right Wing Think Tank": "Melin Drafod Adain Dde y DU",
"DeltaChat": "Gwahoddiad DeltaChat"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Hinter einer Paywall oder nur mit Registrierung",
"Russian State Funded Media": "Russische staatlich finanzierte Medien",
"Satire": "Satire",
"UK Right Wing Think Tank": "Britischer Thinktank mit rechter Front"
"UK Right Wing Think Tank": "Britischer Thinktank mit rechter Front",
"DeltaChat": "DeltaChat-Einladung"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Paywalled ή Μόνο εγγραφή",
"Russian State Funded Media": "Ρωσικά κρατικά χρηματοδοτούμενα ΜΜΕ",
"Satire": "Σάτυρα",
"UK Right Wing Think Tank": "Δεξαμενή Σκέψης Δεξιάς στο Ηνωμένο Βασίλειο"
"UK Right Wing Think Tank": "Δεξαμενή Σκέψης Δεξιάς στο Ηνωμένο Βασίλειο",
"DeltaChat": "Πρόσκληση DeltaChat"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Paywalled or Registration Only",
"Russian State Funded Media": "Russian State Funded Media",
"Satire": "Satire",
"UK Right Wing Think Tank": "UK Right Wing Think Tank"
"UK Right Wing Think Tank": "UK Right Wing Think Tank",
"DeltaChat": "DeltaChat invite"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Pago por muro o solo registro",
"Russian State Funded Media": "Medios de comunicación financiados por el Estado ruso",
"Satire": "Sátira",
"UK Right Wing Think Tank": "Centro de estudios de derecha del Reino Unido"
"UK Right Wing Think Tank": "Centro de estudios de derecha del Reino Unido",
"DeltaChat": "Invitación a DeltaChat"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Paywalled یا فقط ثبت نام",
"Russian State Funded Media": "رسانه های دولتی روسیه",
"Satire": "طنز",
"UK Right Wing Think Tank": "اتاق فکر جناح راست انگلستان"
"UK Right Wing Think Tank": "اتاق فکر جناح راست انگلستان",
"DeltaChat": "دعوت از دلتا چت"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Maksumuuri tai vain rekisteröinti",
"Russian State Funded Media": "Venäjän valtion rahoittama media",
"Satire": "Satiiri",
"UK Right Wing Think Tank": "Ison-Britannian oikeanpuoleinen ajatushautomo"
"UK Right Wing Think Tank": "Ison-Britannian oikeanpuoleinen ajatushautomo",
"DeltaChat": "DeltaChat-kutsu"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Paywall ou inscription uniquement",
"Russian State Funded Media": "Médias financés par l'État russe",
"Satire": "Satire",
"UK Right Wing Think Tank": "Groupe de réflexion de droite britannique"
"UK Right Wing Think Tank": "Groupe de réflexion de droite britannique",
"DeltaChat": "Invitation DeltaChat"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Paywalled nó Clárú Amháin",
"Russian State Funded Media": "Meáin Mhaoinithe Stáit na Rúise",
"Satire": "Aoir",
"UK Right Wing Think Tank": "Umar Smaointeoireachta Sciathán Deis na Ríochta Aontaithe"
"UK Right Wing Think Tank": "Umar Smaointeoireachta Sciathán Deis na Ríochta Aontaithe",
"DeltaChat": "Cuireadh DeltaChat"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Paywall או הרשמה בלבד",
"Russian State Funded Media": "מדיה במימון המדינה הרוסית",
"Satire": "סָאטִירָה",
"UK Right Wing Think Tank": "טנק חשיבה ימני בבריטניה"
"UK Right Wing Think Tank": "טנק חשיבה ימני בבריטניה",
"DeltaChat": "הזמנת DeltaChat"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "पेवॉल्ड या केवल पंजीकरण",
"Russian State Funded Media": "रूसी राज्य वित्तपोषित मीडिया",
"Satire": "हास्य व्यंग्य",
"UK Right Wing Think Tank": "यू.के. दक्षिणपंथी थिंक टैंक"
"UK Right Wing Think Tank": "यू.के. दक्षिणपंथी थिंक टैंक",
"DeltaChat": "डेल्टाचैट आमंत्रण"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Con paywall o solo registrazione",
"Russian State Funded Media": "Media finanziati dallo Stato russo",
"Satire": "Satira",
"UK Right Wing Think Tank": "Think Tank di destra nel Regno Unito"
"UK Right Wing Think Tank": "Think Tank di destra nel Regno Unito",
"DeltaChat": "Invito DeltaChat"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "有料または登録のみ",
"Russian State Funded Media": "ロシアの国営メディア",
"Satire": "風刺",
"UK Right Wing Think Tank": "英国右派シンクタンク"
"UK Right Wing Think Tank": "英国右派シンクタンク",
"DeltaChat": "DeltaChat 招待"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "유료 또는 등록만 가능",
"Russian State Funded Media": "러시아 국가가 자금을 지원하는 미디어",
"Satire": "풍자",
"UK Right Wing Think Tank": "영국 우익 싱크탱크"
"UK Right Wing Think Tank": "영국 우익 싱크탱크",
"DeltaChat": "DeltaChat 초대"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Paywalled an Tenê Tomarkirin",
"Russian State Funded Media": "Medyaya Fînansekirî ya Dewleta Rûsyayê",
"Satire": "Satire",
"UK Right Wing Think Tank": "Tanka Fikirê ya Rastê ya Brîtanyayê"
"UK Right Wing Think Tank": "Tanka Fikirê ya Rastê ya Brîtanyayê",
"DeltaChat": "vexwendina DeltaChat"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Betaalmuur of alleen registratie",
"Russian State Funded Media": "Russische staatsgefinancierde media",
"Satire": "Satire",
"UK Right Wing Think Tank": "Britse rechtse denktank"
"UK Right Wing Think Tank": "Britse rechtse denktank",
"DeltaChat": "DeltaChat-uitnodiging"
}

View File

@ -715,5 +715,6 @@
"Paywalled or Registration Only": "Paywalled or Registration Only",
"Russian State Funded Media": "Russian State Funded Media",
"Satire": "Satire",
"UK Right Wing Think Tank": "UK Right Wing Think Tank"
"UK Right Wing Think Tank": "UK Right Wing Think Tank",
"DeltaChat": "DeltaChat invite"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Tylko płatne lub rejestracja",
"Russian State Funded Media": "Rosyjskie media finansowane przez państwo",
"Satire": "Satyra",
"UK Right Wing Think Tank": "Brytyjski prawicowy think tank"
"UK Right Wing Think Tank": "Brytyjski prawicowy think tank",
"DeltaChat": "Zaproszenie do DeltaChat"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Paywalled ou apenas registo",
"Russian State Funded Media": "Comunicação social financiada pelo Estado russo",
"Satire": "Sátira",
"UK Right Wing Think Tank": "Think Tank de direita do Reino Unido"
"UK Right Wing Think Tank": "Think Tank de direita do Reino Unido",
"DeltaChat": "Convite DeltaChat"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Платный или только регистрация",
"Russian State Funded Media": "Российские государственные СМИ",
"Satire": "Сатира",
"UK Right Wing Think Tank": "Британский правый аналитический центр"
"UK Right Wing Think Tank": "Британский правый аналитический центр",
"DeltaChat": "Приглашение DeltaChat"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Inalipwa au Usajili Pekee",
"Russian State Funded Media": "Vyombo vya Habari vinavyofadhiliwa na Serikali ya Urusi",
"Satire": "Satire",
"UK Right Wing Think Tank": "Uingereza Right Wing Think Tank"
"UK Right Wing Think Tank": "Uingereza Right Wing Think Tank",
"DeltaChat": "mwaliko wa DeltaChat"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Ödeme Duvarı veya Sadece Kayıt",
"Russian State Funded Media": "Rusya Devleti Tarafından Finanse Edilen Medya",
"Satire": "Hiciv",
"UK Right Wing Think Tank": "İngiltere Sağ Kanat Düşünce Kuruluşu"
"UK Right Wing Think Tank": "İngiltere Sağ Kanat Düşünce Kuruluşu",
"DeltaChat": "DeltaChat daveti"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Платний або лише реєстрація",
"Russian State Funded Media": "Російські державні ЗМІ",
"Satire": "Сатира",
"UK Right Wing Think Tank": "Британський правий мозковий центр"
"UK Right Wing Think Tank": "Британський правий мозковий центр",
"DeltaChat": "Запрошення DeltaChat"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "Paywalled אָדער רעגיסטראַציע בלויז",
"Russian State Funded Media": "רוסיש שטאַט פאַנדאַד מידיאַ",
"Satire": "סאַטירע",
"UK Right Wing Think Tank": "וק רעכט פליגל טראַכטן טאַנק"
"UK Right Wing Think Tank": "וק רעכט פליגל טראַכטן טאַנק",
"DeltaChat": "דעלטאַטשאַט פאַרבעטן"
}

View File

@ -719,5 +719,6 @@
"Paywalled or Registration Only": "需付费或注册",
"Russian State Funded Media": "俄罗斯国家资助的媒体",
"Satire": "讽刺",
"UK Right Wing Think Tank": "英国右翼智库"
"UK Right Wing Think Tank": "英国右翼智库",
"DeltaChat": "DeltaChat 邀请"
}

View File

@ -12,7 +12,6 @@ from flags import is_editor
from flags import is_artist
from utils import get_person_icon
from utils import data_dir
from utils import get_url_from_post
from utils import remove_html
from utils import is_account_dir
from utils import get_full_domain

View File

@ -159,6 +159,7 @@ def html_person_options(default_timeline: str,
pgp_pub_key: str,
pgp_fingerprint: str,
email_address: str,
deltachat_invite: str,
dormant_months: int,
back_to_path: str,
locked_account: bool,
@ -404,6 +405,11 @@ def html_person_options(default_timeline: str,
' <p class="imText">' + translate['Email'] + \
': <a href="mailto:' + \
email_address + '">' + remove_html(email_address) + '</a></p>\n'
if deltachat_invite:
options_str += \
' <p class="imText">' + translate['DeltaChat'] + \
': <a href="' + deltachat_invite + '">' + \
remove_html(deltachat_invite) + '</a></p>\n'
if web_address:
web_str = remove_html(web_address)
if '://' not in web_str:

View File

@ -79,6 +79,7 @@ from xmpp import get_xmpp_address
from matrix import get_matrix_address
from ssb import get_ssb_address
from pgp import get_email_address
from pgp import get_deltachat_invite
from pgp import get_pgp_fingerprint
from pgp import get_pgp_pub_key
from enigma import get_enigma_pub_key
@ -1151,6 +1152,7 @@ def html_profile(signing_priv_key_pem: str,
pgp_pub_key = get_pgp_pub_key(profile_json)
pgp_fingerprint = get_pgp_fingerprint(profile_json)
email_address = get_email_address(profile_json)
deltachat_invite = get_deltachat_invite(profile_json, translate)
pronouns = get_pronouns(profile_json)
pixelfed = get_pixelfed(profile_json)
discord = get_discord(profile_json)
@ -1170,7 +1172,8 @@ def html_profile(signing_priv_key_pem: str,
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:
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):
@ -1213,6 +1216,11 @@ def html_profile(signing_priv_key_pem: str,
'<p>' + translate['Email'] + ': <a href="mailto:' + \
email_address + '" tabindex="1">' + \
email_address + '</a></p>\n'
if deltachat_invite:
donate_section += \
'<p>' + translate['DeltaChat'] + ': <a href="' + \
deltachat_invite + '" tabindex="1">' + \
deltachat_invite + '</a></p>\n'
if blog_address:
if site_is_verified(session, base_dir, http_prefix,
nickname, domain,
@ -2863,6 +2871,7 @@ def _html_edit_profile_background(news_instance: bool, translate: {}) -> str:
def _html_edit_profile_contact_info(email_address: str,
deltachat_invite: str,
xmpp_address: str,
matrix_address: str,
ssb_address: str,
@ -2881,6 +2890,8 @@ def _html_edit_profile_contact_info(email_address: str,
edit_profile_form = begin_edit_section(translate['Contact Details'])
edit_profile_form += edit_text_field(translate['Email'],
'email', email_address)
edit_profile_form += edit_text_field(translate['DeltaChat'],
'deltachat', deltachat_invite)
edit_profile_form += edit_text_field(translate['XMPP'],
'xmppAddress', xmpp_address)
edit_profile_form += edit_text_field(translate['Matrix'],
@ -3362,7 +3373,8 @@ def html_edit_profile(server, translate: {},
hide_like_button = hide_reaction_button = media_instance_str = ''
blogs_instance_str = news_instance_str = moved_to = twitter_str = ''
bio_str = donate_url = website_url = gemini_link = ''
email_address = featured_hashtags = pgp_pub_key = enigma_pub_key = ''
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 = ''
cwtch_address = briar_address = xmpp_address = ''
@ -3392,6 +3404,7 @@ def html_edit_profile(server, translate: {},
briar_address = get_briar_address(actor_json)
cwtch_address = get_cwtch_address(actor_json)
email_address = get_email_address(actor_json)
deltachat_invite = get_deltachat_invite(actor_json, translate)
enigma_pub_key = get_enigma_pub_key(actor_json)
pgp_pub_key = get_pgp_pub_key(actor_json)
pgp_fingerprint = get_pgp_fingerprint(actor_json)
@ -3606,6 +3619,7 @@ def html_edit_profile(server, translate: {},
# Contact information
edit_profile_form += \
_html_edit_profile_contact_info(email_address,
deltachat_invite,
xmpp_address, matrix_address,
ssb_address, tox_address,
briar_address,