How can i specify an array of people ids, that will not get an "unread" mark for the message?
Do you want to get a list of users who have read a given message? Hm, this is not possible out of the box yet. But I think this SQL query should do the job:
WHERE EXISTS (
FROM read_marks rm1
WHERE rm1.user_id = users.id
AND rm1.readable_id = 2661 # ID of given message
AND rm1.readable_type = 'Message'
FROM read_marks rm2
WHERE rm2.user_id = users.id
AND rm2.readable_type = 'Message'
AND rm2.readable_id IS NULL
) > "2012-04-26 11:20:08" # timestamp of given message
Do you think the gem should support it? I'm not sure because it' s possible that a user has not actually read the message, but has used the "mark all as read" feature instead, so the query result is not meaningful.
No, I want to prevent 'unread' marks creating for users: [Author, Andy, Rita], but these: [David, Ryan] should receive notifications.
How can i specify this behaviour? The problem is: when message is created, all users get mark.
Hm, why do want to prevent this? For every user there will be only one record created in the read_marks table (containing a timestamp). If a user does not read any messages, no more read_marks will be created.
Important hint: If a message is created, no read_marks are created or touched! This is the basic idea of the gem. read_marks are created only if a user reads a given message.
If you don't want to show unread messages to a given user you should handle this in your controller or view.
Well, i cached this, with marks on new messages. Thank you!
Sorry, i can't understand, where is the place, i set if user reads the message or not(and it then store to 'read_marks' table)?
class User < ActiveRecord::Base
needs some additional methods to set message ids?
If a message is displayed to a user, you should call this method:
message.mark_as_read! :for => current_user
This updates the read_marks table by adding a record.
For usage informations please have a look at the readme
What about pre-sets?
Like Message.new.set_readers([user1, user2, user3]) - these would be people, who will get their read_marks, but others will not. I'm asking this because i think, that gem does extra work in this case:
User.all.each do |user|
@message.mark_as_read! :for => user unless @message.reader_ids.include?(user.id)
<--- This is extra
Why do you want to do this? If some users don't want to get read marks at all, you shouldn't display them. Don't mark a created message as read for a set of users as shown in your code fragment.
The gem is very efficient on touching the database. If a user never reads any message, the read_marks table is not flooded with records.
Great, the main problem in my thoughts was the database scaling! Thanks