summaryrefslogtreecommitdiff
path: root/users/app
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-12-30 15:22:44 -0800
committerjessib <jessib@riseup.net>2013-12-30 15:22:44 -0800
commit16b28882aa7659fb89e1661ed8af0c0db72642c8 (patch)
tree856d7c0caf6a72f2bea4ef134b7de988534c179b /users/app
parent8db811678404aa9a33c54805f8fba4afb932c1f4 (diff)
Change structure to be more no-sql-y, rather than relational.
Diffstat (limited to 'users/app')
-rw-r--r--users/app/controllers/v1/messages_controller.rb12
-rw-r--r--users/app/models/user.rb13
-rw-r--r--users/app/models/user_message.rb3
3 files changed, 27 insertions, 1 deletions
diff --git a/users/app/controllers/v1/messages_controller.rb b/users/app/controllers/v1/messages_controller.rb
index d49b161..18f9f46 100644
--- a/users/app/controllers/v1/messages_controller.rb
+++ b/users/app/controllers/v1/messages_controller.rb
@@ -12,6 +12,7 @@ module V1
# routes ensure this is only for PUT
def mark_read
+=begin
user_message = UserMessage.find_by_user_id_and_message_id([params[:user_id], params[:message_id]])
user_message.seen = true if user_message
@@ -22,6 +23,17 @@ module V1
render json: false
end
end
+=end
+ if (user = User.find(params[:user_id])) && Message.find(params[:message_id])
+ user.message_ids_seen << params[:message_id] if !user.message_ids_seen.include?(params[:message_id]) #is it quicker to instead run uniq after adding?
+ user.message_ids_to_see.delete(params[:message_id])
+ user.save
+ render json: true
+ return
+ else
+ render json: false
+ end
+ end
end
end
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index fe3a127..fc63ae9 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -13,6 +13,9 @@ class User < CouchRest::Model::Base
property :desired_service_level_code, Integer, :accessible => true
property :effective_service_level_code, Integer, :accessible => true
+ property :message_ids_to_see, [String]
+ property :message_ids_seen, [String]
+
before_save :update_effective_service_level
validates :login, :password_salt, :password_verifier,
@@ -74,6 +77,7 @@ class User < CouchRest::Model::Base
def messages(unseen = true)
+=begin
user_messages = unseen ? UserMessage.by_user_id_and_seen(:key => [self.id, false]).all : UserMessage.by_user_id(:key => self.id).all
messages = []
@@ -81,6 +85,15 @@ class User < CouchRest::Model::Base
messages << Message.find(um.message.id)
end
messages
+=end
+
+ message_ids = unseen ? self.message_ids_to_see : self.message_ids_to_see + self.message_ids_seen # TODO check unique?
+
+ messages = []
+ message_ids.each do |message_id|
+ messages << Message.find(message_id)
+ end
+ messages
end
diff --git a/users/app/models/user_message.rb b/users/app/models/user_message.rb
index 37aae0b..51ca46c 100644
--- a/users/app/models/user_message.rb
+++ b/users/app/models/user_message.rb
@@ -1,4 +1,5 @@
-class UserMessage < CouchRest::Model::Base
+# TODO WOULD NOT USE anymore, in proposed alternate, so delete file.
+class XXXXUserMessage < CouchRest::Model::Base
use_database :user_messages
belongs_to :user