mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-14 07:51:01 +00:00
Implement Mention::from_activity07()
This commit is contained in:
parent
991dfccf3b
commit
32cd91cfb9
1 changed files with 43 additions and 0 deletions
|
@ -138,6 +138,49 @@ impl Mention {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn from_activity07(
|
||||
conn: &Connection,
|
||||
ment: &link07::Mention,
|
||||
inside: i32,
|
||||
in_post: bool,
|
||||
notify: bool,
|
||||
) -> Result<Self> {
|
||||
let ap_url = ment.href().ok_or(Error::NotFound)?.as_str();
|
||||
let mentioned = User::find_by_ap_url(conn, ap_url)?;
|
||||
|
||||
if in_post {
|
||||
Post::get(conn, inside).and_then(|post| {
|
||||
let res = Mention::insert(
|
||||
conn,
|
||||
NewMention {
|
||||
mentioned_id: mentioned.id,
|
||||
post_id: Some(post.id),
|
||||
comment_id: None,
|
||||
},
|
||||
)?;
|
||||
if notify {
|
||||
res.notify(conn)?;
|
||||
}
|
||||
Ok(res)
|
||||
})
|
||||
} else {
|
||||
Comment::get(conn, inside).and_then(|comment| {
|
||||
let res = Mention::insert(
|
||||
conn,
|
||||
NewMention {
|
||||
mentioned_id: mentioned.id,
|
||||
post_id: None,
|
||||
comment_id: Some(comment.id),
|
||||
},
|
||||
)?;
|
||||
if notify {
|
||||
res.notify(conn)?;
|
||||
}
|
||||
Ok(res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn delete(&self, conn: &Connection) -> Result<()> {
|
||||
//find related notifications and delete them
|
||||
if let Ok(n) = Notification::find(conn, notification_kind::MENTION, self.id) {
|
||||
|
|
Loading…
Reference in a new issue