Customizing #8

Closed
sadfuzzy opened this Issue Apr 25, 2012 · 8 comments

Comments

Projects
None yet
2 participants
Contributor

sadfuzzy commented Apr 25, 2012

How can i specify an array of people ids, that will not get an "unread" mark for the message?

Owner

ledermann commented Apr 26, 2012

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:

SELECT users.*
FROM users

WHERE EXISTS (
  SELECT rm1.id 
  FROM read_marks rm1
  WHERE rm1.user_id = users.id 
  AND rm1.readable_id = 2661 # ID of given message
  AND rm1.readable_type = 'Message'
)

OR (
  SELECT rm2.timestamp
  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.

Contributor

sadfuzzy commented Apr 26, 2012

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.

Owner

ledermann commented Apr 27, 2012

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.

Contributor

sadfuzzy commented Apr 28, 2012

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
  acts_as_reader
end 

needs some additional methods to set message ids?

Owner

ledermann commented Apr 28, 2012

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

ledermann closed this Apr 28, 2012

Contributor

sadfuzzy commented Apr 28, 2012

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:

  1. Create message.
  2. Gem writes read_marks for all users to DB
  3. I need to do:
User.all.each do |user|
  @message.mark_as_read! :for => user unless @message.reader_ids.include?(user.id)
end

<--- This is extra

Owner

ledermann commented Apr 30, 2012

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.

Contributor

sadfuzzy commented May 1, 2012

Great, the main problem in my thoughts was the database scaling! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment