mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-05 06:00:31 +00:00
Now by default like your own comment.
This commit is contained in:
parent
3637da08de
commit
e3ef57c242
@ -145,7 +145,7 @@ pub struct CommentView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CommentView {
|
impl CommentView {
|
||||||
fn from_comment(comment: &Comment, likes: &Vec<CommentLike>, fedi_user_id: &Option<String>) -> Self {
|
pub fn from_comment(comment: &Comment, likes: &Vec<CommentLike>, fedi_user_id: &Option<String>) -> Self {
|
||||||
let mut upvotes: i32 = 0;
|
let mut upvotes: i32 = 0;
|
||||||
let mut downvotes: i32 = 0;
|
let mut downvotes: i32 = 0;
|
||||||
let mut my_vote: Option<i16> = Some(0);
|
let mut my_vote: Option<i16> = Some(0);
|
||||||
@ -182,10 +182,6 @@ impl CommentView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_new_comment(comment: &Comment) -> Self {
|
|
||||||
Self::from_comment(comment, &Vec::new(), &None)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn read(conn: &PgConnection, comment_id: i32, fedi_user_id: &Option<String>) -> Self {
|
pub fn read(conn: &PgConnection, comment_id: i32, fedi_user_id: &Option<String>) -> Self {
|
||||||
let comment = Comment::read(&conn, comment_id).unwrap();
|
let comment = Comment::read(&conn, comment_id).unwrap();
|
||||||
let likes = CommentLike::read(&conn, comment_id).unwrap();
|
let likes = CommentLike::read(&conn, comment_id).unwrap();
|
||||||
|
@ -693,26 +693,45 @@ impl Perform for CreateComment {
|
|||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
let iss = claims.iss;
|
let iss = claims.iss;
|
||||||
|
let fedi_user_id = format!("{}/{}", iss, user_id);
|
||||||
|
|
||||||
let comment_form = CommentForm {
|
let comment_form = CommentForm {
|
||||||
content: self.content.to_owned(),
|
content: self.content.to_owned(),
|
||||||
parent_id: self.parent_id.to_owned(),
|
parent_id: self.parent_id.to_owned(),
|
||||||
post_id: self.post_id,
|
post_id: self.post_id,
|
||||||
attributed_to: format!("{}/{}", iss, user_id),
|
attributed_to: fedi_user_id.to_owned(),
|
||||||
updated: None
|
updated: None
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_comment = match Comment::create(&conn, &comment_form) {
|
let inserted_comment = match Comment::create(&conn, &comment_form) {
|
||||||
Ok(comment) => comment,
|
Ok(comment) => comment,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return self.error("Couldn't create Post");
|
return self.error("Couldn't create Comment");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO You like your own comment by default
|
// You like your own comment by default
|
||||||
|
let like_form = CommentLikeForm {
|
||||||
|
comment_id: inserted_comment.id,
|
||||||
|
post_id: self.post_id,
|
||||||
|
fedi_user_id: fedi_user_id.to_owned(),
|
||||||
|
score: 1
|
||||||
|
};
|
||||||
|
|
||||||
// Simulate a comment view to get back blank score, no need to fetch anything
|
let inserted_like = match CommentLike::like(&conn, &like_form) {
|
||||||
let comment_view = CommentView::from_new_comment(&inserted_comment);
|
Ok(like) => like,
|
||||||
|
Err(e) => {
|
||||||
|
return self.error("Couldn't like comment.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let likes: Vec<CommentLike> = vec![inserted_like];
|
||||||
|
|
||||||
|
let comment_view = CommentView::from_comment(&inserted_comment, &likes, &Some(fedi_user_id));
|
||||||
|
|
||||||
|
|
||||||
|
let mut comment_sent = comment_view.clone();
|
||||||
|
comment_sent.my_vote = None;
|
||||||
|
|
||||||
let comment_out = serde_json::to_string(
|
let comment_out = serde_json::to_string(
|
||||||
&CreateCommentResponse {
|
&CreateCommentResponse {
|
||||||
@ -721,11 +740,17 @@ impl Perform for CreateComment {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
chat.send_room_message(self.post_id, &comment_out, addr);
|
|
||||||
|
|
||||||
// println!("{:?}", chat.rooms.keys());
|
|
||||||
// println!("{:?}", chat.rooms.get(&5i32).unwrap());
|
let comment_sent_out = serde_json::to_string(
|
||||||
|
&CreateCommentLikeResponse {
|
||||||
|
op: self.op_type().to_string(),
|
||||||
|
comment: comment_sent
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
chat.send_room_message(self.post_id, &comment_sent_out, addr);
|
||||||
|
|
||||||
comment_out
|
comment_out
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user