From b5c6bbd1dfc74bb973c187a6ea67d14ad5f85f57 Mon Sep 17 00:00:00 2001 From: ilya Date: Tue, 17 Aug 2010 13:56:52 -0700 Subject: [PATCH 1/2] DG IZ; moved commenting methods into User (from Person). --- app/models/person.rb | 29 ----------------------------- app/models/user.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/app/models/person.rb b/app/models/person.rb index da666572b..d9cf93145 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -58,35 +58,6 @@ class Person encryption_key.public_key.export end - - - - ######## Commenting ######## - def comment(text, options = {}) - raise "must comment on something!" unless options[:on] - c = Comment.new(:person_id => self.id, :text => text, :post => options[:on]) - c.creator_signature = c.sign_with_key(encryption_key) - if c.save - dispatch_comment c - - c.socket_to_uid owner.id if owner_id - c - else - Rails.logger.warn "this failed to save: #{c.inspect}" - false - end - end - - def dispatch_comment( c ) - if owns? c.post - c.post_creator_signature = c.sign_with_key(encryption_key) - c.save - c.push_downstream - elsif owns? c - c.save - c.push_upstream - end - end ##profile def update_profile(params) if self.update_attributes(params) diff --git a/app/models/user.rb b/app/models/user.rb index 246fca82e..6bd0db76d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -59,6 +59,32 @@ class User self.posts.find_all_by_person_id( (group.person_ids + [self.person.id] ), :order => "created_at desc") end end + + ######## Commenting ######## + def comment(text, options = {}) + raise "must comment on something!" unless options[:on] + c = Comment.new(:person_id => self.person.id, :text => text, :post => options[:on]) + c.creator_signature = c.sign_with_key(encryption_key) + if c.save + dispatch_comment c + c.socket_to_uid id + c + else + Rails.logger.warn "this failed to save: #{c.inspect}" + false + end + end + + def dispatch_comment( c ) + if owns? c.post + c.post_creator_signature = c.sign_with_key(encryption_key) + c.save + c.push_downstream + elsif owns? c + c.save + c.push_upstream + end + end ######### Posts and Such ############### From fd539926c279adf94b42eba67bc8e0d92222c2d7 Mon Sep 17 00:00:00 2001 From: ilya Date: Tue, 17 Aug 2010 13:59:58 -0700 Subject: [PATCH 2/2] DG IZ; changed variable 'c' to 'comment' --- app/models/user.rb | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 6bd0db76d..e8a087d85 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -37,7 +37,7 @@ class User Group.create(opts) end - ######## Posting ######## + ######## Posting ######## def post(class_name, options = {}) options[:person] = self.person model_class = class_name.to_s.camelize.constantize @@ -63,26 +63,26 @@ class User ######## Commenting ######## def comment(text, options = {}) raise "must comment on something!" unless options[:on] - c = Comment.new(:person_id => self.person.id, :text => text, :post => options[:on]) - c.creator_signature = c.sign_with_key(encryption_key) - if c.save - dispatch_comment c - c.socket_to_uid id - c + comment = Comment.new(:person_id => self.person.id, :text => text, :post => options[:on]) + comment.creator_signature = comment.sign_with_key(encryption_key) + if comment.save + dispatch_comment comment + comment.socket_to_uid id + comment else - Rails.logger.warn "this failed to save: #{c.inspect}" + Rails.logger.warn "this failed to save: #{comment.inspect}" false end end - def dispatch_comment( c ) - if owns? c.post - c.post_creator_signature = c.sign_with_key(encryption_key) - c.save - c.push_downstream - elsif owns? c - c.save - c.push_upstream + def dispatch_comment( comment ) + if owns? comment.post + comment.post_creator_signature = comment.sign_with_key(encryption_key) + comment.save + comment.push_downstream + elsif owns? comment + comment.save + comment.push_upstream end end