Pronouns as a separate field within actor

merge-requests/30/head
Bob Mottram 2024-08-12 11:34:50 +01:00
parent 7e03a33d33
commit f69319f760
34 changed files with 209 additions and 33 deletions

View File

@ -79,6 +79,8 @@ from pgp import get_email_address
from pgp import set_email_address
from pgp import set_pgp_fingerprint
from pgp import get_pgp_fingerprint
from pronouns import get_pronouns
from pronouns import set_pronouns
from xmpp import get_xmpp_address
from xmpp import set_xmpp_address
from matrix import get_matrix_address
@ -1980,6 +1982,23 @@ def _profile_post_xmpp_address(actor_json: {}, fields: {},
return actor_changed
def _profile_post_pronouns(actor_json: {}, fields: {},
actor_changed: bool) -> bool:
""" HTTP POST change pronouns
"""
current_pronouns = get_pronouns(actor_json)
if fields.get('setPronouns'):
if fields['setPronouns'] != current_pronouns:
set_pronouns(actor_json,
fields['setPronouns'])
actor_changed = True
else:
if current_pronouns:
set_pronouns(actor_json, '')
actor_changed = True
return actor_changed
def _profile_post_email_address(actor_json: {}, fields: {},
actor_changed: bool) -> bool:
""" HTTP POST change email address
@ -2830,6 +2849,10 @@ def profile_edit(self, calling_domain: str, cookie: str,
_profile_post_xmpp_address(actor_json, fields,
actor_changed)
actor_changed = \
_profile_post_pronouns(actor_json, fields,
actor_changed)
actor_changed = \
_profile_post_matrix_address(actor_json, fields,
actor_changed)

View File

@ -44,6 +44,7 @@ from cache import get_person_from_cache
from donate import get_donation_url
from donate import get_website
from donate import get_gemini_link
from pronouns import get_pronouns
from xmpp import get_xmpp_address
from matrix import get_matrix_address
from ssb import get_ssb_address
@ -654,6 +655,7 @@ def show_person_options(self, calling_domain: str, path: str,
enigma_pub_key = None
pgp_pub_key = None
pgp_fingerprint = None
pronouns = None
xmpp_address = None
matrix_address = None
blog_address = None
@ -682,6 +684,7 @@ def show_person_options(self, calling_domain: str, path: str,
donate_url = get_donation_url(actor_json)
website_url = get_website(actor_json, self.server.translate)
gemini_link = get_gemini_link(actor_json)
pronouns = get_pronouns(actor_json)
xmpp_address = get_xmpp_address(actor_json)
matrix_address = get_matrix_address(actor_json)
ssb_address = get_ssb_address(actor_json)
@ -735,7 +738,7 @@ def show_person_options(self, calling_domain: str, path: str,
options_profile_url,
options_link,
page_number, donate_url, website_url,
gemini_link,
gemini_link, pronouns,
xmpp_address, matrix_address,
ssb_address, blog_address,
tox_address, briar_address,

7
pgp.py
View File

@ -25,6 +25,7 @@ from webfinger import webfinger_handle
from posts import get_person_box
from auth import create_basic_auth_header
from session import post_json
from pronouns import get_pronouns
from xmpp import get_xmpp_address
from matrix import get_matrix_address
from briar import get_briar_address
@ -736,6 +737,9 @@ def actor_to_vcard(actor: {}, domain: str) -> str:
vcard_str += 'EMAIL;TYPE=internet:' + email_address + '\n'
vcard_str += 'IMPP:fediverse:' + \
actor['preferredUsername'] + '@' + domain + '\n'
pronouns = get_pronouns(actor)
if pronouns:
vcard_str += 'PRONOUNS:' + pronouns + '\n'
xmpp_address = get_xmpp_address(actor)
if xmpp_address:
vcard_str += 'IMPP:xmpp:' + xmpp_address + '\n'
@ -784,6 +788,9 @@ def actor_to_vcard_xml(actor: {}, domain: str) -> str:
'<parameters><type><text>fediverse</text></type></parameters>' + \
'<text>' + actor['preferredUsername'] + '@' + domain + \
'</text></impp>\n'
pronouns = get_pronouns(actor)
if pronouns:
vcard_str += ' <pronouns><text>' + pronouns + '</text></pronouns>\n'
xmpp_address = get_xmpp_address(actor)
if xmpp_address:
vcard_str += ' <impp>' + \

98
pronouns.py 100644
View File

@ -0,0 +1,98 @@
__filename__ = "pronouns.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.5.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
def get_pronouns(actor_json: {}) -> str:
"""Returns pronouns 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']:
name_value = None
if property_value.get('name'):
name_value = property_value['name'].lower()
elif property_value.get('schema:name'):
name_value = property_value['schema:name'].lower()
if not name_value:
continue
if 'pronouns' not in name_value:
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
pronouns_text = property_value[prop_value_name]
return remove_html(pronouns_text)
return ''
def set_pronouns(actor_json: {}, pronouns: str) -> None:
"""Sets pronouns for the given actor
"""
if not actor_json.get('attachment'):
actor_json['attachment'] = []
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
name_value = None
if property_value.get('name'):
name_value = property_value['name'].lower()
elif property_value.get('schema:name'):
name_value = property_value['schema:name'].lower()
if not name_value:
continue
if not property_value.get('type'):
continue
if 'pronouns' not in name_value:
continue
property_found = property_value
break
if property_found:
actor_json['attachment'].remove(property_found)
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
if not property_value.get('type'):
continue
name_value = name_value.lower()
if 'pronouns' not in name_value:
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] = pronouns
return
new_pronouns = {
"type": "PropertyValue",
"name": "Pronouns",
"value": pronouns
}
actor_json['attachment'].append(new_pronouns)

