Add new notification type for Move activities

main
Thomas Sileo 2022-09-07 22:21:12 +02:00
parent 032632c4dc
commit 333fa5dc40
5 changed files with 29 additions and 1 deletions

View File

@ -682,7 +682,9 @@ async def get_notifications(
.where(*where) .where(*where)
.options( .options(
joinedload(models.Notification.actor), 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.Notification.outbox_object).options(
joinedload( joinedload(
models.OutboxObject.outbox_object_attachments models.OutboxObject.outbox_object_attachments

View File

@ -1371,6 +1371,13 @@ async def _handle_move_activity(
else: else:
logger.info(f"Already following target {new_actor_id}") 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( async def _handle_update_activity(
db_session: AsyncSession, db_session: AsyncSession,

View File

@ -537,6 +537,8 @@ class NotificationType(str, enum.Enum):
FOLLOW_REQUEST_ACCEPTED = "follow_request_accepted" FOLLOW_REQUEST_ACCEPTED = "follow_request_accepted"
FOLLOW_REQUEST_REJECTED = "follow_request_rejected" FOLLOW_REQUEST_REJECTED = "follow_request_rejected"
MOVE = "move"
LIKE = "like" LIKE = "like"
UNDO_LIKE = "undo_like" UNDO_LIKE = "undo_like"

View File

@ -36,6 +36,14 @@
{%- elif notif.notification_type.value == "follow_request_rejected" %} {%- elif notif.notification_type.value == "follow_request_rejected" %}
{{ notif_actor_action(notif, "rejected your follow request") }} {{ notif_actor_action(notif, "rejected your follow request") }}
{{ utils.display_actor(notif.actor, actors_metadata) }} {{ 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 #}
<div class="actor-action">
<a href="{{ url_for("admin_profile") }}?actor_id={{ notif.inbox_object.actor.ap_id }}">
{{ utils.display_tiny_actor_icon(notif.inbox_object.actor) }} {{ notif.inbox_object.actor.display_name | clean_html(notif.inbox_object.actor) | safe }}</a> has moved to
<span title="{{ notif.created_at.isoformat() }}">{{ notif.created_at | timeago }}</span>
</div>
{{ utils.display_actor(notif.actor) }}
{% elif notif.notification_type.value == "like" %} {% elif notif.notification_type.value == "like" %}
{{ notif_actor_action(notif, "liked a post", with_icon=True) }} {{ notif_actor_action(notif, "liked a post", with_icon=True) }}
{{ utils.display_object(notif.outbox_object) }} {{ utils.display_object(notif.outbox_object) }}

View File

@ -414,3 +414,12 @@ def test_inbox__move_activity(
) )
== 1 == 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