From 333fa5dc40d66a33ab31279c1dd88111ddbbec4e Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Wed, 7 Sep 2022 22:21:12 +0200 Subject: [PATCH] Add new notification type for Move activities --- app/admin.py | 4 +++- app/boxes.py | 7 +++++++ app/models.py | 2 ++ app/templates/notifications.html | 8 ++++++++ tests/test_inbox.py | 9 +++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/admin.py b/app/admin.py index 118cf4b..55538a8 100644 --- a/app/admin.py +++ b/app/admin.py @@ -682,7 +682,9 @@ async def get_notifications( .where(*where) .options( joinedload(models.Notification.actor), - joinedload(models.Notification.inbox_object), + joinedload(models.Notification.inbox_object).options( + joinedload(models.InboxObject.actor) + ), joinedload(models.Notification.outbox_object).options( joinedload( models.OutboxObject.outbox_object_attachments diff --git a/app/boxes.py b/app/boxes.py index 27e1ae0..bf8e708 100644 --- a/app/boxes.py +++ b/app/boxes.py @@ -1371,6 +1371,13 @@ async def _handle_move_activity( else: logger.info(f"Already following target {new_actor_id}") + notif = models.Notification( + notification_type=models.NotificationType.MOVE, + actor_id=new_actor.id, + inbox_object_id=move_activity.id, + ) + db_session.add(notif) + async def _handle_update_activity( db_session: AsyncSession, diff --git a/app/models.py b/app/models.py index 036ef85..30600d1 100644 --- a/app/models.py +++ b/app/models.py @@ -537,6 +537,8 @@ class NotificationType(str, enum.Enum): FOLLOW_REQUEST_ACCEPTED = "follow_request_accepted" FOLLOW_REQUEST_REJECTED = "follow_request_rejected" + MOVE = "move" + LIKE = "like" UNDO_LIKE = "undo_like" diff --git a/app/templates/notifications.html b/app/templates/notifications.html index 97ef851..a5e069f 100644 --- a/app/templates/notifications.html +++ b/app/templates/notifications.html @@ -36,6 +36,14 @@ {%- elif notif.notification_type.value == "follow_request_rejected" %} {{ notif_actor_action(notif, "rejected your follow request") }} {{ utils.display_actor(notif.actor, actors_metadata) }} + {%- elif notif.notification_type.value == "move" %} + {# for move notif, the actor is the target and the inbox object the Move activity #} +
+ + {{ utils.display_tiny_actor_icon(notif.inbox_object.actor) }} {{ notif.inbox_object.actor.display_name | clean_html(notif.inbox_object.actor) | safe }} has moved to + {{ notif.created_at | timeago }} +
+ {{ utils.display_actor(notif.actor) }} {% elif notif.notification_type.value == "like" %} {{ notif_actor_action(notif, "liked a post", with_icon=True) }} {{ utils.display_object(notif.outbox_object) }} diff --git a/tests/test_inbox.py b/tests/test_inbox.py index 48db11c..1cff853 100644 --- a/tests/test_inbox.py +++ b/tests/test_inbox.py @@ -414,3 +414,12 @@ def test_inbox__move_activity( ) == 1 ) + + # And a notification was created + notif = db.execute( + select(models.Notification).where( + models.Notification.notification_type == models.NotificationType.MOVE + ) + ).scalar_one() + assert notif.actor.ap_id == new_ra.ap_id + assert notif.inbox_object_id == inbox_activity.id