View File

@ -696,5 +696,6 @@
"PGP Public Key": "مفتاح PGP العام",
"Don't show already seen posts": "لا تظهر المشاركات التي تمت مشاهدتها بالفعل",
"Watermark image": "صورة العلامة المائية",
"Apply a watermark to uploaded images": "إضافة علامة مائية على الصور التي تم تحميلها"
"Apply a watermark to uploaded images": "إضافة علامة مائية على الصور التي تم تحميلها",
"Pronouns": "الضمائر"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "PGP পাবলিক কী",
"Don't show already seen posts": "ইতিমধ্যে দেখা পোস্ট দেখাবেন না",
"Watermark image": "ওয়াটারমার্ক ইমেজ",
"Apply a watermark to uploaded images": "আপলোড করা ছবিগুলিতে একটি জলছাপ প্রয়োগ করুন"
"Apply a watermark to uploaded images": "আপলোড করা ছবিগুলিতে একটি জলছাপ প্রয়োগ করুন",
"Pronouns": "সর্বনাম"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "Clau pública PGP",
"Don't show already seen posts": "No mostris les publicacions ja vistes",
"Watermark image": "Imatge de filigrana",
"Apply a watermark to uploaded images": "Apliqueu una marca d'aigua a les imatges penjades"
"Apply a watermark to uploaded images": "Apliqueu una marca d'aigua a les imatges penjades",
"Pronouns": "Els pronoms"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "Allwedd Gyhoeddus PGP",
"Don't show already seen posts": "Peidiwch â dangos postiadau a welwyd eisoes",
"Watermark image": "Delwedd dyfrnod",
"Apply a watermark to uploaded images": "Cymhwyso dyfrnod i ddelweddau sydd wedi'u llwytho i fyny"
"Apply a watermark to uploaded images": "Cymhwyso dyfrnod i ddelweddau sydd wedi'u llwytho i fyny",
"Pronouns": "Rhagenwau"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "Öffentlicher PGP-Schlüssel",
"Don't show already seen posts": "Bereits gesehene Beiträge nicht anzeigen",
"Watermark image": "Wasserzeichenbild",
"Apply a watermark to uploaded images": "Hochgeladenen Bildern ein Wasserzeichen hinzufügen"
"Apply a watermark to uploaded images": "Hochgeladenen Bildern ein Wasserzeichen hinzufügen",
"Pronouns": "Pronomen"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "Δημόσιο κλειδί PGP",
"Don't show already seen posts": "Να μην εμφανίζονται οι αναρτήσεις που έχετε ήδη δει",
"Watermark image": "Εικόνα υδατογραφήματος",
"Apply a watermark to uploaded images": "Εφαρμόστε ένα υδατογράφημα στις μεταφορτωμένες εικόνες"
"Apply a watermark to uploaded images": "Εφαρμόστε ένα υδατογράφημα στις μεταφορτωμένες εικόνες",
"Pronouns": "Αντωνυμίες"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "PGP Public Key",
"Don't show already seen posts": "Don't show already seen posts",
"Watermark image": "Watermark image",
"Apply a watermark to uploaded images": "Apply a watermark to uploaded images"
"Apply a watermark to uploaded images": "Apply a watermark to uploaded images",
"Pronouns": "Pronouns"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "Clave pública PGP",
"Don't show already seen posts": "No mostrar publicaciones ya vistas",
"Watermark image": "Imagen de marca de agua",
"Apply a watermark to uploaded images": "Aplicar una marca de agua a las imágenes cargadas"
"Apply a watermark to uploaded images": "Aplicar una marca de agua a las imágenes cargadas",
"Pronouns": "Pronombres"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "کلید عمومی PGP",
"Don't show already seen posts": "پست های قبلا دیده شده را نشان ندهید",
"Watermark image": "تصویر واترمارک",
"Apply a watermark to uploaded images": "اعمال واترمارک روی تصاویر آپلود شده"
"Apply a watermark to uploaded images": "اعمال واترمارک روی تصاویر آپلود شده",
"Pronouns": "ضمایر"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "PGP julkinen avain",
"Don't show already seen posts": "Älä näytä jo nähtyjä viestejä",
"Watermark image": "Vesileiman kuva",
"Apply a watermark to uploaded images": "Lisää ladattuihin kuviin vesileima"
"Apply a watermark to uploaded images": "Lisää ladattuihin kuviin vesileima",
"Pronouns": "Pronominit"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "Clé publique PGP",
"Don't show already seen posts": "Ne pas afficher les messages déjà vus",
"Watermark image": "Image en filigrane",
"Apply a watermark to uploaded images": "Appliquer un filigrane aux images téléchargées"
"Apply a watermark to uploaded images": "Appliquer un filigrane aux images téléchargées",
"Pronouns": "Pronoms"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "Eochair Phoiblí PGP",
"Don't show already seen posts": "Ná taispeáin postálacha atá feicthe cheana féin",
"Watermark image": "Íomhá comhartha uisce",
"Apply a watermark to uploaded images": "Cuir comhartha uisce i bhfeidhm ar íomhánna uaslódáilte"
"Apply a watermark to uploaded images": "Cuir comhartha uisce i bhfeidhm ar íomhánna uaslódáilte",
"Pronouns": "Forainmneacha"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "מפתח PGP ציבורי",
"Don't show already seen posts": "אל תראה פוסטים שכבר נראו",
"Watermark image": "תמונת סימן מים",
"Apply a watermark to uploaded images": "החל סימן מים על תמונות שהועלו"
"Apply a watermark to uploaded images": "החל סימן מים על תמונות שהועלו",
"Pronouns": "כינויים"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "पीजीपी सार्वजनिक कुंजी",
"Don't show already seen posts": "पहले से देखी गई पोस्ट न दिखाएं",
"Watermark image": "वॉटरमार्क छवि",
"Apply a watermark to uploaded images": "अपलोड की गई छवियों पर वॉटरमार्क लागू करें"
"Apply a watermark to uploaded images": "अपलोड की गई छवियों पर वॉटरमार्क लागू करें",
"Pronouns": "सर्वनाम"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "Chiave pubblica PGP",
"Don't show already seen posts": "Non mostrare i post già visti",
"Watermark image": "Immagine filigrana",
"Apply a watermark to uploaded images": "Applicare una filigrana alle immagini caricate"
"Apply a watermark to uploaded images": "Applicare una filigrana alle immagini caricate",
"Pronouns": "Pronomi"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "PGP公開鍵",
"Don't show already seen posts": "すでに閲覧した投稿を表示しない",
"Watermark image": "透かし画像",
"Apply a watermark to uploaded images": "アップロードした画像に透かしを適用する"
"Apply a watermark to uploaded images": "アップロードした画像に透かしを適用する",
"Pronouns": "代名詞"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "PGP 공개 키",
"Don't show already seen posts": "이미 본 게시물을 표시하지 않음",
"Watermark image": "워터마크 이미지",
"Apply a watermark to uploaded images": "업로드한 이미지에 워터마크를 적용합니다"
"Apply a watermark to uploaded images": "업로드한 이미지에 워터마크를 적용합니다",
"Pronouns": "대명사"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "Mifteya Giştî ya PGP",
"Don't show already seen posts": "Mesajên ku berê hatine dîtin nîşan nedin",
"Watermark image": "Wêneyê Watermark",
"Apply a watermark to uploaded images": "Li ser wêneyên barkirî ava nîşanek bicîh bikin"
"Apply a watermark to uploaded images": "Li ser wêneyên barkirî ava nîşanek bicîh bikin",
"Pronouns": "Cînavk"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "PGP publieke sleutel",
"Don't show already seen posts": "Toon geen reeds bekeken berichten",
"Watermark image": "Watermerk afbeelding",
"Apply a watermark to uploaded images": "Een watermerk toepassen op geüploade afbeeldingen"
"Apply a watermark to uploaded images": "Een watermerk toepassen op geüploade afbeeldingen",
"Pronouns": "Voornaamwoorden"
}

