2018-12-24 11:23:04 +01:00
|
|
|
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
|
|
|
|
|
|
|
use comments::Comment;
|
|
|
|
use schema::comment_seers;
|
|
|
|
use users::User;
|
2018-12-29 09:36:07 +01:00
|
|
|
use {Connection, Error, Result};
|
2018-12-24 11:23:04 +01:00
|
|
|
|
2019-03-12 19:40:54 +01:00
|
|
|
#[derive(Queryable, Clone)]
|
2018-12-24 11:23:04 +01:00
|
|
|
pub struct CommentSeers {
|
|
|
|
pub id: i32,
|
|
|
|
pub comment_id: i32,
|
|
|
|
pub user_id: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Insertable, Default)]
|
|
|
|
#[table_name = "comment_seers"]
|
|
|
|
pub struct NewCommentSeers {
|
|
|
|
pub comment_id: i32,
|
|
|
|
pub user_id: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CommentSeers {
|
|
|
|
insert!(comment_seers, NewCommentSeers);
|
|
|
|
|
2018-12-29 09:36:07 +01:00
|
|
|
pub fn can_see(conn: &Connection, c: &Comment, u: &User) -> Result<bool> {
|
2019-03-20 17:56:17 +01:00
|
|
|
comment_seers::table
|
|
|
|
.filter(comment_seers::comment_id.eq(c.id))
|
2018-12-24 11:23:04 +01:00
|
|
|
.filter(comment_seers::user_id.eq(u.id))
|
|
|
|
.load::<CommentSeers>(conn)
|
2018-12-29 09:36:07 +01:00
|
|
|
.map_err(Error::from)
|
|
|
|
.map(|r| !r.is_empty())
|
2018-12-24 11:23:04 +01:00
|
|
|
}
|
|
|
|
}
|