summaryrefslogtreecommitdiff
path: root/app/models/message.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/message.rb')
-rw-r--r--app/models/message.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/app/models/message.rb b/app/models/message.rb
new file mode 100644
index 0000000..424f094
--- /dev/null
+++ b/app/models/message.rb
@@ -0,0 +1,29 @@
+class Message < CouchRest::Model::Base
+
+ use_database :messages
+
+ property :text, String
+ property :user_ids_to_show, [String]
+ property :user_ids_have_shown, [String] # is this necessary to store?
+
+ timestamps!
+
+ design do
+ own_path = Pathname.new(File.dirname(__FILE__))
+ load_views(own_path.join('..', 'designs', 'message'))
+ end
+
+ def mark_as_read_by(user)
+ user_ids_to_show.delete(user.id)
+ # is it necessary to keep track of what users have already seen it?
+ user_ids_have_shown << user.id unless read_by?(user)
+ end
+
+ def read_by?(user)
+ user_ids_have_shown.include?(user.id)
+ end
+
+ def unread_by?(user)
+ user_ids_to_show.include?(user.id)
+ end
+end