Compare commits

...

1 commit

22 changed files with 136 additions and 161 deletions

View file

@ -1,7 +1,7 @@
use crate::{schema::activity, Crud}; use crate::{schema::activity, Crud};
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use log::debug; use log::debug;
use serde::{Serialize}; use serde::Serialize;
use serde_json::Value; use serde_json::Value;
use std::{ use std::{
fmt::Debug, fmt::Debug,
@ -12,7 +12,7 @@ use std::{
#[table_name = "activity"] #[table_name = "activity"]
pub struct Activity { pub struct Activity {
pub id: i32, pub id: i32,
pub user_id: i32, pub activity_id: String,
pub data: Value, pub data: Value,
pub local: bool, pub local: bool,
pub published: chrono::NaiveDateTime, pub published: chrono::NaiveDateTime,
@ -22,16 +22,16 @@ pub struct Activity {
#[derive(Insertable, AsChangeset)] #[derive(Insertable, AsChangeset)]
#[table_name = "activity"] #[table_name = "activity"]
pub struct ActivityForm { pub struct ActivityForm {
pub user_id: i32, pub activity_id: String,
pub data: Value, pub data: Value,
pub local: bool, pub local: bool,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<chrono::NaiveDateTime>,
} }
impl Crud<ActivityForm> for Activity { impl Crud<ActivityForm> for Activity {
fn read(conn: &PgConnection, activity_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, aid: i32) -> Result<Self, Error> {
use crate::schema::activity::dsl::*; use crate::schema::activity::dsl::*;
activity.find(activity_id).first::<Self>(conn) activity.find(aid).first::<Self>(conn)
} }
fn create(conn: &PgConnection, new_activity: &ActivityForm) -> Result<Self, Error> { fn create(conn: &PgConnection, new_activity: &ActivityForm) -> Result<Self, Error> {
@ -42,29 +42,27 @@ impl Crud<ActivityForm> for Activity {
} }
fn update( fn update(
conn: &PgConnection, _conn: &PgConnection,
activity_id: i32, _activity_id: i32,
new_activity: &ActivityForm, _new_activity: &ActivityForm,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
use crate::schema::activity::dsl::*; unimplemented!()
diesel::update(activity.find(activity_id))
.set(new_activity)
.get_result::<Self>(conn)
} }
} }
impl Activity {
pub fn do_insert_activity<T>( pub fn do_insert_activity<T>(
conn: &PgConnection, conn: &PgConnection,
user_id: i32, activity_id: String,
data: &T, data: &T,
local: bool, local: bool,
) -> Result<Activity, IoError> ) -> Result<Activity, IoError>
where where
T: Serialize + Debug, T: Serialize + Debug,
{ {
debug!("inserting activity for user {}, data {:?}", user_id, &data); debug!("inserting activity {} with data {:?}", activity_id, &data);
let activity_form = ActivityForm { let activity_form = ActivityForm {
user_id, activity_id,
data: serde_json::to_value(&data)?, data: serde_json::to_value(&data)?,
local, local,
updated: None, updated: None,
@ -79,6 +77,14 @@ where
} }
} }
pub fn read_from_activity_id(conn: &PgConnection, object_id: String) -> Result<Activity, Error> {
use crate::schema::activity::dsl::*;
activity
.filter(activity_id.eq(object_id))
.first::<Self>(conn)
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{
@ -95,34 +101,7 @@ mod tests {
fn test_crud() { fn test_crud() {
let conn = establish_unpooled_connection(); let conn = establish_unpooled_connection();
let creator_form = UserForm { let test_activity_id = "http://localhost/activities/123";
name: "activity_creator_pm".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: false,
updated: None,
show_nsfw: false,
theme: "darkly".into(),
default_sort_type: SortType::Hot as i16,
default_listing_type: ListingType::Subscribed as i16,
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
actor_id: None,
bio: None,
local: true,
private_key: None,
public_key: None,
last_refreshed_at: None,
};
let inserted_creator = User_::create(&conn, &creator_form).unwrap();
let test_json: Value = serde_json::from_str( let test_json: Value = serde_json::from_str(
r#"{ r#"{
"street": "Article Circle Expressway 1", "street": "Article Circle Expressway 1",
@ -133,7 +112,7 @@ mod tests {
) )
.unwrap(); .unwrap();
let activity_form = ActivityForm { let activity_form = ActivityForm {
user_id: inserted_creator.id, activity_id: test_activity_id.to_string(),
data: test_json.to_owned(), data: test_json.to_owned(),
local: true, local: true,
updated: None, updated: None,
@ -143,15 +122,15 @@ mod tests {
let expected_activity = Activity { let expected_activity = Activity {
id: inserted_activity.id, id: inserted_activity.id,
user_id: inserted_creator.id, activity_id: test_activity_id.to_string(),
data: test_json, data: test_json,
local: true, local: true,
published: inserted_activity.published, published: inserted_activity.published,
updated: None, updated: None,
}; };
let read_activity = Activity::read(&conn, inserted_activity.id).unwrap(); let read_activity =
User_::delete(&conn, inserted_creator.id).unwrap(); Activity::read_from_activity_id(&conn, inserted_activity.activity_id).unwrap();
assert_eq!(expected_activity, read_activity); assert_eq!(expected_activity, read_activity);
assert_eq!(expected_activity, inserted_activity); assert_eq!(expected_activity, inserted_activity);

View file

@ -3,7 +3,7 @@ use crate::{
Crud, Crud,
}; };
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use serde::{Serialize}; use serde::Serialize;
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize)] #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "category"] #[table_name = "category"]

View file

@ -84,9 +84,7 @@ table! {
} }
} }
#[derive( #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "comment_fast_view"] #[table_name = "comment_fast_view"]
pub struct CommentView { pub struct CommentView {
pub id: i32, pub id: i32,

View file

@ -123,9 +123,7 @@ table! {
} }
} }
#[derive( #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "community_fast_view"] #[table_name = "community_fast_view"]
pub struct CommunityView { pub struct CommunityView {
pub id: i32, pub id: i32,

View file

@ -1,6 +1,6 @@
use crate::limit_and_offset; use crate::limit_and_offset;
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use serde::{Serialize}; use serde::Serialize;
table! { table! {
mod_remove_post_view (id) { mod_remove_post_view (id) {
@ -17,9 +17,7 @@ table! {
} }
} }
#[derive( #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_remove_post_view"] #[table_name = "mod_remove_post_view"]
pub struct ModRemovePostView { pub struct ModRemovePostView {
pub id: i32, pub id: i32,
@ -77,9 +75,7 @@ table! {
} }
} }
#[derive( #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_lock_post_view"] #[table_name = "mod_lock_post_view"]
pub struct ModLockPostView { pub struct ModLockPostView {
pub id: i32, pub id: i32,
@ -136,9 +132,7 @@ table! {
} }
} }
#[derive( #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_sticky_post_view"] #[table_name = "mod_sticky_post_view"]
pub struct ModStickyPostView { pub struct ModStickyPostView {
pub id: i32, pub id: i32,
@ -200,9 +194,7 @@ table! {
} }
} }
#[derive( #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_remove_comment_view"] #[table_name = "mod_remove_comment_view"]
pub struct ModRemoveCommentView { pub struct ModRemoveCommentView {
pub id: i32, pub id: i32,
@ -264,9 +256,7 @@ table! {
} }
} }
#[derive( #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_remove_community_view"] #[table_name = "mod_remove_community_view"]
pub struct ModRemoveCommunityView { pub struct ModRemoveCommunityView {
pub id: i32, pub id: i32,
@ -320,9 +310,7 @@ table! {
} }
} }
#[derive( #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_ban_from_community_view"] #[table_name = "mod_ban_from_community_view"]
pub struct ModBanFromCommunityView { pub struct ModBanFromCommunityView {
pub id: i32, pub id: i32,
@ -381,9 +369,7 @@ table! {
} }
} }
#[derive( #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_ban_view"] #[table_name = "mod_ban_view"]
pub struct ModBanView { pub struct ModBanView {
pub id: i32, pub id: i32,
@ -435,9 +421,7 @@ table! {
} }
} }
#[derive( #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_add_community_view"] #[table_name = "mod_add_community_view"]
pub struct ModAddCommunityView { pub struct ModAddCommunityView {
pub id: i32, pub id: i32,
@ -492,9 +476,7 @@ table! {
} }
} }
#[derive( #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "mod_add_view"] #[table_name = "mod_add_view"]
pub struct ModAddView { pub struct ModAddView {
pub id: i32, pub id: i32,

View file

@ -1,7 +1,7 @@
use super::post_view::post_fast_view::BoxedQuery; use super::post_view::post_fast_view::BoxedQuery;
use crate::{fuzzy_search, limit_and_offset, ListingType, MaybeOptional, SortType}; use crate::{fuzzy_search, limit_and_offset, ListingType, MaybeOptional, SortType};
use diesel::{dsl::*, pg::Pg, result::Error, *}; use diesel::{dsl::*, pg::Pg, result::Error, *};
use serde::{Serialize}; use serde::Serialize;
// The faked schema since diesel doesn't do views // The faked schema since diesel doesn't do views
table! { table! {
@ -106,9 +106,7 @@ table! {
} }
} }
#[derive( #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "post_fast_view"] #[table_name = "post_fast_view"]
pub struct PostView { pub struct PostView {
pub id: i32, pub id: i32,

View file

@ -1,6 +1,6 @@
use crate::{limit_and_offset, MaybeOptional}; use crate::{limit_and_offset, MaybeOptional};
use diesel::{pg::Pg, result::Error, *}; use diesel::{pg::Pg, result::Error, *};
use serde::{Serialize}; use serde::Serialize;
// The faked schema since diesel doesn't do views // The faked schema since diesel doesn't do views
table! { table! {
@ -28,9 +28,7 @@ table! {
} }
} }
#[derive( #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "private_message_view"] #[table_name = "private_message_view"]
pub struct PrivateMessageView { pub struct PrivateMessageView {
pub id: i32, pub id: i32,

View file

@ -1,11 +1,11 @@
table! { table! {
activity (id) { activity (id) {
id -> Int4, id -> Int4,
user_id -> Int4,
data -> Jsonb, data -> Jsonb,
local -> Bool, local -> Bool,
published -> Timestamp, published -> Timestamp,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamp>,
activity_id -> Nullable<Text>,
} }
} }
@ -480,7 +480,6 @@ table! {
} }
} }
joinable!(activity -> user_ (user_id));
joinable!(comment -> post (post_id)); joinable!(comment -> post (post_id));
joinable!(comment -> user_ (creator_id)); joinable!(comment -> user_ (creator_id));
joinable!(comment_like -> comment (comment_id)); joinable!(comment_like -> comment (comment_id));

View file

@ -1,5 +1,5 @@
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use serde::{Serialize}; use serde::Serialize;
table! { table! {
site_view (id) { site_view (id) {
@ -24,9 +24,7 @@ table! {
} }
} }
#[derive( #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "site_view"] #[table_name = "site_view"]
pub struct SiteView { pub struct SiteView {
pub id: i32, pub id: i32,

View file

@ -6,7 +6,7 @@ use crate::{
}; };
use bcrypt::{hash, DEFAULT_COST}; use bcrypt::{hash, DEFAULT_COST};
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use serde::{Serialize}; use serde::Serialize;
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)] #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "user_"] #[table_name = "user_"]

View file

@ -1,6 +1,6 @@
use crate::{limit_and_offset, MaybeOptional, SortType}; use crate::{limit_and_offset, MaybeOptional, SortType};
use diesel::{dsl::*, pg::Pg, result::Error, *}; use diesel::{dsl::*, pg::Pg, result::Error, *};
use serde::{Serialize}; use serde::Serialize;
// The faked schema since diesel doesn't do views // The faked schema since diesel doesn't do views
table! { table! {
@ -83,9 +83,7 @@ table! {
} }
} }
#[derive( #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "user_mention_fast_view"] #[table_name = "user_mention_fast_view"]
pub struct UserMentionView { pub struct UserMentionView {
pub id: i32, pub id: i32,

View file

@ -1,7 +1,7 @@
use super::user_view::user_fast::BoxedQuery; use super::user_view::user_fast::BoxedQuery;
use crate::{fuzzy_search, limit_and_offset, MaybeOptional, SortType}; use crate::{fuzzy_search, limit_and_offset, MaybeOptional, SortType};
use diesel::{dsl::*, pg::Pg, result::Error, *}; use diesel::{dsl::*, pg::Pg, result::Error, *};
use serde::{Serialize}; use serde::Serialize;
table! { table! {
user_view (id) { user_view (id) {
@ -51,9 +51,7 @@ table! {
} }
} }
#[derive( #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone,
)]
#[table_name = "user_fast"] #[table_name = "user_fast"]
pub struct UserView { pub struct UserView {
pub id: i32, pub id: i32,

View file

@ -0,0 +1,3 @@
-- Recreate user_id and remove activity_id
ALTER TABLE activity DROP COLUMN activity_id;
ALTER TABLE activity ADD COLUMN user_id Int4;

View file

@ -0,0 +1,4 @@
-- For activity table, remove the user_id column and add activity_id
ALTER TABLE activity ADD COLUMN activity_id Text;
ALTER TABLE activity DROP COLUMN user_id;

View file

@ -3,11 +3,12 @@ use crate::{
LemmyContext, LemmyContext,
}; };
use activitystreams::{ use activitystreams::{
base::{Extends, ExtendsExt}, base::{AsBase, BaseExt, Extends, ExtendsExt},
object::AsObject, object::AsObject,
}; };
use anyhow::Context;
use lemmy_db::{community::Community, user::User_}; use lemmy_db::{community::Community, user::User_};
use lemmy_utils::{get_apub_protocol_string, settings::Settings, LemmyError}; use lemmy_utils::{get_apub_protocol_string, location_info, settings::Settings, LemmyError};
use serde::{export::fmt::Debug, Serialize}; use serde::{export::fmt::Debug, Serialize};
use url::{ParseError, Url}; use url::{ParseError, Url};
use uuid::Uuid; use uuid::Uuid;
@ -20,12 +21,12 @@ pub async fn send_activity_to_community<T, Kind>(
context: &LemmyContext, context: &LemmyContext,
) -> Result<(), LemmyError> ) -> Result<(), LemmyError>
where where
T: AsObject<Kind> + Extends<Kind> + Serialize + Debug + Send + Clone + 'static, T: AsObject<Kind> + Extends<Kind> + AsBase<Kind> + Serialize + Debug + Send + Clone + 'static,
Kind: Serialize, Kind: Serialize,
<T as Extends<Kind>>::Error: From<serde_json::Error> + Send + Sync + 'static, <T as Extends<Kind>>::Error: From<serde_json::Error> + Send + Sync + 'static,
{ {
// TODO: looks like call this sometimes with activity, and sometimes with any_base let id = activity.id_unchecked().context(location_info!())?;
insert_activity(creator.id, activity.clone(), true, context.pool()).await?; insert_activity(id, activity.clone(), true, context.pool()).await?;
// if this is a local community, we need to do an announce from the community instead // if this is a local community, we need to do an announce from the community instead
if community.local { if community.local {

View file

@ -148,12 +148,13 @@ impl ActorType for Community {
let mut accept = Accept::new(self.actor_id.to_owned(), follow.into_any_base()?); let mut accept = Accept::new(self.actor_id.to_owned(), follow.into_any_base()?);
let to = actor.get_inbox_url()?; let to = actor.get_inbox_url()?;
let id = &generate_activity_id(AcceptType::Accept)?;
accept accept
.set_context(activitystreams::context()) .set_context(activitystreams::context())
.set_id(generate_activity_id(AcceptType::Accept)?) .set_id(id.to_owned())
.set_to(to.clone()); .set_to(to.clone());
insert_activity(self.creator_id, accept.clone(), true, context.pool()).await?; insert_activity(id, accept.clone(), true, context.pool()).await?;
send_activity(context.activity_queue(), accept, self, vec![to])?; send_activity(context.activity_queue(), accept, self, vec![to])?;
Ok(()) Ok(())
@ -163,13 +164,14 @@ impl ActorType for Community {
let group = self.to_apub(context.pool()).await?; let group = self.to_apub(context.pool()).await?;
let mut delete = Delete::new(creator.actor_id.to_owned(), group.into_any_base()?); let mut delete = Delete::new(creator.actor_id.to_owned(), group.into_any_base()?);
let id = &generate_activity_id(DeleteType::Delete)?;
delete delete
.set_context(activitystreams::context()) .set_context(activitystreams::context())
.set_id(generate_activity_id(DeleteType::Delete)?) .set_id(id.to_owned())
.set_to(public()) .set_to(public())
.set_many_ccs(vec![self.get_followers_url()?]); .set_many_ccs(vec![self.get_followers_url()?]);
insert_activity(self.creator_id, delete.clone(), true, context.pool()).await?; insert_activity(id, delete.clone(), true, context.pool()).await?;
let inboxes = self.get_follower_inboxes(context.pool()).await?; let inboxes = self.get_follower_inboxes(context.pool()).await?;
@ -195,13 +197,14 @@ impl ActorType for Community {
.set_many_ccs(vec![self.get_followers_url()?]); .set_many_ccs(vec![self.get_followers_url()?]);
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?); let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
let id = &generate_activity_id(UndoType::Undo)?;
undo undo
.set_context(activitystreams::context()) .set_context(activitystreams::context())
.set_id(generate_activity_id(UndoType::Undo)?) .set_id(id.to_owned())
.set_to(public()) .set_to(public())
.set_many_ccs(vec![self.get_followers_url()?]); .set_many_ccs(vec![self.get_followers_url()?]);
insert_activity(self.creator_id, undo.clone(), true, context.pool()).await?; insert_activity(id, undo.clone(), true, context.pool()).await?;
let inboxes = self.get_follower_inboxes(context.pool()).await?; let inboxes = self.get_follower_inboxes(context.pool()).await?;
@ -216,13 +219,14 @@ impl ActorType for Community {
let group = self.to_apub(context.pool()).await?; let group = self.to_apub(context.pool()).await?;
let mut remove = Remove::new(mod_.actor_id.to_owned(), group.into_any_base()?); let mut remove = Remove::new(mod_.actor_id.to_owned(), group.into_any_base()?);
let id = &generate_activity_id(RemoveType::Remove)?;
remove remove
.set_context(activitystreams::context()) .set_context(activitystreams::context())
.set_id(generate_activity_id(RemoveType::Remove)?) .set_id(id.to_owned())
.set_to(public()) .set_to(public())
.set_many_ccs(vec![self.get_followers_url()?]); .set_many_ccs(vec![self.get_followers_url()?]);
insert_activity(mod_.id, remove.clone(), true, context.pool()).await?; insert_activity(id, remove.clone(), true, context.pool()).await?;
let inboxes = self.get_follower_inboxes(context.pool()).await?; let inboxes = self.get_follower_inboxes(context.pool()).await?;
@ -245,13 +249,14 @@ impl ActorType for Community {
// Undo that fake activity // Undo that fake activity
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?); let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
let id = &generate_activity_id(LikeType::Like)?;
undo undo
.set_context(activitystreams::context()) .set_context(activitystreams::context())
.set_id(generate_activity_id(LikeType::Like)?) .set_id(id.to_owned())
.set_to(public()) .set_to(public())
.set_many_ccs(vec![self.get_followers_url()?]); .set_many_ccs(vec![self.get_followers_url()?]);
insert_activity(mod_.id, undo.clone(), true, context.pool()).await?; insert_activity(id, undo.clone(), true, context.pool()).await?;
let inboxes = self.get_follower_inboxes(context.pool()).await?; let inboxes = self.get_follower_inboxes(context.pool()).await?;
@ -493,13 +498,14 @@ pub async fn do_announce(
context: &LemmyContext, context: &LemmyContext,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let mut announce = Announce::new(community.actor_id.to_owned(), activity); let mut announce = Announce::new(community.actor_id.to_owned(), activity);
let id = &generate_activity_id(AnnounceType::Announce)?;
announce announce
.set_context(activitystreams::context()) .set_context(activitystreams::context())
.set_id(generate_activity_id(AnnounceType::Announce)?) .set_id(id.to_owned())
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()?]); .set_many_ccs(vec![community.get_followers_url()?]);
insert_activity(community.creator_id, announce.clone(), true, context.pool()).await?; insert_activity(id, announce.clone(), true, context.pool()).await?;
let mut to: Vec<Url> = community.get_follower_inboxes(context.pool()).await?; let mut to: Vec<Url> = community.get_follower_inboxes(context.pool()).await?;

View file

@ -75,13 +75,15 @@ pub async fn community_inbox(
let any_base = activity.clone().into_any_base()?; let any_base = activity.clone().into_any_base()?;
let kind = activity.kind().context(location_info!())?; let kind = activity.kind().context(location_info!())?;
let user_id = user.id;
let res = match kind { let res = match kind {
ValidTypes::Follow => handle_follow(any_base, user, community, &context).await, ValidTypes::Follow => handle_follow(any_base, user, community, &context).await,
ValidTypes::Undo => handle_undo_follow(any_base, user, community, &context).await, ValidTypes::Undo => handle_undo_follow(any_base, user, community, &context).await,
}; };
insert_activity(user_id, activity.clone(), false, context.pool()).await?; let id = activity
.id(sender.domain().context(location_info!())?)?
.context(location_info!())?;
insert_activity(id, activity.clone(), false, context.pool()).await?;
res res
} }

View file

@ -93,7 +93,10 @@ pub async fn shared_inbox(
ValidTypes::Undo => receive_undo(any_base, &context).await, ValidTypes::Undo => receive_undo(any_base, &context).await,
}; };
insert_activity(actor.user_id(), activity.clone(), false, context.pool()).await?; let id = activity
.id(sender.domain().context(location_info!())?)?
.context(location_info!())?;
insert_activity(id, activity.clone(), false, context.pool()).await?;
res res
} }

View file

@ -76,7 +76,10 @@ pub async fn user_inbox(
ValidTypes::Undo => receive_undo_delete_private_message(any_base, &context).await, ValidTypes::Undo => receive_undo_delete_private_message(any_base, &context).await,
}; };
insert_activity(actor.user_id(), activity.clone(), false, context.pool()).await?; let id = activity
.id(sender.domain().context(location_info!())?)?
.context(location_info!())?;
insert_activity(id, activity.clone(), false, context.pool()).await?;
res res
} }

View file

@ -33,7 +33,7 @@ use activitystreams_ext::{Ext1, Ext2};
use actix_web::{body::Body, HttpResponse}; use actix_web::{body::Body, HttpResponse};
use anyhow::{anyhow, Context}; use anyhow::{anyhow, Context};
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use lemmy_db::{activity::do_insert_activity, user::User_}; use lemmy_db::{activity::Activity, user::User_};
use lemmy_utils::{ use lemmy_utils::{
convert_datetime, convert_datetime,
get_apub_protocol_string, get_apub_protocol_string,
@ -349,7 +349,7 @@ pub async fn fetch_webfinger_url(
} }
pub async fn insert_activity<T>( pub async fn insert_activity<T>(
user_id: i32, activity_id: &Url,
data: T, data: T,
local: bool, local: bool,
pool: &DbPool, pool: &DbPool,
@ -357,8 +357,9 @@ pub async fn insert_activity<T>(
where where
T: Serialize + std::fmt::Debug + Send + 'static, T: Serialize + std::fmt::Debug + Send + 'static,
{ {
let activity_id = activity_id.to_string();
blocking(pool, move |conn| { blocking(pool, move |conn| {
do_insert_activity(conn, user_id, &data, local) Activity::do_insert_activity(conn, activity_id, &data, local)
}) })
.await??; .await??;
Ok(()) Ok(())

View file

@ -127,12 +127,13 @@ impl ApubObjectType for PrivateMessage {
let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?); let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?);
let to = recipient.get_inbox_url()?; let to = recipient.get_inbox_url()?;
let id = &generate_activity_id(CreateType::Create)?;
create create
.set_context(activitystreams::context()) .set_context(activitystreams::context())
.set_id(generate_activity_id(CreateType::Create)?) .set_id(id.to_owned())
.set_to(to.clone()); .set_to(to.clone());
insert_activity(creator.id, create.clone(), true, context.pool()).await?; insert_activity(id, create.clone(), true, context.pool()).await?;
send_activity(context.activity_queue(), create, creator, vec![to])?; send_activity(context.activity_queue(), create, creator, vec![to])?;
Ok(()) Ok(())
@ -147,12 +148,13 @@ impl ApubObjectType for PrivateMessage {
let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?); let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?);
let to = recipient.get_inbox_url()?; let to = recipient.get_inbox_url()?;
let id = &generate_activity_id(UpdateType::Update)?;
update update
.set_context(activitystreams::context()) .set_context(activitystreams::context())
.set_id(generate_activity_id(UpdateType::Update)?) .set_id(id.to_owned())
.set_to(to.clone()); .set_to(to.clone());
insert_activity(creator.id, update.clone(), true, context.pool()).await?; insert_activity(id, update.clone(), true, context.pool()).await?;
send_activity(context.activity_queue(), update, creator, vec![to])?; send_activity(context.activity_queue(), update, creator, vec![to])?;
Ok(()) Ok(())
@ -166,12 +168,13 @@ impl ApubObjectType for PrivateMessage {
let mut delete = Delete::new(creator.actor_id.to_owned(), note.into_any_base()?); let mut delete = Delete::new(creator.actor_id.to_owned(), note.into_any_base()?);
let to = recipient.get_inbox_url()?; let to = recipient.get_inbox_url()?;
let id = &generate_activity_id(DeleteType::Delete)?;
delete delete
.set_context(activitystreams::context()) .set_context(activitystreams::context())
.set_id(generate_activity_id(DeleteType::Delete)?) .set_id(id.to_owned())
.set_to(to.clone()); .set_to(to.clone());
insert_activity(creator.id, delete.clone(), true, context.pool()).await?; insert_activity(id, delete.clone(), true, context.pool()).await?;
send_activity(context.activity_queue(), delete, creator, vec![to])?; send_activity(context.activity_queue(), delete, creator, vec![to])?;
Ok(()) Ok(())
@ -196,12 +199,13 @@ impl ApubObjectType for PrivateMessage {
// Undo that fake activity // Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?); let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
let id = &generate_activity_id(UndoType::Undo)?;
undo undo
.set_context(activitystreams::context()) .set_context(activitystreams::context())
.set_id(generate_activity_id(UndoType::Undo)?) .set_id(id.to_owned())
.set_to(to.clone()); .set_to(to.clone());
insert_activity(creator.id, undo.clone(), true, context.pool()).await?; insert_activity(id, undo.clone(), true, context.pool()).await?;
send_activity(context.activity_queue(), undo, creator, vec![to])?; send_activity(context.activity_queue(), undo, creator, vec![to])?;
Ok(()) Ok(())

View file

@ -119,13 +119,14 @@ impl ActorType for User_ {
context: &LemmyContext, context: &LemmyContext,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let mut follow = Follow::new(self.actor_id.to_owned(), follow_actor_id.as_str()); let mut follow = Follow::new(self.actor_id.to_owned(), follow_actor_id.as_str());
let id = &generate_activity_id(FollowType::Follow)?;
follow follow
.set_context(activitystreams::context()) .set_context(activitystreams::context())
.set_id(generate_activity_id(FollowType::Follow)?); .set_id(id.to_owned());
let follow_actor = get_or_fetch_and_upsert_actor(follow_actor_id, context).await?; let follow_actor = get_or_fetch_and_upsert_actor(follow_actor_id, context).await?;
let to = follow_actor.get_inbox_url()?; let to = follow_actor.get_inbox_url()?;
insert_activity(self.id, follow.clone(), true, context.pool()).await?; insert_activity(id, follow.clone(), true, context.pool()).await?;
send_activity(context.activity_queue(), follow, self, vec![to])?; send_activity(context.activity_queue(), follow, self, vec![to])?;
Ok(()) Ok(())
@ -146,11 +147,12 @@ impl ActorType for User_ {
// Undo that fake activity // Undo that fake activity
let mut undo = Undo::new(Url::parse(&self.actor_id)?, follow.into_any_base()?); let mut undo = Undo::new(Url::parse(&self.actor_id)?, follow.into_any_base()?);
let id = &generate_activity_id(UndoType::Undo)?;
undo undo
.set_context(activitystreams::context()) .set_context(activitystreams::context())
.set_id(generate_activity_id(UndoType::Undo)?); .set_id(id.to_owned());
insert_activity(self.id, undo.clone(), true, context.pool()).await?; insert_activity(id, undo.clone(), true, context.pool()).await?;
send_activity(context.activity_queue(), undo, self, vec![to])?; send_activity(context.activity_queue(), undo, self, vec![to])?;
Ok(()) Ok(())