View File

@ -692,5 +692,6 @@
"PGP Public Key": "PGP Public Key",
"Don't show already seen posts": "Don't show already seen posts",
"Watermark image": "Watermark image",
"Apply a watermark to uploaded images": "Apply a watermark to uploaded images"
"Apply a watermark to uploaded images": "Apply a watermark to uploaded images",
"Pronouns": "Pronouns"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "Klucz publiczny PGP",
"Don't show already seen posts": "Nie pokazuj już wyświetlonych postów",
"Watermark image": "Obraz znaku wodnego",
"Apply a watermark to uploaded images": "Zastosuj znak wodny do przesłanych obrazów"
"Apply a watermark to uploaded images": "Zastosuj znak wodny do przesłanych obrazów",
"Pronouns": "Zaimki"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "Chave pública PGP",
"Don't show already seen posts": "Não mostrar posts já vistos",
"Watermark image": "Imagem de marca de água",
"Apply a watermark to uploaded images": "Aplicar uma marca de água nas imagens enviadas"
"Apply a watermark to uploaded images": "Aplicar uma marca de água nas imagens enviadas",
"Pronouns": "Pronomes"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "Открытый ключ PGP",
"Don't show already seen posts": "Не показывать уже просмотренные публикации",
"Watermark image": "Изображение водяного знака",
"Apply a watermark to uploaded images": "Накладывать водяной знак на загружаемые изображения"
"Apply a watermark to uploaded images": "Накладывать водяной знак на загружаемые изображения",
"Pronouns": "Местоимения"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "Ufunguo wa Umma wa PGP",
"Don't show already seen posts": "Usionyeshe machapisho ambayo tayari yameonekana",
"Watermark image": "Picha ya watermark",
"Apply a watermark to uploaded images": "Tumia watermark kwa picha zilizopakiwa"
"Apply a watermark to uploaded images": "Tumia watermark kwa picha zilizopakiwa",
"Pronouns": "Viwakilishi"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "PGP Genel Anahtarı",
"Don't show already seen posts": "Daha önce görülen gönderileri gösterme",
"Watermark image": "Filigran resmi",
"Apply a watermark to uploaded images": "Yüklenen görsellere filigran uygulayın"
"Apply a watermark to uploaded images": "Yüklenen görsellere filigran uygulayın",
"Pronouns": "Zamirler"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "Відкритий ключ PGP",
"Don't show already seen posts": "Не показувати вже переглянуті публікації",
"Watermark image": "Зображення водяного знака",
"Apply a watermark to uploaded images": "Застосування водяного знака до завантажених зображень"
"Apply a watermark to uploaded images": "Застосування водяного знака до завантажених зображень",
"Pronouns": "Займенники"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "PGP ציבור שליסל",
"Don't show already seen posts": "צי ניט ווייַזן שוין געזען אַרטיקלען",
"Watermark image": "וואָטערמאַרק בילד",
"Apply a watermark to uploaded images": "צולייגן אַ וואָטערמאַרק צו ופּלאָאַדעד בילדער"
"Apply a watermark to uploaded images": "צולייגן אַ וואָטערמאַרק צו ופּלאָאַדעד בילדער",
"Pronouns": "פּראָנאָונס"
}

