Store history of edited posts

main
Bob Mottram 2022-04-09 17:02:18 +01:00
parent 4be7edd5f5
commit a21c19eac1
2 changed files with 23 additions and 3 deletions

View File

@ -1038,6 +1038,17 @@ def _receive_edit_to_post(recent_posts_cache: {}, message_json: {},
print('EDITPOST: actors do not match ' + print('EDITPOST: actors do not match ' +
post_json_object['actor'] + ' != ' + message_json['actor']) post_json_object['actor'] + ' != ' + message_json['actor'])
return False return False
# save the edit history to file
post_history_filename = post_filename.replace('.json', '') + '.edits'
post_history_json = {}
if os.path.isfile(post_history_filename):
post_history_json = load_json(post_history_filename, 1)
if post_json_object['object'].get('updated'):
published_str = post_json_object['object']['updated']
else:
published_str = post_json_object['object']['published']
post_history_json[published_str] = post_json_object
save_json(post_history_json, post_history_filename)
# Change Update to Create # Change Update to Create
message_json['type'] = 'Create' message_json['type'] = 'Create'
save_json(message_json, post_filename) save_json(message_json, post_filename)
@ -1080,8 +1091,7 @@ def _receive_edit_to_post(recent_posts_cache: {}, message_json: {},
session, cached_webfingers, person_cache, session, cached_webfingers, person_cache,
nickname, domain, port, message_json, nickname, domain, port, message_json,
None, True, allow_deletion, None, True, allow_deletion,
http_prefix, __version__, http_prefix, __version__, 'inbox',
'inbox',
yt_replace_domain, yt_replace_domain,
twitter_replacement_domain, twitter_replacement_domain,
show_published_date_only, show_published_date_only,

View File

@ -1831,7 +1831,9 @@ def delete_post(base_dir: str, http_prefix: str,
# remove any attachment # remove any attachment
_remove_attachment(base_dir, http_prefix, domain, post_json_object) _remove_attachment(base_dir, http_prefix, domain, post_json_object)
extensions = ('votes', 'arrived', 'muted', 'tts', 'reject', 'mitm') extensions = (
'votes', 'arrived', 'muted', 'tts', 'reject', 'mitm', 'edits'
)
for ext in extensions: for ext in extensions:
ext_filename = post_filename + '.' + ext ext_filename = post_filename + '.' + ext
if os.path.isfile(ext_filename): if os.path.isfile(ext_filename):
@ -1840,6 +1842,14 @@ def delete_post(base_dir: str, http_prefix: str,
except OSError: except OSError:
print('EX: delete_post unable to remove ext ' + print('EX: delete_post unable to remove ext ' +
str(ext_filename)) str(ext_filename))
elif post_filename.endswith('.json'):
ext_filename = post_filename.replace('.json', '') + '.' + ext
if os.path.isfile(ext_filename):
try:
os.remove(ext_filename)
except OSError:
print('EX: delete_post unable to remove ext ' +
str(ext_filename))
# remove cached html version of the post # remove cached html version of the post
delete_cached_html(base_dir, nickname, domain, post_json_object) delete_cached_html(base_dir, nickname, domain, post_json_object)