.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(note)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: creator.id,
- data: serde_json::to_value(&create)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, creator.id, &create, true)?;
send_activity(
&create,
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(note)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: creator.id,
- data: serde_json::to_value(&update)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, creator.id, &update, true)?;
send_activity(
&update,
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(note)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: creator.id,
- data: serde_json::to_value(&delete)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, creator.id, &delete, true)?;
send_activity(
&delete,
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(delete)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: creator.id,
- data: serde_json::to_value(&undo)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, creator.id, &undo, true)?;
send_activity(
&undo,
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
.set_object_base_box(note)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: mod_.id,
- data: serde_json::to_value(&remove)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, mod_.id, &remove, true)?;
send_activity(
&remove,
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
.set_object_base_box(remove)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: mod_.id,
- data: serde_json::to_value(&undo)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, mod_.id, &undo, true)?;
send_activity(
&undo,
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(note)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: creator.id,
- data: serde_json::to_value(&like)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, creator.id, &like, true)?;
send_activity(
&like,
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(note)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: creator.id,
- data: serde_json::to_value(&dislike)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, creator.id, &dislike, true)?;
send_activity(
&dislike,
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(like)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: creator.id,
- data: serde_json::to_value(&undo)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, creator.id, &undo, true)?;
send_activity(
&undo,
.set_object_base_box(BaseBox::from_concrete(follow.clone())?)?;
let to = format!("{}/inbox", actor_uri);
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: self.creator_id,
- data: serde_json::to_value(&accept)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, self.creator_id, &accept, true)?;
send_activity(
&accept,
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(group)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: self.creator_id,
- data: serde_json::to_value(&delete)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, self.creator_id, &delete, true)?;
// Note: For an accept, since it was automatic, no one pushed a button,
// the community was the actor.
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(delete)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: self.creator_id,
- data: serde_json::to_value(&undo)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, self.creator_id, &undo, true)?;
// Note: For an accept, since it was automatic, no one pushed a button,
// the community was the actor.
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
.set_object_base_box(group)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: mod_.id,
- data: serde_json::to_value(&remove)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, mod_.id, &remove, true)?;
// Note: For an accept, since it was automatic, no one pushed a button,
// the community was the actor.
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
.set_object_base_box(remove)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: mod_.id,
- data: serde_json::to_value(&undo)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, mod_.id, &undo, true)?;
// Note: For an accept, since it was automatic, no one pushed a button,
// the community was the actor.
verify(&request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&follow)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &follow, false)?;
let community_follower_form = CommunityFollowerForm {
community_id: community.id,
verify(&request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&follow)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &follow, false)?;
let community_follower_form = CommunityFollowerForm {
community_id: community.id,
pub mod user_inbox;
use crate::api::community::CommunityResponse;
+use crate::db::activity::insert_activity;
use crate::websocket::server::SendCommunityRoomMessage;
use activitystreams::object::kind::{NoteType, PageType};
use activitystreams::{
use crate::db::private_message_view::PrivateMessageView;
use crate::db::user::{UserForm, User_};
use crate::db::user_view::UserView;
-use crate::db::{activity, Crud, Followable, Joinable, Likeable, SearchType};
+use crate::db::{Crud, Followable, Joinable, Likeable, SearchType};
use crate::routes::nodeinfo::{NodeInfo, NodeInfoWellKnown};
use crate::routes::{ChatServerParam, DbPoolParam};
use crate::websocket::{
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(page)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: creator.id,
- data: serde_json::to_value(&create)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, creator.id, &create, true)?;
send_activity(
&create,
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(page)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: creator.id,
- data: serde_json::to_value(&update)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, creator.id, &update, true)?;
send_activity(
&update,
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(page)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: self.creator_id,
- data: serde_json::to_value(&delete)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, self.creator_id, &delete, true)?;
let community = Community::read(conn, self.community_id)?;
send_activity(
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(delete)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: self.creator_id,
- data: serde_json::to_value(&undo)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, self.creator_id, &undo, true)?;
let community = Community::read(conn, self.community_id)?;
send_activity(
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
.set_object_base_box(page)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: mod_.id,
- data: serde_json::to_value(&remove)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, mod_.id, &remove, true)?;
let community = Community::read(conn, self.community_id)?;
send_activity(
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
.set_object_base_box(remove)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: mod_.id,
- data: serde_json::to_value(&undo)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, mod_.id, &undo, true)?;
let community = Community::read(conn, self.community_id)?;
send_activity(
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(page)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: creator.id,
- data: serde_json::to_value(&like)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, creator.id, &like, true)?;
send_activity(
&like,
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(page)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: creator.id,
- data: serde_json::to_value(&dislike)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, creator.id, &dislike, true)?;
send_activity(
&dislike,
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(like)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: creator.id,
- data: serde_json::to_value(&undo)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, creator.id, &undo, true)?;
send_activity(
&undo,
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(note)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: creator.id,
- data: serde_json::to_value(&create)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, creator.id, &create, true)?;
send_activity(
&create,
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(note)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: creator.id,
- data: serde_json::to_value(&update)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, creator.id, &update, true)?;
send_activity(
&update,
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(note)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: creator.id,
- data: serde_json::to_value(&delete)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, creator.id, &delete, true)?;
send_activity(
&delete,
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(delete)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: creator.id,
- data: serde_json::to_value(&undo)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, creator.id, &undo, true)?;
send_activity(
&undo,
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&create)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &create, false)?;
let post = PostForm::from_apub(&page, &conn)?;
let inserted_post = Post::create(conn, &post)?;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&create)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &create, false)?;
let comment = CommentForm::from_apub(¬e, &conn)?;
let inserted_comment = Comment::create(conn, &comment)?;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&update)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &update, false)?;
let post = PostForm::from_apub(&page, conn)?;
let post_id = Post::read_from_apub_id(conn, &post.ap_id)?.id;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&like)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &like, false)?;
let post = PostForm::from_apub(&page, conn)?;
let post_id = Post::read_from_apub_id(conn, &post.ap_id)?.id;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&dislike)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &dislike, false)?;
let post = PostForm::from_apub(&page, conn)?;
let post_id = Post::read_from_apub_id(conn, &post.ap_id)?.id;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&update)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &update, false)?;
let comment = CommentForm::from_apub(¬e, &conn)?;
let comment_id = Comment::read_from_apub_id(conn, &comment.ap_id)?.id;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&like)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &like, false)?;
let comment = CommentForm::from_apub(¬e, &conn)?;
let comment_id = Comment::read_from_apub_id(conn, &comment.ap_id)?.id;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&dislike)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &dislike, false)?;
let comment = CommentForm::from_apub(¬e, &conn)?;
let comment_id = Comment::read_from_apub_id(conn, &comment.ap_id)?.id;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&delete)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &delete, false)?;
let community_actor_id = CommunityForm::from_apub(&group, &conn)?.actor_id;
let community = Community::read_from_actor_id(conn, &community_actor_id)?;
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
verify(request, &mod_.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: mod_.id,
- data: serde_json::to_value(&remove)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, mod_.id, &remove, false)?;
let community_actor_id = CommunityForm::from_apub(&group, &conn)?.actor_id;
let community = Community::read_from_actor_id(conn, &community_actor_id)?;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&delete)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &delete, false)?;
let post_ap_id = PostForm::from_apub(&page, conn)?.ap_id;
let post = Post::read_from_apub_id(conn, &post_ap_id)?;
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
verify(request, &mod_.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: mod_.id,
- data: serde_json::to_value(&remove)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, mod_.id, &remove, false)?;
let post_ap_id = PostForm::from_apub(&page, conn)?.ap_id;
let post = Post::read_from_apub_id(conn, &post_ap_id)?;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&delete)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &delete, false)?;
let comment_ap_id = CommentForm::from_apub(¬e, &conn)?.ap_id;
let comment = Comment::read_from_apub_id(conn, &comment_ap_id)?;
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
verify(request, &mod_.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: mod_.id,
- data: serde_json::to_value(&remove)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, mod_.id, &remove, false)?;
let comment_ap_id = CommentForm::from_apub(¬e, &conn)?.ap_id;
let comment = Comment::read_from_apub_id(conn, &comment_ap_id)?;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&delete)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &delete, false)?;
let comment_ap_id = CommentForm::from_apub(¬e, &conn)?.ap_id;
let comment = Comment::read_from_apub_id(conn, &comment_ap_id)?;
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
verify(request, &mod_.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: mod_.id,
- data: serde_json::to_value(&remove)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, mod_.id, &remove, false)?;
let comment_ap_id = CommentForm::from_apub(¬e, &conn)?.ap_id;
let comment = Comment::read_from_apub_id(conn, &comment_ap_id)?;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&delete)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &delete, false)?;
let post_ap_id = PostForm::from_apub(&page, conn)?.ap_id;
let post = Post::read_from_apub_id(conn, &post_ap_id)?;
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
verify(request, &mod_.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: mod_.id,
- data: serde_json::to_value(&remove)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, mod_.id, &remove, false)?;
let post_ap_id = PostForm::from_apub(&page, conn)?.ap_id;
let post = Post::read_from_apub_id(conn, &post_ap_id)?;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&delete)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &delete, false)?;
let community_actor_id = CommunityForm::from_apub(&group, &conn)?.actor_id;
let community = Community::read_from_actor_id(conn, &community_actor_id)?;
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
verify(request, &mod_.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: mod_.id,
- data: serde_json::to_value(&remove)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, mod_.id, &remove, false)?;
let community_actor_id = CommunityForm::from_apub(&group, &conn)?.actor_id;
let community = Community::read_from_actor_id(conn, &community_actor_id)?;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&like)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &like, false)?;
let comment = CommentForm::from_apub(¬e, &conn)?;
let comment_id = Comment::read_from_apub_id(conn, &comment.ap_id)?.id;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&like)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &like, false)?;
let post = PostForm::from_apub(&page, conn)?;
let post_id = Post::read_from_apub_id(conn, &post.ap_id)?.id;
.set_object_xsd_any_uri(follow_actor_id)?;
let to = format!("{}/inbox", follow_actor_id);
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: self.id,
- data: serde_json::to_value(&follow)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, self.id, &follow, true)?;
send_activity(
&follow,
.set_actor_xsd_any_uri(self.actor_id.to_owned())?
.set_object_base_box(follow)?;
- // Insert the sent activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: self.id,
- data: serde_json::to_value(&undo)?,
- local: true,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, self.id, &undo, true)?;
send_activity(
&undo,
let user = User_::read_from_name(&conn, username)?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: community.creator_id,
- data: serde_json::to_value(&accept)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, community.creator_id, &accept, false)?;
// Now you need to add this to the community follower
let community_follower_form = CommunityFollowerForm {
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&create)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &create, false)?;
let private_message = PrivateMessageForm::from_apub(¬e, &conn)?;
let inserted_private_message = PrivateMessage::create(&conn, &private_message)?;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&update)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &update, false)?;
let private_message = PrivateMessageForm::from_apub(¬e, &conn)?;
let private_message_id = PrivateMessage::read_from_apub_id(&conn, &private_message.ap_id)?.id;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&delete)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &delete, false)?;
let private_message = PrivateMessageForm::from_apub(¬e, &conn)?;
let private_message_id = PrivateMessage::read_from_apub_id(&conn, &private_message.ap_id)?.id;
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
verify(request, &user.public_key.unwrap())?;
- // Insert the received activity into the activity table
- let activity_form = activity::ActivityForm {
- user_id: user.id,
- data: serde_json::to_value(&delete)?,
- local: false,
- updated: None,
- };
- activity::Activity::create(&conn, &activity_form)?;
+ insert_activity(&conn, user.id, &delete, false)?;
let private_message = PrivateMessageForm::from_apub(¬e, &conn)?;
let private_message_id = PrivateMessage::read_from_apub_id(&conn, &private_message.ap_id)?.id;
use super::*;
use crate::schema::activity;
-use crate::schema::activity::dsl::*;
use serde_json::Value;
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
impl Crud<ActivityForm> for Activity {
fn read(conn: &PgConnection, activity_id: i32) -> Result<Self, Error> {
+ use crate::schema::activity::dsl::*;
activity.find(activity_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, activity_id: i32) -> Result<usize, Error> {
+ use crate::schema::activity::dsl::*;
diesel::delete(activity.find(activity_id)).execute(conn)
}
fn create(conn: &PgConnection, new_activity: &ActivityForm) -> Result<Self, Error> {
+ use crate::schema::activity::dsl::*;
insert_into(activity)
.values(new_activity)
.get_result::<Self>(conn)
activity_id: i32,
new_activity: &ActivityForm,
) -> Result<Self, Error> {
+ use crate::schema::activity::dsl::*;
diesel::update(activity.find(activity_id))
.set(new_activity)
.get_result::<Self>(conn)
}
}
+pub fn insert_activity<T>(
+ conn: &PgConnection,
+ user_id: i32,
+ data: &T,
+ local: bool,
+) -> Result<Activity, failure::Error>
+where
+ T: Serialize,
+{
+ let activity_form = ActivityForm {
+ user_id,
+ data: serde_json::to_value(&data)?,
+ local,
+ updated: None,
+ };
+ Ok(Activity::create(&conn, &activity_form)?)
+}
+
#[cfg(test)]
mod tests {
use super::super::user::*;