mirror of https://gitlab.com/bashrc2/epicyon
Move reaction function
parent
31a560f8f1
commit
388ecf2b2f
|
|
@ -11,7 +11,6 @@ __module_group__ = "Daemon GET"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from utils import undo_reaction_collection_entry
|
|
||||||
from utils import get_cached_post_filename
|
from utils import get_cached_post_filename
|
||||||
from utils import load_json
|
from utils import load_json
|
||||||
from utils import locate_post
|
from utils import locate_post
|
||||||
|
|
@ -26,6 +25,7 @@ from httpcodes import http_404
|
||||||
from posts import get_original_post_from_announce_url
|
from posts import get_original_post_from_announce_url
|
||||||
from daemon_utils import post_to_outbox
|
from daemon_utils import post_to_outbox
|
||||||
from fitnessFunctions import fitness_performance
|
from fitnessFunctions import fitness_performance
|
||||||
|
from reaction import undo_reaction_collection_entry
|
||||||
from reaction import update_reaction_collection
|
from reaction import update_reaction_collection
|
||||||
from follow import follower_approval_active
|
from follow import follower_approval_active
|
||||||
from webapp_post import individual_post_as_html
|
from webapp_post import individual_post_as_html
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ from utils import has_object_dict
|
||||||
from utils import remove_domain_port
|
from utils import remove_domain_port
|
||||||
from utils import remove_id_ending
|
from utils import remove_id_ending
|
||||||
from utils import get_url_from_post
|
from utils import get_url_from_post
|
||||||
from utils import undo_reaction_collection_entry
|
|
||||||
from utils import remove_html
|
from utils import remove_html
|
||||||
from utils import is_dm
|
from utils import is_dm
|
||||||
from utils import get_cached_post_filename
|
from utils import get_cached_post_filename
|
||||||
|
|
@ -35,6 +34,7 @@ from follow import unfollower_of_account
|
||||||
from follow import follower_approval_active
|
from follow import follower_approval_active
|
||||||
from bookmarks import undo_bookmarks_collection_entry
|
from bookmarks import undo_bookmarks_collection_entry
|
||||||
from webapp_post import individual_post_as_html
|
from webapp_post import individual_post_as_html
|
||||||
|
from reaction import undo_reaction_collection_entry
|
||||||
|
|
||||||
|
|
||||||
def _receive_undo_follow(base_dir: str, message_json: {},
|
def _receive_undo_follow(base_dir: str, message_json: {},
|
||||||
|
|
|
||||||
70
reaction.py
70
reaction.py
|
|
@ -25,7 +25,6 @@ from utils import remove_id_ending
|
||||||
from utils import get_nickname_from_actor
|
from utils import get_nickname_from_actor
|
||||||
from utils import get_domain_from_actor
|
from utils import get_domain_from_actor
|
||||||
from utils import locate_post
|
from utils import locate_post
|
||||||
from utils import undo_reaction_collection_entry
|
|
||||||
from utils import local_actor_url
|
from utils import local_actor_url
|
||||||
from utils import load_json
|
from utils import load_json
|
||||||
from utils import save_json
|
from utils import save_json
|
||||||
|
|
@ -695,3 +694,72 @@ def html_emoji_reactions(post_json_object: {}, interactive: bool,
|
||||||
html_str += ' </div>\n'
|
html_str += ' </div>\n'
|
||||||
html_str += '</div>\n'
|
html_str += '</div>\n'
|
||||||
return html_str
|
return html_str
|
||||||
|
|
||||||
|
|
||||||
|
def undo_reaction_collection_entry(recent_posts_cache: {},
|
||||||
|
base_dir: str, post_filename: str,
|
||||||
|
actor: str, domain: str, debug: bool,
|
||||||
|
post_json_object: {},
|
||||||
|
emoji_content: str) -> None:
|
||||||
|
"""Undoes an emoji reaction for a particular actor
|
||||||
|
"""
|
||||||
|
if not post_json_object:
|
||||||
|
post_json_object = load_json(post_filename)
|
||||||
|
if not post_json_object:
|
||||||
|
return
|
||||||
|
# remove any cached version of this post so that the
|
||||||
|
# like icon is changed
|
||||||
|
nickname = get_nickname_from_actor(actor)
|
||||||
|
if not nickname:
|
||||||
|
return
|
||||||
|
cached_post_filename = \
|
||||||
|
get_cached_post_filename(base_dir, nickname,
|
||||||
|
domain, post_json_object)
|
||||||
|
if cached_post_filename:
|
||||||
|
if os.path.isfile(cached_post_filename):
|
||||||
|
try:
|
||||||
|
os.remove(cached_post_filename)
|
||||||
|
except OSError:
|
||||||
|
print('EX: undo_reaction_collection_entry ' +
|
||||||
|
'unable to delete cached post ' +
|
||||||
|
str(cached_post_filename))
|
||||||
|
remove_post_from_cache(post_json_object, recent_posts_cache)
|
||||||
|
|
||||||
|
if not post_json_object.get('type'):
|
||||||
|
return
|
||||||
|
if post_json_object['type'] != 'Create':
|
||||||
|
return
|
||||||
|
obj = post_json_object
|
||||||
|
if has_object_dict(post_json_object):
|
||||||
|
obj = post_json_object['object']
|
||||||
|
if not obj.get('reactions'):
|
||||||
|
return
|
||||||
|
if not isinstance(obj['reactions'], dict):
|
||||||
|
return
|
||||||
|
if not obj['reactions'].get('items'):
|
||||||
|
return
|
||||||
|
total_items = 0
|
||||||
|
if obj['reactions'].get('totalItems'):
|
||||||
|
total_items = obj['reactions']['totalItems']
|
||||||
|
item_found = False
|
||||||
|
for like_item in obj['reactions']['items']:
|
||||||
|
if not like_item.get('actor'):
|
||||||
|
continue
|
||||||
|
if like_item['actor'] == actor and \
|
||||||
|
like_item['content'] == emoji_content:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: emoji reaction was removed for ' + actor)
|
||||||
|
obj['reactions']['items'].remove(like_item)
|
||||||
|
item_found = True
|
||||||
|
break
|
||||||
|
if not item_found:
|
||||||
|
return
|
||||||
|
if total_items == 1:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: emoji reaction was removed from post')
|
||||||
|
del obj['reactions']
|
||||||
|
else:
|
||||||
|
itlen = len(obj['reactions']['items'])
|
||||||
|
obj['reactions']['totalItems'] = itlen
|
||||||
|
|
||||||
|
save_json(post_json_object, post_filename)
|
||||||
|
|
|
||||||
69
utils.py
69
utils.py
|
|
@ -2607,75 +2607,6 @@ def get_file_case_insensitive(path: str) -> str:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def undo_reaction_collection_entry(recent_posts_cache: {},
|
|
||||||
base_dir: str, post_filename: str,
|
|
||||||
actor: str, domain: str, debug: bool,
|
|
||||||
post_json_object: {},
|
|
||||||
emoji_content: str) -> None:
|
|
||||||
"""Undoes an emoji reaction for a particular actor
|
|
||||||
"""
|
|
||||||
if not post_json_object:
|
|
||||||
post_json_object = load_json(post_filename)
|
|
||||||
if not post_json_object:
|
|
||||||
return
|
|
||||||
# remove any cached version of this post so that the
|
|
||||||
# like icon is changed
|
|
||||||
nickname = get_nickname_from_actor(actor)
|
|
||||||
if not nickname:
|
|
||||||
return
|
|
||||||
cached_post_filename = \
|
|
||||||
get_cached_post_filename(base_dir, nickname,
|
|
||||||
domain, post_json_object)
|
|
||||||
if cached_post_filename:
|
|
||||||
if os.path.isfile(cached_post_filename):
|
|
||||||
try:
|
|
||||||
os.remove(cached_post_filename)
|
|
||||||
except OSError:
|
|
||||||
print('EX: undo_reaction_collection_entry ' +
|
|
||||||
'unable to delete cached post ' +
|
|
||||||
str(cached_post_filename))
|
|
||||||
remove_post_from_cache(post_json_object, recent_posts_cache)
|
|
||||||
|
|
||||||
if not post_json_object.get('type'):
|
|
||||||
return
|
|
||||||
if post_json_object['type'] != 'Create':
|
|
||||||
return
|
|
||||||
obj = post_json_object
|
|
||||||
if has_object_dict(post_json_object):
|
|
||||||
obj = post_json_object['object']
|
|
||||||
if not obj.get('reactions'):
|
|
||||||
return
|
|
||||||
if not isinstance(obj['reactions'], dict):
|
|
||||||
return
|
|
||||||
if not obj['reactions'].get('items'):
|
|
||||||
return
|
|
||||||
total_items = 0
|
|
||||||
if obj['reactions'].get('totalItems'):
|
|
||||||
total_items = obj['reactions']['totalItems']
|
|
||||||
item_found = False
|
|
||||||
for like_item in obj['reactions']['items']:
|
|
||||||
if not like_item.get('actor'):
|
|
||||||
continue
|
|
||||||
if like_item['actor'] == actor and \
|
|
||||||
like_item['content'] == emoji_content:
|
|
||||||
if debug:
|
|
||||||
print('DEBUG: emoji reaction was removed for ' + actor)
|
|
||||||
obj['reactions']['items'].remove(like_item)
|
|
||||||
item_found = True
|
|
||||||
break
|
|
||||||
if not item_found:
|
|
||||||
return
|
|
||||||
if total_items == 1:
|
|
||||||
if debug:
|
|
||||||
print('DEBUG: emoji reaction was removed from post')
|
|
||||||
del obj['reactions']
|
|
||||||
else:
|
|
||||||
itlen = len(obj['reactions']['items'])
|
|
||||||
obj['reactions']['totalItems'] = itlen
|
|
||||||
|
|
||||||
save_json(post_json_object, post_filename)
|
|
||||||
|
|
||||||
|
|
||||||
def undo_announce_collection_entry(recent_posts_cache: {},
|
def undo_announce_collection_entry(recent_posts_cache: {},
|
||||||
base_dir: str, post_filename: str,
|
base_dir: str, post_filename: str,
|
||||||
actor: str, domain: str,
|
actor: str, domain: str,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue