FIX: Topic user bookmarked column logic was not correct (PR #9563)

Make sure the topic_user.bookmarked column is set correctly when user bookmarks/unbookmarks any post in a topic.

  • Previously this was only setting it to true if bookmarking the OP/topic, which was not correct – we want to show the icon on the topic list if any post is bookmarked.
  • Also set to false if unbookmarking the last bookmarked post in the topic.

Also in this PR is a migration to correct any out of sync topic_user.bookmarked columns, based on the new logic.

GitHub

IS false feels a bit weird … NOT topic_users.bookmarked … for the true case where topic_users.bookmarked

Overall change looks good! Feel free to merge the fix after the minor style change.

why put this in a before block just for one test?

…good point

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/improved-bookmarks-with-reminders/144542/121

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/bookmark-icon-reamains-in-pm-after-deleting-the-bookmark/149356/5

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/reporting-few-issues-with-bookmarks/149283/4