diff --git a/backend/app/services/plugin_manager.py b/backend/app/services/plugin_manager.py index da8957a..f210bcf 100644 --- a/backend/app/services/plugin_manager.py +++ b/backend/app/services/plugin_manager.py @@ -3,6 +3,7 @@ import json import logging +from datetime import datetime, timezone from urllib.error import HTTPError, URLError from urllib.parse import urlencode from urllib.request import Request @@ -77,7 +78,19 @@ class MastodonPlugin(BasePlugin): if event.get('comment'): status_parts.append(event['comment']) if title: - status_parts.append(f'from: {event.get("url", "")}') + timestamp_value = event.get('timestamp') or event.get('created_at') + url = str(event.get('url', '') or '').strip() + if timestamp_value: + try: + parsed = datetime.fromisoformat(str(timestamp_value).replace('Z', '+00:00')) + if parsed.tzinfo is None: + parsed = parsed.replace(tzinfo=timezone.utc) + formatted = parsed.astimezone(timezone.utc).strftime('%Y %B %d - %H:%M') + status_parts.append(f'Logged on {formatted} from: {url}') + except ValueError: + status_parts.append(f'Logged from: {url}') + else: + status_parts.append(f'Logged from: {url}') if event.get('tags'): status_parts.append(' '.join(event['tags'])) post_body = '\n\n'.join(status_parts) diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py index b1664f2..1c440bf 100644 --- a/backend/tests/test_api.py +++ b/backend/tests/test_api.py @@ -885,6 +885,7 @@ def test_link_submission_posts_to_enabled_mastodon_plugin(): 'title': 'A useful page', 'url': 'https://example.com/useful', 'comment': 'Worth sharing', + 'timestamp': '2026-08-29T21:10:00Z', 'tags': ['#python', '#web'], }) @@ -892,7 +893,7 @@ def test_link_submission_posts_to_enabled_mastodon_plugin(): assert received['path'] == '/api/v1/statuses' assert received['authorization'] == 'Bearer test-token' assert received['content_type'] == 'application/x-www-form-urlencoded' - assert received['body'] == {'status': ['From my #LinkLog:\n\nA useful page\n\nWorth sharing\n\nfrom: https://example.com/useful\n\n#python #web']} + assert received['body'] == {'status': ['From my #LinkLog:\n\nA useful page\n\nWorth sharing\n\nLogged on 2026 August 29 - 21:10 from: https://example.com/useful\n\n#python #web']} posted_item = next(item for item in client.get('/api/public/feed/alice', headers=headers).json() if item['id'] == response.json()['id']) assert posted_item['mastodon_posted'] is True finally: