Notification bug with forum threads and block lists #33

Closed
opened 2024-01-06 05:21:33 +00:00 by noah · 1 comment

The Bug

Reproduction steps:

  1. Have two users, Alice and Bob, and a forum thread that has many comments by many people.
    • Alice has blocked several of those people, so her view of the thread shows only one page of comments that exist.
    • Bob does not block anybody, so his view of the thread has 2 or 3 pages worth of comments.
  2. Have Bob add a new comment to the thread. Say, his comment would appear on page 3.
  3. Alice gets a notification about Bob's comment, but the link to his comment expects it to appear on page 3, which from Alice's perspective, does not exist.
    • Alice, clicking the link, sees an "empty" forum thread page, with the pager only showing a page 1 button but no comments in between.
    • Clicking on the page 1 comment would go to the first page, where Bob's new comment can be seen at the bottom.

Root cause:

  • When leaving a comment, a notification is sent to everyone who subscribes to that comment thread.
  • The notification tries to be helpful by linking to the page and comment anchor of the new comment.
  • Bob saw 3 pages so the link added to his notification goes to page 3.ll
  • If a recipient of the comment sees it on a different page number, the link is not valid.

Solution Idea

Trying to determine everybody's individual block list status and view of the thread at notification-time would be madness so an idea to resolve this may be:

  • Instead of computing the correct link at comment time, have the comment link go to a "proxy endpoint" that will determine the correct link dynamically.
    • Example: /forum/go-to-comment?comment_id=1234
  • The endpoint would compute, for the current user, what page the comment would appear on and link them there, taking into account block lists and things.

An idea how to do this efficiently is to gather all of the comment IDs for the entire thread, and then find out what page the comment appears on, e.g.

-- find out the thread ID for the linked comment
SELECT table_id
FROM comments
WHERE table_name='threads'
AND id=1234;

-- get ALL comment IDs from this thread respecting blocklists
SELECT id
FROM comments
WHERE table_name='threads' AND table_id=123
AND user_id NOT IN (blocklist)
ORDER BY created_at

And then scan the ID list for the matching comment ID, and thus know what page it belongs on.

This URL to "go to a forum comment wherever it is" will also be useful to have around for other features:

  • The "Newest" tab on the forum: currently every comment there links to the thread with page=-1 which means "the last page" and if you were to go far back on the Newest tab, comments would no longer link to the correct pages on long threads since it always goes to the final page.
  • If we add a "Search" feature to the forum: it will be significantly simpler if the search results are just the comments and each one links to the new URL that magically brings the user to the correct page of whatever thread it appeared on.

Outcome

In 70402b42c9

  • Add the route /go/comment?id=123 that finds and redirects to the comment.
    • If the user can't see the comment, goes to the thread it should've been on (page 1) with an error flash.
  • All new comment notifications going forward will use the new link.
  • The new link has also been sprinkled around various pages:
    • The "Newest" tab of the forum will directly link to the new comments now, instead of going to the final page of the thread.
    • All comments (in forums and photos) have a new "copy permalink to clipboard" button, that copies the new link.
    • The forum index page on the "Latest post" section links directly to the latest comment.

Still to do:

  • add a forum search page.
  • "Like" notifications don't use the new link.
### The Bug Reproduction steps: 1. Have two users, Alice and Bob, and a forum thread that has many comments by many people. * Alice has blocked several of those people, so her view of the thread shows only one page of comments that exist. * Bob does not block anybody, so his view of the thread has 2 or 3 pages worth of comments. 2. Have Bob add a new comment to the thread. Say, his comment would appear on page 3. 3. Alice gets a notification about Bob's comment, but the link to his comment expects it to appear on page 3, which from Alice's perspective, does not exist. * Alice, clicking the link, sees an "empty" forum thread page, with the pager only showing a page 1 button but no comments in between. * Clicking on the page 1 comment would go to the first page, where Bob's new comment can be seen at the bottom. Root cause: * When leaving a comment, a notification is sent to everyone who subscribes to that comment thread. * The notification tries to be helpful by linking to the page and comment anchor of the new comment. * Bob saw 3 pages so the link added to his notification goes to page 3.ll * If a recipient of the comment sees it on a different page number, the link is not valid. ### Solution Idea Trying to determine everybody's individual block list status and view of the thread at notification-time would be madness so an idea to resolve this may be: * Instead of computing the correct link at comment time, have the comment link go to a "proxy endpoint" that will determine the correct link dynamically. * Example: /forum/go-to-comment?comment_id=1234 * The endpoint would compute, for the current user, what page the comment would appear on and link them there, taking into account block lists and things. An idea how to do this _efficiently_ is to gather all of the comment IDs for the entire thread, and then find out what page the comment appears on, e.g. ```sql -- find out the thread ID for the linked comment SELECT table_id FROM comments WHERE table_name='threads' AND id=1234; -- get ALL comment IDs from this thread respecting blocklists SELECT id FROM comments WHERE table_name='threads' AND table_id=123 AND user_id NOT IN (blocklist) ORDER BY created_at ``` And then scan the ID list for the matching comment ID, and thus know what page it belongs on. This URL to "go to a forum comment wherever it is" will also be useful to have around for other features: * The "Newest" tab on the forum: currently every comment there links to the thread with `page=-1` which means "the last page" and if you were to go _far_ back on the Newest tab, comments would no longer link to the correct pages on long threads since it always goes to the final page. * If we add a "Search" feature to the forum: it will be significantly simpler if the search results are just the comments and each one links to the new URL that magically brings the user to the correct page of whatever thread it appeared on. #### Outcome In 70402b42c940828af91e77421ba078bdfbdb6936 * Add the route `/go/comment?id=123` that finds and redirects to the comment. * If the user can't see the comment, goes to the thread it should've been on (page 1) with an error flash. * All new comment notifications going forward will use the new link. * The new link has also been sprinkled around various pages: * The "Newest" tab of the forum will directly link to the new comments now, instead of going to the final page of the thread. * All comments (in forums and photos) have a new "copy permalink to clipboard" button, that copies the new link. * The forum index page on the "Latest post" section links directly to the latest comment. Still to do: * add a forum search page. * "Like" notifications don't use the new link.
noah added the
bug
label 2024-01-06 05:21:33 +00:00
Poster
Owner

Forum search added in cca449090a

Forum search added in cca449090a596921b7ce56ac04755935bf5ccaf7
noah closed this issue 2024-01-07 00:57:13 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: nonshy/website#33
There is no content yet.