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
This commit is contained in:
dessalines 2020-08-31 13:46:49 +00:00
commit 04a367b365
34 changed files with 361 additions and 162 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -27,7 +27,7 @@ pub struct PrivateMessageForm {
pub read: Option<bool>, pub read: Option<bool>,
pub published: Option<chrono::NaiveDateTime>, pub published: Option<chrono::NaiveDateTime>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<chrono::NaiveDateTime>,
pub ap_id: String, pub ap_id: Option<String>,
pub local: bool, pub local: bool,
} }
@ -119,6 +119,17 @@ impl PrivateMessage {
.set(read.eq(true)) .set(read.eq(true))
.get_results::<Self>(conn) .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)] #[cfg(test)]
@ -153,7 +164,7 @@ mod tests {
lang: "browser".into(), lang: "browser".into(),
show_avatars: true, show_avatars: true,
send_notifications_to_email: false, send_notifications_to_email: false,
actor_id: "changeme_6723878".into(), actor_id: None,
bio: None, bio: None,
local: true, local: true,
private_key: None, private_key: None,
@ -181,7 +192,7 @@ mod tests {
lang: "browser".into(), lang: "browser".into(),
show_avatars: true, show_avatars: true,
send_notifications_to_email: false, send_notifications_to_email: false,
actor_id: "changeme_287263876".into(), actor_id: None,
bio: None, bio: None,
local: true, local: true,
private_key: None, private_key: None,
@ -199,7 +210,7 @@ mod tests {
read: None, read: None,
published: None, published: None,
updated: None, updated: None,
ap_id: "http://fake.com".into(), ap_id: None,
local: true, local: true,
}; };
@ -214,7 +225,7 @@ mod tests {
read: false, read: false,
updated: None, updated: None,
published: inserted_private_message.published, published: inserted_private_message.published,
ap_id: "http://fake.com".into(), ap_id: inserted_private_message.ap_id.to_owned(),
local: true, local: true,
}; };

View file

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

View file

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

View file

@ -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_%';

View file

@ -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);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -175,7 +175,11 @@ async fn receive_update_private_message(
let domain = Some(update.id_unchecked().context(location_info!())?.to_owned()); 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_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| { let private_message = blocking(&context.pool(), move |conn| {
PrivateMessage::read_from_apub_id(conn, &private_message_ap_id) 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 domain = Some(delete.id_unchecked().context(location_info!())?.to_owned());
let private_message_form = PrivateMessageForm::from_apub(&note, context, domain).await?; 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| { let private_message = blocking(&context.pool(), move |conn| {
PrivateMessage::read_from_apub_id(conn, &private_message_ap_id) 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, creator_id: private_message.creator_id,
deleted: Some(true), deleted: Some(true),
read: None, read: None,
ap_id: private_message.ap_id, ap_id: Some(private_message.ap_id),
local: private_message.local, local: private_message.local,
published: None, published: None,
updated: Some(naive_now()), 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 domain = Some(undo.id_unchecked().context(location_info!())?.to_owned());
let private_message = PrivateMessageForm::from_apub(&note, context, domain).await?; 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| { let private_message_id = blocking(&context.pool(), move |conn| {
PrivateMessage::read_from_apub_id(conn, &private_message_ap_id).map(|pm| pm.id) PrivateMessage::read_from_apub_id(conn, &private_message_ap_id).map(|pm| pm.id)
}) })

View file

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

View file

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

View file

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

View file

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

View file

@ -1,3 +1,4 @@
jest.setTimeout(120000);
import { import {
alpha, alpha,
beta, beta,
@ -19,6 +20,7 @@ import {
createCommunity, createCommunity,
registerUser, registerUser,
API, API,
delay,
} from './shared'; } from './shared';
import { PostResponse } from 'lemmy-js-client'; import { PostResponse } from 'lemmy-js-client';
@ -30,6 +32,7 @@ beforeAll(async () => {
await followBeta(alpha); await followBeta(alpha);
await followBeta(gamma); await followBeta(gamma);
let search = await searchForBetaCommunity(alpha); let search = await searchForBetaCommunity(alpha);
await delay(10000);
postRes = await createPost( postRes = await createPost(
alpha, alpha,
search.communities.filter(c => c.local == false)[0].id 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.community_local).toBe(false);
expect(commentRes.comment.creator_local).toBe(true); expect(commentRes.comment.creator_local).toBe(true);
expect(commentRes.comment.score).toBe(1); expect(commentRes.comment.score).toBe(1);
await delay();
// Make sure that comment is liked on beta // Make sure that comment is liked on beta
let searchBeta = await searchComment(beta, commentRes.comment); 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 () => { test('Update a comment', async () => {
let commentRes = await createComment(alpha, postRes.post.id); let commentRes = await createComment(alpha, postRes.post.id);
await delay();
let updateCommentRes = await updateComment(alpha, commentRes.comment.id); let updateCommentRes = await updateComment(alpha, commentRes.comment.id);
expect(updateCommentRes.comment.content).toBe( expect(updateCommentRes.comment.content).toBe(
'A jest test federated comment update' 'A jest test federated comment update'
); );
expect(updateCommentRes.comment.community_local).toBe(false); expect(updateCommentRes.comment.community_local).toBe(false);
expect(updateCommentRes.comment.creator_local).toBe(true); expect(updateCommentRes.comment.creator_local).toBe(true);
await delay();
// Make sure that post is updated on beta // Make sure that post is updated on beta
let searchBeta = await searchComment(beta, commentRes.comment); let searchBeta = await searchComment(beta, commentRes.comment);
@ -79,23 +85,21 @@ test('Update a comment', async () => {
test('Delete a comment', async () => { test('Delete a comment', async () => {
let commentRes = await createComment(alpha, postRes.post.id); let commentRes = await createComment(alpha, postRes.post.id);
await delay();
let deleteCommentRes = await deleteComment( let deleteCommentRes = await deleteComment(
alpha, alpha,
true, true,
commentRes.comment.id commentRes.comment.id
); );
expect(deleteCommentRes.comment.deleted).toBe(true); expect(deleteCommentRes.comment.deleted).toBe(true);
await delay();
// Make sure that comment is deleted on beta // Make sure that comment is undefined on beta
// The search doesnt work below, because it returns a tombstone / http::gone let searchBeta = await searchComment(beta, commentRes.comment);
// let searchBeta = await searchComment(beta, commentRes.comment); let betaComment = searchBeta.comments[0];
// console.log(searchBeta); expect(betaComment).toBeUndefined();
// let betaComment = searchBeta.comments[0]; await delay();
// 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);
let undeleteCommentRes = await deleteComment( let undeleteCommentRes = await deleteComment(
alpha, alpha,
@ -103,6 +107,7 @@ test('Delete a comment', async () => {
commentRes.comment.id commentRes.comment.id
); );
expect(undeleteCommentRes.comment.deleted).toBe(false); expect(undeleteCommentRes.comment.deleted).toBe(false);
await delay();
// Make sure that comment is undeleted on beta // Make sure that comment is undeleted on beta
let searchBeta2 = await searchComment(beta, commentRes.comment); 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 () => { test('Remove a comment from admin and community on the same instance', async () => {
let commentRes = await createComment(alpha, postRes.post.id); let commentRes = await createComment(alpha, postRes.post.id);
await delay();
// Get the id for beta // Get the id for beta
let betaCommentId = (await searchComment(beta, commentRes.comment)) 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) // The beta admin removes it (the community lives on beta)
let removeCommentRes = await removeComment(beta, true, betaCommentId); let removeCommentRes = await removeComment(beta, true, betaCommentId);
expect(removeCommentRes.comment.removed).toBe(true); 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) // 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); 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); let unremoveCommentRes = await removeComment(beta, false, betaCommentId);
expect(unremoveCommentRes.comment.removed).toBe(false); expect(unremoveCommentRes.comment.removed).toBe(false);
await delay();
// Make sure that comment is unremoved on beta // Make sure that comment is unremoved on beta
let refetchedPost2 = await getPost(alpha, postRes.post.id); 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. // New alpha user creates a community, post, and comment.
let newCommunity = await createCommunity(newAlphaApi); let newCommunity = await createCommunity(newAlphaApi);
await delay();
let newPost = await createPost(newAlphaApi, newCommunity.community.id); let newPost = await createPost(newAlphaApi, newCommunity.community.id);
await delay();
let commentRes = await createComment(newAlphaApi, newPost.post.id); let commentRes = await createComment(newAlphaApi, newPost.post.id);
expect(commentRes.comment.content).toBeDefined(); expect(commentRes.comment.content).toBeDefined();
await delay();
// Beta searches that to cache it, then removes it // Beta searches that to cache it, then removes it
let searchBeta = await searchComment(beta, commentRes.comment); let searchBeta = await searchComment(beta, commentRes.comment);
let betaComment = searchBeta.comments[0]; let betaComment = searchBeta.comments[0];
let removeCommentRes = await removeComment(beta, true, betaComment.id); let removeCommentRes = await removeComment(beta, true, betaComment.id);
expect(removeCommentRes.comment.removed).toBe(true); expect(removeCommentRes.comment.removed).toBe(true);
await delay();
// Make sure its not removed on alpha // Make sure its not removed on alpha
let refetchedPost = await getPost(newAlphaApi, newPost.post.id); 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 () => { test('Unlike a comment', async () => {
let commentRes = await createComment(alpha, postRes.post.id); let commentRes = await createComment(alpha, postRes.post.id);
await delay();
let unlike = await likeComment(alpha, 0, commentRes.comment); let unlike = await likeComment(alpha, 0, commentRes.comment);
expect(unlike.comment.score).toBe(0); expect(unlike.comment.score).toBe(0);
await delay();
// Make sure that post is unliked on beta // Make sure that post is unliked on beta
let searchBeta = await searchComment(beta, commentRes.comment); let searchBeta = await searchComment(beta, commentRes.comment);
@ -173,6 +187,7 @@ test('Unlike a comment', async () => {
test('Federated comment like', async () => { test('Federated comment like', async () => {
let commentRes = await createComment(alpha, postRes.post.id); let commentRes = await createComment(alpha, postRes.post.id);
await delay();
// Find the comment on beta // Find the comment on beta
let searchBeta = await searchComment(beta, commentRes.comment); let searchBeta = await searchComment(beta, commentRes.comment);
@ -180,6 +195,7 @@ test('Federated comment like', async () => {
let like = await likeComment(beta, 1, betaComment); let like = await likeComment(beta, 1, betaComment);
expect(like.comment.score).toBe(2); expect(like.comment.score).toBe(2);
await delay();
// Get the post from alpha, check the likes // Get the post from alpha, check the likes
let post = await getPost(alpha, postRes.post.id); let post = await getPost(alpha, postRes.post.id);
@ -189,6 +205,7 @@ test('Federated comment like', async () => {
test('Reply to a comment', async () => { test('Reply to a comment', async () => {
// Create a comment on alpha, find it on beta // Create a comment on alpha, find it on beta
let commentRes = await createComment(alpha, postRes.post.id); let commentRes = await createComment(alpha, postRes.post.id);
await delay();
let searchBeta = await searchComment(beta, commentRes.comment); let searchBeta = await searchComment(beta, commentRes.comment);
let betaComment = searchBeta.comments[0]; 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.creator_local).toBe(true);
expect(replyRes.comment.parent_id).toBe(betaComment.id); expect(replyRes.comment.parent_id).toBe(betaComment.id);
expect(replyRes.comment.score).toBe(1); expect(replyRes.comment.score).toBe(1);
await delay();
// Make sure that comment is seen on alpha // Make sure that comment is seen on alpha
// TODO not sure why, but a searchComment back to alpha, for the ap_id of betas // TODO not sure why, but a searchComment back to alpha, for the ap_id of betas
@ -219,6 +237,7 @@ test('Mention beta', async () => {
// Create a mention on alpha // Create a mention on alpha
let mentionContent = 'A test mention of @lemmy_beta@lemmy-beta:8550'; let mentionContent = 'A test mention of @lemmy_beta@lemmy-beta:8550';
let commentRes = await createComment(alpha, postRes.post.id); let commentRes = await createComment(alpha, postRes.post.id);
await delay();
let mentionRes = await createComment( let mentionRes = await createComment(
alpha, alpha,
postRes.post.id, postRes.post.id,
@ -229,6 +248,7 @@ test('Mention beta', async () => {
expect(mentionRes.comment.community_local).toBe(false); expect(mentionRes.comment.community_local).toBe(false);
expect(mentionRes.comment.creator_local).toBe(true); expect(mentionRes.comment.creator_local).toBe(true);
expect(mentionRes.comment.score).toBe(1); expect(mentionRes.comment.score).toBe(1);
await delay();
let mentionsRes = await getMentions(beta); let mentionsRes = await getMentions(beta);
expect(mentionsRes.mentions[0].content).toBeDefined(); expect(mentionsRes.mentions[0].content).toBeDefined();
@ -239,6 +259,7 @@ test('Mention beta', async () => {
test('Comment Search', async () => { test('Comment Search', async () => {
let commentRes = await createComment(alpha, postRes.post.id); let commentRes = await createComment(alpha, postRes.post.id);
await delay();
let searchBeta = await searchComment(beta, commentRes.comment); let searchBeta = await searchComment(beta, commentRes.comment);
expect(searchBeta.comments[0].ap_id).toBe(commentRes.comment.ap_id); expect(searchBeta.comments[0].ap_id).toBe(commentRes.comment.ap_id);
}); });
@ -247,6 +268,7 @@ test('A and G subscribe to B (center) A posts, G mentions B, it gets announced t
// Create a local post // Create a local post
let alphaPost = await createPost(alpha, 2); let alphaPost = await createPost(alpha, 2);
expect(alphaPost.post.community_local).toBe(true); expect(alphaPost.post.community_local).toBe(true);
await delay();
// Make sure gamma sees it // Make sure gamma sees it
let search = await searchPost(gamma, alphaPost.post); let search = await searchPost(gamma, alphaPost.post);
@ -264,6 +286,7 @@ test('A and G subscribe to B (center) A posts, G mentions B, it gets announced t
expect(commentRes.comment.community_local).toBe(false); expect(commentRes.comment.community_local).toBe(false);
expect(commentRes.comment.creator_local).toBe(true); expect(commentRes.comment.creator_local).toBe(true);
expect(commentRes.comment.score).toBe(1); expect(commentRes.comment.score).toBe(1);
await delay();
// Make sure alpha sees it // Make sure alpha sees it
let alphaPost2 = await getPost(alpha, alphaPost.post.id); let alphaPost2 = await getPost(alpha, alphaPost.post.id);
@ -291,6 +314,7 @@ test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde
// B creates a post, and two comments, should be invisible to A // B creates a post, and two comments, should be invisible to A
let postRes = await createPost(beta, 2); let postRes = await createPost(beta, 2);
expect(postRes.post.name).toBeDefined(); expect(postRes.post.name).toBeDefined();
await delay();
let parentCommentContent = 'An invisible top level comment from beta'; let parentCommentContent = 'An invisible top level comment from beta';
let parentCommentRes = await createComment( let parentCommentRes = await createComment(
@ -300,6 +324,7 @@ test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde
parentCommentContent parentCommentContent
); );
expect(parentCommentRes.comment.content).toBe(parentCommentContent); expect(parentCommentRes.comment.content).toBe(parentCommentContent);
await delay();
// B creates a comment, then a child one of that. // B creates a comment, then a child one of that.
let childCommentContent = 'An invisible child comment from beta'; let childCommentContent = 'An invisible child comment from beta';
@ -310,11 +335,13 @@ test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde
childCommentContent childCommentContent
); );
expect(childCommentRes.comment.content).toBe(childCommentContent); expect(childCommentRes.comment.content).toBe(childCommentContent);
await delay();
// Follow beta again // Follow beta again
let follow = await followBeta(alpha); let follow = await followBeta(alpha);
expect(follow.community.local).toBe(false); expect(follow.community.local).toBe(false);
expect(follow.community.name).toBe('main'); expect(follow.community.name).toBe('main');
await delay();
// An update to the child comment on beta, should push the post, parent, and child to alpha now // An update to the child comment on beta, should push the post, parent, and child to alpha now
let updatedCommentContent = 'An update child comment from beta'; let updatedCommentContent = 'An update child comment from beta';
@ -324,10 +351,14 @@ test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde
updatedCommentContent updatedCommentContent
); );
expect(updateRes.comment.content).toBe(updatedCommentContent); expect(updateRes.comment.content).toBe(updatedCommentContent);
await delay();
// Get the post from alpha // Get the post from alpha
let createFakeAlphaPostToGetId = await createPost(alpha, 2); let search = await searchPost(alpha, postRes.post);
let alphaPost = await getPost(alpha, createFakeAlphaPostToGetId.post.id - 1); let alphaPostB = search.posts[0];
await delay();
let alphaPost = await getPost(alpha, alphaPostB.id);
expect(alphaPost.post.name).toBeDefined(); expect(alphaPost.post.name).toBeDefined();
expect(alphaPost.comments[1].content).toBe(parentCommentContent); expect(alphaPost.comments[1].content).toBe(parentCommentContent);
expect(alphaPost.comments[0].content).toBe(updatedCommentContent); expect(alphaPost.comments[0].content).toBe(updatedCommentContent);

View file

@ -6,6 +6,7 @@ import {
createCommunity, createCommunity,
deleteCommunity, deleteCommunity,
removeCommunity, removeCommunity,
delay,
} from './shared'; } from './shared';
beforeAll(async () => { beforeAll(async () => {
@ -24,12 +25,14 @@ test('Create community', async () => {
test('Delete community', async () => { test('Delete community', async () => {
let communityRes = await createCommunity(beta); let communityRes = await createCommunity(beta);
await delay();
let deleteCommunityRes = await deleteCommunity( let deleteCommunityRes = await deleteCommunity(
beta, beta,
true, true,
communityRes.community.id communityRes.community.id
); );
expect(deleteCommunityRes.community.deleted).toBe(true); expect(deleteCommunityRes.community.deleted).toBe(true);
await delay();
// Make sure it got deleted on A // Make sure it got deleted on A
let search = await searchForBetaCommunity(alpha); let search = await searchForBetaCommunity(alpha);
@ -44,6 +47,7 @@ test('Delete community', async () => {
communityRes.community.id communityRes.community.id
); );
expect(undeleteCommunityRes.community.deleted).toBe(false); expect(undeleteCommunityRes.community.deleted).toBe(false);
await delay();
// Make sure it got undeleted on A // Make sure it got undeleted on A
let search2 = await searchForBetaCommunity(alpha); let search2 = await searchForBetaCommunity(alpha);
@ -54,6 +58,7 @@ test('Delete community', async () => {
test('Remove community', async () => { test('Remove community', async () => {
let communityRes = await createCommunity(beta); let communityRes = await createCommunity(beta);
await delay();
let removeCommunityRes = await removeCommunity( let removeCommunityRes = await removeCommunity(
beta, beta,
true, true,
@ -66,6 +71,7 @@ test('Remove community', async () => {
let communityA = search.communities[0]; let communityA = search.communities[0];
// TODO this fails currently, because no updates are pushed // TODO this fails currently, because no updates are pushed
// expect(communityA.removed).toBe(true); // expect(communityA.removed).toBe(true);
await delay();
// unremove // unremove
let unremoveCommunityRes = await removeCommunity( let unremoveCommunityRes = await removeCommunity(
@ -74,6 +80,7 @@ test('Remove community', async () => {
communityRes.community.id communityRes.community.id
); );
expect(unremoveCommunityRes.community.removed).toBe(false); expect(unremoveCommunityRes.community.removed).toBe(false);
await delay();
// Make sure it got unremoved on A // Make sure it got unremoved on A
let search2 = await searchForBetaCommunity(alpha); let search2 = await searchForBetaCommunity(alpha);

View file

@ -5,6 +5,7 @@ import {
followCommunity, followCommunity,
checkFollowedCommunities, checkFollowedCommunities,
unfollowRemotes, unfollowRemotes,
delay,
} from './shared'; } from './shared';
beforeAll(async () => { beforeAll(async () => {
@ -22,6 +23,7 @@ test('Follow federated community', async () => {
// Make sure the follow response went through // Make sure the follow response went through
expect(follow.community.local).toBe(false); expect(follow.community.local).toBe(false);
expect(follow.community.name).toBe('main'); expect(follow.community.name).toBe('main');
await delay();
// Check it from local // Check it from local
let followCheck = await checkFollowedCommunities(alpha); let followCheck = await checkFollowedCommunities(alpha);
@ -33,6 +35,7 @@ test('Follow federated community', async () => {
// Test an unfollow // Test an unfollow
let unfollow = await followCommunity(alpha, false, remoteCommunityId); let unfollow = await followCommunity(alpha, false, remoteCommunityId);
expect(unfollow.community.local).toBe(false); expect(unfollow.community.local).toBe(false);
await delay();
// Make sure you are unsubbed locally // Make sure you are unsubbed locally
let unfollowCheck = await checkFollowedCommunities(alpha); let unfollowCheck = await checkFollowedCommunities(alpha);

View file

@ -1,3 +1,4 @@
jest.setTimeout(120000);
import { import {
alpha, alpha,
beta, beta,
@ -18,6 +19,7 @@ import {
removePost, removePost,
getPost, getPost,
unfollowRemotes, unfollowRemotes,
delay,
} from './shared'; } from './shared';
beforeAll(async () => { beforeAll(async () => {
@ -26,6 +28,7 @@ beforeAll(async () => {
await followBeta(gamma); await followBeta(gamma);
await followBeta(delta); await followBeta(delta);
await followBeta(epsilon); await followBeta(epsilon);
await delay(10000);
}); });
afterAll(async () => { afterAll(async () => {
@ -37,11 +40,13 @@ afterAll(async () => {
test('Create a post', async () => { test('Create a post', async () => {
let search = await searchForBetaCommunity(alpha); let search = await searchForBetaCommunity(alpha);
await delay();
let postRes = await createPost(alpha, search.communities[0].id); let postRes = await createPost(alpha, search.communities[0].id);
expect(postRes.post).toBeDefined(); expect(postRes.post).toBeDefined();
expect(postRes.post.community_local).toBe(false); expect(postRes.post.community_local).toBe(false);
expect(postRes.post.creator_local).toBe(true); expect(postRes.post.creator_local).toBe(true);
expect(postRes.post.score).toBe(1); expect(postRes.post.score).toBe(1);
await delay();
// Make sure that post is liked on beta // Make sure that post is liked on beta
let searchBeta = await searchPost(beta, postRes.post); let searchBeta = await searchPost(beta, postRes.post);
@ -69,12 +74,15 @@ test('Create a post in a non-existent community', async () => {
test('Unlike a post', async () => { test('Unlike a post', async () => {
let search = await searchForBetaCommunity(alpha); let search = await searchForBetaCommunity(alpha);
let postRes = await createPost(alpha, search.communities[0].id); let postRes = await createPost(alpha, search.communities[0].id);
await delay();
let unlike = await likePost(alpha, 0, postRes.post); let unlike = await likePost(alpha, 0, postRes.post);
expect(unlike.post.score).toBe(0); expect(unlike.post.score).toBe(0);
await delay();
// Try to unlike it again, make sure it stays at 0 // Try to unlike it again, make sure it stays at 0
let unlike2 = await likePost(alpha, 0, postRes.post); let unlike2 = await likePost(alpha, 0, postRes.post);
expect(unlike2.post.score).toBe(0); expect(unlike2.post.score).toBe(0);
await delay();
// Make sure that post is unliked on beta // Make sure that post is unliked on beta
let searchBeta = await searchPost(beta, postRes.post); let searchBeta = await searchPost(beta, postRes.post);
@ -89,12 +97,14 @@ test('Unlike a post', async () => {
test('Update a post', async () => { test('Update a post', async () => {
let search = await searchForBetaCommunity(alpha); let search = await searchForBetaCommunity(alpha);
let postRes = await createPost(alpha, search.communities[0].id); let postRes = await createPost(alpha, search.communities[0].id);
await delay();
let updatedName = 'A jest test federated post, updated'; let updatedName = 'A jest test federated post, updated';
let updatedPost = await updatePost(alpha, postRes.post); let updatedPost = await updatePost(alpha, postRes.post);
expect(updatedPost.post.name).toBe(updatedName); expect(updatedPost.post.name).toBe(updatedName);
expect(updatedPost.post.community_local).toBe(false); expect(updatedPost.post.community_local).toBe(false);
expect(updatedPost.post.creator_local).toBe(true); expect(updatedPost.post.creator_local).toBe(true);
await delay();
// Make sure that post is updated on beta // Make sure that post is updated on beta
let searchBeta = await searchPost(beta, postRes.post); let searchBeta = await searchPost(beta, postRes.post);
@ -102,6 +112,7 @@ test('Update a post', async () => {
expect(betaPost.community_local).toBe(true); expect(betaPost.community_local).toBe(true);
expect(betaPost.creator_local).toBe(false); expect(betaPost.creator_local).toBe(false);
expect(betaPost.name).toBe(updatedName); expect(betaPost.name).toBe(updatedName);
await delay();
// Make sure lemmy beta cannot update the post // Make sure lemmy beta cannot update the post
let updatedPostBeta = await updatePost(beta, betaPost); let updatedPostBeta = await updatePost(beta, betaPost);
@ -111,9 +122,11 @@ test('Update a post', async () => {
test('Sticky a post', async () => { test('Sticky a post', async () => {
let search = await searchForBetaCommunity(alpha); let search = await searchForBetaCommunity(alpha);
let postRes = await createPost(alpha, search.communities[0].id); let postRes = await createPost(alpha, search.communities[0].id);
await delay();
let stickiedPostRes = await stickyPost(alpha, true, postRes.post); let stickiedPostRes = await stickyPost(alpha, true, postRes.post);
expect(stickiedPostRes.post.stickied).toBe(true); expect(stickiedPostRes.post.stickied).toBe(true);
await delay();
// Make sure that post is stickied on beta // Make sure that post is stickied on beta
let searchBeta = await searchPost(beta, postRes.post); let searchBeta = await searchPost(beta, postRes.post);
@ -125,6 +138,7 @@ test('Sticky a post', async () => {
// Unsticky a post // Unsticky a post
let unstickiedPost = await stickyPost(alpha, false, postRes.post); let unstickiedPost = await stickyPost(alpha, false, postRes.post);
expect(unstickiedPost.post.stickied).toBe(false); expect(unstickiedPost.post.stickied).toBe(false);
await delay();
// Make sure that post is unstickied on beta // Make sure that post is unstickied on beta
let searchBeta2 = await searchPost(beta, postRes.post); let searchBeta2 = await searchPost(beta, postRes.post);
@ -137,6 +151,7 @@ test('Sticky a post', async () => {
let searchGamma = await searchPost(gamma, postRes.post); let searchGamma = await searchPost(gamma, postRes.post);
let gammaPost = searchGamma.posts[0]; let gammaPost = searchGamma.posts[0];
let gammaTrySticky = await stickyPost(gamma, true, gammaPost); let gammaTrySticky = await stickyPost(gamma, true, gammaPost);
await delay();
let searchBeta3 = await searchPost(beta, postRes.post); let searchBeta3 = await searchPost(beta, postRes.post);
let betaPost3 = searchBeta3.posts[0]; let betaPost3 = searchBeta3.posts[0];
expect(gammaTrySticky.post.stickied).toBe(true); expect(gammaTrySticky.post.stickied).toBe(true);
@ -145,10 +160,13 @@ test('Sticky a post', async () => {
test('Lock a post', async () => { test('Lock a post', async () => {
let search = await searchForBetaCommunity(alpha); let search = await searchForBetaCommunity(alpha);
await delay();
let postRes = await createPost(alpha, search.communities[0].id); let postRes = await createPost(alpha, search.communities[0].id);
await delay();
let lockedPostRes = await lockPost(alpha, true, postRes.post); let lockedPostRes = await lockPost(alpha, true, postRes.post);
expect(lockedPostRes.post.locked).toBe(true); expect(lockedPostRes.post.locked).toBe(true);
await delay();
// Make sure that post is locked on beta // Make sure that post is locked on beta
let searchBeta = await searchPost(beta, postRes.post); let searchBeta = await searchPost(beta, postRes.post);
@ -160,14 +178,17 @@ test('Lock a post', async () => {
// Try to make a new comment there, on alpha // Try to make a new comment there, on alpha
let comment = await createComment(alpha, postRes.post.id); let comment = await createComment(alpha, postRes.post.id);
expect(comment['error']).toBe('locked'); expect(comment['error']).toBe('locked');
await delay();
// Try to create a new comment, on beta // Try to create a new comment, on beta
let commentBeta = await createComment(beta, betaPost.id); let commentBeta = await createComment(beta, betaPost.id);
expect(commentBeta['error']).toBe('locked'); expect(commentBeta['error']).toBe('locked');
await delay();
// Unlock a post // Unlock a post
let unlockedPost = await lockPost(alpha, false, postRes.post); let unlockedPost = await lockPost(alpha, false, postRes.post);
expect(unlockedPost.post.locked).toBe(false); expect(unlockedPost.post.locked).toBe(false);
await delay();
// Make sure that post is unlocked on beta // Make sure that post is unlocked on beta
let searchBeta2 = await searchPost(beta, postRes.post); let searchBeta2 = await searchPost(beta, postRes.post);
@ -180,68 +201,84 @@ test('Lock a post', async () => {
test('Delete a post', async () => { test('Delete a post', async () => {
let search = await searchForBetaCommunity(alpha); let search = await searchForBetaCommunity(alpha);
let postRes = await createPost(alpha, search.communities[0].id); let postRes = await createPost(alpha, search.communities[0].id);
await delay();
let deletedPost = await deletePost(alpha, true, postRes.post); let deletedPost = await deletePost(alpha, true, postRes.post);
expect(deletedPost.post.deleted).toBe(true); expect(deletedPost.post.deleted).toBe(true);
await delay();
// Make sure lemmy beta sees post is deleted // Make sure lemmy beta sees post is deleted
let createFakeBetaPostToGetId = (await createPost(beta, 2)).post.id - 1; let searchBeta = await searchPost(beta, postRes.post);
let betaPost = await getPost(beta, createFakeBetaPostToGetId); let betaPost = searchBeta.posts[0];
expect(betaPost.post.deleted).toBe(true); // This will be undefined because of the tombstone
expect(betaPost).toBeUndefined();
await delay();
// Undelete // Undelete
let undeletedPost = await deletePost(alpha, false, postRes.post); let undeletedPost = await deletePost(alpha, false, postRes.post);
expect(undeletedPost.post.deleted).toBe(false); expect(undeletedPost.post.deleted).toBe(false);
await delay();
// Make sure lemmy beta sees post is undeleted // Make sure lemmy beta sees post is undeleted
let betaPost2 = await getPost(beta, createFakeBetaPostToGetId); let searchBeta2 = await searchPost(beta, postRes.post);
expect(betaPost2.post.deleted).toBe(false); let betaPost2 = searchBeta2.posts[0];
expect(betaPost2.deleted).toBe(false);
// Make sure lemmy beta cannot delete the post // Make sure lemmy beta cannot delete the post
let deletedPostBeta = await deletePost(beta, true, betaPost2.post); let deletedPostBeta = await deletePost(beta, true, betaPost2);
expect(deletedPostBeta).toStrictEqual({ error: 'no_post_edit_allowed' }); expect(deletedPostBeta).toStrictEqual({ error: 'no_post_edit_allowed' });
}); });
test('Remove a post from admin and community on different instance', async () => { test('Remove a post from admin and community on different instance', async () => {
let search = await searchForBetaCommunity(alpha); let search = await searchForBetaCommunity(alpha);
let postRes = await createPost(alpha, search.communities[0].id); let postRes = await createPost(alpha, search.communities[0].id);
await delay();
let removedPost = await removePost(alpha, true, postRes.post); let removedPost = await removePost(alpha, true, postRes.post);
expect(removedPost.post.removed).toBe(true); expect(removedPost.post.removed).toBe(true);
await delay();
// Make sure lemmy beta sees post is NOT removed // Make sure lemmy beta sees post is NOT removed
let createFakeBetaPostToGetId = (await createPost(beta, 2)).post.id - 1; let searchBeta = await searchPost(beta, postRes.post);
let betaPost = await getPost(beta, createFakeBetaPostToGetId); let betaPost = searchBeta.posts[0];
expect(betaPost.post.removed).toBe(false); expect(betaPost.removed).toBe(false);
await delay();
// Undelete // Undelete
let undeletedPost = await removePost(alpha, false, postRes.post); let undeletedPost = await removePost(alpha, false, postRes.post);
expect(undeletedPost.post.removed).toBe(false); expect(undeletedPost.post.removed).toBe(false);
await delay();
// Make sure lemmy beta sees post is undeleted // Make sure lemmy beta sees post is undeleted
let betaPost2 = await getPost(beta, createFakeBetaPostToGetId); let searchBeta2 = await searchPost(beta, postRes.post);
expect(betaPost2.post.removed).toBe(false); let betaPost2 = searchBeta2.posts[0];
expect(betaPost2.removed).toBe(false);
}); });
test('Remove a post from admin and community on same instance', async () => { test('Remove a post from admin and community on same instance', async () => {
let search = await searchForBetaCommunity(alpha); let search = await searchForBetaCommunity(alpha);
let postRes = await createPost(alpha, search.communities[0].id); let postRes = await createPost(alpha, search.communities[0].id);
await delay();
// Get the id for beta // Get the id for beta
let createFakeBetaPostToGetId = (await createPost(beta, 2)).post.id - 1; let searchBeta = await searchPost(beta, postRes.post);
let betaPost = await getPost(beta, createFakeBetaPostToGetId); let betaPost = searchBeta.posts[0];
await delay();
// The beta admin removes it (the community lives on beta) // The beta admin removes it (the community lives on beta)
let removePostRes = await removePost(beta, true, betaPost.post); let removePostRes = await removePost(beta, true, betaPost);
expect(removePostRes.post.removed).toBe(true); expect(removePostRes.post.removed).toBe(true);
await delay();
// Make sure lemmy alpha sees post is removed // Make sure lemmy alpha sees post is removed
let alphaPost = await getPost(alpha, postRes.post.id); let alphaPost = await getPost(alpha, postRes.post.id);
expect(alphaPost.post.removed).toBe(true); expect(alphaPost.post.removed).toBe(true);
await delay();
// Undelete // Undelete
let undeletedPost = await removePost(beta, false, betaPost.post); let undeletedPost = await removePost(beta, false, betaPost);
expect(undeletedPost.post.removed).toBe(false); expect(undeletedPost.post.removed).toBe(false);
await delay();
// Make sure lemmy alpha sees post is undeleted // Make sure lemmy alpha sees post is undeleted
let alphaPost2 = await getPost(alpha, postRes.post.id); let alphaPost2 = await getPost(alpha, postRes.post.id);
@ -250,7 +287,9 @@ test('Remove a post from admin and community on same instance', async () => {
test('Search for a post', async () => { test('Search for a post', async () => {
let search = await searchForBetaCommunity(alpha); let search = await searchForBetaCommunity(alpha);
await delay();
let postRes = await createPost(alpha, search.communities[0].id); let postRes = await createPost(alpha, search.communities[0].id);
await delay();
let searchBeta = await searchPost(beta, postRes.post); let searchBeta = await searchPost(beta, postRes.post);
expect(searchBeta.posts[0].name).toBeDefined(); expect(searchBeta.posts[0].name).toBeDefined();
@ -259,6 +298,7 @@ test('Search for a post', async () => {
test('A and G subscribe to B (center) A posts, it gets announced to G', async () => { test('A and G subscribe to B (center) A posts, it gets announced to G', async () => {
let search = await searchForBetaCommunity(alpha); let search = await searchForBetaCommunity(alpha);
let postRes = await createPost(alpha, search.communities[0].id); let postRes = await createPost(alpha, search.communities[0].id);
await delay();
let search2 = await searchPost(gamma, postRes.post); let search2 = await searchPost(gamma, postRes.post);
expect(search2.posts[0].name).toBeDefined(); expect(search2.posts[0].name).toBeDefined();

View file

@ -8,13 +8,16 @@ import {
listPrivateMessages, listPrivateMessages,
deletePrivateMessage, deletePrivateMessage,
unfollowRemotes, unfollowRemotes,
delay,
} from './shared'; } from './shared';
let recipient_id: number; let recipient_id: number;
beforeAll(async () => { beforeAll(async () => {
await setupLogins(); await setupLogins();
recipient_id = (await followBeta(alpha)).community.creator_id; let follow = await followBeta(alpha);
await delay(10000);
recipient_id = follow.community.creator_id;
}); });
afterAll(async () => { afterAll(async () => {
@ -27,6 +30,7 @@ test('Create a private message', async () => {
expect(pmRes.message.local).toBe(true); expect(pmRes.message.local).toBe(true);
expect(pmRes.message.creator_local).toBe(true); expect(pmRes.message.creator_local).toBe(true);
expect(pmRes.message.recipient_local).toBe(false); expect(pmRes.message.recipient_local).toBe(false);
await delay();
let betaPms = await listPrivateMessages(beta); let betaPms = await listPrivateMessages(beta);
expect(betaPms.messages[0].content).toBeDefined(); expect(betaPms.messages[0].content).toBeDefined();
@ -41,6 +45,7 @@ test('Update a private message', async () => {
let pmRes = await createPrivateMessage(alpha, recipient_id); let pmRes = await createPrivateMessage(alpha, recipient_id);
let pmUpdated = await updatePrivateMessage(alpha, pmRes.message.id); let pmUpdated = await updatePrivateMessage(alpha, pmRes.message.id);
expect(pmUpdated.message.content).toBe(updatedContent); expect(pmUpdated.message.content).toBe(updatedContent);
await delay();
let betaPms = await listPrivateMessages(beta); let betaPms = await listPrivateMessages(beta);
expect(betaPms.messages[0].content).toBe(updatedContent); expect(betaPms.messages[0].content).toBe(updatedContent);
@ -48,15 +53,18 @@ test('Update a private message', async () => {
test('Delete a private message', async () => { test('Delete a private message', async () => {
let pmRes = await createPrivateMessage(alpha, recipient_id); let pmRes = await createPrivateMessage(alpha, recipient_id);
await delay();
let betaPms1 = await listPrivateMessages(beta); let betaPms1 = await listPrivateMessages(beta);
let deletedPmRes = await deletePrivateMessage(alpha, true, pmRes.message.id); let deletedPmRes = await deletePrivateMessage(alpha, true, pmRes.message.id);
expect(deletedPmRes.message.deleted).toBe(true); expect(deletedPmRes.message.deleted).toBe(true);
await delay();
// The GetPrivateMessages filters out deleted, // The GetPrivateMessages filters out deleted,
// even though they are in the actual database. // even though they are in the actual database.
// no reason to show them // no reason to show them
let betaPms2 = await listPrivateMessages(beta); let betaPms2 = await listPrivateMessages(beta);
expect(betaPms2.messages.length).toBe(betaPms1.messages.length - 1); expect(betaPms2.messages.length).toBe(betaPms1.messages.length - 1);
await delay();
// Undelete // Undelete
let undeletedPmRes = await deletePrivateMessage( let undeletedPmRes = await deletePrivateMessage(
@ -65,6 +73,7 @@ test('Delete a private message', async () => {
pmRes.message.id pmRes.message.id
); );
expect(undeletedPmRes.message.deleted).toBe(false); expect(undeletedPmRes.message.deleted).toBe(false);
await delay();
let betaPms3 = await listPrivateMessages(beta); let betaPms3 = await listPrivateMessages(beta);
expect(betaPms3.messages.length).toBe(betaPms1.messages.length); expect(betaPms3.messages.length).toBe(betaPms1.messages.length);

View file

@ -198,7 +198,7 @@ export async function searchPost(
): Promise<SearchResponse> { ): Promise<SearchResponse> {
let form: SearchForm = { let form: SearchForm = {
q: post.ap_id, q: post.ap_id,
type_: SearchType.All, type_: SearchType.Posts,
sort: SortType.TopAll, sort: SortType.TopAll,
}; };
return api.client.search(form); return api.client.search(form);
@ -220,7 +220,7 @@ export async function searchComment(
): Promise<SearchResponse> { ): Promise<SearchResponse> {
let form: SearchForm = { let form: SearchForm = {
q: comment.ap_id, q: comment.ap_id,
type_: SearchType.All, type_: SearchType.Comments,
sort: SortType.TopAll, sort: SortType.TopAll,
}; };
return api.client.search(form); return api.client.search(form);
@ -233,7 +233,7 @@ export async function searchForBetaCommunity(
// Use short-hand search url // Use short-hand search url
let form: SearchForm = { let form: SearchForm = {
q: '!main@lemmy-beta:8550', q: '!main@lemmy-beta:8550',
type_: SearchType.All, type_: SearchType.Communities,
sort: SortType.TopAll, sort: SortType.TopAll,
}; };
return api.client.search(form); return api.client.search(form);
@ -247,7 +247,7 @@ export async function searchForUser(
// Use short-hand search url // Use short-hand search url
let form: SearchForm = { let form: SearchForm = {
q: apShortname, q: apShortname,
type_: SearchType.All, type_: SearchType.Users,
sort: SortType.TopAll, sort: SortType.TopAll,
}; };
return api.client.search(form); return api.client.search(form);
@ -524,6 +524,11 @@ export async function followBeta(api: API): Promise<CommunityResponse> {
} }
} }
export const delay = (millis: number = 1500) =>
new Promise((resolve, _reject) => {
setTimeout(_ => resolve(), millis);
});
export function wrapper(form: any): string { export function wrapper(form: any): string {
return JSON.stringify(form); return JSON.stringify(form);
} }