mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-29 23:11:02 +00:00
Implement FromId07 for Like
This commit is contained in:
parent
b2528c21ff
commit
a1c3bfb646
1 changed files with 51 additions and 2 deletions
|
@ -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<DbConn> for Like {
|
|||
}
|
||||
}
|
||||
|
||||
impl FromId07<DbConn> for Like {
|
||||
type Error = Error;
|
||||
type Object = Like07;
|
||||
|
||||
fn from_db07(conn: &DbConn, id: &str) -> Result<Self> {
|
||||
Like::find_by_ap_url(conn, id)
|
||||
}
|
||||
|
||||
fn from_activity07(conn: &DbConn, act: Like07) -> Result<Self> {
|
||||
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<User, activity::Undo, &DbConn> for Like {
|
||||
type Error = Error;
|
||||
type Output = ();
|
||||
|
|
Loading…
Reference in a new issue