Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mark_as_read! :all, for: current_user is not working as intended #119

Open
masudhossain opened this issue Oct 27, 2020 · 1 comment
Open

Comments

@masudhossain
Copy link

masudhossain commented Oct 27, 2020

I noticed that doing mark_ass_read! :all, for: current_user does not work, but mark_as_read! for: current_user works fine. I'm not sure if i'm doing anything wrong, but when i run it, it returns nil for some reason as well.

https://prnt.sc/v7iroq

Doesn't work

@organization.replays.mark_as_read! :all, for: current_user

Works

@organization.replays.each do |replay|
        replay.mark_as_read! for: current_user
end
@fatkodima
Copy link
Contributor

:all can be used only with the model classes, like Replay.mark_as_read!(:all, for: current_user). It is not currently working on relations/associations.

For your use case, currently you need to use Replay.mark_as_read!(@organization.replays, for: current_user).

I think, we can extend mark_as_read! with something like

...
         if target == :all
-          reset_read_marks_for_user(reader)
+          if is_a?(ActiveRecord::Relation)
+            mark_collection_as_read(self, reader)
+          else
+            reset_read_marks_for_user(reader)
+          end
         elsif target.respond_to?(:each)
           mark_collection_as_read(target, reader)
         else
...

@ledermann Wdyt on this change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants