-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #595 from MaMpf-HD/dev
- Loading branch information
Showing
9 changed files
with
147 additions
and
64 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -57,3 +57,4 @@ | |
//= require vertices | ||
//= require watchlists | ||
//= require turbolinks | ||
//= require search_tags |
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,19 @@ | ||
$(document).on("turbolinks:load", function () { | ||
$("#search_all_tags").change(evt => toggleSearchAllTags(evt)); | ||
}); | ||
|
||
/** | ||
* Dynamically enable/disable the OR/AND buttons in the media search form. | ||
* If the user has decided to search for media regardless of the tags, | ||
* i.e. they enable the "all" (tags) button, we disable the "OR/AND" buttons | ||
* as it is pointless to search for media that references *all* available tags | ||
* at once. | ||
*/ | ||
function toggleSearchAllTags(evt) { | ||
const searchAllTags = evt.target.checked; | ||
if (searchAllTags) { | ||
$("#search_tag_operator_or").prop("checked", true); | ||
} | ||
$("#search_tag_operator_or").prop("disabled", searchAllTags); | ||
$("#search_tag_operator_and").prop("disabled", searchAllTags); | ||
} |
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
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
45 changes: 45 additions & 0 deletions
45
db/migrate/20240215100000_fix_unread_comments_inconsistencies_again.rb
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,45 @@ | ||
# Fixes the unread_comments flag for all users. Unintended behavior was | ||
# introduced in pull request #515. Behavior fixed in #585 | ||
# A migration was introduced in #587, but it turned out it contained a bug. | ||
# This migration here is a fix for the migration in #587. | ||
# | ||
# This migration is generally *not* idempotent since users might have interacted | ||
# with the website since the migration was run and thus they will probably have | ||
# different unread comments flags as the ones at the time of the migration. | ||
# | ||
# This migration is not reversible as we don't store the previous state of | ||
# the unread_comments flag. | ||
class FixUnreadCommentsInconsistenciesAgain < ActiveRecord::Migration[7.0] | ||
def up | ||
num_fixed_users = 0 | ||
|
||
User.find_each do |user| | ||
had_user_unread_comments = user.unread_comments # boolean | ||
has_user_unread_comments = user_unread_comments?(user) | ||
|
||
has_flag_changed = (had_user_unread_comments != has_user_unread_comments) | ||
user.update(unread_comments: has_user_unread_comments) if has_flag_changed | ||
num_fixed_users += 1 if has_flag_changed | ||
end | ||
|
||
Rails.logger.warn { "Ran through #{User.count} users (unread comments flag again)" } | ||
Rails.logger.warn { "Fixed #{num_fixed_users} users (unread comments flag again)" } | ||
end | ||
|
||
# Checks and returns whether the user has unread comments. | ||
def user_unread_comments?(user) | ||
# see the method "comments" in app/controllers/main_controller.rb | ||
unseen_media = user.subscribed_media_with_latest_comments_not_by_creator | ||
unseen_media.select! do |m| | ||
(Reader.find_by(user: user, thread: m[:thread]) | ||
&.updated_at || 1000.years.ago) < m[:latest_comment].created_at && | ||
m[:medium].visible_for_user?(user) | ||
end | ||
|
||
unseen_media.present? | ||
end | ||
|
||
def down | ||
raise ActiveRecord::IrreversibleMigration | ||
end | ||
end |
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