mirror of https://gitlab.com/bashrc2/epicyon
Check searchableBy on posts when performing search
parent
aa6e483bd8
commit
53545813e5
17
follow.py
17
follow.py
|
@ -17,7 +17,6 @@ from utils import has_object_string_type
|
||||||
from utils import remove_domain_port
|
from utils import remove_domain_port
|
||||||
from utils import has_users_path
|
from utils import has_users_path
|
||||||
from utils import get_full_domain
|
from utils import get_full_domain
|
||||||
from utils import get_followers_list
|
|
||||||
from utils import valid_nickname
|
from utils import valid_nickname
|
||||||
from utils import domain_permitted
|
from utils import domain_permitted
|
||||||
from utils import get_domain_from_actor
|
from utils import get_domain_from_actor
|
||||||
|
@ -213,22 +212,6 @@ def is_following_actor(base_dir: str,
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_mutuals_of_person(base_dir: str,
|
|
||||||
nickname: str, domain: str) -> []:
|
|
||||||
"""Returns the mutuals of a person
|
|
||||||
i.e. accounts which they follow and which also follow back
|
|
||||||
"""
|
|
||||||
followers = \
|
|
||||||
get_followers_list(base_dir, nickname, domain, 'followers.txt')
|
|
||||||
following = \
|
|
||||||
get_followers_list(base_dir, nickname, domain, 'following.txt')
|
|
||||||
mutuals = []
|
|
||||||
for handle in following:
|
|
||||||
if handle in followers:
|
|
||||||
mutuals.append(handle)
|
|
||||||
return mutuals
|
|
||||||
|
|
||||||
|
|
||||||
def add_follower_of_person(base_dir: str, nickname: str, domain: str,
|
def add_follower_of_person(base_dir: str, nickname: str, domain: str,
|
||||||
follower_nickname: str, follower_domain: str,
|
follower_nickname: str, follower_domain: str,
|
||||||
federation_list: [], debug: bool,
|
federation_list: [], debug: bool,
|
||||||
|
|
1
tests.py
1
tests.py
|
@ -5878,7 +5878,6 @@ def _test_functions():
|
||||||
'thread_send_post',
|
'thread_send_post',
|
||||||
'send_to_followers',
|
'send_to_followers',
|
||||||
'expire_cache',
|
'expire_cache',
|
||||||
'get_mutuals_of_person',
|
|
||||||
'run_posts_queue',
|
'run_posts_queue',
|
||||||
'run_shares_expire',
|
'run_shares_expire',
|
||||||
'run_posts_watchdog',
|
'run_posts_watchdog',
|
||||||
|
|
65
utils.py
65
utils.py
|
@ -3015,6 +3015,22 @@ def _search_virtual_box_posts(base_dir: str, nickname: str, domain: str,
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def _get_mutuals_of_person(base_dir: str,
|
||||||
|
nickname: str, domain: str) -> []:
|
||||||
|
"""Returns the mutuals of a person
|
||||||
|
i.e. accounts which they follow and which also follow back
|
||||||
|
"""
|
||||||
|
followers = \
|
||||||
|
get_followers_list(base_dir, nickname, domain, 'followers.txt')
|
||||||
|
following = \
|
||||||
|
get_followers_list(base_dir, nickname, domain, 'following.txt')
|
||||||
|
mutuals = []
|
||||||
|
for handle in following:
|
||||||
|
if handle in followers:
|
||||||
|
mutuals.append(handle)
|
||||||
|
return mutuals
|
||||||
|
|
||||||
|
|
||||||
def search_box_posts(base_dir: str, nickname: str, domain: str,
|
def search_box_posts(base_dir: str, nickname: str, domain: str,
|
||||||
search_str: str, max_results: int,
|
search_str: str, max_results: int,
|
||||||
box_name='outbox') -> []:
|
box_name='outbox') -> []:
|
||||||
|
@ -3038,22 +3054,67 @@ def search_box_posts(base_dir: str, nickname: str, domain: str,
|
||||||
else:
|
else:
|
||||||
search_words = [search_str]
|
search_words = [search_str]
|
||||||
|
|
||||||
|
mutuals_list = []
|
||||||
|
check_searchable_by = False
|
||||||
|
if box_name == 'inbox':
|
||||||
|
check_searchable_by = True
|
||||||
|
# create a string containing all of the mutuals
|
||||||
|
mutuals_list = _get_mutuals_of_person(base_dir, nickname, domain)
|
||||||
|
|
||||||
res = []
|
res = []
|
||||||
for root, _, fnames in os.walk(path):
|
for root, _, fnames in os.walk(path):
|
||||||
for fname in fnames:
|
for fname in fnames:
|
||||||
file_path = os.path.join(root, fname)
|
file_path = os.path.join(root, fname)
|
||||||
try:
|
try:
|
||||||
with open(file_path, 'r', encoding='utf-8') as fp_post:
|
with open(file_path, 'r', encoding='utf-8') as fp_post:
|
||||||
data = fp_post.read().lower()
|
data = fp_post.read()
|
||||||
|
data_lower = data.lower()
|
||||||
|
|
||||||
not_found = False
|
not_found = False
|
||||||
for keyword in search_words:
|
for keyword in search_words:
|
||||||
if keyword not in data:
|
if keyword not in data_lower:
|
||||||
not_found = True
|
not_found = True
|
||||||
break
|
break
|
||||||
if not_found:
|
if not_found:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# if this is not an outbox/bookmarks search then is the
|
||||||
|
# post marked as being searchable?
|
||||||
|
if check_searchable_by:
|
||||||
|
if '"searchableBy":' not in data:
|
||||||
|
continue
|
||||||
|
searchable_by = \
|
||||||
|
data.split('"searchableBy":')[1].strip()
|
||||||
|
if searchable_by.startswith('['):
|
||||||
|
searchable_by = searchable_by.split(']')[0]
|
||||||
|
if '"' in searchable_by:
|
||||||
|
searchable_by = searchable_by.split('"')[1]
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
if '#Public' not in searchable_by and \
|
||||||
|
'/followers' not in searchable_by:
|
||||||
|
if '/mutuals' in searchable_by and mutuals_list:
|
||||||
|
data_actor = \
|
||||||
|
searchable_by.split('/mutuals')[0]
|
||||||
|
if '"' in data_actor:
|
||||||
|
data_actor = data_actor.split('"')[-1]
|
||||||
|
if data_actor not in mutuals_list:
|
||||||
|
data_nickname = \
|
||||||
|
get_nickname_from_actor(data_actor)
|
||||||
|
data_domain, data_port = \
|
||||||
|
get_domain_from_actor(data_actor)
|
||||||
|
if not data_nickname or \
|
||||||
|
not data_domain:
|
||||||
|
continue
|
||||||
|
data_domain_full = \
|
||||||
|
get_full_domain(data_domain, data_port)
|
||||||
|
data_handle = \
|
||||||
|
data_nickname + '@' + data_domain_full
|
||||||
|
if data_handle not in mutuals_list:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
res.append(file_path)
|
res.append(file_path)
|
||||||
if len(res) >= max_results:
|
if len(res) >= max_results:
|
||||||
return res
|
return res
|
||||||
|
|
|
@ -730,6 +730,10 @@ def html_history_search(translate: {}, base_dir: str,
|
||||||
box_filenames = \
|
box_filenames = \
|
||||||
search_box_posts(base_dir, nickname, domain,
|
search_box_posts(base_dir, nickname, domain,
|
||||||
historysearch, posts_per_page, box_name)
|
historysearch, posts_per_page, box_name)
|
||||||
|
if box_name == 'outbox':
|
||||||
|
box_filenames += \
|
||||||
|
search_box_posts(base_dir, nickname, domain,
|
||||||
|
historysearch, posts_per_page, 'inbox')
|
||||||
|
|
||||||
css_filename = base_dir + '/epicyon-profile.css'
|
css_filename = base_dir + '/epicyon-profile.css'
|
||||||
if os.path.isfile(base_dir + '/epicyon.css'):
|
if os.path.isfile(base_dir + '/epicyon.css'):
|
||||||
|
|
Loading…
Reference in New Issue