mirror of https://gitlab.com/bashrc2/epicyon
Snake case
parent
32cae80019
commit
0e87c9a362
32
announce.py
32
announce.py
|
@ -21,7 +21,7 @@ from utils import getDomainFromActor
|
|||
from utils import locate_post
|
||||
from utils import save_json
|
||||
from utils import undoAnnounceCollectionEntry
|
||||
from utils import updateAnnounceCollection
|
||||
from utils import update_announce_collection
|
||||
from utils import local_actor_url
|
||||
from utils import replace_users_with_at
|
||||
from utils import has_actor
|
||||
|
@ -74,13 +74,13 @@ def outboxAnnounce(recent_posts_cache: {},
|
|||
print('WARN: no nickname found in ' + message_json['actor'])
|
||||
return False
|
||||
domain, _ = getDomainFromActor(message_json['actor'])
|
||||
postFilename = locate_post(base_dir, nickname, domain,
|
||||
message_json['object'])
|
||||
if postFilename:
|
||||
updateAnnounceCollection(recent_posts_cache,
|
||||
base_dir, postFilename,
|
||||
message_json['actor'],
|
||||
nickname, domain, debug)
|
||||
post_filename = locate_post(base_dir, nickname, domain,
|
||||
message_json['object'])
|
||||
if post_filename:
|
||||
update_announce_collection(recent_posts_cache,
|
||||
base_dir, post_filename,
|
||||
message_json['actor'],
|
||||
nickname, domain, debug)
|
||||
return True
|
||||
elif message_json['type'] == 'Undo':
|
||||
if not has_object_stringType(message_json, debug):
|
||||
|
@ -93,11 +93,11 @@ def outboxAnnounce(recent_posts_cache: {},
|
|||
print('WARN: no nickname found in ' + message_json['actor'])
|
||||
return False
|
||||
domain, _ = getDomainFromActor(message_json['actor'])
|
||||
postFilename = locate_post(base_dir, nickname, domain,
|
||||
message_json['object']['object'])
|
||||
if postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain,
|
||||
message_json['object']['object'])
|
||||
if post_filename:
|
||||
undoAnnounceCollectionEntry(recent_posts_cache,
|
||||
base_dir, postFilename,
|
||||
base_dir, post_filename,
|
||||
message_json['actor'],
|
||||
domain, debug)
|
||||
return True
|
||||
|
@ -410,13 +410,13 @@ def outboxUndoAnnounce(recent_posts_cache: {},
|
|||
|
||||
messageId = removeIdEnding(message_json['object']['object'])
|
||||
domain = remove_domain_port(domain)
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: c2s undo announce post not found in inbox or outbox')
|
||||
print(messageId)
|
||||
return True
|
||||
undoAnnounceCollectionEntry(recent_posts_cache, base_dir, postFilename,
|
||||
undoAnnounceCollectionEntry(recent_posts_cache, base_dir, post_filename,
|
||||
message_json['actor'], domain, debug)
|
||||
if debug:
|
||||
print('DEBUG: post undo announce via c2s - ' + postFilename)
|
||||
print('DEBUG: post undo announce via c2s - ' + post_filename)
|
||||
|
|
80
blocking.py
80
blocking.py
|
@ -17,7 +17,7 @@ from utils import has_object_stringType
|
|||
from utils import remove_domain_port
|
||||
from utils import has_object_dict
|
||||
from utils import is_account_dir
|
||||
from utils import getCachedPostFilename
|
||||
from utils import get_cached_post_filename
|
||||
from utils import load_json
|
||||
from utils import save_json
|
||||
from utils import fileLastModified
|
||||
|
@ -442,8 +442,8 @@ def outboxBlock(base_dir: str, http_prefix: str,
|
|||
print('DEBUG: c2s block object has no nickname')
|
||||
return False
|
||||
domain = remove_domain_port(domain)
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: c2s block post not found in inbox or outbox')
|
||||
print(messageId)
|
||||
|
@ -459,7 +459,7 @@ def outboxBlock(base_dir: str, http_prefix: str,
|
|||
nicknameBlocked, domainBlockedFull)
|
||||
|
||||
if debug:
|
||||
print('DEBUG: post blocked via c2s - ' + postFilename)
|
||||
print('DEBUG: post blocked via c2s - ' + post_filename)
|
||||
return True
|
||||
|
||||
|
||||
|
@ -498,8 +498,8 @@ def outboxUndoBlock(base_dir: str, http_prefix: str,
|
|||
print('DEBUG: c2s undo block object has no nickname')
|
||||
return
|
||||
domain = remove_domain_port(domain)
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: c2s undo block post not found in inbox or outbox')
|
||||
print(messageId)
|
||||
|
@ -516,7 +516,7 @@ def outboxUndoBlock(base_dir: str, http_prefix: str,
|
|||
removeBlock(base_dir, nickname, domain,
|
||||
nicknameBlocked, domainBlockedFull)
|
||||
if debug:
|
||||
print('DEBUG: post undo blocked via c2s - ' + postFilename)
|
||||
print('DEBUG: post undo blocked via c2s - ' + post_filename)
|
||||
|
||||
|
||||
def mutePost(base_dir: str, nickname: str, domain: str, port: int,
|
||||
|
@ -525,11 +525,11 @@ def mutePost(base_dir: str, nickname: str, domain: str, port: int,
|
|||
""" Mutes the given post
|
||||
"""
|
||||
print('mutePost: post_id ' + post_id)
|
||||
postFilename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not post_filename:
|
||||
print('mutePost: file not found ' + post_id)
|
||||
return
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not post_json_object:
|
||||
print('mutePost: object not loaded ' + post_id)
|
||||
return
|
||||
|
@ -581,13 +581,13 @@ def mutePost(base_dir: str, nickname: str, domain: str, port: int,
|
|||
itemsList.append(newIgnore)
|
||||
postJsonObj['ignores']['totalItems'] = igIt
|
||||
postJsonObj['muted'] = True
|
||||
if save_json(post_json_object, postFilename):
|
||||
print('mutePost: saved ' + postFilename)
|
||||
if save_json(post_json_object, post_filename):
|
||||
print('mutePost: saved ' + post_filename)
|
||||
|
||||
# remove cached post so that the muted version gets recreated
|
||||
# without its content text and/or image
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname, domain, post_json_object)
|
||||
get_cached_post_filename(base_dir, nickname, domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -601,12 +601,12 @@ def mutePost(base_dir: str, nickname: str, domain: str, port: int,
|
|||
print('MUTE: cached post not found ' + cachedPostFilename)
|
||||
|
||||
try:
|
||||
with open(postFilename + '.muted', 'w+') as muteFile:
|
||||
with open(post_filename + '.muted', 'w+') as muteFile:
|
||||
muteFile.write('\n')
|
||||
except OSError:
|
||||
print('EX: Failed to save mute file ' + postFilename + '.muted')
|
||||
print('EX: Failed to save mute file ' + post_filename + '.muted')
|
||||
return
|
||||
print('MUTE: ' + postFilename + '.muted file added')
|
||||
print('MUTE: ' + post_filename + '.muted file added')
|
||||
|
||||
# if the post is in the recent posts cache then mark it as muted
|
||||
if recent_posts_cache.get('index'):
|
||||
|
@ -624,13 +624,13 @@ def mutePost(base_dir: str, nickname: str, domain: str, port: int,
|
|||
print('MUTE: ' + post_id + ' removed cached html')
|
||||
|
||||
if alsoUpdatePostId:
|
||||
postFilename = locate_post(base_dir, nickname, domain,
|
||||
alsoUpdatePostId)
|
||||
if os.path.isfile(postFilename):
|
||||
postJsonObj = load_json(postFilename)
|
||||
post_filename = locate_post(base_dir, nickname, domain,
|
||||
alsoUpdatePostId)
|
||||
if os.path.isfile(post_filename):
|
||||
postJsonObj = load_json(post_filename)
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname, domain,
|
||||
postJsonObj)
|
||||
get_cached_post_filename(base_dir, nickname, domain,
|
||||
postJsonObj)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -658,14 +658,14 @@ def unmutePost(base_dir: str, nickname: str, domain: str, port: int,
|
|||
debug: bool) -> None:
|
||||
""" Unmutes the given post
|
||||
"""
|
||||
postFilename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not post_filename:
|
||||
return
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not post_json_object:
|
||||
return
|
||||
|
||||
muteFilename = postFilename + '.muted'
|
||||
muteFilename = post_filename + '.muted'
|
||||
if os.path.isfile(muteFilename):
|
||||
try:
|
||||
os.remove(muteFilename)
|
||||
|
@ -709,12 +709,12 @@ def unmutePost(base_dir: str, nickname: str, domain: str, port: int,
|
|||
igItLen = len(postJsonObj['ignores']['items'])
|
||||
postJsonObj['ignores']['totalItems'] = igItLen
|
||||
postJsonObj['muted'] = False
|
||||
save_json(post_json_object, postFilename)
|
||||
save_json(post_json_object, post_filename)
|
||||
|
||||
# remove cached post so that the muted version gets recreated
|
||||
# with its content text and/or image
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname, domain, post_json_object)
|
||||
get_cached_post_filename(base_dir, nickname, domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -739,13 +739,13 @@ def unmutePost(base_dir: str, nickname: str, domain: str, port: int,
|
|||
del recent_posts_cache['html'][post_id]
|
||||
print('UNMUTE: ' + post_id + ' removed cached html')
|
||||
if alsoUpdatePostId:
|
||||
postFilename = locate_post(base_dir, nickname, domain,
|
||||
alsoUpdatePostId)
|
||||
if os.path.isfile(postFilename):
|
||||
postJsonObj = load_json(postFilename)
|
||||
post_filename = locate_post(base_dir, nickname, domain,
|
||||
alsoUpdatePostId)
|
||||
if os.path.isfile(post_filename):
|
||||
postJsonObj = load_json(post_filename)
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname, domain,
|
||||
postJsonObj)
|
||||
get_cached_post_filename(base_dir, nickname, domain,
|
||||
postJsonObj)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -800,8 +800,8 @@ def outboxMute(base_dir: str, http_prefix: str,
|
|||
print('DEBUG: c2s mute object has no nickname')
|
||||
return
|
||||
domain = remove_domain_port(domain)
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: c2s mute post not found in inbox or outbox')
|
||||
print(messageId)
|
||||
|
@ -816,7 +816,7 @@ def outboxMute(base_dir: str, http_prefix: str,
|
|||
debug)
|
||||
|
||||
if debug:
|
||||
print('DEBUG: post muted via c2s - ' + postFilename)
|
||||
print('DEBUG: post muted via c2s - ' + post_filename)
|
||||
|
||||
|
||||
def outboxUndoMute(base_dir: str, http_prefix: str,
|
||||
|
@ -855,8 +855,8 @@ def outboxUndoMute(base_dir: str, http_prefix: str,
|
|||
print('DEBUG: c2s undo mute object has no nickname')
|
||||
return
|
||||
domain = remove_domain_port(domain)
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: c2s undo mute post not found in inbox or outbox')
|
||||
print(messageId)
|
||||
|
@ -872,7 +872,7 @@ def outboxUndoMute(base_dir: str, http_prefix: str,
|
|||
recent_posts_cache, debug)
|
||||
|
||||
if debug:
|
||||
print('DEBUG: post undo mute via c2s - ' + postFilename)
|
||||
print('DEBUG: post undo mute via c2s - ' + post_filename)
|
||||
|
||||
|
||||
def broch_modeIsActive(base_dir: str) -> bool:
|
||||
|
|
54
blog.py
54
blog.py
|
@ -53,19 +53,19 @@ def _noOfBlogReplies(base_dir: str, http_prefix: str, translate: {},
|
|||
tryPostBox = ('tlblogs', 'inbox', 'outbox')
|
||||
boxFound = False
|
||||
for postBox in tryPostBox:
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
acct_dir(base_dir, nickname, domain) + '/' + postBox + '/' + \
|
||||
post_id.replace('/', '#') + '.replies'
|
||||
if os.path.isfile(postFilename):
|
||||
if os.path.isfile(post_filename):
|
||||
boxFound = True
|
||||
break
|
||||
if not boxFound:
|
||||
# post may exist but has no replies
|
||||
for postBox in tryPostBox:
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
acct_dir(base_dir, nickname, domain) + '/' + postBox + '/' + \
|
||||
post_id.replace('/', '#')
|
||||
if os.path.isfile(postFilename):
|
||||
if os.path.isfile(post_filename):
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
@ -73,10 +73,10 @@ def _noOfBlogReplies(base_dir: str, http_prefix: str, translate: {},
|
|||
replies = 0
|
||||
lines = []
|
||||
try:
|
||||
with open(postFilename, 'r') as f:
|
||||
with open(post_filename, 'r') as f:
|
||||
lines = f.readlines()
|
||||
except OSError:
|
||||
print('EX: failed to read blog ' + postFilename)
|
||||
print('EX: failed to read blog ' + post_filename)
|
||||
|
||||
for replyPostId in lines:
|
||||
replyPostId = replyPostId.replace('\n', '').replace('\r', '')
|
||||
|
@ -93,10 +93,10 @@ def _noOfBlogReplies(base_dir: str, http_prefix: str, translate: {},
|
|||
|
||||
# remove posts from .replies file if they don't exist
|
||||
if lines and removals:
|
||||
print('Rewriting ' + postFilename + ' to remove ' +
|
||||
print('Rewriting ' + post_filename + ' to remove ' +
|
||||
str(len(removals)) + ' entries')
|
||||
try:
|
||||
with open(postFilename, 'w+') as f:
|
||||
with open(post_filename, 'w+') as f:
|
||||
for replyPostId in lines:
|
||||
replyPostId = \
|
||||
replyPostId.replace('\n', '').replace('\r', '')
|
||||
|
@ -104,7 +104,7 @@ def _noOfBlogReplies(base_dir: str, http_prefix: str, translate: {},
|
|||
f.write(replyPostId + '\n')
|
||||
except OSError as ex:
|
||||
print('EX: unable to remove replies from post ' +
|
||||
postFilename + ' ' + str(ex))
|
||||
post_filename + ' ' + str(ex))
|
||||
|
||||
return replies
|
||||
|
||||
|
@ -122,36 +122,36 @@ def _getBlogReplies(base_dir: str, http_prefix: str, translate: {},
|
|||
tryPostBox = ('tlblogs', 'inbox', 'outbox')
|
||||
boxFound = False
|
||||
for postBox in tryPostBox:
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
acct_dir(base_dir, nickname, domain) + '/' + postBox + '/' + \
|
||||
post_id.replace('/', '#') + '.replies'
|
||||
if os.path.isfile(postFilename):
|
||||
if os.path.isfile(post_filename):
|
||||
boxFound = True
|
||||
break
|
||||
if not boxFound:
|
||||
# post may exist but has no replies
|
||||
for postBox in tryPostBox:
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
acct_dir(base_dir, nickname, domain) + '/' + postBox + '/' + \
|
||||
post_id.replace('/', '#') + '.json'
|
||||
if os.path.isfile(postFilename):
|
||||
postFilename = acct_dir(base_dir, nickname, domain) + \
|
||||
if os.path.isfile(post_filename):
|
||||
post_filename = acct_dir(base_dir, nickname, domain) + \
|
||||
'/postcache/' + \
|
||||
post_id.replace('/', '#') + '.html'
|
||||
if os.path.isfile(postFilename):
|
||||
if os.path.isfile(post_filename):
|
||||
try:
|
||||
with open(postFilename, 'r') as postFile:
|
||||
with open(post_filename, 'r') as postFile:
|
||||
return postFile.read() + '\n'
|
||||
except OSError:
|
||||
print('EX: unable to read blog 3 ' + postFilename)
|
||||
print('EX: unable to read blog 3 ' + post_filename)
|
||||
return ''
|
||||
|
||||
lines = []
|
||||
try:
|
||||
with open(postFilename, 'r') as f:
|
||||
with open(post_filename, 'r') as f:
|
||||
lines = f.readlines()
|
||||
except OSError:
|
||||
print('EX: unable to read blog 4 ' + postFilename)
|
||||
print('EX: unable to read blog 4 ' + post_filename)
|
||||
|
||||
if lines:
|
||||
repliesStr = ''
|
||||
|
@ -159,16 +159,16 @@ def _getBlogReplies(base_dir: str, http_prefix: str, translate: {},
|
|||
replyPostId = replyPostId.replace('\n', '').replace('\r', '')
|
||||
replyPostId = replyPostId.replace('.json', '')
|
||||
replyPostId = replyPostId.replace('.replies', '')
|
||||
postFilename = acct_dir(base_dir, nickname, domain) + \
|
||||
post_filename = acct_dir(base_dir, nickname, domain) + \
|
||||
'/postcache/' + \
|
||||
replyPostId.replace('/', '#') + '.html'
|
||||
if not os.path.isfile(postFilename):
|
||||
if not os.path.isfile(post_filename):
|
||||
continue
|
||||
try:
|
||||
with open(postFilename, 'r') as postFile:
|
||||
with open(post_filename, 'r') as postFile:
|
||||
repliesStr += postFile.read() + '\n'
|
||||
except OSError:
|
||||
print('EX: unable to read blog replies ' + postFilename)
|
||||
print('EX: unable to read blog replies ' + post_filename)
|
||||
rply = _getBlogReplies(base_dir, http_prefix, translate,
|
||||
nickname, domain, domain_full,
|
||||
replyPostId, depth+1)
|
||||
|
@ -780,14 +780,14 @@ def htmlEditBlog(media_instance: bool, translate: {},
|
|||
postUrl: str, system_language: str) -> str:
|
||||
"""Edit a blog post after it was created
|
||||
"""
|
||||
postFilename = locate_post(base_dir, nickname, domain, postUrl)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, postUrl)
|
||||
if not post_filename:
|
||||
print('Edit blog: Filename not found for ' + postUrl)
|
||||
return None
|
||||
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not post_json_object:
|
||||
print('Edit blog: json not loaded for ' + postFilename)
|
||||
print('Edit blog: json not loaded for ' + post_filename)
|
||||
return None
|
||||
|
||||
editBlogText = '<h1">' + translate['Write your post text below.'] + '</h1>'
|
||||
|
|
60
bookmarks.py
60
bookmarks.py
|
@ -20,7 +20,7 @@ from utils import urlPermitted
|
|||
from utils import getNicknameFromActor
|
||||
from utils import getDomainFromActor
|
||||
from utils import locate_post
|
||||
from utils import getCachedPostFilename
|
||||
from utils import get_cached_post_filename
|
||||
from utils import load_json
|
||||
from utils import save_json
|
||||
from utils import has_object_dict
|
||||
|
@ -33,20 +33,21 @@ from session import postJson
|
|||
|
||||
|
||||
def undoBookmarksCollectionEntry(recent_posts_cache: {},
|
||||
base_dir: str, postFilename: str,
|
||||
base_dir: str, post_filename: str,
|
||||
objectUrl: str,
|
||||
actor: str, domain: str, debug: bool) -> None:
|
||||
"""Undoes a bookmark for a particular actor
|
||||
"""
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not post_json_object:
|
||||
return
|
||||
|
||||
# remove any cached version of this post so that the
|
||||
# bookmark icon is changed
|
||||
nickname = getNicknameFromActor(actor)
|
||||
cachedPostFilename = getCachedPostFilename(base_dir, nickname,
|
||||
domain, post_json_object)
|
||||
cachedPostFilename = \
|
||||
get_cached_post_filename(base_dir, nickname,
|
||||
domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -63,10 +64,10 @@ def undoBookmarksCollectionEntry(recent_posts_cache: {},
|
|||
acct_dir(base_dir, nickname, domain) + '/bookmarks.index'
|
||||
if not os.path.isfile(bookmarksIndexFilename):
|
||||
return
|
||||
if '/' in postFilename:
|
||||
bookmarkIndex = postFilename.split('/')[-1].strip()
|
||||
if '/' in post_filename:
|
||||
bookmarkIndex = post_filename.split('/')[-1].strip()
|
||||
else:
|
||||
bookmarkIndex = postFilename.strip()
|
||||
bookmarkIndex = post_filename.strip()
|
||||
bookmarkIndex = bookmarkIndex.replace('\n', '').replace('\r', '')
|
||||
if bookmarkIndex not in open(bookmarksIndexFilename).read():
|
||||
return
|
||||
|
@ -122,7 +123,7 @@ def undoBookmarksCollectionEntry(recent_posts_cache: {},
|
|||
else:
|
||||
bmItLen = len(post_json_object['object']['bookmarks']['items'])
|
||||
post_json_object['object']['bookmarks']['totalItems'] = bmItLen
|
||||
save_json(post_json_object, postFilename)
|
||||
save_json(post_json_object, post_filename)
|
||||
|
||||
|
||||
def bookmarkedByPerson(post_json_object: {},
|
||||
|
@ -154,18 +155,19 @@ def _noOfBookmarks(post_json_object: {}) -> int:
|
|||
|
||||
|
||||
def updateBookmarksCollection(recent_posts_cache: {},
|
||||
base_dir: str, postFilename: str,
|
||||
base_dir: str, post_filename: str,
|
||||
objectUrl: str,
|
||||
actor: str, domain: str, debug: bool) -> None:
|
||||
"""Updates the bookmarks collection within a post
|
||||
"""
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if post_json_object:
|
||||
# remove any cached version of this post so that the
|
||||
# bookmark icon is changed
|
||||
nickname = getNicknameFromActor(actor)
|
||||
cachedPostFilename = getCachedPostFilename(base_dir, nickname,
|
||||
domain, post_json_object)
|
||||
cachedPostFilename = \
|
||||
get_cached_post_filename(base_dir, nickname,
|
||||
domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -220,12 +222,12 @@ def updateBookmarksCollection(recent_posts_cache: {},
|
|||
print('DEBUG: saving post with bookmarks added')
|
||||
pprint(post_json_object)
|
||||
|
||||
save_json(post_json_object, postFilename)
|
||||
save_json(post_json_object, post_filename)
|
||||
|
||||
# prepend to the index
|
||||
bookmarksIndexFilename = \
|
||||
acct_dir(base_dir, nickname, domain) + '/bookmarks.index'
|
||||
bookmarkIndex = postFilename.split('/')[-1]
|
||||
bookmarkIndex = post_filename.split('/')[-1]
|
||||
if os.path.isfile(bookmarksIndexFilename):
|
||||
if bookmarkIndex not in open(bookmarksIndexFilename).read():
|
||||
try:
|
||||
|
@ -292,8 +294,8 @@ def bookmark(recent_posts_cache: {},
|
|||
bookmarkedPostDomain, bookmarkedPostPort = getDomainFromActor(ou)
|
||||
|
||||
if bookmarkedPostNickname:
|
||||
postFilename = locate_post(base_dir, nickname, domain, objectUrl)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, objectUrl)
|
||||
if not post_filename:
|
||||
print('DEBUG: bookmark base_dir: ' + base_dir)
|
||||
print('DEBUG: bookmark nickname: ' + nickname)
|
||||
print('DEBUG: bookmark domain: ' + domain)
|
||||
|
@ -301,7 +303,7 @@ def bookmark(recent_posts_cache: {},
|
|||
return None
|
||||
|
||||
updateBookmarksCollection(recent_posts_cache,
|
||||
base_dir, postFilename, objectUrl,
|
||||
base_dir, post_filename, objectUrl,
|
||||
newBookmarkJson['actor'], domain, debug)
|
||||
|
||||
return newBookmarkJson
|
||||
|
@ -356,12 +358,12 @@ def undoBookmark(recent_posts_cache: {},
|
|||
bookmarkedPostDomain, bookmarkedPostPort = getDomainFromActor(ou)
|
||||
|
||||
if bookmarkedPostNickname:
|
||||
postFilename = locate_post(base_dir, nickname, domain, objectUrl)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, objectUrl)
|
||||
if not post_filename:
|
||||
return None
|
||||
|
||||
undoBookmarksCollectionEntry(recent_posts_cache,
|
||||
base_dir, postFilename, objectUrl,
|
||||
base_dir, post_filename, objectUrl,
|
||||
newUndoBookmarkJson['actor'],
|
||||
domain, debug)
|
||||
else:
|
||||
|
@ -593,17 +595,17 @@ def outboxBookmark(recent_posts_cache: {},
|
|||
|
||||
messageUrl = removeIdEnding(message_json['object']['url'])
|
||||
domain = remove_domain_port(domain)
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageUrl)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageUrl)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: c2s like post not found in inbox or outbox')
|
||||
print(messageUrl)
|
||||
return True
|
||||
updateBookmarksCollection(recent_posts_cache,
|
||||
base_dir, postFilename, messageUrl,
|
||||
base_dir, post_filename, messageUrl,
|
||||
message_json['actor'], domain, debug)
|
||||
if debug:
|
||||
print('DEBUG: post bookmarked via c2s - ' + postFilename)
|
||||
print('DEBUG: post bookmarked via c2s - ' + post_filename)
|
||||
|
||||
|
||||
def outboxUndoBookmark(recent_posts_cache: {},
|
||||
|
@ -649,14 +651,14 @@ def outboxUndoBookmark(recent_posts_cache: {},
|
|||
|
||||
messageUrl = removeIdEnding(message_json['object']['url'])
|
||||
domain = remove_domain_port(domain)
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageUrl)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageUrl)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: c2s unbookmark post not found in inbox or outbox')
|
||||
print(messageUrl)
|
||||
return True
|
||||
updateBookmarksCollection(recent_posts_cache,
|
||||
base_dir, postFilename, messageUrl,
|
||||
base_dir, post_filename, messageUrl,
|
||||
message_json['actor'], domain, debug)
|
||||
if debug:
|
||||
print('DEBUG: post unbookmarked via c2s - ' + postFilename)
|
||||
print('DEBUG: post unbookmarked via c2s - ' + post_filename)
|
||||
|
|
116
daemon.py
116
daemon.py
|
@ -291,7 +291,7 @@ from utils import deletePost
|
|||
from utils import isBlogPost
|
||||
from utils import removeAvatarFromCache
|
||||
from utils import locate_post
|
||||
from utils import getCachedPostFilename
|
||||
from utils import get_cached_post_filename
|
||||
from utils import removePostFromCache
|
||||
from utils import getNicknameFromActor
|
||||
from utils import getDomainFromActor
|
||||
|
@ -524,11 +524,11 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
message_json['object']['name'] = answer
|
||||
if self._postToOutbox(message_json,
|
||||
self.server.project_version, nickname):
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
locate_post(self.server.base_dir, nickname,
|
||||
self.server.domain, messageId)
|
||||
if postFilename:
|
||||
post_json_object = load_json(postFilename)
|
||||
if post_filename:
|
||||
post_json_object = load_json(post_filename)
|
||||
if post_json_object:
|
||||
populateReplies(self.server.base_dir,
|
||||
self.server.http_prefix,
|
||||
|
@ -547,10 +547,10 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
# ensure that the cached post is removed if it exists,
|
||||
# so that it then will be recreated
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(self.server.base_dir,
|
||||
nickname,
|
||||
self.server.domain,
|
||||
post_json_object)
|
||||
get_cached_post_filename(self.server.base_dir,
|
||||
nickname,
|
||||
self.server.domain,
|
||||
post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -2005,33 +2005,33 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
removeAccount(base_dir, nickname, domain, port)
|
||||
else:
|
||||
# remove a post or thread
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
locate_post(base_dir, nickname, domain,
|
||||
moderationText)
|
||||
if postFilename:
|
||||
if post_filename:
|
||||
if canRemovePost(base_dir,
|
||||
nickname, domain, port,
|
||||
moderationText):
|
||||
deletePost(base_dir,
|
||||
http_prefix,
|
||||
nickname, domain,
|
||||
postFilename,
|
||||
post_filename,
|
||||
debug,
|
||||
self.server.recent_posts_cache)
|
||||
if nickname != 'news':
|
||||
# if this is a local blog post then also remove it
|
||||
# from the news actor
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
locate_post(base_dir, 'news', domain,
|
||||
moderationText)
|
||||
if postFilename:
|
||||
if post_filename:
|
||||
if canRemovePost(base_dir,
|
||||
'news', domain, port,
|
||||
moderationText):
|
||||
deletePost(base_dir,
|
||||
http_prefix,
|
||||
'news', domain,
|
||||
postFilename,
|
||||
post_filename,
|
||||
debug,
|
||||
self.server.recent_posts_cache)
|
||||
|
||||
|
@ -4627,11 +4627,11 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
|
||||
if newsPostUrl and newsPostContent and newsPostTitle:
|
||||
# load the post
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
locate_post(base_dir, nickname, domain,
|
||||
newsPostUrl)
|
||||
if postFilename:
|
||||
post_json_object = load_json(postFilename)
|
||||
if post_filename:
|
||||
post_json_object = load_json(post_filename)
|
||||
# update the content and title
|
||||
post_json_object['object']['summary'] = \
|
||||
newsPostTitle
|
||||
|
@ -4666,7 +4666,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
newsId)
|
||||
|
||||
# save the news post
|
||||
save_json(post_json_object, postFilename)
|
||||
save_json(post_json_object, post_filename)
|
||||
|
||||
# redirect back to the default timeline
|
||||
if self.server.news_instance:
|
||||
|
@ -7739,8 +7739,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
if debug:
|
||||
print('Generating html post for announce')
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, self.postToNickname,
|
||||
domain, announceJson)
|
||||
get_cached_post_filename(base_dir, self.postToNickname,
|
||||
domain, announceJson)
|
||||
if debug:
|
||||
print('Announced post json: ' + str(announceJson))
|
||||
print('Announced post nickname: ' +
|
||||
|
@ -7867,15 +7867,15 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
announceUrl = path.split('?unannounce=')[1]
|
||||
if '?' in announceUrl:
|
||||
announceUrl = announceUrl.split('?')[0]
|
||||
postFilename = None
|
||||
post_filename = None
|
||||
nickname = getNicknameFromActor(announceUrl)
|
||||
if nickname:
|
||||
if domain_full + '/users/' + nickname + '/' in announceUrl:
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
locate_post(base_dir, nickname, domain, announceUrl)
|
||||
if postFilename:
|
||||
if post_filename:
|
||||
deletePost(base_dir, http_prefix,
|
||||
nickname, domain, postFilename,
|
||||
nickname, domain, post_filename,
|
||||
debug, recent_posts_cache)
|
||||
|
||||
self._postToOutbox(newUndoAnnounce,
|
||||
|
@ -8200,8 +8200,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
# clear the icon from the cache so that it gets updated
|
||||
if likedPostJson:
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, self.postToNickname,
|
||||
domain, likedPostJson)
|
||||
get_cached_post_filename(base_dir, self.postToNickname,
|
||||
domain, likedPostJson)
|
||||
if debug:
|
||||
print('Liked post json: ' + str(likedPostJson))
|
||||
print('Liked post nickname: ' +
|
||||
|
@ -8538,8 +8538,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
# clear the icon from the cache so that it gets updated
|
||||
if reactionPostJson:
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, self.postToNickname,
|
||||
domain, reactionPostJson)
|
||||
get_cached_post_filename(base_dir, self.postToNickname,
|
||||
domain, reactionPostJson)
|
||||
if debug:
|
||||
print('Reaction post json: ' + str(reactionPostJson))
|
||||
print('Reaction post nickname: ' +
|
||||
|
@ -8932,8 +8932,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
bookmarkPostJson = load_json(bookmarkFilename, 0, 1)
|
||||
if bookmarkPostJson:
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, self.postToNickname,
|
||||
domain, bookmarkPostJson)
|
||||
get_cached_post_filename(base_dir, self.postToNickname,
|
||||
domain, bookmarkPostJson)
|
||||
print('Bookmarked post json: ' + str(bookmarkPostJson))
|
||||
print('Bookmarked post nickname: ' +
|
||||
self.postToNickname + ' ' + domain)
|
||||
|
@ -9060,8 +9060,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
bookmarkPostJson = load_json(bookmarkFilename, 0, 1)
|
||||
if bookmarkPostJson:
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, self.postToNickname,
|
||||
domain, bookmarkPostJson)
|
||||
get_cached_post_filename(base_dir, self.postToNickname,
|
||||
domain, bookmarkPostJson)
|
||||
print('Unbookmarked post json: ' + str(bookmarkPostJson))
|
||||
print('Unbookmarked post nickname: ' +
|
||||
self.postToNickname + ' ' + domain)
|
||||
|
@ -9255,8 +9255,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
mutePostJson = load_json(muteFilename, 0, 1)
|
||||
if mutePostJson:
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname,
|
||||
domain, mutePostJson)
|
||||
get_cached_post_filename(base_dir, nickname,
|
||||
domain, mutePostJson)
|
||||
print('mutePost: Muted post json: ' + str(mutePostJson))
|
||||
print('mutePost: Muted post nickname: ' +
|
||||
nickname + ' ' + domain)
|
||||
|
@ -9365,8 +9365,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
mutePostJson = load_json(muteFilename, 0, 1)
|
||||
if mutePostJson:
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname,
|
||||
domain, mutePostJson)
|
||||
get_cached_post_filename(base_dir, nickname,
|
||||
domain, mutePostJson)
|
||||
print('unmutePost: Unmuted post json: ' + str(mutePostJson))
|
||||
print('unmutePost: Unmuted post nickname: ' +
|
||||
nickname + ' ' + domain)
|
||||
|
@ -9930,7 +9930,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
if len(statusNumber) <= 10 or not statusNumber.isdigit():
|
||||
return False
|
||||
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
acct_dir(base_dir, nickname, domain) + '/outbox/' + \
|
||||
http_prefix + ':##' + domain_full + '#users#' + nickname + \
|
||||
'#statuses#' + statusNumber + '.json'
|
||||
|
@ -9939,7 +9939,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
if postSections[-1] == 'activity':
|
||||
includeCreateWrapper = True
|
||||
|
||||
result = self._showPostFromFile(postFilename, likedBy,
|
||||
result = self._showPostFromFile(post_filename, likedBy,
|
||||
reactBy, reactEmoji,
|
||||
authorized, calling_domain, path,
|
||||
base_dir, http_prefix, nickname,
|
||||
|
@ -9953,7 +9953,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.debug)
|
||||
return result
|
||||
|
||||
def _showPostFromFile(self, postFilename: str, likedBy: str,
|
||||
def _showPostFromFile(self, post_filename: str, likedBy: str,
|
||||
reactBy: str, reactEmoji: str,
|
||||
authorized: bool,
|
||||
calling_domain: str, path: str,
|
||||
|
@ -9965,12 +9965,12 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
debug: str, includeCreateWrapper: bool) -> bool:
|
||||
"""Shows an individual post from its filename
|
||||
"""
|
||||
if not os.path.isfile(postFilename):
|
||||
if not os.path.isfile(post_filename):
|
||||
self._404()
|
||||
self.server.GETbusy = False
|
||||
return True
|
||||
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not post_json_object:
|
||||
self.send_response(429)
|
||||
self.end_headers()
|
||||
|
@ -10088,7 +10088,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
if len(statusNumber) <= 10 or (not statusNumber.isdigit()):
|
||||
return False
|
||||
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
acct_dir(base_dir, nickname, domain) + '/outbox/' + \
|
||||
http_prefix + ':##' + domain_full + '#users#' + nickname + \
|
||||
'#statuses#' + statusNumber + '.json'
|
||||
|
@ -10097,7 +10097,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
if postSections[-1] == 'activity':
|
||||
includeCreateWrapper = True
|
||||
|
||||
result = self._showPostFromFile(postFilename, likedBy,
|
||||
result = self._showPostFromFile(post_filename, likedBy,
|
||||
reactBy, reactEmoji,
|
||||
authorized, calling_domain, path,
|
||||
base_dir, http_prefix, nickname,
|
||||
|
@ -10133,16 +10133,16 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
return False
|
||||
replies = False
|
||||
|
||||
postFilename = locate_post(base_dir, nickname, domain,
|
||||
post_id, replies)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain,
|
||||
post_id, replies)
|
||||
if not post_filename:
|
||||
return False
|
||||
|
||||
includeCreateWrapper = False
|
||||
if path.endswith('/activity'):
|
||||
includeCreateWrapper = True
|
||||
|
||||
result = self._showPostFromFile(postFilename, likedBy,
|
||||
result = self._showPostFromFile(post_filename, likedBy,
|
||||
reactBy, reactEmoji,
|
||||
authorized, calling_domain, path,
|
||||
base_dir, http_prefix, nickname,
|
||||
|
@ -16749,12 +16749,12 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
return -1
|
||||
elif postType == 'editblogpost':
|
||||
print('Edited blog post received')
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
locate_post(self.server.base_dir,
|
||||
nickname, self.server.domain,
|
||||
fields['postUrl'])
|
||||
if os.path.isfile(postFilename):
|
||||
post_json_object = load_json(postFilename)
|
||||
if os.path.isfile(post_filename):
|
||||
post_json_object = load_json(post_filename)
|
||||
if post_json_object:
|
||||
cachedFilename = \
|
||||
acct_dir(self.server.base_dir,
|
||||
|
@ -16832,19 +16832,19 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
replaceTwitter(post_json_object,
|
||||
self.server.twitter_replacement_domain,
|
||||
self.server.system_language)
|
||||
save_json(post_json_object, postFilename)
|
||||
save_json(post_json_object, post_filename)
|
||||
# also save to the news actor
|
||||
if nickname != 'news':
|
||||
postFilename = \
|
||||
postFilename.replace('#users#' +
|
||||
nickname + '#',
|
||||
'#users#news#')
|
||||
save_json(post_json_object, postFilename)
|
||||
print('Edited blog post, resaved ' + postFilename)
|
||||
post_filename = \
|
||||
post_filename.replace('#users#' +
|
||||
nickname + '#',
|
||||
'#users#news#')
|
||||
save_json(post_json_object, post_filename)
|
||||
print('Edited blog post, resaved ' + post_filename)
|
||||
return 1
|
||||
else:
|
||||
print('Edited blog post, unable to load json for ' +
|
||||
postFilename)
|
||||
post_filename)
|
||||
else:
|
||||
print('Edited blog post not found ' +
|
||||
str(fields['postUrl']))
|
||||
|
|
10
delete.py
10
delete.py
|
@ -161,17 +161,17 @@ def outboxDelete(base_dir: str, http_prefix: str,
|
|||
"wasn't created by you (domain does not match)")
|
||||
return
|
||||
removeModerationPostFromIndex(base_dir, messageId, debug)
|
||||
postFilename = locate_post(base_dir, deleteNickname, deleteDomain,
|
||||
messageId)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, deleteNickname, deleteDomain,
|
||||
messageId)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: c2s delete post not found in inbox or outbox')
|
||||
print(messageId)
|
||||
return True
|
||||
deletePost(base_dir, http_prefix, deleteNickname, deleteDomain,
|
||||
postFilename, debug, recent_posts_cache)
|
||||
post_filename, debug, recent_posts_cache)
|
||||
if debug:
|
||||
print('DEBUG: post deleted via c2s - ' + postFilename)
|
||||
print('DEBUG: post deleted via c2s - ' + post_filename)
|
||||
|
||||
|
||||
def removeOldHashtags(base_dir: str, maxMonths: int) -> str:
|
||||
|
|
24
happening.py
24
happening.py
|
@ -205,12 +205,12 @@ def getTodaysEvents(base_dir: str, nickname: str, domain: str,
|
|||
with open(calendarFilename, 'r') as eventsFile:
|
||||
for post_id in eventsFile:
|
||||
post_id = post_id.replace('\n', '').replace('\r', '')
|
||||
postFilename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not post_filename:
|
||||
recreateEventsFile = True
|
||||
continue
|
||||
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not _isHappeningPost(post_json_object):
|
||||
continue
|
||||
|
||||
|
@ -280,11 +280,11 @@ def dayEventsCheck(base_dir: str, nickname: str, domain: str,
|
|||
with open(calendarFilename, 'r') as eventsFile:
|
||||
for post_id in eventsFile:
|
||||
post_id = post_id.replace('\n', '').replace('\r', '')
|
||||
postFilename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not post_filename:
|
||||
continue
|
||||
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not _isHappeningPost(post_json_object):
|
||||
continue
|
||||
|
||||
|
@ -336,12 +336,12 @@ def getThisWeeksEvents(base_dir: str, nickname: str, domain: str) -> {}:
|
|||
with open(calendarFilename, 'r') as eventsFile:
|
||||
for post_id in eventsFile:
|
||||
post_id = post_id.replace('\n', '').replace('\r', '')
|
||||
postFilename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not post_filename:
|
||||
recreateEventsFile = True
|
||||
continue
|
||||
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not _isHappeningPost(post_json_object):
|
||||
continue
|
||||
|
||||
|
@ -401,12 +401,12 @@ def getCalendarEvents(base_dir: str, nickname: str, domain: str,
|
|||
with open(calendarFilename, 'r') as eventsFile:
|
||||
for post_id in eventsFile:
|
||||
post_id = post_id.replace('\n', '').replace('\r', '')
|
||||
postFilename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not post_filename:
|
||||
recreateEventsFile = True
|
||||
continue
|
||||
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not _isHappeningPost(post_json_object):
|
||||
continue
|
||||
|
||||
|
|
189
inbox.py
189
inbox.py
|
@ -44,7 +44,7 @@ from utils import getProtocolPrefixes
|
|||
from utils import isBlogPost
|
||||
from utils import removeAvatarFromCache
|
||||
from utils import isPublicPost
|
||||
from utils import getCachedPostFilename
|
||||
from utils import get_cached_post_filename
|
||||
from utils import removePostFromCache
|
||||
from utils import urlPermitted
|
||||
from utils import createInboxQueueDir
|
||||
|
@ -86,7 +86,7 @@ from blocking import isBlocked
|
|||
from blocking import isBlockedDomain
|
||||
from blocking import broch_modeLapses
|
||||
from filters import isFiltered
|
||||
from utils import updateAnnounceCollection
|
||||
from utils import update_announce_collection
|
||||
from utils import undoAnnounceCollectionEntry
|
||||
from utils import dangerousMarkup
|
||||
from utils import is_dm
|
||||
|
@ -913,11 +913,11 @@ def _receiveUpdateToQuestion(recent_posts_cache: {}, message_json: {},
|
|||
if '#' in messageId:
|
||||
messageId = messageId.split('#', 1)[0]
|
||||
# find the question post
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not post_filename:
|
||||
return
|
||||
# load the json for the question
|
||||
post_json_object = load_json(postFilename, 1)
|
||||
post_json_object = load_json(post_filename, 1)
|
||||
if not post_json_object:
|
||||
return
|
||||
if not post_json_object.get('actor'):
|
||||
|
@ -925,11 +925,11 @@ def _receiveUpdateToQuestion(recent_posts_cache: {}, message_json: {},
|
|||
# does the actor match?
|
||||
if post_json_object['actor'] != message_json['actor']:
|
||||
return
|
||||
save_json(message_json, postFilename)
|
||||
save_json(message_json, post_filename)
|
||||
# ensure that the cached post is removed if it exists, so
|
||||
# that it then will be recreated
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname, domain, message_json)
|
||||
get_cached_post_filename(base_dir, nickname, domain, message_json)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -1038,8 +1038,8 @@ def _receiveLike(recent_posts_cache: {},
|
|||
handleName = handle.split('@')[0]
|
||||
handleDom = handle.split('@')[1]
|
||||
postLikedId = message_json['object']
|
||||
postFilename = locate_post(base_dir, handleName, handleDom, postLikedId)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, handleName, handleDom, postLikedId)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: post not found in inbox or outbox')
|
||||
print(postLikedId)
|
||||
|
@ -1056,11 +1056,11 @@ def _receiveLike(recent_posts_cache: {},
|
|||
likeActor):
|
||||
_likeNotify(base_dir, domain, onion_domain, handle,
|
||||
likeActor, postLikedId)
|
||||
updateLikesCollection(recent_posts_cache, base_dir, postFilename,
|
||||
updateLikesCollection(recent_posts_cache, base_dir, post_filename,
|
||||
postLikedId, likeActor,
|
||||
handleName, domain, debug, None)
|
||||
# regenerate the html
|
||||
likedPostJson = load_json(postFilename, 0, 1)
|
||||
likedPostJson = load_json(post_filename, 0, 1)
|
||||
if likedPostJson:
|
||||
if likedPostJson.get('type'):
|
||||
if likedPostJson['type'] == 'Announce' and \
|
||||
|
@ -1072,10 +1072,10 @@ def _receiveLike(recent_posts_cache: {},
|
|||
domain, announceLikeUrl)
|
||||
if announceLikedFilename:
|
||||
postLikedId = announceLikeUrl
|
||||
postFilename = announceLikedFilename
|
||||
post_filename = announceLikedFilename
|
||||
updateLikesCollection(recent_posts_cache,
|
||||
base_dir,
|
||||
postFilename,
|
||||
post_filename,
|
||||
postLikedId,
|
||||
likeActor,
|
||||
handleName,
|
||||
|
@ -1083,8 +1083,8 @@ def _receiveLike(recent_posts_cache: {},
|
|||
if likedPostJson:
|
||||
if debug:
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, handleName, domain,
|
||||
likedPostJson)
|
||||
get_cached_post_filename(base_dir, handleName, domain,
|
||||
likedPostJson)
|
||||
print('Liked post json: ' + str(likedPostJson))
|
||||
print('Liked post nickname: ' + handleName + ' ' + domain)
|
||||
print('Liked post cache: ' + str(cachedPostFilename))
|
||||
|
@ -1159,10 +1159,10 @@ def _receiveUndoLike(recent_posts_cache: {},
|
|||
# if this post in the outbox of the person?
|
||||
handleName = handle.split('@')[0]
|
||||
handleDom = handle.split('@')[1]
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
locate_post(base_dir, handleName, handleDom,
|
||||
message_json['object']['object'])
|
||||
if not postFilename:
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: unliked post not found in inbox or outbox')
|
||||
print(message_json['object']['object'])
|
||||
|
@ -1171,10 +1171,10 @@ def _receiveUndoLike(recent_posts_cache: {},
|
|||
print('DEBUG: liked post found in inbox. Now undoing.')
|
||||
likeActor = message_json['actor']
|
||||
postLikedId = message_json['object']
|
||||
undoLikesCollectionEntry(recent_posts_cache, base_dir, postFilename,
|
||||
undoLikesCollectionEntry(recent_posts_cache, base_dir, post_filename,
|
||||
postLikedId, likeActor, domain, debug, None)
|
||||
# regenerate the html
|
||||
likedPostJson = load_json(postFilename, 0, 1)
|
||||
likedPostJson = load_json(post_filename, 0, 1)
|
||||
if likedPostJson:
|
||||
if likedPostJson.get('type'):
|
||||
if likedPostJson['type'] == 'Announce' and \
|
||||
|
@ -1186,16 +1186,16 @@ def _receiveUndoLike(recent_posts_cache: {},
|
|||
domain, announceLikeUrl)
|
||||
if announceLikedFilename:
|
||||
postLikedId = announceLikeUrl
|
||||
postFilename = announceLikedFilename
|
||||
post_filename = announceLikedFilename
|
||||
undoLikesCollectionEntry(recent_posts_cache, base_dir,
|
||||
postFilename, postLikedId,
|
||||
post_filename, postLikedId,
|
||||
likeActor, domain, debug,
|
||||
None)
|
||||
if likedPostJson:
|
||||
if debug:
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, handleName, domain,
|
||||
likedPostJson)
|
||||
get_cached_post_filename(base_dir, handleName, domain,
|
||||
likedPostJson)
|
||||
print('Unliked post json: ' + str(likedPostJson))
|
||||
print('Unliked post nickname: ' + handleName + ' ' + domain)
|
||||
print('Unliked post cache: ' + str(cachedPostFilename))
|
||||
|
@ -1295,8 +1295,9 @@ def _receiveReaction(recent_posts_cache: {},
|
|||
if debug:
|
||||
print('DEBUG: emoji reaction has no content')
|
||||
return True
|
||||
postFilename = locate_post(base_dir, handleName, handleDom, postReactionId)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, handleName, handleDom,
|
||||
postReactionId)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: emoji reaction post not found in inbox or outbox')
|
||||
print(postReactionId)
|
||||
|
@ -1314,11 +1315,11 @@ def _receiveReaction(recent_posts_cache: {},
|
|||
emojiContent):
|
||||
_reactionNotify(base_dir, domain, onion_domain, handle,
|
||||
reactionActor, postReactionId, emojiContent)
|
||||
updateReactionCollection(recent_posts_cache, base_dir, postFilename,
|
||||
updateReactionCollection(recent_posts_cache, base_dir, post_filename,
|
||||
postReactionId, reactionActor,
|
||||
handleName, domain, debug, None, emojiContent)
|
||||
# regenerate the html
|
||||
reactionPostJson = load_json(postFilename, 0, 1)
|
||||
reactionPostJson = load_json(post_filename, 0, 1)
|
||||
if reactionPostJson:
|
||||
if reactionPostJson.get('type'):
|
||||
if reactionPostJson['type'] == 'Announce' and \
|
||||
|
@ -1330,10 +1331,10 @@ def _receiveReaction(recent_posts_cache: {},
|
|||
domain, announceReactionUrl)
|
||||
if announceReactionFilename:
|
||||
postReactionId = announceReactionUrl
|
||||
postFilename = announceReactionFilename
|
||||
post_filename = announceReactionFilename
|
||||
updateReactionCollection(recent_posts_cache,
|
||||
base_dir,
|
||||
postFilename,
|
||||
post_filename,
|
||||
postReactionId,
|
||||
reactionActor,
|
||||
handleName,
|
||||
|
@ -1342,8 +1343,8 @@ def _receiveReaction(recent_posts_cache: {},
|
|||
if reactionPostJson:
|
||||
if debug:
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, handleName, domain,
|
||||
reactionPostJson)
|
||||
get_cached_post_filename(base_dir, handleName, domain,
|
||||
reactionPostJson)
|
||||
print('Reaction post json: ' + str(reactionPostJson))
|
||||
print('Reaction post nickname: ' + handleName + ' ' + domain)
|
||||
print('Reaction post cache: ' + str(cachedPostFilename))
|
||||
|
@ -1428,10 +1429,10 @@ def _receiveUndoReaction(recent_posts_cache: {},
|
|||
# if this post in the outbox of the person?
|
||||
handleName = handle.split('@')[0]
|
||||
handleDom = handle.split('@')[1]
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
locate_post(base_dir, handleName, handleDom,
|
||||
message_json['object']['object'])
|
||||
if not postFilename:
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: unreaction post not found in inbox or outbox')
|
||||
print(message_json['object']['object'])
|
||||
|
@ -1445,11 +1446,11 @@ def _receiveUndoReaction(recent_posts_cache: {},
|
|||
if debug:
|
||||
print('DEBUG: unreaction has no content')
|
||||
return True
|
||||
undoReactionCollectionEntry(recent_posts_cache, base_dir, postFilename,
|
||||
undoReactionCollectionEntry(recent_posts_cache, base_dir, post_filename,
|
||||
postReactionId, reactionActor, domain,
|
||||
debug, None, emojiContent)
|
||||
# regenerate the html
|
||||
reactionPostJson = load_json(postFilename, 0, 1)
|
||||
reactionPostJson = load_json(post_filename, 0, 1)
|
||||
if reactionPostJson:
|
||||
if reactionPostJson.get('type'):
|
||||
if reactionPostJson['type'] == 'Announce' and \
|
||||
|
@ -1461,10 +1462,10 @@ def _receiveUndoReaction(recent_posts_cache: {},
|
|||
domain, announceReactionUrl)
|
||||
if announceReactionFilename:
|
||||
postReactionId = announceReactionUrl
|
||||
postFilename = announceReactionFilename
|
||||
post_filename = announceReactionFilename
|
||||
undoReactionCollectionEntry(recent_posts_cache,
|
||||
base_dir,
|
||||
postFilename,
|
||||
post_filename,
|
||||
postReactionId,
|
||||
reactionActor, domain,
|
||||
debug, None,
|
||||
|
@ -1472,8 +1473,8 @@ def _receiveUndoReaction(recent_posts_cache: {},
|
|||
if reactionPostJson:
|
||||
if debug:
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, handleName, domain,
|
||||
reactionPostJson)
|
||||
get_cached_post_filename(base_dir, handleName, domain,
|
||||
reactionPostJson)
|
||||
print('Unreaction post json: ' + str(reactionPostJson))
|
||||
print('Unreaction post nickname: ' + handleName + ' ' + domain)
|
||||
print('Unreaction post cache: ' + str(cachedPostFilename))
|
||||
|
@ -1567,23 +1568,23 @@ def _receiveBookmark(recent_posts_cache: {},
|
|||
|
||||
messageUrl = removeIdEnding(message_json['object']['url'])
|
||||
domain = remove_domain_port(domain)
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageUrl)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageUrl)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: c2s inbox like post not found in inbox or outbox')
|
||||
print(messageUrl)
|
||||
return True
|
||||
|
||||
updateBookmarksCollection(recent_posts_cache, base_dir, postFilename,
|
||||
updateBookmarksCollection(recent_posts_cache, base_dir, post_filename,
|
||||
message_json['object']['url'],
|
||||
message_json['actor'], domain, debug)
|
||||
# regenerate the html
|
||||
bookmarkedPostJson = load_json(postFilename, 0, 1)
|
||||
bookmarkedPostJson = load_json(post_filename, 0, 1)
|
||||
if bookmarkedPostJson:
|
||||
if debug:
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname, domain,
|
||||
bookmarkedPostJson)
|
||||
get_cached_post_filename(base_dir, nickname, domain,
|
||||
bookmarkedPostJson)
|
||||
print('Bookmarked post json: ' + str(bookmarkedPostJson))
|
||||
print('Bookmarked post nickname: ' + nickname + ' ' + domain)
|
||||
print('Bookmarked post cache: ' + str(cachedPostFilename))
|
||||
|
@ -1680,23 +1681,23 @@ def _receiveUndoBookmark(recent_posts_cache: {},
|
|||
|
||||
messageUrl = removeIdEnding(message_json['object']['url'])
|
||||
domain = remove_domain_port(domain)
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageUrl)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageUrl)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: c2s inbox like post not found in inbox or outbox')
|
||||
print(messageUrl)
|
||||
return True
|
||||
|
||||
undoBookmarksCollectionEntry(recent_posts_cache, base_dir, postFilename,
|
||||
undoBookmarksCollectionEntry(recent_posts_cache, base_dir, post_filename,
|
||||
message_json['object']['url'],
|
||||
message_json['actor'], domain, debug)
|
||||
# regenerate the html
|
||||
bookmarkedPostJson = load_json(postFilename, 0, 1)
|
||||
bookmarkedPostJson = load_json(post_filename, 0, 1)
|
||||
if bookmarkedPostJson:
|
||||
if debug:
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname, domain,
|
||||
bookmarkedPostJson)
|
||||
get_cached_post_filename(base_dir, nickname, domain,
|
||||
bookmarkedPostJson)
|
||||
print('Unbookmarked post json: ' + str(bookmarkedPostJson))
|
||||
print('Unbookmarked post nickname: ' + nickname + ' ' + domain)
|
||||
print('Unbookmarked post cache: ' + str(cachedPostFilename))
|
||||
|
@ -1776,29 +1777,29 @@ def _receiveDelete(session, handle: str, isGroup: bool, base_dir: str,
|
|||
removeModerationPostFromIndex(base_dir, messageId, debug)
|
||||
handleNickname = handle.split('@')[0]
|
||||
handleDomain = handle.split('@')[1]
|
||||
postFilename = locate_post(base_dir, handleNickname,
|
||||
handleDomain, messageId)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, handleNickname,
|
||||
handleDomain, messageId)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: delete post not found in inbox or outbox')
|
||||
print(messageId)
|
||||
return True
|
||||
deletePost(base_dir, http_prefix, handleNickname,
|
||||
handleDomain, postFilename, debug,
|
||||
handleDomain, post_filename, debug,
|
||||
recent_posts_cache)
|
||||
if debug:
|
||||
print('DEBUG: post deleted - ' + postFilename)
|
||||
print('DEBUG: post deleted - ' + post_filename)
|
||||
|
||||
# also delete any local blogs saved to the news actor
|
||||
if handleNickname != 'news' and handleDomain == domain_full:
|
||||
postFilename = locate_post(base_dir, 'news',
|
||||
handleDomain, messageId)
|
||||
if postFilename:
|
||||
post_filename = locate_post(base_dir, 'news',
|
||||
handleDomain, messageId)
|
||||
if post_filename:
|
||||
deletePost(base_dir, http_prefix, 'news',
|
||||
handleDomain, postFilename, debug,
|
||||
handleDomain, post_filename, debug,
|
||||
recent_posts_cache)
|
||||
if debug:
|
||||
print('DEBUG: blog post deleted - ' + postFilename)
|
||||
print('DEBUG: blog post deleted - ' + post_filename)
|
||||
return True
|
||||
|
||||
|
||||
|
@ -1889,15 +1890,15 @@ def _receiveAnnounce(recent_posts_cache: {},
|
|||
return False
|
||||
|
||||
# is this post in the outbox of the person?
|
||||
postFilename = locate_post(base_dir, nickname, domain,
|
||||
message_json['object'])
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain,
|
||||
message_json['object'])
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: announce post not found in inbox or outbox')
|
||||
print(message_json['object'])
|
||||
return True
|
||||
updateAnnounceCollection(recent_posts_cache, base_dir, postFilename,
|
||||
message_json['actor'], nickname, domain, debug)
|
||||
update_announce_collection(recent_posts_cache, base_dir, post_filename,
|
||||
message_json['actor'], nickname, domain, debug)
|
||||
if debug:
|
||||
print('DEBUG: Downloading announce post ' + message_json['actor'] +
|
||||
' -> ' + message_json['object'])
|
||||
|
@ -1959,13 +1960,13 @@ def _receiveAnnounce(recent_posts_cache: {},
|
|||
if onion_domain in message_json['object']:
|
||||
notInOnion = False
|
||||
if domain not in message_json['object'] and notInOnion:
|
||||
if os.path.isfile(postFilename):
|
||||
if os.path.isfile(post_filename):
|
||||
# if the announce can't be downloaded then remove it
|
||||
try:
|
||||
os.remove(postFilename)
|
||||
os.remove(post_filename)
|
||||
except OSError:
|
||||
print('EX: _receiveAnnounce unable to delete ' +
|
||||
str(postFilename))
|
||||
str(post_filename))
|
||||
else:
|
||||
if debug:
|
||||
print('DEBUG: Announce post downloaded for ' +
|
||||
|
@ -1991,7 +1992,7 @@ def _receiveAnnounce(recent_posts_cache: {},
|
|||
lookupActor = lookupActor.split('/statuses/')[0]
|
||||
|
||||
if is_recent_post(post_json_object, 3):
|
||||
if not os.path.isfile(postFilename + '.tts'):
|
||||
if not os.path.isfile(post_filename + '.tts'):
|
||||
domain_full = get_full_domain(domain, port)
|
||||
updateSpeaker(base_dir, http_prefix,
|
||||
nickname, domain, domain_full,
|
||||
|
@ -1999,11 +2000,11 @@ def _receiveAnnounce(recent_posts_cache: {},
|
|||
translate, lookupActor,
|
||||
theme_name)
|
||||
try:
|
||||
with open(postFilename + '.tts', 'w+') as ttsFile:
|
||||
with open(post_filename + '.tts', 'w+') as ttsFile:
|
||||
ttsFile.write('\n')
|
||||
except OSError:
|
||||
print('EX: unable to write recent post ' +
|
||||
postFilename)
|
||||
post_filename)
|
||||
|
||||
if debug:
|
||||
print('DEBUG: Obtaining actor for announce post ' +
|
||||
|
@ -2060,9 +2061,9 @@ def _receiveUndoAnnounce(recent_posts_cache: {},
|
|||
# if this post in the outbox of the person?
|
||||
handleName = handle.split('@')[0]
|
||||
handleDom = handle.split('@')[1]
|
||||
postFilename = locate_post(base_dir, handleName, handleDom,
|
||||
message_json['object']['object'])
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, handleName, handleDom,
|
||||
message_json['object']['object'])
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: undo announce post not found in inbox or outbox')
|
||||
print(message_json['object']['object'])
|
||||
|
@ -2070,7 +2071,7 @@ def _receiveUndoAnnounce(recent_posts_cache: {},
|
|||
if debug:
|
||||
print('DEBUG: announced/repeated post to be undone found in inbox')
|
||||
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if post_json_object:
|
||||
if not post_json_object.get('type'):
|
||||
if post_json_object['type'] != 'Announce':
|
||||
|
@ -2078,14 +2079,14 @@ def _receiveUndoAnnounce(recent_posts_cache: {},
|
|||
print("DEBUG: Attempt to undo something " +
|
||||
"which isn't an announcement")
|
||||
return False
|
||||
undoAnnounceCollectionEntry(recent_posts_cache, base_dir, postFilename,
|
||||
undoAnnounceCollectionEntry(recent_posts_cache, base_dir, post_filename,
|
||||
message_json['actor'], domain, debug)
|
||||
if os.path.isfile(postFilename):
|
||||
if os.path.isfile(post_filename):
|
||||
try:
|
||||
os.remove(postFilename)
|
||||
os.remove(post_filename)
|
||||
except OSError:
|
||||
print('EX: _receiveUndoAnnounce unable to delete ' +
|
||||
str(postFilename))
|
||||
str(post_filename))
|
||||
return True
|
||||
|
||||
|
||||
|
@ -2106,10 +2107,10 @@ def jsonPostAllowsComments(post_json_object: {}) -> bool:
|
|||
return True
|
||||
|
||||
|
||||
def _postAllowsComments(postFilename: str) -> bool:
|
||||
def _postAllowsComments(post_filename: str) -> bool:
|
||||
"""Returns true if the given post allows comments/replies
|
||||
"""
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not post_json_object:
|
||||
return False
|
||||
return jsonPostAllowsComments(post_json_object)
|
||||
|
@ -2150,19 +2151,19 @@ def populateReplies(base_dir: str, http_prefix: str, domain: str,
|
|||
print('DEBUG: no domain found for ' + replyTo)
|
||||
return False
|
||||
|
||||
postFilename = locate_post(base_dir, replyToNickname,
|
||||
replyToDomain, replyTo)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, replyToNickname,
|
||||
replyToDomain, replyTo)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: post may have expired - ' + replyTo)
|
||||
return False
|
||||
|
||||
if not _postAllowsComments(postFilename):
|
||||
if not _postAllowsComments(post_filename):
|
||||
if debug:
|
||||
print('DEBUG: post does not allow comments - ' + replyTo)
|
||||
return False
|
||||
# populate a text file containing the ids of replies
|
||||
postRepliesFilename = postFilename.replace('.json', '.replies')
|
||||
postRepliesFilename = post_filename.replace('.json', '.replies')
|
||||
messageId = removeIdEnding(message_json['id'])
|
||||
if os.path.isfile(postRepliesFilename):
|
||||
numLines = sum(1 for line in open(postRepliesFilename))
|
||||
|
@ -2365,11 +2366,11 @@ def _alreadyLiked(base_dir: str, nickname: str, domain: str,
|
|||
postUrl: str, likerActor: str) -> bool:
|
||||
"""Is the given post already liked by the given handle?
|
||||
"""
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
locate_post(base_dir, nickname, domain, postUrl)
|
||||
if not postFilename:
|
||||
if not post_filename:
|
||||
return False
|
||||
post_json_object = load_json(postFilename, 1)
|
||||
post_json_object = load_json(post_filename, 1)
|
||||
if not post_json_object:
|
||||
return False
|
||||
if not has_object_dict(post_json_object):
|
||||
|
@ -2395,11 +2396,11 @@ def _alreadyReacted(base_dir: str, nickname: str, domain: str,
|
|||
emojiContent: str) -> bool:
|
||||
"""Is the given post already emoji reacted by the given handle?
|
||||
"""
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
locate_post(base_dir, nickname, domain, postUrl)
|
||||
if not postFilename:
|
||||
if not post_filename:
|
||||
return False
|
||||
post_json_object = load_json(postFilename, 1)
|
||||
post_json_object = load_json(post_filename, 1)
|
||||
if not post_json_object:
|
||||
return False
|
||||
if not has_object_dict(post_json_object):
|
||||
|
@ -3013,7 +3014,7 @@ def _receiveQuestionVote(base_dir: str, nickname: str, domain: str,
|
|||
# ensure that the cached post is removed if it exists, so
|
||||
# that it then will be recreated
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname, domain, questionJson)
|
||||
get_cached_post_filename(base_dir, nickname, domain, questionJson)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
|
35
like.py
35
like.py
|
@ -27,7 +27,7 @@ from utils import local_actor_url
|
|||
from utils import load_json
|
||||
from utils import save_json
|
||||
from utils import removePostFromCache
|
||||
from utils import getCachedPostFilename
|
||||
from utils import get_cached_post_filename
|
||||
from posts import sendSignedJson
|
||||
from session import postJson
|
||||
from webfinger import webfingerHandle
|
||||
|
@ -119,8 +119,8 @@ def _like(recent_posts_cache: {},
|
|||
has_group_type(base_dir, actorLiked, person_cache)
|
||||
|
||||
if likedPostNickname:
|
||||
postFilename = locate_post(base_dir, nickname, domain, objectUrl)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, objectUrl)
|
||||
if not post_filename:
|
||||
print('DEBUG: like base_dir: ' + base_dir)
|
||||
print('DEBUG: like nickname: ' + nickname)
|
||||
print('DEBUG: like domain: ' + domain)
|
||||
|
@ -128,7 +128,7 @@ def _like(recent_posts_cache: {},
|
|||
return None
|
||||
|
||||
updateLikesCollection(recent_posts_cache,
|
||||
base_dir, postFilename, objectUrl,
|
||||
base_dir, post_filename, objectUrl,
|
||||
newLikeJson['actor'],
|
||||
nickname, domain, debug, None)
|
||||
|
||||
|
@ -360,18 +360,18 @@ def outboxLike(recent_posts_cache: {},
|
|||
|
||||
messageId = removeIdEnding(message_json['object'])
|
||||
domain = remove_domain_port(domain)
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: c2s like post not found in inbox or outbox')
|
||||
print(messageId)
|
||||
return True
|
||||
updateLikesCollection(recent_posts_cache,
|
||||
base_dir, postFilename, messageId,
|
||||
base_dir, post_filename, messageId,
|
||||
message_json['actor'],
|
||||
nickname, domain, debug, None)
|
||||
if debug:
|
||||
print('DEBUG: post liked via c2s - ' + postFilename)
|
||||
print('DEBUG: post liked via c2s - ' + post_filename)
|
||||
|
||||
|
||||
def outboxUndoLike(recent_posts_cache: {},
|
||||
|
@ -397,36 +397,37 @@ def outboxUndoLike(recent_posts_cache: {},
|
|||
|
||||
messageId = removeIdEnding(message_json['object']['object'])
|
||||
domain = remove_domain_port(domain)
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: c2s undo like post not found in inbox or outbox')
|
||||
print(messageId)
|
||||
return True
|
||||
undoLikesCollectionEntry(recent_posts_cache, base_dir, postFilename,
|
||||
undoLikesCollectionEntry(recent_posts_cache, base_dir, post_filename,
|
||||
messageId, message_json['actor'],
|
||||
domain, debug, None)
|
||||
if debug:
|
||||
print('DEBUG: post undo liked via c2s - ' + postFilename)
|
||||
print('DEBUG: post undo liked via c2s - ' + post_filename)
|
||||
|
||||
|
||||
def updateLikesCollection(recent_posts_cache: {},
|
||||
base_dir: str, postFilename: str,
|
||||
base_dir: str, post_filename: str,
|
||||
objectUrl: str, actor: str,
|
||||
nickname: str, domain: str, debug: bool,
|
||||
post_json_object: {}) -> None:
|
||||
"""Updates the likes collection within a post
|
||||
"""
|
||||
if not post_json_object:
|
||||
post_json_object = load_json(postFilename)
|
||||
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
|
||||
removePostFromCache(post_json_object, recent_posts_cache)
|
||||
cachedPostFilename = getCachedPostFilename(base_dir, nickname,
|
||||
domain, post_json_object)
|
||||
cachedPostFilename = \
|
||||
get_cached_post_filename(base_dir, nickname,
|
||||
domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -474,4 +475,4 @@ def updateLikesCollection(recent_posts_cache: {},
|
|||
if debug:
|
||||
print('DEBUG: saving post with likes added')
|
||||
pprint(post_json_object)
|
||||
save_json(post_json_object, postFilename)
|
||||
save_json(post_json_object, post_filename)
|
||||
|
|
|
@ -64,14 +64,14 @@ def _updateFeedsOutboxIndex(base_dir: str, domain: str, post_id: str) -> None:
|
|||
print('EX: unable to write ' + indexFilename)
|
||||
|
||||
|
||||
def _saveArrivedTime(base_dir: str, postFilename: str, arrived: str) -> None:
|
||||
def _saveArrivedTime(base_dir: str, post_filename: str, arrived: str) -> None:
|
||||
"""Saves the time when an rss post arrived to a file
|
||||
"""
|
||||
try:
|
||||
with open(postFilename + '.arrived', 'w+') as arrivedFile:
|
||||
with open(post_filename + '.arrived', 'w+') as arrivedFile:
|
||||
arrivedFile.write(arrived)
|
||||
except OSError:
|
||||
print('EX: unable to write ' + postFilename + '.arrived')
|
||||
print('EX: unable to write ' + post_filename + '.arrived')
|
||||
|
||||
|
||||
def _removeControlCharacters(content: str) -> str:
|
||||
|
|
38
newswire.py
38
newswire.py
|
@ -200,7 +200,7 @@ def _downloadNewswireFeedFavicon(session, base_dir: str,
|
|||
def _addNewswireDictEntry(base_dir: str, domain: str,
|
||||
newswire: {}, dateStr: str,
|
||||
title: str, link: str,
|
||||
votesStatus: str, postFilename: str,
|
||||
votesStatus: str, post_filename: str,
|
||||
description: str, moderated: bool,
|
||||
mirrored: bool,
|
||||
tags: [],
|
||||
|
@ -243,7 +243,7 @@ def _addNewswireDictEntry(base_dir: str, domain: str,
|
|||
title,
|
||||
link,
|
||||
votesStatus,
|
||||
postFilename,
|
||||
post_filename,
|
||||
description,
|
||||
moderated,
|
||||
postTags,
|
||||
|
@ -445,12 +445,12 @@ def _xml2StrToDict(base_dir: str, domain: str, xmlStr: str,
|
|||
pubDateStr = parseFeedDate(pubDate)
|
||||
if pubDateStr:
|
||||
if _validFeedDate(pubDateStr):
|
||||
postFilename = ''
|
||||
post_filename = ''
|
||||
votesStatus = []
|
||||
_addNewswireDictEntry(base_dir, domain,
|
||||
result, pubDateStr,
|
||||
title, link,
|
||||
votesStatus, postFilename,
|
||||
votesStatus, post_filename,
|
||||
description, moderated,
|
||||
mirrored, [], 32, session, debug)
|
||||
postCtr += 1
|
||||
|
@ -533,12 +533,12 @@ def _xml1StrToDict(base_dir: str, domain: str, xmlStr: str,
|
|||
pubDateStr = parseFeedDate(pubDate)
|
||||
if pubDateStr:
|
||||
if _validFeedDate(pubDateStr):
|
||||
postFilename = ''
|
||||
post_filename = ''
|
||||
votesStatus = []
|
||||
_addNewswireDictEntry(base_dir, domain,
|
||||
result, pubDateStr,
|
||||
title, link,
|
||||
votesStatus, postFilename,
|
||||
votesStatus, post_filename,
|
||||
description, moderated,
|
||||
mirrored, [], 32, session, debug)
|
||||
postCtr += 1
|
||||
|
@ -609,12 +609,12 @@ def _atomFeedToDict(base_dir: str, domain: str, xmlStr: str,
|
|||
pubDateStr = parseFeedDate(pubDate)
|
||||
if pubDateStr:
|
||||
if _validFeedDate(pubDateStr):
|
||||
postFilename = ''
|
||||
post_filename = ''
|
||||
votesStatus = []
|
||||
_addNewswireDictEntry(base_dir, domain,
|
||||
result, pubDateStr,
|
||||
title, link,
|
||||
votesStatus, postFilename,
|
||||
votesStatus, post_filename,
|
||||
description, moderated,
|
||||
mirrored, [], 32, session, debug)
|
||||
postCtr += 1
|
||||
|
@ -721,12 +721,12 @@ def _jsonFeedV1ToDict(base_dir: str, domain: str, xmlStr: str,
|
|||
pubDateStr = parseFeedDate(pubDate)
|
||||
if pubDateStr:
|
||||
if _validFeedDate(pubDateStr):
|
||||
postFilename = ''
|
||||
post_filename = ''
|
||||
votesStatus = []
|
||||
_addNewswireDictEntry(base_dir, domain,
|
||||
result, pubDateStr,
|
||||
title, link,
|
||||
votesStatus, postFilename,
|
||||
votesStatus, post_filename,
|
||||
description, moderated,
|
||||
mirrored, [], 32, session, debug)
|
||||
postCtr += 1
|
||||
|
@ -794,12 +794,12 @@ def _atomFeedYTToDict(base_dir: str, domain: str, xmlStr: str,
|
|||
pubDateStr = parseFeedDate(pubDate)
|
||||
if pubDateStr:
|
||||
if _validFeedDate(pubDateStr):
|
||||
postFilename = ''
|
||||
post_filename = ''
|
||||
votesStatus = []
|
||||
_addNewswireDictEntry(base_dir, domain,
|
||||
result, pubDateStr,
|
||||
title, link,
|
||||
votesStatus, postFilename,
|
||||
votesStatus, post_filename,
|
||||
description, moderated, mirrored,
|
||||
[], 32, session, debug)
|
||||
postCtr += 1
|
||||
|
@ -1024,20 +1024,20 @@ def _addAccountBlogsToNewswire(base_dir: str, nickname: str, domain: str,
|
|||
moderated = True
|
||||
|
||||
with open(indexFilename, 'r') as indexFile:
|
||||
postFilename = 'start'
|
||||
post_filename = 'start'
|
||||
ctr = 0
|
||||
while postFilename:
|
||||
postFilename = indexFile.readline()
|
||||
if postFilename:
|
||||
while post_filename:
|
||||
post_filename = indexFile.readline()
|
||||
if post_filename:
|
||||
# if this is a full path then remove the directories
|
||||
if '/' in postFilename:
|
||||
postFilename = postFilename.split('/')[-1]
|
||||
if '/' in post_filename:
|
||||
post_filename = post_filename.split('/')[-1]
|
||||
|
||||
# filename of the post without any extension or path
|
||||
# This should also correspond to any index entry in
|
||||
# the posts cache
|
||||
postUrl = \
|
||||
postFilename.replace('\n', '').replace('\r', '')
|
||||
post_filename.replace('\n', '').replace('\r', '')
|
||||
postUrl = postUrl.replace('.json', '').strip()
|
||||
|
||||
# read the post from file
|
||||
|
|
72
posts.py
72
posts.py
|
@ -3445,10 +3445,10 @@ def createModeration(base_dir: str, nickname: str, domain: str, port: int,
|
|||
lineNumber -= 1
|
||||
|
||||
for postUrl in pageLines:
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
boxDir + '/' + postUrl.replace('/', '#') + '.json'
|
||||
if os.path.isfile(postFilename):
|
||||
post_json_object = load_json(postFilename)
|
||||
if os.path.isfile(post_filename):
|
||||
post_json_object = load_json(post_filename)
|
||||
if post_json_object:
|
||||
boxItems['orderedItems'].append(post_json_object)
|
||||
|
||||
|
@ -3607,7 +3607,7 @@ def removePostInteractions(post_json_object: {}, force: bool) -> bool:
|
|||
|
||||
def _passedNewswireVoting(newswire_votes_threshold: int,
|
||||
base_dir: str, domain: str,
|
||||
postFilename: str,
|
||||
post_filename: str,
|
||||
positive_voting: bool,
|
||||
voting_time_mins: int) -> bool:
|
||||
"""Returns true if the post has passed through newswire voting
|
||||
|
@ -3618,7 +3618,7 @@ def _passedNewswireVoting(newswire_votes_threshold: int,
|
|||
# note that the presence of an arrival file also indicates
|
||||
# that this post is moderated
|
||||
arrivalDate = \
|
||||
locateNewsArrival(base_dir, domain, postFilename)
|
||||
locateNewsArrival(base_dir, domain, post_filename)
|
||||
if not arrivalDate:
|
||||
return True
|
||||
# how long has elapsed since this post arrived?
|
||||
|
@ -3632,7 +3632,7 @@ def _passedNewswireVoting(newswire_votes_threshold: int,
|
|||
return False
|
||||
# if there a votes file for this post?
|
||||
votesFilename = \
|
||||
locateNewsVotes(base_dir, domain, postFilename)
|
||||
locateNewsVotes(base_dir, domain, post_filename)
|
||||
if not votesFilename:
|
||||
return True
|
||||
# load the votes file and count the votes
|
||||
|
@ -3733,15 +3733,15 @@ def _createBoxIndexed(recent_posts_cache: {},
|
|||
with open(indexFilename, 'r') as indexFile:
|
||||
postsAddedToTimeline = 0
|
||||
while postsAddedToTimeline < itemsPerPage:
|
||||
postFilename = indexFile.readline()
|
||||
post_filename = indexFile.readline()
|
||||
|
||||
if not postFilename:
|
||||
if not post_filename:
|
||||
break
|
||||
|
||||
# Has this post passed through the newswire voting stage?
|
||||
if not _passedNewswireVoting(newswire_votes_threshold,
|
||||
base_dir, domain,
|
||||
postFilename,
|
||||
post_filename,
|
||||
positive_voting,
|
||||
voting_time_mins):
|
||||
continue
|
||||
|
@ -3752,14 +3752,14 @@ def _createBoxIndexed(recent_posts_cache: {},
|
|||
continue
|
||||
|
||||
# if this is a full path then remove the directories
|
||||
if '/' in postFilename:
|
||||
postFilename = postFilename.split('/')[-1]
|
||||
if '/' in post_filename:
|
||||
post_filename = post_filename.split('/')[-1]
|
||||
|
||||
# filename of the post without any extension or path
|
||||
# This should also correspond to any index entry in
|
||||
# the posts cache
|
||||
postUrl = \
|
||||
postFilename.replace('\n', '').replace('\r', '')
|
||||
post_filename.replace('\n', '').replace('\r', '')
|
||||
postUrl = postUrl.replace('.json', '').strip()
|
||||
|
||||
if postUrl in postUrlsInBox:
|
||||
|
@ -3983,12 +3983,12 @@ def archivePostsForPerson(http_prefix: str, nickname: str, domain: str,
|
|||
postsInBoxDict = {}
|
||||
postsCtr = 0
|
||||
postsInBox = os.scandir(boxDir)
|
||||
for postFilename in postsInBox:
|
||||
postFilename = postFilename.name
|
||||
if not postFilename.endswith('.json'):
|
||||
for post_filename in postsInBox:
|
||||
post_filename = post_filename.name
|
||||
if not post_filename.endswith('.json'):
|
||||
continue
|
||||
# Time of file creation
|
||||
fullFilename = os.path.join(boxDir, postFilename)
|
||||
fullFilename = os.path.join(boxDir, post_filename)
|
||||
if os.path.isfile(fullFilename):
|
||||
content = open(fullFilename).read()
|
||||
if '"published":' in content:
|
||||
|
@ -3996,7 +3996,7 @@ def archivePostsForPerson(http_prefix: str, nickname: str, domain: str,
|
|||
if '"' in publishedStr:
|
||||
publishedStr = publishedStr.split('"')[1]
|
||||
if publishedStr.endswith('Z'):
|
||||
postsInBoxDict[publishedStr] = postFilename
|
||||
postsInBoxDict[publishedStr] = post_filename
|
||||
postsCtr += 1
|
||||
|
||||
noOfPosts = postsCtr
|
||||
|
@ -4013,12 +4013,12 @@ def archivePostsForPerson(http_prefix: str, nickname: str, domain: str,
|
|||
postCacheDir = boxDir.replace('/' + boxname, '/postcache')
|
||||
|
||||
removeCtr = 0
|
||||
for publishedStr, postFilename in postsInBoxSorted.items():
|
||||
filePath = os.path.join(boxDir, postFilename)
|
||||
for publishedStr, post_filename in postsInBoxSorted.items():
|
||||
filePath = os.path.join(boxDir, post_filename)
|
||||
if not os.path.isfile(filePath):
|
||||
continue
|
||||
if archive_dir:
|
||||
archivePath = os.path.join(archive_dir, postFilename)
|
||||
archivePath = os.path.join(archive_dir, post_filename)
|
||||
os.rename(filePath, archivePath)
|
||||
|
||||
extensions = ('replies', 'votes', 'arrived', 'muted')
|
||||
|
@ -4039,7 +4039,7 @@ def archivePostsForPerson(http_prefix: str, nickname: str, domain: str,
|
|||
|
||||
# remove cached html posts
|
||||
postCacheFilename = \
|
||||
os.path.join(postCacheDir, postFilename).replace('.json', '.html')
|
||||
os.path.join(postCacheDir, post_filename).replace('.json', '.html')
|
||||
if os.path.isfile(postCacheFilename):
|
||||
try:
|
||||
os.remove(postCacheFilename)
|
||||
|
@ -4754,10 +4754,10 @@ def isMuted(base_dir: str, nickname: str, domain: str, post_id: str,
|
|||
conversationId.replace('/', '#') + '.muted'
|
||||
if os.path.isfile(convMutedFilename):
|
||||
return True
|
||||
postFilename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not post_filename:
|
||||
return False
|
||||
if os.path.isfile(postFilename + '.muted'):
|
||||
if os.path.isfile(post_filename + '.muted'):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -5225,11 +5225,11 @@ def editedPostFilename(base_dir: str, nickname: str, domain: str,
|
|||
return ''
|
||||
if lastpost_id == post_id:
|
||||
return ''
|
||||
lastpostFilename = \
|
||||
lastpost_filename = \
|
||||
locate_post(base_dir, nickname, domain, lastpost_id, False)
|
||||
if not lastpostFilename:
|
||||
if not lastpost_filename:
|
||||
return ''
|
||||
lastpostJson = load_json(lastpostFilename, 0)
|
||||
lastpostJson = load_json(lastpost_filename, 0)
|
||||
if not lastpostJson:
|
||||
return ''
|
||||
if not lastpostJson.get('type'):
|
||||
|
@ -5261,7 +5261,7 @@ def editedPostFilename(base_dir: str, nickname: str, domain: str,
|
|||
post_json_object['object']['content'], 10) < 70:
|
||||
return ''
|
||||
print(post_id + ' is an edit of ' + lastpost_id)
|
||||
return lastpostFilename
|
||||
return lastpost_filename
|
||||
|
||||
|
||||
def getOriginalPostFromAnnounceUrl(announceUrl: str, base_dir: str,
|
||||
|
@ -5270,20 +5270,20 @@ def getOriginalPostFromAnnounceUrl(announceUrl: str, base_dir: str,
|
|||
"""From the url of an announce this returns the actor, url and
|
||||
filename (if available) of the original post being announced
|
||||
"""
|
||||
postFilename = locate_post(base_dir, nickname, domain, announceUrl)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, announceUrl)
|
||||
if not post_filename:
|
||||
return None, None, None
|
||||
announcePostJson = load_json(postFilename, 0, 1)
|
||||
announcePostJson = load_json(post_filename, 0, 1)
|
||||
if not announcePostJson:
|
||||
return None, None, postFilename
|
||||
return None, None, post_filename
|
||||
if not announcePostJson.get('type'):
|
||||
return None, None, postFilename
|
||||
return None, None, post_filename
|
||||
if announcePostJson['type'] != 'Announce':
|
||||
return None, None, postFilename
|
||||
return None, None, post_filename
|
||||
if not announcePostJson.get('object'):
|
||||
return None, None, postFilename
|
||||
return None, None, post_filename
|
||||
if not isinstance(announcePostJson['object'], str):
|
||||
return None, None, postFilename
|
||||
return None, None, post_filename
|
||||
actor = url = None
|
||||
# do we have the original post?
|
||||
origPostId = announcePostJson['object']
|
||||
|
|
35
reaction.py
35
reaction.py
|
@ -29,7 +29,7 @@ from utils import local_actor_url
|
|||
from utils import load_json
|
||||
from utils import save_json
|
||||
from utils import removePostFromCache
|
||||
from utils import getCachedPostFilename
|
||||
from utils import get_cached_post_filename
|
||||
from utils import containsInvalidChars
|
||||
from posts import sendSignedJson
|
||||
from session import postJson
|
||||
|
@ -118,8 +118,8 @@ def _reaction(recent_posts_cache: {},
|
|||
has_group_type(base_dir, actorReaction, person_cache)
|
||||
|
||||
if reactionPostNickname:
|
||||
postFilename = locate_post(base_dir, nickname, domain, objectUrl)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, objectUrl)
|
||||
if not post_filename:
|
||||
print('DEBUG: reaction base_dir: ' + base_dir)
|
||||
print('DEBUG: reaction nickname: ' + nickname)
|
||||
print('DEBUG: reaction domain: ' + domain)
|
||||
|
@ -127,7 +127,7 @@ def _reaction(recent_posts_cache: {},
|
|||
return None
|
||||
|
||||
updateReactionCollection(recent_posts_cache,
|
||||
base_dir, postFilename, objectUrl,
|
||||
base_dir, post_filename, objectUrl,
|
||||
newReactionJson['actor'],
|
||||
nickname, domain, debug, None,
|
||||
emojiContent)
|
||||
|
@ -384,18 +384,18 @@ def outboxReaction(recent_posts_cache: {},
|
|||
messageId = removeIdEnding(message_json['object'])
|
||||
domain = remove_domain_port(domain)
|
||||
emojiContent = message_json['content']
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: c2s reaction post not found in inbox or outbox')
|
||||
print(messageId)
|
||||
return True
|
||||
updateReactionCollection(recent_posts_cache,
|
||||
base_dir, postFilename, messageId,
|
||||
base_dir, post_filename, messageId,
|
||||
message_json['actor'],
|
||||
nickname, domain, debug, None, emojiContent)
|
||||
if debug:
|
||||
print('DEBUG: post reaction via c2s - ' + postFilename)
|
||||
print('DEBUG: post reaction via c2s - ' + post_filename)
|
||||
|
||||
|
||||
def outboxUndoReaction(recent_posts_cache: {},
|
||||
|
@ -426,21 +426,21 @@ def outboxUndoReaction(recent_posts_cache: {},
|
|||
messageId = removeIdEnding(message_json['object']['object'])
|
||||
emojiContent = message_json['object']['content']
|
||||
domain = remove_domain_port(domain)
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not post_filename:
|
||||
if debug:
|
||||
print('DEBUG: c2s undo reaction post not found in inbox or outbox')
|
||||
print(messageId)
|
||||
return True
|
||||
undoReactionCollectionEntry(recent_posts_cache, base_dir, postFilename,
|
||||
undoReactionCollectionEntry(recent_posts_cache, base_dir, post_filename,
|
||||
messageId, message_json['actor'],
|
||||
domain, debug, None, emojiContent)
|
||||
if debug:
|
||||
print('DEBUG: post undo reaction via c2s - ' + postFilename)
|
||||
print('DEBUG: post undo reaction via c2s - ' + post_filename)
|
||||
|
||||
|
||||
def updateReactionCollection(recent_posts_cache: {},
|
||||
base_dir: str, postFilename: str,
|
||||
base_dir: str, post_filename: str,
|
||||
objectUrl: str, actor: str,
|
||||
nickname: str, domain: str, debug: bool,
|
||||
post_json_object: {},
|
||||
|
@ -448,15 +448,16 @@ def updateReactionCollection(recent_posts_cache: {},
|
|||
"""Updates the reactions collection within a post
|
||||
"""
|
||||
if not post_json_object:
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not post_json_object:
|
||||
return
|
||||
|
||||
# remove any cached version of this post so that the
|
||||
# reaction icon is changed
|
||||
removePostFromCache(post_json_object, recent_posts_cache)
|
||||
cachedPostFilename = getCachedPostFilename(base_dir, nickname,
|
||||
domain, post_json_object)
|
||||
cachedPostFilename = \
|
||||
get_cached_post_filename(base_dir, nickname,
|
||||
domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -510,7 +511,7 @@ def updateReactionCollection(recent_posts_cache: {},
|
|||
if debug:
|
||||
print('DEBUG: saving post with emoji reaction added')
|
||||
pprint(post_json_object)
|
||||
save_json(post_json_object, postFilename)
|
||||
save_json(post_json_object, post_filename)
|
||||
|
||||
|
||||
def htmlEmojiReactions(post_json_object: {}, interactive: bool,
|
||||
|
|
24
schedule.py
24
schedule.py
|
@ -43,15 +43,15 @@ def _updatePostSchedule(base_dir: str, handle: str, httpd,
|
|||
if 'T' not in dateStr:
|
||||
continue
|
||||
post_id = line.split(' ', 1)[1].replace('\n', '').replace('\r', '')
|
||||
postFilename = scheduleDir + post_id + '.json'
|
||||
post_filename = scheduleDir + post_id + '.json'
|
||||
if deleteSchedulePost:
|
||||
# delete extraneous scheduled posts
|
||||
if os.path.isfile(postFilename):
|
||||
if os.path.isfile(post_filename):
|
||||
try:
|
||||
os.remove(postFilename)
|
||||
os.remove(post_filename)
|
||||
except OSError:
|
||||
print('EX: _updatePostSchedule unable to delete ' +
|
||||
str(postFilename))
|
||||
str(post_filename))
|
||||
continue
|
||||
# create the new index file
|
||||
indexLines.append(line)
|
||||
|
@ -68,12 +68,12 @@ def _updatePostSchedule(base_dir: str, handle: str, httpd,
|
|||
continue
|
||||
if curr_time.time().minute < postTime.time().minute:
|
||||
continue
|
||||
if not os.path.isfile(postFilename):
|
||||
print('WARN: schedule missing postFilename=' + postFilename)
|
||||
if not os.path.isfile(post_filename):
|
||||
print('WARN: schedule missing post_filename=' + post_filename)
|
||||
indexLines.remove(line)
|
||||
continue
|
||||
# load post
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not post_json_object:
|
||||
print('WARN: schedule json not loaded')
|
||||
indexLines.remove(line)
|
||||
|
@ -132,16 +132,16 @@ def _updatePostSchedule(base_dir: str, handle: str, httpd,
|
|||
httpd.content_license_url):
|
||||
indexLines.remove(line)
|
||||
try:
|
||||
os.remove(postFilename)
|
||||
os.remove(post_filename)
|
||||
except OSError:
|
||||
print('EX: _updatePostSchedule unable to delete ' +
|
||||
str(postFilename))
|
||||
str(post_filename))
|
||||
continue
|
||||
|
||||
# move to the outbox
|
||||
outboxPostFilename = postFilename.replace('/scheduled/',
|
||||
'/outbox/')
|
||||
os.rename(postFilename, outboxPostFilename)
|
||||
outboxPostFilename = \
|
||||
post_filename.replace('/scheduled/', '/outbox/')
|
||||
os.rename(post_filename, outboxPostFilename)
|
||||
|
||||
print('Scheduled post sent ' + post_id)
|
||||
|
||||
|
|
162
utils.py
162
utils.py
|
@ -1256,9 +1256,9 @@ def locateNewsVotes(base_dir: str, domain: str,
|
|||
postUrl = postUrl + '.json.votes'
|
||||
|
||||
accountDir = base_dir + '/accounts/news@' + domain + '/'
|
||||
postFilename = accountDir + 'outbox/' + postUrl
|
||||
if os.path.isfile(postFilename):
|
||||
return postFilename
|
||||
post_filename = accountDir + 'outbox/' + postUrl
|
||||
if os.path.isfile(post_filename):
|
||||
return post_filename
|
||||
|
||||
return None
|
||||
|
||||
|
@ -1280,9 +1280,9 @@ def locateNewsArrival(base_dir: str, domain: str,
|
|||
postUrl = postUrl + '.json.arrived'
|
||||
|
||||
accountDir = base_dir + '/accounts/news@' + domain + '/'
|
||||
postFilename = accountDir + 'outbox/' + postUrl
|
||||
if os.path.isfile(postFilename):
|
||||
with open(postFilename, 'r') as arrivalFile:
|
||||
post_filename = accountDir + 'outbox/' + postUrl
|
||||
if os.path.isfile(post_filename):
|
||||
with open(post_filename, 'r') as arrivalFile:
|
||||
arrival = arrivalFile.read()
|
||||
if arrival:
|
||||
arrivalDate = \
|
||||
|
@ -1306,13 +1306,13 @@ def clearFromPostCaches(base_dir: str, recent_posts_cache: {},
|
|||
if acct.startswith('inbox@'):
|
||||
continue
|
||||
cacheDir = os.path.join(base_dir + '/accounts', acct)
|
||||
postFilename = cacheDir + filename
|
||||
if os.path.isfile(postFilename):
|
||||
post_filename = cacheDir + filename
|
||||
if os.path.isfile(post_filename):
|
||||
try:
|
||||
os.remove(postFilename)
|
||||
os.remove(post_filename)
|
||||
except OSError:
|
||||
print('EX: clearFromPostCaches file not removed ' +
|
||||
str(postFilename))
|
||||
str(post_filename))
|
||||
# if the post is in the recent posts cache then remove it
|
||||
if recent_posts_cache.get('index'):
|
||||
if post_id in recent_posts_cache['index']:
|
||||
|
@ -1345,20 +1345,20 @@ def locate_post(base_dir: str, nickname: str, domain: str,
|
|||
boxes = ('inbox', 'outbox', 'tlblogs')
|
||||
accountDir = acct_dir(base_dir, nickname, domain) + '/'
|
||||
for boxName in boxes:
|
||||
postFilename = accountDir + boxName + '/' + postUrl
|
||||
if os.path.isfile(postFilename):
|
||||
return postFilename
|
||||
post_filename = accountDir + boxName + '/' + postUrl
|
||||
if os.path.isfile(post_filename):
|
||||
return post_filename
|
||||
|
||||
# check news posts
|
||||
accountDir = base_dir + '/accounts/news' + '@' + domain + '/'
|
||||
postFilename = accountDir + 'outbox/' + postUrl
|
||||
if os.path.isfile(postFilename):
|
||||
return postFilename
|
||||
post_filename = accountDir + 'outbox/' + postUrl
|
||||
if os.path.isfile(post_filename):
|
||||
return post_filename
|
||||
|
||||
# is it in the announce cache?
|
||||
postFilename = base_dir + '/cache/announce/' + nickname + '/' + postUrl
|
||||
if os.path.isfile(postFilename):
|
||||
return postFilename
|
||||
post_filename = base_dir + '/cache/announce/' + nickname + '/' + postUrl
|
||||
if os.path.isfile(post_filename):
|
||||
return post_filename
|
||||
|
||||
# print('WARN: unable to locate ' + nickname + ' ' + postUrl)
|
||||
return None
|
||||
|
@ -1427,10 +1427,10 @@ def canReplyTo(base_dir: str, nickname: str, domain: str,
|
|||
if '/statuses/' not in postUrl:
|
||||
return True
|
||||
if not post_json_object:
|
||||
postFilename = locate_post(base_dir, nickname, domain, postUrl)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, postUrl)
|
||||
if not post_filename:
|
||||
return False
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not post_json_object:
|
||||
return False
|
||||
published = _getPublishedDate(post_json_object)
|
||||
|
@ -1528,15 +1528,15 @@ def _is_reply_to_blog_post(base_dir: str, nickname: str, domain: str,
|
|||
|
||||
|
||||
def _deletePostRemoveReplies(base_dir: str, nickname: str, domain: str,
|
||||
http_prefix: str, postFilename: str,
|
||||
http_prefix: str, post_filename: str,
|
||||
recent_posts_cache: {}, debug: bool) -> None:
|
||||
"""Removes replies when deleting a post
|
||||
"""
|
||||
repliesFilename = postFilename.replace('.json', '.replies')
|
||||
repliesFilename = post_filename.replace('.json', '.replies')
|
||||
if not os.path.isfile(repliesFilename):
|
||||
return
|
||||
if debug:
|
||||
print('DEBUG: removing replies to ' + postFilename)
|
||||
print('DEBUG: removing replies to ' + post_filename)
|
||||
with open(repliesFilename, 'r') as f:
|
||||
for replyId in f:
|
||||
replyFile = locate_post(base_dir, nickname, domain, replyId)
|
||||
|
@ -1555,13 +1555,13 @@ def _deletePostRemoveReplies(base_dir: str, nickname: str, domain: str,
|
|||
|
||||
|
||||
def _isBookmarked(base_dir: str, nickname: str, domain: str,
|
||||
postFilename: str) -> bool:
|
||||
post_filename: str) -> bool:
|
||||
"""Returns True if the given post is bookmarked
|
||||
"""
|
||||
bookmarksIndexFilename = \
|
||||
acct_dir(base_dir, nickname, domain) + '/bookmarks.index'
|
||||
if os.path.isfile(bookmarksIndexFilename):
|
||||
bookmarkIndex = postFilename.split('/')[-1] + '\n'
|
||||
bookmarkIndex = post_filename.split('/')[-1] + '\n'
|
||||
if bookmarkIndex in open(bookmarksIndexFilename).read():
|
||||
return True
|
||||
return False
|
||||
|
@ -1604,7 +1604,7 @@ def _deleteCachedHtml(base_dir: str, nickname: str, domain: str,
|
|||
"""Removes cached html file for the given post
|
||||
"""
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname, domain, post_json_object)
|
||||
get_cached_post_filename(base_dir, nickname, domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -1712,27 +1712,27 @@ def _deleteConversationPost(base_dir: str, nickname: str, domain: str,
|
|||
|
||||
|
||||
def deletePost(base_dir: str, http_prefix: str,
|
||||
nickname: str, domain: str, postFilename: str,
|
||||
nickname: str, domain: str, post_filename: str,
|
||||
debug: bool, recent_posts_cache: {}) -> None:
|
||||
"""Recursively deletes a post and its replies and attachments
|
||||
"""
|
||||
post_json_object = load_json(postFilename, 1)
|
||||
post_json_object = load_json(post_filename, 1)
|
||||
if not post_json_object:
|
||||
# remove any replies
|
||||
_deletePostRemoveReplies(base_dir, nickname, domain,
|
||||
http_prefix, postFilename,
|
||||
http_prefix, post_filename,
|
||||
recent_posts_cache, debug)
|
||||
# finally, remove the post itself
|
||||
try:
|
||||
os.remove(postFilename)
|
||||
os.remove(post_filename)
|
||||
except OSError:
|
||||
if debug:
|
||||
print('EX: deletePost unable to delete post ' +
|
||||
str(postFilename))
|
||||
str(post_filename))
|
||||
return
|
||||
|
||||
# don't allow deletion of bookmarked posts
|
||||
if _isBookmarked(base_dir, nickname, domain, postFilename):
|
||||
if _isBookmarked(base_dir, nickname, domain, post_filename):
|
||||
return
|
||||
|
||||
# don't remove replies to blog posts
|
||||
|
@ -1751,7 +1751,7 @@ def deletePost(base_dir: str, http_prefix: str,
|
|||
|
||||
extensions = ('votes', 'arrived', 'muted', 'tts', 'reject')
|
||||
for ext in extensions:
|
||||
extFilename = postFilename + '.' + ext
|
||||
extFilename = post_filename + '.' + ext
|
||||
if os.path.isfile(extFilename):
|
||||
try:
|
||||
os.remove(extFilename)
|
||||
|
@ -1780,14 +1780,14 @@ def deletePost(base_dir: str, http_prefix: str,
|
|||
|
||||
# remove any replies
|
||||
_deletePostRemoveReplies(base_dir, nickname, domain,
|
||||
http_prefix, postFilename,
|
||||
http_prefix, post_filename,
|
||||
recent_posts_cache, debug)
|
||||
# finally, remove the post itself
|
||||
try:
|
||||
os.remove(postFilename)
|
||||
os.remove(post_filename)
|
||||
except OSError:
|
||||
if debug:
|
||||
print('EX: deletePost unable to delete post ' + str(postFilename))
|
||||
print('EX: deletePost unable to delete post ' + str(post_filename))
|
||||
|
||||
|
||||
def isValidLanguage(text: str) -> bool:
|
||||
|
@ -1946,10 +1946,10 @@ def isPublicPostFromUrl(base_dir: str, nickname: str, domain: str,
|
|||
postUrl: str) -> bool:
|
||||
"""Returns whether the given url is a public post
|
||||
"""
|
||||
postFilename = locate_post(base_dir, nickname, domain, postUrl)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, postUrl)
|
||||
if not post_filename:
|
||||
return False
|
||||
post_json_object = load_json(postFilename, 1)
|
||||
post_json_object = load_json(post_filename, 1)
|
||||
if not post_json_object:
|
||||
return False
|
||||
return isPublicPost(post_json_object)
|
||||
|
@ -1991,8 +1991,8 @@ def getCachedPostDirectory(base_dir: str, nickname: str, domain: str) -> str:
|
|||
return htmlPostCacheDir
|
||||
|
||||
|
||||
def getCachedPostFilename(base_dir: str, nickname: str, domain: str,
|
||||
post_json_object: {}) -> str:
|
||||
def get_cached_post_filename(base_dir: str, nickname: str, domain: str,
|
||||
post_json_object: {}) -> str:
|
||||
"""Returns the html cache filename for the given post
|
||||
"""
|
||||
cachedPostDir = getCachedPostDirectory(base_dir, nickname, domain)
|
||||
|
@ -2124,17 +2124,17 @@ def _searchVirtualBoxPosts(base_dir: str, nickname: str, domain: str,
|
|||
|
||||
res = []
|
||||
with open(indexFilename, 'r') as indexFile:
|
||||
postFilename = 'start'
|
||||
while postFilename:
|
||||
postFilename = indexFile.readline()
|
||||
if not postFilename:
|
||||
post_filename = 'start'
|
||||
while post_filename:
|
||||
post_filename = indexFile.readline()
|
||||
if not post_filename:
|
||||
break
|
||||
if '.json' not in postFilename:
|
||||
if '.json' not in post_filename:
|
||||
break
|
||||
postFilename = path + '/' + postFilename.strip()
|
||||
if not os.path.isfile(postFilename):
|
||||
post_filename = path + '/' + post_filename.strip()
|
||||
if not os.path.isfile(post_filename):
|
||||
continue
|
||||
with open(postFilename, 'r') as postFile:
|
||||
with open(post_filename, 'r') as postFile:
|
||||
data = postFile.read().lower()
|
||||
|
||||
notFound = False
|
||||
|
@ -2145,7 +2145,7 @@ def _searchVirtualBoxPosts(base_dir: str, nickname: str, domain: str,
|
|||
if notFound:
|
||||
continue
|
||||
|
||||
res.append(postFilename)
|
||||
res.append(post_filename)
|
||||
if len(res) >= maxResults:
|
||||
return res
|
||||
return res
|
||||
|
@ -2208,20 +2208,21 @@ def getFileCaseInsensitive(path: str) -> str:
|
|||
|
||||
|
||||
def undoLikesCollectionEntry(recent_posts_cache: {},
|
||||
base_dir: str, postFilename: str, objectUrl: str,
|
||||
base_dir: str, post_filename: str, objectUrl: str,
|
||||
actor: str, domain: str, debug: bool,
|
||||
post_json_object: {}) -> None:
|
||||
"""Undoes a like for a particular actor
|
||||
"""
|
||||
if not post_json_object:
|
||||
post_json_object = load_json(postFilename)
|
||||
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 = getNicknameFromActor(actor)
|
||||
cachedPostFilename = getCachedPostFilename(base_dir, nickname,
|
||||
domain, post_json_object)
|
||||
cachedPostFilename = \
|
||||
get_cached_post_filename(base_dir, nickname,
|
||||
domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -2267,11 +2268,11 @@ def undoLikesCollectionEntry(recent_posts_cache: {},
|
|||
itlen = len(obj['likes']['items'])
|
||||
obj['likes']['totalItems'] = itlen
|
||||
|
||||
save_json(post_json_object, postFilename)
|
||||
save_json(post_json_object, post_filename)
|
||||
|
||||
|
||||
def undoReactionCollectionEntry(recent_posts_cache: {},
|
||||
base_dir: str, postFilename: str,
|
||||
base_dir: str, post_filename: str,
|
||||
objectUrl: str,
|
||||
actor: str, domain: str, debug: bool,
|
||||
post_json_object: {},
|
||||
|
@ -2279,14 +2280,15 @@ def undoReactionCollectionEntry(recent_posts_cache: {},
|
|||
"""Undoes an emoji reaction for a particular actor
|
||||
"""
|
||||
if not post_json_object:
|
||||
post_json_object = load_json(postFilename)
|
||||
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 = getNicknameFromActor(actor)
|
||||
cachedPostFilename = getCachedPostFilename(base_dir, nickname,
|
||||
domain, post_json_object)
|
||||
cachedPostFilename = \
|
||||
get_cached_post_filename(base_dir, nickname,
|
||||
domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -2333,25 +2335,26 @@ def undoReactionCollectionEntry(recent_posts_cache: {},
|
|||
itlen = len(obj['reactions']['items'])
|
||||
obj['reactions']['totalItems'] = itlen
|
||||
|
||||
save_json(post_json_object, postFilename)
|
||||
save_json(post_json_object, post_filename)
|
||||
|
||||
|
||||
def undoAnnounceCollectionEntry(recent_posts_cache: {},
|
||||
base_dir: str, postFilename: str,
|
||||
base_dir: str, post_filename: str,
|
||||
actor: str, domain: str, debug: bool) -> None:
|
||||
"""Undoes an announce for a particular actor by removing it from
|
||||
the "shares" collection within a post. Note that the "shares"
|
||||
collection has no relation to shared items in shares.py. It's
|
||||
shares of posts, not shares of physical objects.
|
||||
"""
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not post_json_object:
|
||||
return
|
||||
# remove any cached version of this announce so that the announce
|
||||
# icon is changed
|
||||
nickname = getNicknameFromActor(actor)
|
||||
cachedPostFilename = getCachedPostFilename(base_dir, nickname, domain,
|
||||
post_json_object)
|
||||
cachedPostFilename = \
|
||||
get_cached_post_filename(base_dir, nickname, domain,
|
||||
post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -2400,32 +2403,33 @@ def undoAnnounceCollectionEntry(recent_posts_cache: {},
|
|||
itlen = len(post_json_object['object']['shares']['items'])
|
||||
post_json_object['object']['shares']['totalItems'] = itlen
|
||||
|
||||
save_json(post_json_object, postFilename)
|
||||
save_json(post_json_object, post_filename)
|
||||
|
||||
|
||||
def updateAnnounceCollection(recent_posts_cache: {},
|
||||
base_dir: str, postFilename: str,
|
||||
actor: str,
|
||||
nickname: str, domain: str, debug: bool) -> None:
|
||||
def update_announce_collection(recent_posts_cache: {},
|
||||
base_dir: str, post_filename: str,
|
||||
actor: str, nickname: str, domain: str,
|
||||
debug: bool) -> None:
|
||||
"""Updates the announcements collection within a post
|
||||
Confusingly this is known as "shares", but isn't the
|
||||
same as shared items within shares.py
|
||||
It's shares of posts, not shares of physical objects.
|
||||
"""
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not post_json_object:
|
||||
return
|
||||
# remove any cached version of this announce so that the announce
|
||||
# icon is changed
|
||||
cachedPostFilename = getCachedPostFilename(base_dir, nickname, domain,
|
||||
post_json_object)
|
||||
cachedPostFilename = \
|
||||
get_cached_post_filename(base_dir, nickname, domain,
|
||||
post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
os.remove(cachedPostFilename)
|
||||
except OSError:
|
||||
if debug:
|
||||
print('EX: updateAnnounceCollection ' +
|
||||
print('EX: update_announce_collection ' +
|
||||
'unable to delete cached post ' +
|
||||
str(cachedPostFilename))
|
||||
removePostFromCache(post_json_object, recent_posts_cache)
|
||||
|
@ -2433,7 +2437,7 @@ def updateAnnounceCollection(recent_posts_cache: {},
|
|||
if not has_object_dict(post_json_object):
|
||||
if debug:
|
||||
pprint(post_json_object)
|
||||
print('DEBUG: post ' + postFilename + ' has no object')
|
||||
print('DEBUG: post ' + post_filename + ' has no object')
|
||||
return
|
||||
postUrl = removeIdEnding(post_json_object['id']) + '/shares'
|
||||
if not post_json_object['object'].get('shares'):
|
||||
|
@ -2473,7 +2477,7 @@ def updateAnnounceCollection(recent_posts_cache: {},
|
|||
if debug:
|
||||
print('DEBUG: saving post with shares (announcements) added')
|
||||
pprint(post_json_object)
|
||||
save_json(post_json_object, postFilename)
|
||||
save_json(post_json_object, post_filename)
|
||||
|
||||
|
||||
def week_day_of_month_start(month_number: int, year: int) -> int:
|
||||
|
@ -2534,9 +2538,9 @@ def is_recent_post(post_json_object: {}, max_days: int) -> bool:
|
|||
str(published_date_str))
|
||||
return False
|
||||
|
||||
publishedDaysSinceEpoch = \
|
||||
published_days_since_epoch = \
|
||||
(published_date - datetime.datetime(1970, 1, 1)).days
|
||||
if publishedDaysSinceEpoch < recently:
|
||||
if published_days_since_epoch < recently:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -43,11 +43,11 @@ def htmlCalendarDeleteConfirm(cssCache: {}, translate: {}, base_dir: str,
|
|||
domain, port = getDomainFromActor(actor)
|
||||
messageId = actor + '/statuses/' + post_id
|
||||
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not post_filename:
|
||||
return None
|
||||
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not post_json_object:
|
||||
return None
|
||||
|
||||
|
|
|
@ -660,10 +660,10 @@ def htmlEditNewsPost(cssCache: {}, translate: {}, base_dir: str, path: str,
|
|||
return ''
|
||||
|
||||
postUrl = postUrl.replace('/', '#')
|
||||
postFilename = locate_post(base_dir, nickname, domain, postUrl)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, postUrl)
|
||||
if not post_filename:
|
||||
return ''
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not post_json_object:
|
||||
return ''
|
||||
|
||||
|
|
|
@ -47,11 +47,11 @@ def htmlConfirmDelete(cssCache: {},
|
|||
domain, port = getDomainFromActor(actor)
|
||||
domain_full = get_full_domain(domain, port)
|
||||
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if not post_filename:
|
||||
return None
|
||||
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not post_json_object:
|
||||
return None
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ from utils import get_actor_languages_list
|
|||
from utils import get_base_content_from_post
|
||||
from utils import get_content_from_post
|
||||
from utils import has_object_dict
|
||||
from utils import updateAnnounceCollection
|
||||
from utils import update_announce_collection
|
||||
from utils import is_pgp_encrypted
|
||||
from utils import is_dm
|
||||
from utils import reject_post_id
|
||||
|
@ -40,7 +40,7 @@ from utils import is_editor
|
|||
from utils import locate_post
|
||||
from utils import load_json
|
||||
from utils import getCachedPostDirectory
|
||||
from utils import getCachedPostFilename
|
||||
from utils import get_cached_post_filename
|
||||
from utils import getProtocolPrefixes
|
||||
from utils import isNewsPost
|
||||
from utils import isBlogPost
|
||||
|
@ -252,7 +252,7 @@ def _saveIndividualPostAsHtmlToCache(base_dir: str,
|
|||
htmlPostCacheDir = \
|
||||
getCachedPostDirectory(base_dir, nickname, domain)
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname, domain, post_json_object)
|
||||
get_cached_post_filename(base_dir, nickname, domain, post_json_object)
|
||||
|
||||
# create the cache directory if needed
|
||||
if not os.path.isdir(htmlPostCacheDir):
|
||||
|
@ -1539,9 +1539,10 @@ def individualPostAsHtml(signing_priv_key_pem: str,
|
|||
announceFilename = \
|
||||
locate_post(base_dir, nickname, domain, post_json_object['id'])
|
||||
if announceFilename:
|
||||
updateAnnounceCollection(recent_posts_cache,
|
||||
base_dir, announceFilename,
|
||||
postActor, nickname, domain_full, False)
|
||||
update_announce_collection(recent_posts_cache,
|
||||
base_dir, announceFilename,
|
||||
postActor, nickname,
|
||||
domain_full, False)
|
||||
|
||||
# create a file for use by text-to-speech
|
||||
if is_recent_post(post_json_object, 3):
|
||||
|
@ -2078,12 +2079,12 @@ def htmlIndividualPost(cssCache: {},
|
|||
# show the previous posts
|
||||
if has_object_dict(post_json_object):
|
||||
while post_json_object['object'].get('inReplyTo'):
|
||||
postFilename = \
|
||||
post_filename = \
|
||||
locate_post(base_dir, nickname, domain,
|
||||
post_json_object['object']['inReplyTo'])
|
||||
if not postFilename:
|
||||
if not post_filename:
|
||||
break
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if post_json_object:
|
||||
postStr = \
|
||||
individualPostAsHtml(signing_priv_key_pem,
|
||||
|
@ -2108,10 +2109,10 @@ def htmlIndividualPost(cssCache: {},
|
|||
cw_lists, lists_enabled) + postStr
|
||||
|
||||
# show the following posts
|
||||
postFilename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, messageId)
|
||||
if post_filename:
|
||||
# is there a replies file for this post?
|
||||
repliesFilename = postFilename.replace('.json', '.replies')
|
||||
repliesFilename = post_filename.replace('.json', '.replies')
|
||||
if os.path.isfile(repliesFilename):
|
||||
# get items from the replies file
|
||||
repliesJson = {
|
||||
|
|
|
@ -662,11 +662,11 @@ def htmlHistorySearch(cssCache: {}, translate: {}, base_dir: str,
|
|||
|
||||
index = startIndex
|
||||
while index <= endIndex:
|
||||
postFilename = boxFilenames[index]
|
||||
if not postFilename:
|
||||
post_filename = boxFilenames[index]
|
||||
if not post_filename:
|
||||
index += 1
|
||||
continue
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not post_json_object:
|
||||
index += 1
|
||||
continue
|
||||
|
@ -831,11 +831,11 @@ def htmlHashtagSearch(cssCache: {},
|
|||
continue
|
||||
nickname = postFields[1]
|
||||
post_id = postFields[2]
|
||||
postFilename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not post_filename:
|
||||
index += 1
|
||||
continue
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if not post_json_object:
|
||||
index += 1
|
||||
continue
|
||||
|
@ -956,13 +956,13 @@ def rssHashtagSearch(nickname: str, domain: str, port: int,
|
|||
continue
|
||||
nickname = postFields[1]
|
||||
post_id = postFields[2]
|
||||
postFilename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not postFilename:
|
||||
post_filename = locate_post(base_dir, nickname, domain, post_id)
|
||||
if not post_filename:
|
||||
index += 1
|
||||
if index >= maxFeedLength:
|
||||
break
|
||||
continue
|
||||
post_json_object = load_json(postFilename)
|
||||
post_json_object = load_json(post_filename)
|
||||
if post_json_object:
|
||||
if not isPublicPost(post_json_object):
|
||||
index += 1
|
||||
|
|
|
@ -15,7 +15,7 @@ from utils import is_account_dir
|
|||
from utils import removeHtml
|
||||
from utils import getProtocolPrefixes
|
||||
from utils import load_json
|
||||
from utils import getCachedPostFilename
|
||||
from utils import get_cached_post_filename
|
||||
from utils import get_config_param
|
||||
from utils import acct_dir
|
||||
from utils import getNicknameFromActor
|
||||
|
@ -864,7 +864,7 @@ def loadIndividualPostAsHtmlFromCache(base_dir: str,
|
|||
This is much quicker than generating the html from the json object
|
||||
"""
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname, domain, post_json_object)
|
||||
get_cached_post_filename(base_dir, nickname, domain, post_json_object)
|
||||
|
||||
postHtml = ''
|
||||
if not cachedPostFilename:
|
||||
|
|
Loading…
Reference in New Issue