merge-requests/30/head
Bob Mottram 2023-01-01 12:05:51 +00:00
commit 04a7d04e5f
2 changed files with 67 additions and 7 deletions

View File

@ -63,7 +63,7 @@ from filters import is_filtered
from follow import is_follower_of_person
from follow import get_follower_domains
from webapp_frontscreen import html_front_screen
from webapp_utils import html_following_data_list
from webapp_utils import html_following_dropdown
from webapp_utils import edit_number_field
from webapp_utils import html_keyboard_navigation
from webapp_utils import html_hide_from_screen_reader
@ -1110,14 +1110,11 @@ def html_profile(signing_priv_key_pem: str,
' <input type="hidden" ' + \
'name="actor" value="' + actor + '">\n'
follow_search_str += \
' <input type="search" name="searchtext" ' + \
'list="' + selected + 'Handles" placeholder="🔎">\n'
follow_search_str += \
html_following_data_list(base_dir, nickname, domain,
domain_full, selected, False)
html_following_dropdown(base_dir, nickname, domain,
domain_full, selected, False)
follow_search_str += \
' <button type="submit" class="button" ' + \
'name="submitSearch">' + translate['Search'] + '</button>\n'
'name="submitSearch">' + translate['View'] + '</button>\n'
follow_search_str += '</form>\n</div>\n'
profile_str += follow_search_str

View File

@ -2016,3 +2016,66 @@ def html_following_data_list(base_dir: str, nickname: str,
list_str += '<option>@' + following_address + '</option>\n'
list_str += '</datalist>\n'
return list_str
def html_following_dropdown(base_dir: str, nickname: str,
domain: str, domain_full: str,
following_type: str,
use_petnames: bool) -> str:
"""Returns a select list of handles being followed or of followers
"""
list_str = '<select name="searchtext">\n'
following_filename = \
acct_dir(base_dir, nickname, domain) + '/' + following_type + '.txt'
msg = None
if os.path.isfile(following_filename):
with open(following_filename, 'r',
encoding='utf-8') as following_file:
msg = following_file.read()
# add your own handle, so that you can send DMs
# to yourself as reminders
msg += nickname + '@' + domain_full + '\n'
if msg:
# include petnames
petnames_filename = \
acct_dir(base_dir, nickname, domain) + '/petnames.txt'
if use_petnames and os.path.isfile(petnames_filename):
following_list = []
with open(petnames_filename, 'r',
encoding='utf-8') as petnames_file:
pet_str = petnames_file.read()
# extract each petname and append it
petnames_list = pet_str.split('\n')
for pet in petnames_list:
following_list.append(pet.split(' ')[0])
# add the following.txt entries
following_list += msg.split('\n')
else:
# no petnames list exists - just use following.txt
following_list = msg.split('\n')
list_str += '<option value="" selected></option>\n'
if following_list:
domain_sorted_list = []
for following_address in following_list:
if '@' not in following_address and \
'://' not in following_address:
continue
foll_nick = get_nickname_from_actor(following_address)
foll_domain, _ = get_domain_from_actor(following_address)
if not foll_domain or not foll_nick:
continue
domain_sorted_list.append(foll_domain + ' ' +
foll_nick + '@' + foll_domain)
domain_sorted_list.sort()
prev_foll_domain = ''
for following_line in domain_sorted_list:
following_address = following_line.split(' ')[1]
foll_domain, _ = get_domain_from_actor(following_address)
if prev_foll_domain and prev_foll_domain != foll_domain:
list_str += '<option value="" disabled></option>\n'
prev_foll_domain = foll_domain
list_str += '<option value="' + following_address + '">' + \
following_address + '</option>\n'
list_str += '</select>\n'
return list_str