You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Conversation < ApplicationRecord
has_many :messages, dependent: :destroy
def read(user)
# messages.unread_by(user).each { |message| message.mark_as_read! for: user }
# or
# messages.mark_as_read! :all, for: user
end
class Message < ApplicationRecord
acts_as_readable on: :created_at
belongs_to :conversation, counter_cache: true
end
conversation.read(current_user)
The first example works (messages.unread_by(user).each), but it creates 1 record per resource+user (with 2 users per conversation, this table will be twice as long as the messages table).
mark_as_read! :all for associations doesn't seem to be supported, since it just <NULL>s the column in the database, to make the optimized version, and I can't know for which conversation I've read all messages. And therefore, the cleanup_read_marks also won't work ofc.
Is there a way around this? Or is it out-of-scope for this gem?
The text was updated successfully, but these errors were encountered:
Instead of handling Message as readable, you can use Conversation instead and touch the corresponding conversation if a message is added or updated. Consequence: Multiple new messages in one conversion will result in only one unread conversation.
messages.unread_by(user).each
), but it creates 1 record per resource+user (with 2 users per conversation, this table will be twice as long as themessages
table).mark_as_read! :all
for associations doesn't seem to be supported, since it just<NULL>
s the column in the database, to make the optimized version, and I can't know for which conversation I've read all messages. And therefore, thecleanup_read_marks
also won't work ofc.Is there a way around this? Or is it out-of-scope for this gem?
The text was updated successfully, but these errors were encountered: