.values(comment_like_form)
.get_result::<Self>(conn)
}
- fn remove(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<usize, Error> {
- use crate::schema::comment_like::dsl::*;
+ fn remove(conn: &PgConnection, user_id: i32, comment_id: i32) -> Result<usize, Error> {
+ use crate::schema::comment_like::dsl;
diesel::delete(
- comment_like
- .filter(comment_id.eq(comment_like_form.comment_id))
- .filter(user_id.eq(comment_like_form.user_id)),
+ dsl::comment_like
+ .filter(dsl::comment_id.eq(comment_id))
+ .filter(dsl::user_id.eq(user_id)),
)
.execute(conn)
}
let read_comment = Comment::read(&conn, inserted_comment.id).unwrap();
let updated_comment = Comment::update(&conn, inserted_comment.id, &comment_form).unwrap();
- let like_removed = CommentLike::remove(&conn, &comment_like_form).unwrap();
+ let like_removed = CommentLike::remove(&conn, inserted_user.id, inserted_comment.id).unwrap();
let saved_removed = CommentSaved::unsave(&conn, &comment_saved_form).unwrap();
let num_deleted = Comment::delete(&conn, inserted_comment.id).unwrap();
Comment::delete(&conn, inserted_child_comment.id).unwrap();
read_comment_views_with_user[0].hot_rank = 0;
read_comment_views_with_user[0].hot_rank_active = 0;
- let like_removed = CommentLike::remove(&conn, &comment_like_form).unwrap();
+ let like_removed = CommentLike::remove(&conn, inserted_user.id, inserted_comment.id).unwrap();
let num_deleted = Comment::delete(&conn, inserted_comment.id).unwrap();
Post::delete(&conn, inserted_post.id).unwrap();
Community::delete(&conn, inserted_community.id).unwrap();
fn like(conn: &PgConnection, form: &T) -> Result<Self, Error>
where
Self: Sized;
- fn remove(conn: &PgConnection, form: &T) -> Result<usize, Error>
+ fn remove(conn: &PgConnection, user_id: i32, item_id: i32) -> Result<usize, Error>
where
Self: Sized;
}
-use crate::{
- naive_now,
- schema::{post, post_like, post_read, post_saved},
- Crud,
- Likeable,
- Readable,
- Saveable,
-};
+use crate::{naive_now, schema::{post, post_like, post_read, post_saved}, Crud, Likeable, Saveable, Readable};
use diesel::{dsl::*, result::Error, *};
use serde::{Deserialize, Serialize};
use url::{ParseError, Url};
.values(post_like_form)
.get_result::<Self>(conn)
}
- fn remove(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<usize, Error> {
- use crate::schema::post_like::dsl::*;
+ fn remove(conn: &PgConnection, user_id: i32, post_id: i32) -> Result<usize, Error> {
+ use crate::schema::post_like::dsl;
diesel::delete(
- post_like
- .filter(post_id.eq(post_like_form.post_id))
- .filter(user_id.eq(post_like_form.user_id)),
+ dsl::post_like
+ .filter(dsl::post_id.eq(post_id))
+ .filter(dsl::user_id.eq(user_id)),
)
.execute(conn)
}
// Post Read
let post_read_form = PostReadForm {
- post_id: inserted_post.id,
- user_id: inserted_user.id,
- };
+ post_id: inserted_post.id,
+ user_id: inserted_user.id,
+ };
let inserted_post_read = PostRead::mark_as_read(&conn, &post_read_form).unwrap();
let expected_post_read = PostRead {
- id: inserted_post_read.id,
- post_id: inserted_post.id,
- user_id: inserted_user.id,
- published: inserted_post_read.published,
+ id: inserted_post_read.id,
+ post_id: inserted_post.id,
+ user_id: inserted_user.id,
+ published: inserted_post_read.published,
};
let read_post = Post::read(&conn, inserted_post.id).unwrap();
let updated_post = Post::update(&conn, inserted_post.id, &new_post).unwrap();
- let like_removed = PostLike::remove(&conn, &post_like_form).unwrap();
+ let like_removed = PostLike::remove(&conn, inserted_user.id, inserted_post.id).unwrap();
let saved_removed = PostSaved::unsave(&conn, &post_saved_form).unwrap();
let read_removed = PostRead::mark_as_unread(&conn, &post_read_form).unwrap();
let num_deleted = Post::delete(&conn, inserted_post.id).unwrap();
score: 1,
};
- let post_like_form = PostLikeForm {
- post_id: inserted_post.id,
- user_id: inserted_user.id,
- score: 1,
- };
-
let read_post_listings_with_user = PostQueryBuilder::create(&conn)
.listing_type(ListingType::Community)
.sort(&SortType::New)
community_local: true,
};
- let like_removed = PostLike::remove(&conn, &post_like_form).unwrap();
+ let like_removed = PostLike::remove(&conn, inserted_user.id, inserted_post.id).unwrap();
let num_deleted = Post::delete(&conn, inserted_post.id).unwrap();
Community::delete(&conn, inserted_community.id).unwrap();
User_::delete(&conn, inserted_user.id).unwrap();
};
// Remove any likes first
- let like_form2 = like_form.clone();
- blocking(pool, move |conn| CommentLike::remove(conn, &like_form2)).await??;
+ let user_id = user.id;
+ blocking(pool, move |conn| {
+ CommentLike::remove(conn, user_id, comment_id)
+ })
+ .await??;
// Only add the like if the score isnt 0
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
};
// Remove any likes first
- let like_form2 = like_form.clone();
- blocking(pool, move |conn| PostLike::remove(conn, &like_form2)).await??;
+ let user_id = user.id;
+ blocking(pool, move |conn| PostLike::remove(conn, user_id, post_id)).await??;
// Only add the like if the score isnt 0
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
.set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&creator,
.set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
.set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&creator,
.set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&mod_,
.set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
.set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&mod_,
.set_context(context())
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&creator,
.set_context(context())
.set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&creator,
.set_context(context())
.set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
.set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&creator,
}
struct MentionsAndAddresses {
- addressed_ccs: Vec<String>,
+ addressed_ccs: Vec<Url>,
inboxes: Vec<Url>,
tags: Vec<Mention>,
}
client: &Client,
pool: &DbPool,
) -> Result<MentionsAndAddresses, LemmyError> {
- let mut addressed_ccs = vec![community.get_followers_url()];
+ let mut addressed_ccs = vec![community.get_followers_url()?];
// Add the mention tag
let mut tags = Vec::new();
// TODO should it be fetching it every time?
if let Ok(actor_id) = fetch_webfinger_url(mention, client).await {
debug!("mention actor_id: {}", actor_id);
- addressed_ccs.push(actor_id.to_owned().to_string());
+ addressed_ccs.push(actor_id.to_owned().to_string().parse()?);
let mention_user = get_or_fetch_and_upsert_user(&actor_id, client, pool).await?;
let shared_inbox = mention_user.get_shared_inbox_url()?;
ap_actor
.set_preferred_username(self.title.to_owned())
.set_outbox(self.get_outbox_url()?)
- .set_followers(self.get_followers_url().parse()?)
+ .set_followers(self.get_followers_url()?)
.set_following(self.get_following_url().parse()?)
.set_liked(self.get_liked_url().parse()?)
.set_endpoints(Endpoints {
.set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
- .set_many_ccs(vec![self.get_followers_url()]);
+ .set_many_ccs(vec![self.get_followers_url()?]);
insert_activity(self.creator_id, delete.clone(), true, pool).await?;
.set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
- .set_many_ccs(vec![self.get_followers_url()]);
+ .set_many_ccs(vec![self.get_followers_url()?]);
- // TODO
- // Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
undo
.set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
- .set_many_ccs(vec![self.get_followers_url()]);
+ .set_many_ccs(vec![self.get_followers_url()?]);
insert_activity(self.creator_id, undo.clone(), true, pool).await?;
.set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
- .set_many_ccs(vec![self.get_followers_url()]);
+ .set_many_ccs(vec![self.get_followers_url()?]);
insert_activity(mod_.id, remove.clone(), true, pool).await?;
.set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
- .set_many_ccs(vec![self.get_followers_url()]);
+ .set_many_ccs(vec![self.get_followers_url()?]);
// Undo that fake activity
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
.set_context(context())
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
- .set_many_ccs(vec![self.get_followers_url()]);
+ .set_many_ccs(vec![self.get_followers_url()?]);
insert_activity(mod_.id, undo.clone(), true, pool).await?;
let mut collection = UnorderedCollection::new();
collection
.set_context(context())
- // TODO: this needs its own ID
- .set_id(community.actor_id.parse()?)
+ .set_id(community.get_followers_url()?)
.set_total_items(community_followers.len() as u64);
Ok(create_apub_response(&collection))
}
.set_context(context())
.set_id(generate_activity_id(AnnounceType::Announce)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
insert_activity(community.creator_id, announce.clone(), true, pool).await?;
let community = get_or_fetch_and_upsert_community(community_uri, client, pool).await?;
- // TODO Maybe at some point in the future, fetch all the history of a community
- // fetch_community_outbox(&c, conn)?;
response.communities = vec![
blocking(pool, move |conn| {
CommunityView::read(conn, community.id, None)
response
}
SearchAcceptedObjects::Comment(c) => {
- let post_url = c
- .in_reply_to()
- .as_ref()
- .context(location_info!())?
- .as_many()
- .context(location_info!())?;
-
- // TODO: also fetch parent comments if any
- let x = post_url
- .first()
- .context(location_info!())?
- .as_xsd_any_uri()
- .context(location_info!())?;
- let post = fetch_remote_object(client, x).await?;
- let post_form = PostForm::from_apub(&post, client, pool, Some(query_url.clone())).await?;
let comment_form = CommentForm::from_apub(&c, client, pool, Some(query_url)).await?;
- blocking(pool, move |conn| upsert_post(&post_form, conn)).await??;
let c = blocking(pool, move |conn| upsert_comment(&comment_form, conn)).await??;
response.comments =
vec![blocking(pool, move |conn| CommentView::read(conn, c.id, None)).await??];
user_id: user.id,
score: -1,
};
+ let user_id = user.id;
blocking(pool, move |conn| {
- PostLike::remove(conn, &like_form)?;
+ PostLike::remove(conn, user_id, post_id)?;
PostLike::like(conn, &like_form)
})
.await??;
user_id: user.id,
score: -1,
};
+ let user_id = user.id;
blocking(pool, move |conn| {
- CommentLike::remove(conn, &like_form)?;
+ CommentLike::remove(conn, user_id, comment_id)?;
CommentLike::like(conn, &like_form)
})
.await??;
user_id: user.id,
score: 1,
};
+ let user_id = user.id;
blocking(pool, move |conn| {
- PostLike::remove(conn, &like_form)?;
+ PostLike::remove(conn, user_id, post_id)?;
PostLike::like(conn, &like_form)
})
.await??;
user_id: user.id,
score: 1,
};
+ let user_id = user.id;
blocking(pool, move |conn| {
- CommentLike::remove(conn, &like_form)?;
+ CommentLike::remove(conn, user_id, comment_id)?;
CommentLike::like(conn, &like_form)
})
.await??;
use actix_web::{client::Client, HttpResponse};
use anyhow::{anyhow, Context};
use lemmy_db::{
- comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
+ comment::{Comment, CommentForm, CommentLike},
comment_view::CommentView,
community::{Community, CommunityForm},
community_view::CommunityView,
naive_now,
- post::{Post, PostForm, PostLike, PostLikeForm},
+ post::{Post, PostForm, PostLike},
post_view::PostView,
Crud,
Likeable,
async fn receive_undo_dislike(
undo: Undo,
- _client: &Client,
- _pool: &DbPool,
- _chat_server: ChatServerParam,
+ client: &Client,
+ pool: &DbPool,
+ chat_server: ChatServerParam,
) -> Result<HttpResponse, LemmyError> {
let dislike = Dislike::from_any_base(undo.object().to_owned().one().context(location_info!())?)?
.context(location_info!())?;
check_is_undo_valid(&undo, &dislike)?;
- // TODO: need to implement Undo<Dislike>
-
let type_ = dislike
.object()
.as_single_kind_str()
.context(location_info!())?;
- Err(anyhow!("Undo Delete type {} not supported", type_).into())
+ match type_ {
+ "Note" => receive_undo_dislike_comment(undo, &dislike, client, pool, chat_server).await,
+ "Page" => receive_undo_dislike_post(undo, &dislike, client, pool, chat_server).await,
+ d => Err(anyhow!("Undo Delete type {} not supported", d).into()),
+ }
}
async fn receive_undo_delete_comment(
.await?
.id;
- let like_form = CommentLikeForm {
- comment_id,
- post_id: comment.post_id,
- user_id: user.id,
- score: 0,
- };
- blocking(pool, move |conn| CommentLike::remove(conn, &like_form)).await??;
+ let user_id = user.id;
+ blocking(pool, move |conn| {
+ CommentLike::remove(conn, user_id, comment_id)
+ })
+ .await??;
// Refetch the view
let comment_view =
.await?
.id;
- let like_form = PostLikeForm {
- post_id,
- user_id: user.id,
- score: 1,
+ let user_id = user.id;
+ blocking(pool, move |conn| PostLike::remove(conn, user_id, post_id)).await??;
+
+ // Refetch the view
+ let post_view = blocking(pool, move |conn| PostView::read(conn, post_id, None)).await??;
+
+ let res = PostResponse { post: post_view };
+
+ chat_server.do_send(SendPost {
+ op: UserOperation::CreatePostLike,
+ post: res,
+ my_id: None,
+ });
+
+ announce_if_community_is_local(undo, &user, client, pool).await?;
+ Ok(HttpResponse::Ok().finish())
+}
+
+async fn receive_undo_dislike_comment(
+ undo: Undo,
+ dislike: &Dislike,
+ client: &Client,
+ pool: &DbPool,
+ chat_server: ChatServerParam,
+) -> Result<HttpResponse, LemmyError> {
+ let user = get_user_from_activity(dislike, client, pool).await?;
+ let note = Note::from_any_base(
+ dislike
+ .object()
+ .to_owned()
+ .one()
+ .context(location_info!())?,
+ )?
+ .context(location_info!())?;
+
+ let comment = CommentForm::from_apub(¬e, client, pool, None).await?;
+
+ let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool)
+ .await?
+ .id;
+
+ let user_id = user.id;
+ blocking(pool, move |conn| {
+ CommentLike::remove(conn, user_id, comment_id)
+ })
+ .await??;
+
+ // Refetch the view
+ let comment_view =
+ blocking(pool, move |conn| CommentView::read(conn, comment_id, None)).await??;
+
+ // TODO get those recipient actor ids from somewhere
+ let recipient_ids = vec![];
+ let res = CommentResponse {
+ comment: comment_view,
+ recipient_ids,
+ form_id: None,
};
- blocking(pool, move |conn| PostLike::remove(conn, &like_form)).await??;
+
+ chat_server.do_send(SendComment {
+ op: UserOperation::CreateCommentLike,
+ comment: res,
+ my_id: None,
+ });
+
+ announce_if_community_is_local(undo, &user, client, pool).await?;
+ Ok(HttpResponse::Ok().finish())
+}
+
+async fn receive_undo_dislike_post(
+ undo: Undo,
+ dislike: &Dislike,
+ client: &Client,
+ pool: &DbPool,
+ chat_server: ChatServerParam,
+) -> Result<HttpResponse, LemmyError> {
+ let user = get_user_from_activity(dislike, client, pool).await?;
+ let page = PageExt::from_any_base(
+ dislike
+ .object()
+ .to_owned()
+ .one()
+ .context(location_info!())?,
+ )?
+ .context(location_info!())?;
+
+ let post = PostForm::from_apub(&page, client, pool, None).await?;
+
+ let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool)
+ .await?
+ .id;
+
+ let user_id = user.id;
+ blocking(pool, move |conn| PostLike::remove(conn, user_id, post_id)).await??;
// Refetch the view
let post_view = blocking(pool, move |conn| PostView::read(conn, post_id, None)).await??;
Url::parse(&format!("{}/outbox", &self.actor_id_str()))
}
- fn get_followers_url(&self) -> String {
- format!("{}/followers", &self.actor_id_str())
+ fn get_followers_url(&self) -> Result<Url, ParseError> {
+ Url::parse(&format!("{}/followers", &self.actor_id_str()))
}
fn get_following_url(&self) -> String {
.set_context(context())
.set_id(generate_activity_id(CreateType::Create)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
creator,
.set_context(context())
.set_id(generate_activity_id(UpdateType::Update)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
creator,
.set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
creator,
.set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
.set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
creator,
.set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
mod_,
.set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
.set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
mod_,
.set_context(context())
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&creator,
.set_context(context())
.set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&creator,
.set_context(context())
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
.set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()]);
+ .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&creator,
let mut ap_actor = ApActor::new(self.get_inbox_url()?, person);
ap_actor
.set_outbox(self.get_outbox_url()?)
- .set_followers(self.get_followers_url().parse()?)
+ .set_followers(self.get_followers_url()?)
.set_following(self.get_following_url().parse()?)
.set_liked(self.get_liked_url().parse()?)
.set_endpoints(Endpoints {