View File

@ -696,5 +696,6 @@
"PGP Public Key": "PGP 公钥",
"Don't show already seen posts": "不显示已经看过的帖子",
"Watermark image": "水印图像",
"Apply a watermark to uploaded images": "将水印应用于上传的图像"
"Apply a watermark to uploaded images": "将水印应用于上传的图像",
"Pronouns": "代词"
}

View File

@ -145,6 +145,7 @@ def html_person_options(default_timeline: str,
donate_url: str,
web_address: str,
gemini_link: str,
pronouns: str,
xmpp_address: str,
matrix_address: str,
ssb_address: str,
@ -388,6 +389,10 @@ def html_person_options(default_timeline: str,
if ctr > 0:
options_str += other_accounts_html
if pronouns:
options_str += \
' <p class="imText">' + translate['Pronouns'] + \
': ' + pronouns + '</a></p>\n'
if email_address:
options_str += \
' <p class="imText">' + translate['Email'] + \

View File

@ -66,6 +66,7 @@ from posts import get_max_profile_posts
from donate import get_donation_url
from donate import get_website
from donate import get_gemini_link
from pronouns import get_pronouns
from xmpp import get_xmpp_address
from matrix import get_matrix_address
from ssb import get_ssb_address
@ -1082,6 +1083,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)
pronouns = get_pronouns(profile_json)
xmpp_address = get_xmpp_address(profile_json)
matrix_address = get_matrix_address(profile_json)
ssb_address = get_ssb_address(profile_json)
@ -1090,7 +1092,7 @@ def html_profile(signing_priv_key_pem: str,
cwtch_address = get_cwtch_address(profile_json)
verified_site_checkmark = ''
premium = is_premium_account(base_dir, nickname, domain)
if donate_url or website_url or repo_url or xmpp_address or \
if donate_url or website_url or repo_url or pronouns 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:
@ -1150,6 +1152,9 @@ def html_profile(signing_priv_key_pem: str,
'<p>Blog: <a href="' + \
blog_address + '" rel="me" tabindex="1">' + \
blog_address + '</a></p>\n'
if pronouns:
donate_section += \
'<p>' + translate['Pronouns'] + ': ' + pronouns + '</p>\n'
if xmpp_address:
donate_section += \
'<p>' + translate['XMPP'] + ': <a href="xmpp:' + \
@ -2944,7 +2949,8 @@ def _get_supported_languagesSorted(base_dir: str) -> str:
return languages_str
def _html_edit_profile_main(base_dir: str, display_nickname: str, bio_str: str,
def _html_edit_profile_main(base_dir: str, display_nickname: str,
pronouns: str, bio_str: str,
moved_to: str, donate_url: str, website_url: str,
gemini_link: str, blog_address: str,
actor_json: {}, translate: {},
@ -2961,6 +2967,10 @@ def _html_edit_profile_main(base_dir: str, display_nickname: str, bio_str: str,
edit_text_field(translate['Nickname'], 'displayNickname',
display_nickname)
edit_profile_form += \
edit_text_field(translate['Pronouns'], 'setPronouns',
pronouns)
edit_profile_form += \
edit_text_area(translate['Your bio'], None, 'bio', bio_str,
200, '', True)
@ -3154,7 +3164,7 @@ def html_edit_profile(server, translate: {},
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 = ''
pgp_fingerprint = xmpp_address = matrix_address = ''
pgp_fingerprint = pronouns = xmpp_address = matrix_address = ''
ssb_address = blog_address = tox_address = ''
cwtch_address = briar_address = ''
manually_approves_followers = reject_spam_actors = ''
@ -3167,6 +3177,7 @@ def html_edit_profile(server, translate: {},
donate_url = get_donation_url(actor_json)
website_url = get_website(actor_json, translate)
gemini_link = get_gemini_link(actor_json)
pronouns = get_pronouns(actor_json)
xmpp_address = get_xmpp_address(actor_json)
matrix_address = get_matrix_address(actor_json)
ssb_address = get_ssb_address(actor_json)
@ -3309,7 +3320,8 @@ def html_edit_profile(server, translate: {},
# main info
edit_profile_form += \
_html_edit_profile_main(base_dir, display_nickname, bio_str,
_html_edit_profile_main(base_dir, display_nickname,
pronouns, bio_str,
moved_to, donate_url, website_url,
gemini_link,
blog_address, actor_json, translate,