Ruby gem to manage read/unread status of Mongoid objects.
First and foremost this is a fork of Unread by Georg Ledermann. If you are using a relational DB, make sure to check it out.
- Manages unread records for anything you want users to read (like messages, documents, comments etc.)
- Supports mark as read to mark a single record as read
- Supports mark all as read to mark all records (loops through creating a readmark for each)
- Gives you a scope to get the unread or read records for a given user
- Needs only one additional collection
class User
include Mongoid::Document
include UnreadMongoid
acts_as_reader
end
class Message
include Mongoid::Document
include Mongoid::Timestamps
include UnreadMongoid
acts_as_readable
end
message1 = Message.create!
message2 = Message.create!
## Get unread messages for a given user
Message.unread_by(current_user).entries
# => [ message1, message2 ]
message1.mark_as_read! :for => current_user
Message.unread_by(current_user).entries
# => [ message2 ]
Message.mark_as_read! :all, :for => current_user
Message.unread_by(current_user).entries
# => [ ]