Browse Source

Merge pull request 'Adding unique ap_ids. Fixes #1100' (#90) from unique_ap_ids into activity-sender

Reviewed-on: https://yerbamate.dev/LemmyNet/lemmy/pulls/90
pull/89/head
dessalines 1 year ago
parent
commit
04a367b365
  1. 2
      server/lemmy_db/src/activity.rs
  2. 35
      server/lemmy_db/src/comment.rs
  3. 12
      server/lemmy_db/src/comment_view.rs
  4. 6
      server/lemmy_db/src/community.rs
  5. 10
      server/lemmy_db/src/moderator.rs
  6. 2
      server/lemmy_db/src/password_reset_request.rs
  7. 16
      server/lemmy_db/src/post.rs
  8. 10
      server/lemmy_db/src/post_view.rs
  9. 21
      server/lemmy_db/src/private_message.rs
  10. 4
      server/lemmy_db/src/user.rs
  11. 10
      server/lemmy_db/src/user_mention.rs
  12. 27
      server/migrations/2020-08-25-132005_add_unique_ap_ids/down.sql
  13. 56
      server/migrations/2020-08-25-132005_add_unique_ap_ids/up.sql
  14. 2
      server/src/api/comment.rs
  15. 4
      server/src/api/community.rs
  16. 4
      server/src/api/post.rs
  17. 69
      server/src/api/user.rs
  18. 2
      server/src/apub/comment.rs
  19. 2
      server/src/apub/community.rs
  20. 2
      server/src/apub/fetcher.rs
  21. 9
      server/src/apub/inbox/activities/delete.rs
  22. 9
      server/src/apub/inbox/activities/remove.rs
  23. 18
      server/src/apub/inbox/activities/undo.rs
  24. 16
      server/src/apub/inbox/user_inbox.rs
  25. 2
      server/src/apub/post.rs
  26. 2
      server/src/apub/private_message.rs
  27. 2
      server/src/apub/user.rs
  28. 10
      server/src/code_migrations.rs
  29. 55
      ui/src/api_tests/comment.spec.ts
  30. 7
      ui/src/api_tests/community.spec.ts
  31. 3
      ui/src/api_tests/follow.spec.ts
  32. 70
      ui/src/api_tests/post.spec.ts
  33. 11
      ui/src/api_tests/private_message.spec.ts
  34. 13
      ui/src/api_tests/shared.ts

2
server/lemmy_db/src/activity.rs

@ -113,7 +113,7 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
actor_id: "changeme_862362".into(),
actor_id: None,
bio: None,
local: true,
private_key: None,

35
server/lemmy_db/src/comment.rs

@ -39,13 +39,13 @@ pub struct CommentForm {
pub published: Option<chrono::NaiveDateTime>,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: Option<bool>,
pub ap_id: String,
pub ap_id: Option<String>,
pub local: bool,
}
impl CommentForm {
pub fn get_ap_id(&self) -> Result<Url, ParseError> {
Url::parse(&self.ap_id)
Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
}
}
@ -61,7 +61,6 @@ impl Crud<CommentForm> for Comment {
}
fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
println!("creating {}", &comment_form.ap_id);
use crate::schema::comment::dsl::*;
insert_into(comment)
.values(comment_form)
@ -164,17 +163,13 @@ impl Comment {
}
pub fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
println!("Comment::upsert() (entered into function)");
let existing = Self::read_from_apub_id(conn, &comment_form.ap_id);
println!("Comment::upsert() (checked if comment exists)");
let x = match existing {
Err(NotFound {}) => Ok(Self::create(conn, &comment_form)?),
// both the old and new comment should be identical so no need to do an update here
Ok(p) => Ok(Self::read(conn, p.id)?),
Err(e) => Err(e),
};
println!("Comment::upsert() (after match statement)");
x
use crate::schema::comment::dsl::*;
insert_into(comment)
.values(comment_form)
.on_conflict(ap_id)
.do_update()
.set(comment_form)
.get_result::<Self>(conn)
}
}
@ -278,7 +273,7 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
actor_id: "changeme_283687".into(),
actor_id: None,
bio: None,
local: true,
private_key: None,
@ -298,7 +293,7 @@ mod tests {
deleted: None,
updated: None,
nsfw: false,
actor_id: "changeme_928738972".into(),
actor_id: None,
local: true,
private_key: None,
public_key: None,
@ -326,7 +321,7 @@ mod tests {
embed_description: None,
embed_html: None,
thumbnail_url: None,
ap_id: "http://fake.com".into(),
ap_id: None,
local: true,
published: None,
};
@ -343,7 +338,7 @@ mod tests {
parent_id: None,
published: None,
updated: None,
ap_id: "http://fake.com".into(),
ap_id: None,
local: true,
};
@ -360,7 +355,7 @@ mod tests {
parent_id: None,
published: inserted_comment.published,
updated: None,
ap_id: "http://fake.com".into(),
ap_id: inserted_comment.ap_id.to_owned(),
local: true,
};
@ -374,7 +369,7 @@ mod tests {
read: None,
published: None,
updated: None,
ap_id: "http://fake.com".into(),
ap_id: None,
local: true,
};

12
server/lemmy_db/src/comment_view.rs

@ -517,7 +517,7 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
actor_id: "changeme_92873982".into(),
actor_id: None,
bio: None,
local: true,
private_key: None,
@ -537,7 +537,7 @@ mod tests {
deleted: None,
updated: None,
nsfw: false,
actor_id: "changeme_7625376".into(),
actor_id: None,
local: true,
private_key: None,
public_key: None,
@ -565,7 +565,7 @@ mod tests {
embed_description: None,
embed_html: None,
thumbnail_url: None,
ap_id: "http://fake.com".into(),
ap_id: None,
local: true,
published: None,
};
@ -582,7 +582,7 @@ mod tests {
read: None,
published: None,
updated: None,
ap_id: "http://fake.com".into(),
ap_id: None,
local: true,
};
@ -627,7 +627,7 @@ mod tests {
my_vote: None,
subscribed: None,
saved: None,
ap_id: "http://fake.com".to_string(),
ap_id: inserted_comment.ap_id.to_owned(),
local: true,
community_actor_id: inserted_community.actor_id.to_owned(),
community_local: true,
@ -665,7 +665,7 @@ mod tests {
my_vote: Some(1),
subscribed: Some(false),
saved: Some(false),
ap_id: "http://fake.com".to_string(),
ap_id: inserted_comment.ap_id.to_owned(),
local: true,
community_actor_id: inserted_community.actor_id.to_owned(),
community_local: true,

6
server/lemmy_db/src/community.rs

@ -45,7 +45,7 @@ pub struct CommunityForm {
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: Option<bool>,
pub nsfw: bool,
pub actor_id: String,
pub actor_id: Option<String>,
pub local: bool,
pub private_key: Option<String>,
pub public_key: Option<String>,
@ -330,7 +330,7 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
actor_id: "changeme_8266238".into(),
actor_id: None,
bio: None,
local: true,
private_key: None,
@ -350,7 +350,7 @@ mod tests {
removed: None,
deleted: None,
updated: None,
actor_id: "changeme_7625376".into(),
actor_id: None,
local: true,
private_key: None,
public_key: None,

10
server/lemmy_db/src/moderator.rs

@ -426,7 +426,7 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
actor_id: "changeme_829398".into(),
actor_id: None,
bio: None,
local: true,
private_key: None,
@ -454,7 +454,7 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
actor_id: "changeme_82982738".into(),
actor_id: None,
bio: None,
local: true,
private_key: None,
@ -474,7 +474,7 @@ mod tests {
deleted: None,
updated: None,
nsfw: false,
actor_id: "changeme_283687".into(),
actor_id: None,
local: true,
private_key: None,
public_key: None,
@ -502,7 +502,7 @@ mod tests {
embed_description: None,
embed_html: None,
thumbnail_url: None,
ap_id: "http://fake.com".into(),
ap_id: None,
local: true,
published: None,
};
@ -519,7 +519,7 @@ mod tests {
parent_id: None,
published: None,
updated: None,
ap_id: "http://fake.com".into(),
ap_id: None,
local: true,
};

2
server/lemmy_db/src/password_reset_request.rs

@ -103,7 +103,7 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
actor_id: "changeme_8292378".into(),
actor_id: None,
bio: None,
local: true,
private_key: None,

16
server/lemmy_db/src/post.rs

@ -53,13 +53,13 @@ pub struct PostForm {
pub embed_description: Option<String>,
pub embed_html: Option<String>,
pub thumbnail_url: Option<String>,
pub ap_id: String,
pub ap_id: Option<String>,
pub local: bool,
}
impl PostForm {
pub fn get_ap_id(&self) -> Result<Url, ParseError> {
Url::parse(&self.ap_id)
Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
}
}
@ -183,7 +183,9 @@ impl Post {
use crate::schema::post::dsl::*;
insert_into(post)
.values(post_form)
.on_conflict_do_nothing()
.on_conflict(ap_id)
.do_update()
.set(post_form)
.get_result::<Self>(conn)
}
}
@ -357,7 +359,7 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
actor_id: "changeme_8292683678".into(),
actor_id: None,
bio: None,
local: true,
private_key: None,
@ -377,7 +379,7 @@ mod tests {
deleted: None,
updated: None,
nsfw: false,
actor_id: "changeme_8223262378".into(),
actor_id: None,
local: true,
private_key: None,
public_key: None,
@ -405,7 +407,7 @@ mod tests {
embed_description: None,
embed_html: None,
thumbnail_url: None,
ap_id: "http://fake.com".into(),
ap_id: None,
local: true,
published: None,
};
@ -430,7 +432,7 @@ mod tests {
embed_description: None,
embed_html: None,
thumbnail_url: None,
ap_id: "http://fake.com".into(),
ap_id: inserted_post.ap_id.to_owned(),
local: true,
};

10
server/lemmy_db/src/post_view.rs

@ -423,7 +423,7 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
actor_id: "changeme_8282738268".into(),
actor_id: None,
bio: None,
local: true,
private_key: None,
@ -443,7 +443,7 @@ mod tests {
deleted: None,
updated: None,
nsfw: false,
actor_id: "changeme_2763".into(),
actor_id: None,
local: true,
private_key: None,
public_key: None,
@ -471,7 +471,7 @@ mod tests {
embed_description: None,
embed_html: None,
thumbnail_url: None,
ap_id: "http://fake.com".into(),
ap_id: None,
local: true,
published: None,
};
@ -555,7 +555,7 @@ mod tests {
embed_description: None,
embed_html: None,
thumbnail_url: None,
ap_id: "http://fake.com".to_string(),
ap_id: inserted_post.ap_id.to_owned(),
local: true,
creator_actor_id: inserted_user.actor_id.to_owned(),
creator_local: true,
@ -604,7 +604,7 @@ mod tests {
embed_description: None,
embed_html: None,
thumbnail_url: None,
ap_id: "http://fake.com".to_string(),
ap_id: inserted_post.ap_id.to_owned(),
local: true,
creator_actor_id: inserted_user.actor_id.to_owned(),
creator_local: true,

21
server/lemmy_db/src/private_message.rs

@ -27,7 +27,7 @@ pub struct PrivateMessageForm {
pub read: Option<bool>,
pub published: Option<chrono::NaiveDateTime>,
pub updated: Option<chrono::NaiveDateTime>,
pub ap_id: String,
pub ap_id: Option<String>,
pub local: bool,
}
@ -119,6 +119,17 @@ impl PrivateMessage {
.set(read.eq(true))
.get_results::<Self>(conn)
}
// TODO use this
pub fn upsert(conn: &PgConnection, private_message_form: &PrivateMessageForm) -> Result<Self, Error> {
use crate::schema::private_message::dsl::*;
insert_into(private_message)
.values(private_message_form)
.on_conflict(ap_id)
.do_update()
.set(private_message_form)
.get_result::<Self>(conn)
}
}
#[cfg(test)]
@ -153,7 +164,7 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
actor_id: "changeme_6723878".into(),
actor_id: None,
bio: None,
local: true,
private_key: None,
@ -181,7 +192,7 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
actor_id: "changeme_287263876".into(),
actor_id: None,
bio: None,
local: true,
private_key: None,
@ -199,7 +210,7 @@ mod tests {
read: None,
published: None,
updated: None,
ap_id: "http://fake.com".into(),
ap_id: None,
local: true,
};
@ -214,7 +225,7 @@ mod tests {
read: false,
updated: None,
published: inserted_private_message.published,
ap_id: "http://fake.com".into(),
ap_id: inserted_private_message.ap_id.to_owned(),
local: true,
};

4
server/lemmy_db/src/user.rs

@ -57,7 +57,7 @@ pub struct UserForm {
pub show_avatars: bool,
pub send_notifications_to_email: bool,
pub matrix_user_id: Option<String>,
pub actor_id: String,
pub actor_id: Option<String>,
pub bio: Option<String>,
pub local: bool,
pub private_key: Option<String>,
@ -189,7 +189,7 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
actor_id: "changeme_9826382637".into(),
actor_id: None,
bio: None,
local: true,
private_key: None,

10
server/lemmy_db/src/user_mention.rs

@ -106,7 +106,7 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
actor_id: "changeme_628763".into(),
actor_id: None,
bio: None,
local: true,
private_key: None,
@ -134,7 +134,7 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
actor_id: "changeme_927389278".into(),
actor_id: None,
bio: None,
local: true,
private_key: None,
@ -154,7 +154,7 @@ mod tests {
deleted: None,
updated: None,
nsfw: false,
actor_id: "changeme_876238".into(),
actor_id: None,
local: true,
private_key: None,
public_key: None,
@ -182,7 +182,7 @@ mod tests {
embed_description: None,
embed_html: None,
thumbnail_url: None,
ap_id: "http://fake.com".into(),
ap_id: None,
local: true,
published: None,
};
@ -199,7 +199,7 @@ mod tests {
parent_id: None,
published: None,
updated: None,
ap_id: "http://fake.com".into(),
ap_id: None,
local: true,
};

27
server/migrations/2020-08-25-132005_add_unique_ap_ids/down.sql

@ -0,0 +1,27 @@
-- Drop the uniques
alter table private_message drop constraint idx_private_message_ap_id;
alter table post drop constraint idx_post_ap_id;
alter table comment drop constraint idx_comment_ap_id;
alter table user_ drop constraint idx_user_actor_id;
alter table community drop constraint idx_community_actor_id;
alter table private_message alter column ap_id set not null;
alter table private_message alter column ap_id set default 'http://fake.com';
alter table post alter column ap_id set not null;
alter table post alter column ap_id set default 'http://fake.com';
alter table comment alter column ap_id set not null;
alter table comment alter column ap_id set default 'http://fake.com';
update private_message
set ap_id = 'http://fake.com'
where ap_id like 'changeme_%';
update post
set ap_id = 'http://fake.com'
where ap_id like 'changeme_%';
update comment
set ap_id = 'http://fake.com'
where ap_id like 'changeme_%';

56
server/migrations/2020-08-25-132005_add_unique_ap_ids/up.sql

@ -0,0 +1,56 @@
-- Add unique ap_id for private_message, comment, and post
-- Need to delete the possible dupes for ones that don't start with the fake one
delete from private_message a using (
select min(id) as id, ap_id
from private_message
group by ap_id having count(*) > 1
) b
where a.ap_id = b.ap_id
and a.id <> b.id;
delete from post a using (
select min(id) as id, ap_id
from post
group by ap_id having count(*) > 1
) b
where a.ap_id = b.ap_id
and a.id <> b.id;
delete from comment a using (
select min(id) as id, ap_id
from comment
group by ap_id having count(*) > 1
) b
where a.ap_id = b.ap_id
and a.id <> b.id;
-- Replacing the current default on the columns, to the unique one
update private_message
set ap_id = generate_unique_changeme()
where ap_id = 'http://fake.com';
update post
set ap_id = generate_unique_changeme()
where ap_id = 'http://fake.com';
update comment
set ap_id = generate_unique_changeme()
where ap_id = 'http://fake.com';
-- Add the unique indexes
alter table private_message alter column ap_id set not null;
alter table private_message alter column ap_id set default generate_unique_changeme();
alter table post alter column ap_id set not null;
alter table post alter column ap_id set default generate_unique_changeme();
alter table comment alter column ap_id set not null;
alter table comment alter column ap_id set default generate_unique_changeme();
-- Add the uniques, for user_ and community too
alter table private_message add constraint idx_private_message_ap_id unique (ap_id);
alter table post add constraint idx_post_ap_id unique (ap_id);
alter table comment add constraint idx_comment_ap_id unique (ap_id);
alter table user_ add constraint idx_user_actor_id unique (actor_id);
alter table community add constraint idx_community_actor_id unique (actor_id);

2
server/src/api/comment.rs

@ -146,7 +146,7 @@ impl Perform for CreateComment {
read: None,
published: None,
updated: None,
ap_id: "http://fake.com".into(),
ap_id: None,
local: true,
};

4
server/src/api/community.rs

@ -274,7 +274,7 @@ impl Perform for CreateCommunity {
deleted: None,
nsfw: data.nsfw,
updated: None,
actor_id,
actor_id: Some(actor_id),
local: true,
private_key: Some(keypair.private_key),
public_key: Some(keypair.public_key),
@ -368,7 +368,7 @@ impl Perform for EditCommunity {
deleted: Some(read_community.deleted),
nsfw: data.nsfw,
updated: Some(naive_now()),
actor_id: read_community.actor_id,
actor_id: Some(read_community.actor_id),
local: read_community.local,
private_key: read_community.private_key,
public_key: read_community.public_key,

4
server/src/api/post.rs

@ -187,7 +187,7 @@ impl Perform for CreatePost {
embed_description: iframely_description,
embed_html: iframely_html,
thumbnail_url: pictrs_thumbnail,
ap_id: "http://fake.com".into(),
ap_id: None,
local: true,
published: None,
};
@ -518,7 +518,7 @@ impl Perform for EditPost {
embed_description: iframely_description,
embed_html: iframely_html,
thumbnail_url: pictrs_thumbnail,
ap_id: orig_post.ap_id,
ap_id: Some(orig_post.ap_id),
local: orig_post.local,
published: None,
};

69
server/src/api/user.rs

@ -410,7 +410,7 @@ impl Perform for Register {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
actor_id: make_apub_endpoint(EndpointType::User, &data.username).to_string(),
actor_id: Some(make_apub_endpoint(EndpointType::User, &data.username).to_string()),
bio: None,
local: true,
private_key: Some(user_keypair.private_key),
@ -441,37 +441,38 @@ impl Perform for Register {
let main_community_keypair = generate_actor_keypair()?;
// Create the main community if it doesn't exist
let main_community = match blocking(context.pool(), move |conn| Community::read(conn, 2))
.await?
{
Ok(c) => c,
Err(_e) => {
let default_community_name = "main";
let community_form = CommunityForm {
name: default_community_name.to_string(),
title: "The Default Community".to_string(),
description: Some("The Default Community".to_string()),
category_id: 1,
nsfw: false,
creator_id: inserted_user.id,
removed: None,
deleted: None,
updated: None,
actor_id: make_apub_endpoint(EndpointType::Community, default_community_name).to_string(),
local: true,
private_key: Some(main_community_keypair.private_key),
public_key: Some(main_community_keypair.public_key),
last_refreshed_at: None,
published: None,
icon: None,
banner: None,
};
blocking(context.pool(), move |conn| {
Community::create(conn, &community_form)
})
.await??
}
};
let main_community =
match blocking(context.pool(), move |conn| Community::read(conn, 2)).await? {
Ok(c) => c,
Err(_e) => {
let default_community_name = "main";
let community_form = CommunityForm {
name: default_community_name.to_string(),
title: "The Default Community".to_string(),
description: Some("The Default Community".to_string()),
category_id: 1,
nsfw: false,
creator_id: inserted_user.id,
removed: None,
deleted: None,
updated: None,
actor_id: Some(
make_apub_endpoint(EndpointType::Community, default_community_name).to_string(),
),
local: true,
private_key: Some(main_community_keypair.private_key),
public_key: Some(main_community_keypair.public_key),
last_refreshed_at: None,
published: None,
icon: None,
banner: None,
};
blocking(context.pool(), move |conn| {
Community::create(conn, &community_form)
})
.await??
}
};
// Sign them up for main community no matter what
let community_follower_form = CommunityFollowerForm {
@ -643,7 +644,7 @@ impl Perform for SaveUserSettings {
lang: data.lang.to_owned(),
show_avatars: data.show_avatars,
send_notifications_to_email: data.send_notifications_to_email,
actor_id: read_user.actor_id,
actor_id: Some(read_user.actor_id),
bio,
local: read_user.local,
private_key: read_user.private_key,
@ -1218,7 +1219,7 @@ impl Perform for CreatePrivateMessage {
deleted: None,
read: None,
updated: None,
ap_id: "http://fake.com".into(),
ap_id: None,
local: true,
published: None,
};

2
server/src/apub/comment.rs

@ -192,7 +192,7 @@ impl FromApub for CommentForm {
published: note.published().map(|u| u.to_owned().naive_local()),
updated: note.updated().map(|u| u.to_owned().naive_local()),
deleted: None,
ap_id: check_actor_domain(note, expected_domain)?,
ap_id: Some(check_actor_domain(note, expected_domain)?),
local: false,
})
}

2
server/src/apub/community.rs

@ -403,7 +403,7 @@ impl FromApub for CommunityForm {
updated: group.inner.updated().map(|u| u.to_owned().naive_local()),
deleted: None,
nsfw: group.ext_one.sensitive,
actor_id: check_actor_domain(group, expected_domain)?,
actor_id: Some(check_actor_domain(group, expected_domain)?),
local: false,
private_key: None,
public_key: Some(group.ext_two.to_owned().public_key.public_key_pem),

2
server/src/apub/fetcher.rs

@ -337,7 +337,7 @@ async fn fetch_remote_community(
for o in outbox_items {
let page = PageExt::from_any_base(o)?.context(location_info!())?;
let post = PostForm::from_apub(&page, context, None).await?;
let post_ap_id = post.ap_id.clone();
let post_ap_id = post.ap_id.as_ref().context(location_info!())?.clone();
// Check whether the post already exists in the local db
let existing = blocking(context.pool(), move |conn| {
Post::read_from_apub_id(conn, &post_ap_id)

9
server/src/apub/inbox/activities/delete.rs

@ -78,7 +78,7 @@ async fn receive_delete_post(
embed_description: post.embed_description,
embed_html: post.embed_html,
thumbnail_url: post.thumbnail_url,
ap_id: post.ap_id,
ap_id: Some(post.ap_id),
local: post.local,
published: None,
};
@ -131,7 +131,7 @@ async fn receive_delete_comment(
read: None,
published: None,
updated: Some(naive_now()),
ap_id: comment.ap_id,
ap_id: Some(comment.ap_id),
local: comment.local,
};
let comment_id = comment.id;
@ -175,7 +175,8 @@ async fn receive_delete_community(
let community_actor_id = CommunityForm::from_apub(&group, context, Some(user.actor_id()?))
.await?
.actor_id;
.actor_id
.context(location_info!())?;
let community = blocking(context.pool(), move |conn| {
Community::read_from_actor_id(conn, &community_actor_id)
@ -193,7 +194,7 @@ async fn receive_delete_community(
updated: Some(naive_now()),
deleted: Some(true),
nsfw: community.nsfw,
actor_id: community.actor_id,
actor_id: Some(community.actor_id),
local: community.local,
private_key: community.private_key,
public_key: community.public_key,

9
server/src/apub/inbox/activities/remove.rs

@ -85,7 +85,7 @@ async fn receive_remove_post(
embed_description: post.embed_description,
embed_html: post.embed_html,
thumbnail_url: post.thumbnail_url,
ap_id: post.ap_id,
ap_id: Some(post.ap_id),
local: post.local,
published: None,
};
@ -138,7 +138,7 @@ async fn receive_remove_comment(
read: None,
published: None,
updated: Some(naive_now()),
ap_id: comment.ap_id,
ap_id: Some(comment.ap_id),
local: comment.local,
};
let comment_id = comment.id;
@ -182,7 +182,8 @@ async fn receive_remove_community(
let community_actor_id = CommunityForm::from_apub(&group, context, Some(mod_.actor_id()?))
.await?
.actor_id;
.actor_id
.context(location_info!())?;
let community = blocking(context.pool(), move |conn| {
Community::read_from_actor_id(conn, &community_actor_id)
@ -200,7 +201,7 @@ async fn receive_remove_community(
updated: Some(naive_now()),
deleted: None,
nsfw: community.nsfw,
actor_id: community.actor_id,
actor_id: Some(community.actor_id),
local: community.local,
private_key: community.private_key,
public_key: community.public_key,

18
server/src/apub/inbox/activities/undo.rs

@ -175,7 +175,7 @@ async fn receive_undo_delete_comment(
read: None,
published: None,
updated: Some(naive_now()),
ap_id: comment.ap_id,
ap_id: Some(comment.ap_id),
local: comment.local,
};
let comment_id = comment.id;
@ -234,7 +234,7 @@ async fn receive_undo_remove_comment(
read: None,
published: None,
updated: Some(naive_now()),
ap_id: comment.ap_id,
ap_id: Some(comment.ap_id),
local: comment.local,
};
let comment_id = comment.id;
@ -299,7 +299,7 @@ async fn receive_undo_delete_post(
embed_description: post.embed_description,
embed_html: post.embed_html,
thumbnail_url: post.thumbnail_url,
ap_id: post.ap_id,
ap_id: Some(post.ap_id),
local: post.local,
published: None,
};
@ -359,7 +359,7 @@ async fn receive_undo_remove_post(
embed_description: post.embed_description,
embed_html: post.embed_html,
thumbnail_url: post.thumbnail_url,
ap_id: post.ap_id,
ap_id: Some(post.ap_id),
local: post.local,
published: None,
};
@ -399,7 +399,8 @@ async fn receive_undo_delete_community(
let community_actor_id = CommunityForm::from_apub(&group, context, Some(user.actor_id()?))
.await?
.actor_id;
.actor_id
.context(location_info!())?;
let community = blocking(context.pool(), move |conn| {
Community::read_from_actor_id(conn, &community_actor_id)
@ -417,7 +418,7 @@ async fn receive_undo_delete_community(
updated: Some(naive_now()),
deleted: Some(false),
nsfw: community.nsfw,
actor_id: community.actor_id,
actor_id: Some(community.actor_id),
local: community.local,
private_key: community.private_key,
public_key: community.public_key,
@ -464,7 +465,8 @@ async fn receive_undo_remove_community(
let community_actor_id = CommunityForm::from_apub(&group, context, Some(mod_.actor_id()?))
.await?
.actor_id;
.actor_id
.context(location_info!())?;
let community = blocking(context.pool(), move |conn| {
Community::read_from_actor_id(conn, &community_actor_id)
@ -482,7 +484,7 @@ async fn receive_undo_remove_community(
updated: Some(naive_now()),
deleted: None,
nsfw: community.nsfw,
actor_id: community.actor_id,
actor_id: Some(community.actor_id),
local: community.local,
private_key: community.private_key,
public_key: community.public_key,

16
server/src/apub/inbox/user_inbox.rs

@ -175,7 +175,11 @@ async fn receive_update_private_message(
let domain = Some(update.id_unchecked().context(location_info!())?.to_owned());
let private_message_form = PrivateMessageForm::from_apub(&note, context, domain).await?;
let private_message_ap_id = private_message_form.ap_id.clone();
let private_message_ap_id = private_message_form
.ap_id
.as_ref()
.context(location_info!())?
.clone();
let private_message = blocking(&context.pool(), move |conn| {
PrivateMessage::read_from_apub_id(conn, &private_message_ap_id)
})
@ -224,7 +228,7 @@ async fn receive_delete_private_message(
let domain = Some(delete.id_unchecked().context(location_info!())?.to_owned());
let private_message_form = PrivateMessageForm::from_apub(&note, context, domain).await?;
let private_message_ap_id = private_message_form.ap_id;
let private_message_ap_id = private_message_form.ap_id.context(location_info!())?;
let private_message = blocking(&context.pool(), move |conn| {
PrivateMessage::read_from_apub_id(conn, &private_message_ap_id)
})
@ -236,7 +240,7 @@ async fn receive_delete_private_message(
creator_id: private_message.creator_id,
deleted: Some(true),
read: None,
ap_id: private_message.ap_id,
ap_id: Some(private_message.ap_id),
local: private_message.local,
published: None,
updated: Some(naive_now()),
@ -287,7 +291,11 @@ async fn receive_undo_delete_private_message(
let domain = Some(undo.id_unchecked().context(location_info!())?.to_owned());
let private_message = PrivateMessageForm::from_apub(&note, context, domain).await?;
let private_message_ap_id = private_message.ap_id.clone();
let private_message_ap_id = private_message
.ap_id
.as_ref()
.context(location_info!())?
.clone();
let private_message_id = blocking(&context.pool(), move |conn| {
PrivateMessage::read_from_apub_id(conn, &private_message_ap_id).map(|pm| pm.id)
})

2
server/src/apub/post.rs

@ -289,7 +289,7 @@ impl FromApub for PostForm {
embed_description: embed.description,
embed_html: embed.html,
thumbnail_url,
ap_id: check_actor_domain(page, expected_domain)?,
ap_id: Some(check_actor_domain(page, expected_domain)?),
local: false,
})
}

2
server/src/apub/private_message.rs

@ -111,7 +111,7 @@ impl FromApub for PrivateMessageForm {
updated: note.updated().map(|u| u.to_owned().naive_local()),
deleted: None,
read: None,
ap_id: check_actor_domain(note, expected_domain)?,
ap_id: Some(check_actor_domain(note, expected_domain)?),
local: false,
})
}

2
server/src/apub/user.rs

@ -269,7 +269,7 @@ impl FromApub for UserForm {
show_avatars: false,
send_notifications_to_email: false,
matrix_user_id: None,
actor_id: check_actor_domain(person, expected_domain)?,
actor_id: Some(check_actor_domain(person, expected_domain)?),
bio,
local: false,
private_key: None,

10
server/src/code_migrations.rs

@ -67,7 +67,7 @@ fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
lang: cuser.lang.to_owned(),
show_avatars: cuser.show_avatars,
send_notifications_to_email: cuser.send_notifications_to_email,
actor_id: make_apub_endpoint(EndpointType::User, &cuser.name).to_string(),
actor_id: Some(make_apub_endpoint(EndpointType::User, &cuser.name).to_string()),
bio: cuser.bio.to_owned(),
local: cuser.local,
private_key: Some(keypair.private_key),
@ -111,7 +111,7 @@ fn community_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
deleted: None,
nsfw: ccommunity.nsfw,
updated: None,
actor_id: make_apub_endpoint(EndpointType::Community, &ccommunity.name).to_string(),
actor_id: Some(make_apub_endpoint(EndpointType::Community, &ccommunity.name).to_string()),
local: ccommunity.local,
private_key: Some(keypair.private_key),
public_key: Some(keypair.public_key),
@ -138,7 +138,7 @@ fn post_updates_2020_04_03(conn: &PgConnection) -> Result<(), LemmyError> {
// Update the ap_id
let incorrect_posts = post
.filter(ap_id.eq("http://fake.com"))
.filter(ap_id.eq("changeme_%"))
.filter(local.eq(true))
.load::<Post>(conn)?;
@ -163,7 +163,7 @@ fn comment_updates_2020_04_03(conn: &PgConnection) -> Result<(), LemmyError> {
// Update the ap_id
let incorrect_comments = comment
.filter(ap_id.eq("http://fake.com"))
.filter(ap_id.eq("changeme_%"))
.filter(local.eq(true))
.load::<Comment>(conn)?;
@ -188,7 +188,7 @@ fn private_message_updates_2020_05_05(conn: &PgConnection) -> Result<(), LemmyEr
// Update the ap_id
let incorrect_pms = private_message
.filter(ap_id.eq("http://fake.com"))
.filter(ap_id.eq("changeme_%"))
.filter(local.eq(true))
.load::<PrivateMessage>(conn)?;

55
ui/src/api_tests/comment.spec.ts

@ -1,3 +1,4 @@
jest.setTimeout(120000);
import {
alpha,
beta,
@ -19,6 +20,7 @@ import {
createCommunity,
registerUser,
API,
delay,
} from './shared';
import { PostResponse } from 'lemmy-js-client';
@ -30,6 +32,7 @@ beforeAll(async () => {
await followBeta(alpha);
await followBeta(gamma);
let search = await searchForBetaCommunity(alpha);
await delay(10000);
postRes = await createPost(
alpha,
search.communities.filter(c => c.local == false)[0].id
@ -47,6 +50,7 @@ test('Create a comment', async () => {
expect(commentRes.comment.community_local).toBe(false);
expect(commentRes.comment.creator_local).toBe(true);
expect(commentRes.comment.score).toBe(1);
await delay();
// Make sure that comment is liked on beta
let searchBeta = await searchComment(beta, commentRes.comment);
@ -64,12 +68,14 @@ test('Create a comment in a non-existent post', async () => {
test('Update a comment', async () => {
let commentRes = await createComment(alpha, postRes.post.id);
await delay();
let updateCommentRes = await updateComment(alpha, commentRes.comment.id);
expect(updateCommentRes.comment.content).toBe(
'A jest test federated comment update'
);
expect(updateCommentRes.comment.community_local).toBe(false);
expect(updateCommentRes.comment.creator_local).toBe(true);
await delay();
// Make sure that post is updated on beta
let searchBeta = await searchComment(beta, commentRes.comment);
@ -79,23 +85,21 @@ test('Update a comment', async () => {
test('Delete a comment', async () => {
let commentRes = await createComment(alpha, postRes.post.id);
await delay();
let deleteCommentRes = await deleteComment(
alpha,
true,
commentRes.comment.id
);
expect(deleteCommentRes.comment.deleted).toBe(true);
await delay();
// Make sure that comment is deleted on beta
// The search doesnt work below, because it returns a tombstone / http::gone
// let searchBeta = await searchComment(beta, commentRes.comment);
// console.log(searchBeta);
// let betaComment = searchBeta.comments[0];
// Create a fake post, just to get the previous new post id
let createdBetaPostJustToGetId = await createPost(beta, 2);
let betaPost = await getPost(beta, createdBetaPostJustToGetId.post.id - 1);
let betaComment = betaPost.comments[0];
expect(betaComment.deleted).toBe(true);
// Make sure that comment is undefined on beta
let searchBeta = await searchComment(beta, commentRes.comment);
let betaComment = searchBeta.comments[0];
expect(betaComment).toBeUndefined();
await delay();
let undeleteCommentRes = await deleteComment(
alpha,
@ -103,6 +107,7 @@ test('Delete a comment', async () => {
commentRes.comment.id
);
expect(undeleteCommentRes.comment.deleted).toBe(false);
await delay();
// Make sure that comment is undeleted on beta
let searchBeta2 = await searchComment(beta, commentRes.comment);
@ -112,6 +117,7 @@ test('Delete a comment', async () => {
test('Remove a comment from admin and community on the same instance', async () => {
let commentRes = await createComment(alpha, postRes.post.id);
await delay();
// Get the id for beta
let betaCommentId = (await searchComment(beta, commentRes.comment))
@ -120,6 +126,7 @@ test('Remove a comment from admin and community on the same instance', async ()
// The beta admin removes it (the community lives on beta)
let removeCommentRes = await removeComment(beta, true, betaCommentId);
expect(removeCommentRes.comment.removed).toBe(true);
await delay();
// Make sure that comment is removed on alpha (it gets pushed since an admin from beta removed it)
let refetchedPost = await getPost(alpha, postRes.post.id);
@ -127,6 +134,7 @@ test('Remove a comment from admin and community on the same instance', async ()
let unremoveCommentRes = await removeComment(beta, false, betaCommentId);
expect(unremoveCommentRes.comment.removed).toBe(false);
await delay();
// Make sure that comment is unremoved on beta
let refetchedPost2 = await getPost(alpha, postRes.post.id);
@ -142,15 +150,19 @@ test('Remove a comment from admin and community on different instance', async ()
// New alpha user creates a community, post, and comment.
let newCommunity = await createCommunity(newAlphaApi);
await delay();
let newPost = await createPost(newAlphaApi, newCommunity.community.id);
await delay();
let commentRes = await createComment(newAlphaApi, newPost.post.id);
expect(commentRes.comment.content).toBeDefined();
await delay();
// Beta searches that to cache it, then removes it
let searchBeta = await searchComment(beta, commentRes.comment);
let betaComment = searchBeta.comments[0];
let removeCommentRes = await removeComment(beta, true, betaComment.id);
expect(removeCommentRes.comment.removed).toBe(true);
await delay();
// Make sure its not removed on alpha
let refetchedPost = await getPost(newAlphaApi, newPost.post.id);
@ -159,8 +171,10 @@ test('Remove a comment from admin and community on different instance', async ()
test('Unlike a comment', async () => {
let commentRes = await createComment(alpha, postRes.post.id);
await delay();
let unlike = await likeComment(alpha, 0, commentRes.comment);
expect(unlike.comment.score).toBe(0);
await delay();
// Make sure that post is unliked on beta
let searchBeta = await searchComment(beta, commentRes.comment);
@ -173,6 +187,7 @@ test('Unlike a comment', async () => {
test('Federated comment like', async () => {
let commentRes = await createComment(alpha, postRes.post.id);
await delay();
// Find the comment on beta
let searchBeta = await searchComment(beta, commentRes.comment);
@ -180,6 +195,7 @@ test('Federated comment like', async () => {
let like = await likeComment(beta, 1, betaComment);
expect(like.comment.score).toBe(2);
await delay();
// Get the post from alpha, check the likes
let post = await getPost(alpha, postRes.post.id);
@ -189,6 +205,7 @@ test('Federated comment like', async () => {
test('Reply to a comment', async () => {
// Create a comment on alpha, find it on beta
let commentRes = await createComment(alpha, postRes.post.id);
await delay();
let searchBeta = await searchComment(beta, commentRes.comment);
let betaComment = searchBeta.comments[0];
@ -201,6 +218,7 @@ test('Reply to a comment', async () => {
expect(replyRes.comment.creator_local).toBe(true);
expect(replyRes.comment.parent_id).toBe(betaComment.id);
expect(replyRes.comment.score).toBe(1);
await delay();