-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some support for comment visibility, fix #217 This add a new column to comment, denoting if they are public or not, and a new table linking private comments to those allowed to read them. There is currently no way to write a private comment from Plume. Git is having a hard time what happened in Comment::from_activity, but most of it is just re-indentation because a new block was needed to please the borrow checker. I've marked with comments where things actually changed. At this point only mentioned users can see private comments, even when posted as "follower only" or equivalent. What should we do when someone isn't allowed to see a comment? Hide the whole thread, or just the comment? If hiding just the comment, should we mark there is a comment one can't see, but answers they can, or put other comments like if they answered to the same comment the hidden one do?
- Loading branch information
1 parent
2621549
commit fdfeeed
Showing
13 changed files
with
261 additions
and
67 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
migrations/postgres/2018-12-17-221135_comment_visibility/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- This file should undo anything in `up.sql` | ||
ALTER TABLE comments DROP COLUMN public_visibility; | ||
|
||
DROP TABLE comment_seers; |
9 changes: 9 additions & 0 deletions
9
migrations/postgres/2018-12-17-221135_comment_visibility/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-- Your SQL goes here | ||
ALTER TABLE comments ADD public_visibility BOOLEAN NOT NULL DEFAULT 't'; | ||
|
||
CREATE TABLE comment_seers ( | ||
id SERIAL PRIMARY KEY, | ||
comment_id INTEGER REFERENCES comments(id) ON DELETE CASCADE NOT NULL, | ||
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL, | ||
UNIQUE (comment_id, user_id) | ||
) |
28 changes: 28 additions & 0 deletions
28
migrations/sqlite/2018-12-17-221135_comment_visibility/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- This file should undo anything in `up.sql` | ||
CREATE TABLE comments2 ( | ||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
content TEXT NOT NULL DEFAULT '', | ||
in_response_to_id INTEGER REFERENCES comments(id), | ||
post_id INTEGER REFERENCES posts(id) ON DELETE CASCADE NOT NULL, | ||
author_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL, | ||
creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
ap_url VARCHAR, | ||
sensitive BOOLEAN NOT NULL DEFAULT 'f', | ||
spoiler_text TEXT NOT NULL DEFAULT '' | ||
); | ||
|
||
INSERT INTO comments2 SELECT | ||
id, | ||
content, | ||
in_response_to_id, | ||
post_id, | ||
author_id, | ||
creation_date, | ||
ap_url, | ||
sensitive, | ||
spoiler_text | ||
FROM comments; | ||
DROP TABLE comments; | ||
ALTER TABLE comments2 RENAME TO comments; | ||
|
||
DROP TABLE comment_seers; |
9 changes: 9 additions & 0 deletions
9
migrations/sqlite/2018-12-17-221135_comment_visibility/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-- Your SQL goes here | ||
ALTER TABLE comments ADD public_visibility BOOLEAN NOT NULL DEFAULT 't'; | ||
|
||
CREATE TABLE comment_seers ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
comment_id INTEGER REFERENCES comments(id) ON DELETE CASCADE NOT NULL, | ||
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL, | ||
UNIQUE (comment_id, user_id) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; | ||
|
||
use comments::Comment; | ||
use schema::comment_seers; | ||
use users::User; | ||
use Connection; | ||
|
||
#[derive(Queryable, Serialize, Clone)] | ||
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); | ||
|
||
pub fn can_see(conn: &Connection, c: &Comment, u: &User) -> bool { | ||
!comment_seers::table.filter(comment_seers::comment_id.eq(c.id)) | ||
.filter(comment_seers::user_id.eq(u.id)) | ||
.load::<CommentSeers>(conn) | ||
.expect("Comment::get_responses: loading error") | ||
.is_empty() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.