diff --git a/plume-models/src/likes.rs b/plume-models/src/likes.rs index 3738d4d1..2190fbc7 100644 --- a/plume-models/src/likes.rs +++ b/plume-models/src/likes.rs @@ -4,7 +4,7 @@ use crate::{ }; use activitypub::activity; use activitystreams::{ - activity::{Like as Like07, Undo as Undo07}, + activity::{ActorAndObjectRef, Like as Like07, Undo as Undo07}, base::AnyBase, iri_string::types::IriString, prelude::*, @@ -12,7 +12,7 @@ use activitystreams::{ use chrono::NaiveDateTime; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; use plume_common::activity_pub::{ - inbox::{AsActor, AsObject, AsObject07, FromId}, + inbox::{AsActor, AsObject, AsObject07, FromId, FromId07}, sign::Signer, Id, IntoId, PUBLIC_VISIBILITY, }; @@ -198,6 +198,55 @@ impl FromId for Like { } } +impl FromId07 for Like { + type Error = Error; + type Object = Like07; + + fn from_db07(conn: &DbConn, id: &str) -> Result { + Like::find_by_ap_url(conn, id) + } + + fn from_activity07(conn: &DbConn, act: Like07) -> Result { + let res = Like::insert( + conn, + NewLike { + post_id: Post::from_id( + conn, + act.object_field_ref() + .as_single_id() + .ok_or(Error::MissingApProperty)? + .as_str(), + None, + CONFIG.proxy(), + ) + .map_err(|(_, e)| e)? + .id, + user_id: User::from_id07( + conn, + act.actor_field_ref() + .as_single_id() + .ok_or(Error::MissingApProperty)? + .as_str(), + None, + CONFIG.proxy(), + ) + .map_err(|(_, e)| e)? + .id, + ap_url: act + .id_unchecked() + .ok_or(Error::MissingApProperty)? + .to_string(), + }, + )?; + res.notify(conn)?; + Ok(res) + } + + fn get_sender07() -> &'static dyn Signer { + Instance::get_local_instance_user().expect("Failed to local instance user") + } +} + impl AsObject for Like { type Error = Error; type Output = ();