Getting threads via their id

merge-requests/30/head
Bob Mottram 2024-10-06 15:09:54 +01:00
parent c667bae209
commit 9a548f32a6
3 changed files with 36 additions and 1 deletions

View File

@ -425,3 +425,21 @@ def conversation_tag_to_convthread_id(tag: str) -> str:
if tag_chr.isdigit():
convthread_id += tag_chr
return convthread_id
def convthread_id_to_conversation_tag(domain: str,
convthread_id: str) -> str:
"""Converts a convthread id such as 20240928647832678
into a converation tag, such as
tag:domain,2024-09-28:objectId=647832678:objectType=Conversation
"""
if len(convthread_id) < 10:
return ''
year = convthread_id[:4]
month = convthread_id[4:][:2]
day = convthread_id[6:][:2]
post_id = convthread_id[8:]
conversation_id = \
'tag:' + domain + ',' + year + '-' + month + '-' + day + \
':objectId=' + post_id + ':objectType=Conversation'
return conversation_id

View File

@ -45,6 +45,7 @@ from webapp_likers import html_likers_of_post
from fitnessFunctions import fitness_performance
from securemode import secure_mode
from context import get_individual_post_context
from conversation import convthread_id_to_conversation_tag
def _show_post_from_file(self, post_filename: str, liked_by: str,
@ -1281,6 +1282,15 @@ def show_conversation_thread(self, authorized: bool,
if not path.startswith('/users/'):
return False
conv_separator = '?convthread='
# https://codeberg.org/fediverse/fep/src/branch/main/fep/76ea/fep-76ea.md
if conv_separator not in path and '/thread/' in path:
convthread_id = path.split('/thread/', 1)[1].strip()
if convthread_id.isdigit():
new_tag = convthread_id_to_conversation_tag(domain_full,
convthread_id)
if new_tag:
path = \
path.split(conv_separator)[0] + conv_separator + new_tag
if conv_separator not in path:
return False
post_id = path.split(conv_separator)[1].strip()

View File

@ -226,6 +226,7 @@ from reading import get_book_from_post
from reading import get_reading_status
from reading import store_book_events
from conversation import conversation_tag_to_convthread_id
from conversation import convthread_id_to_conversation_tag
TEST_SERVER_GROUP_RUNNING = False
@ -9044,11 +9045,17 @@ def _test_bridgy() -> None:
def _test_conversation_to_convthread() -> None:
print('conversation to thread')
domain = 'the.domain.of.last.resort'
conversation_id = \
'tag:domain,2024-09-28:objectId=647832678:objectType=Conversation'
'tag:' + domain + \
',2024-09-28:objectId=647832678:objectType=Conversation'
convthread_id = conversation_tag_to_convthread_id(conversation_id)
assert convthread_id == '20240928647832678'
conversation_id2 = \
convthread_id_to_conversation_tag(domain, convthread_id)
assert conversation_id2 == conversation_id
def run_all_tests():
base_dir = os.getcwd()