From b0088c73d87c1db3e108e158d53aa2db5f42dcae Mon Sep 17 00:00:00 2001 From: ilya Date: Wed, 18 Aug 2010 10:37:33 -0700 Subject: [PATCH 1/4] DG IZ; user's own post gets referenced in group model --- app/controllers/application_controller.rb | 1 - app/controllers/status_messages_controller.rb | 3 --- app/models/group.rb | 2 ++ app/models/user.rb | 9 +++++++++ spec/models/group_spec.rb | 14 +++++++++++++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c3b74a861..291246750 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -19,7 +19,6 @@ class ApplicationController < ActionController::Base if current_user @groups = current_user.groups @friends = current_user.friends - @latest_status_message = StatusMessage.newest_for(current_user.person) @group = params[:group] ? current_user.group_by_id(params[:group]) : current_user.groups.first end end diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index f941389a5..9b363032e 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -3,12 +3,9 @@ class StatusMessagesController < ApplicationController def index @status_messages = StatusMessage.paginate :page => params[:page], :order => 'created_at DESC' - - respond_to do |format| format.html end - end def create diff --git a/app/models/group.rb b/app/models/group.rb index 0f40d6d9b..e872bc30c 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -5,9 +5,11 @@ class Group key :person_ids, Array key :request_ids, Array + key :my_post_ids, Array many :people, :in => :person_ids, :class_name => 'Person' many :requests, :in => :request_ids, :class_name => 'Request' + many :my_posts, :in => :my_post_ids, :class_name => 'Post' belongs_to :user, :class_name => 'User' diff --git a/app/models/user.rb b/app/models/user.rb index 12067eee7..8cca14abe 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -41,6 +41,10 @@ class User ######## Posting ######## def post(class_name, options = {}) options[:person] = self.person + + group = options[:group] + options.delete(:group) + model_class = class_name.to_s.camelize.constantize post = model_class.instantiate(options) post.creator_signature = post.sign_with_key(encryption_key) @@ -51,6 +55,11 @@ class User self.raw_visible_posts << post self.save + + if group + group.my_posts << post + group.save + end post end diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 1d0f400d5..896d12962 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -33,7 +33,6 @@ describe Group do group.people.include?(@friend_2).should be true group.people.size.should == 2 end - end describe 'querying' do @@ -52,4 +51,17 @@ describe Group do @group.people.size.should == 1 end end + + describe 'posting' do + + it 'should add post to group via post method' do + @group = @user.group(:name => 'losers', :people => [@friend]) + + status_message = @user.post( :status_message, :message => "hey", :group => @group ) + + @group.reload + @group.my_posts.include?(status_message).should be true + end + + end end From 055c222fc2b084ee836d3a0901900dfb33888038 Mon Sep 17 00:00:00 2001 From: ilya Date: Wed, 18 Aug 2010 10:53:43 -0700 Subject: [PATCH 2/4] DG IZ; using group_id instead of group in post method. passing in :group_id into publisher partial --- app/models/user.rb | 7 ++++--- app/views/groups/index.html.haml | 2 +- app/views/groups/show.html.haml | 2 +- app/views/shared/_publisher.haml | 3 +++ spec/models/group_spec.rb | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 8cca14abe..a979af879 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -42,8 +42,8 @@ class User def post(class_name, options = {}) options[:person] = self.person - group = options[:group] - options.delete(:group) + group_id = options[:group_id] + options.delete(:group_id) model_class = class_name.to_s.camelize.constantize post = model_class.instantiate(options) @@ -56,7 +56,8 @@ class User self.raw_visible_posts << post self.save - if group + if group_id + group = self.groups.find_by_id(group_id) group.my_posts << post group.save end diff --git a/app/views/groups/index.html.haml b/app/views/groups/index.html.haml index e4d1ecca2..4ed9db19e 100644 --- a/app/views/groups/index.html.haml +++ b/app/views/groups/index.html.haml @@ -2,7 +2,7 @@ welcome home, = current_user.profile.first_name -= render "shared/publisher" += render "shared/publisher", :group_id => @group.id %ul#stream - for post in @posts diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml index daaaaaabc..73f799c72 100644 --- a/app/views/groups/show.html.haml +++ b/app/views/groups/show.html.haml @@ -1,4 +1,4 @@ -= render "shared/publisher" += render "shared/publisher", :group_id => @group.id %ul#stream - for post in @posts = render type_partial(post), :post => post diff --git a/app/views/shared/_publisher.haml b/app/views/shared/_publisher.haml index 4d2f8640b..fe52ac354 100644 --- a/app/views/shared/_publisher.haml +++ b/app/views/shared/_publisher.haml @@ -3,6 +3,9 @@ #publisher_form = form_for StatusMessage.new, :remote => true do |f| = f.error_messages + + = f.hidden_field :group_id, :value => group_id + %p %label{:for => "status_message_message"} Message = f.text_area :message, :rows => 2 diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 896d12962..035e9be2f 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -57,7 +57,7 @@ describe Group do it 'should add post to group via post method' do @group = @user.group(:name => 'losers', :people => [@friend]) - status_message = @user.post( :status_message, :message => "hey", :group => @group ) + status_message = @user.post( :status_message, :message => "hey", :group_id => @group.id ) @group.reload @group.my_posts.include?(status_message).should be true From 4d86933f4a8140dbc9cc3dc03d8622d837f5d95a Mon Sep 17 00:00:00 2001 From: ilya Date: Wed, 18 Aug 2010 11:39:41 -0700 Subject: [PATCH 3/4] DG IZ; user's visible posts method queries group objects for their posts --- app/models/group.rb | 4 ++-- app/models/user.rb | 9 +++++++-- spec/models/group_spec.rb | 16 +++++++++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/models/group.rb b/app/models/group.rb index e872bc30c..6b8f18921 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -5,11 +5,11 @@ class Group key :person_ids, Array key :request_ids, Array - key :my_post_ids, Array + key :post_ids, Array many :people, :in => :person_ids, :class_name => 'Person' many :requests, :in => :request_ids, :class_name => 'Request' - many :my_posts, :in => :my_post_ids, :class_name => 'Post' + many :posts, :in => :post_ids, :class_name => 'Post' belongs_to :user, :class_name => 'User' diff --git a/app/models/user.rb b/app/models/user.rb index a979af879..210714fcd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -58,7 +58,7 @@ class User if group_id group = self.groups.find_by_id(group_id) - group.my_posts << post + group.posts << post group.save end @@ -68,7 +68,7 @@ class User def visible_posts( opts = {} ) if opts[:by_members_of] group = self.groups.find_by_id( opts[:by_members_of].id ) - self.raw_visible_posts.find_all_by_person_id( (group.person_ids + [self.person.id] ), :order => "created_at desc") + group.posts end end @@ -267,6 +267,11 @@ class User self.raw_visible_posts << object self.save + groups = self.groups_with_person(object.person) + groups.each{ |group| group.posts << object + group.save + } + groups = groups_with_person(object.person) object.socket_to_uid(id, :group_id => groups.first.id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object)) end diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 035e9be2f..26f3397d4 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -60,7 +60,21 @@ describe Group do status_message = @user.post( :status_message, :message => "hey", :group_id => @group.id ) @group.reload - @group.my_posts.include?(status_message).should be true + @group.posts.include?(status_message).should be true + end + + it 'should add post to group via receive method' do + group = @user.group(:name => 'losers') + group2 = @user2.group(:name => 'winners') + friend_users(@user, group, @user2, group2) + + message = @user2.post(:status_message, :message => "Hey Dude") + + @user.receive message.to_diaspora_xml + + group.reload + group.posts.include?(message).should be true + @user.visible_posts(:by_members_of => group).include?(message).should be true end end From f5811df5b73a62a1adb59ad7641e80afb637f6dd Mon Sep 17 00:00:00 2001 From: ilya Date: Wed, 18 Aug 2010 11:59:20 -0700 Subject: [PATCH 4/4] DG IZ; added info text to add new friend button --- app/views/shared/_group_nav.haml | 7 +++++- public/stylesheets/application.css | 21 ++++++++--------- public/stylesheets/sass/application.sass | 29 ++++++++++++------------ 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/app/views/shared/_group_nav.haml b/app/views/shared/_group_nav.haml index 66f4fa0bd..455d90bb4 100644 --- a/app/views/shared/_group_nav.haml +++ b/app/views/shared/_group_nav.haml @@ -14,7 +14,12 @@ #friend_pictures - for friend in @group.people = person_image_link(friend) - = link_to "+", "#add_request_pane", :id => 'add_request_button', :class => "add_new" + = link_to (image_tag 'add_friend_button.png'), "#add_request_pane", :id => 'add_request_button' + + - if @group.people.count == 0 + %span.add_new_description + << click the plus to add friends to this group + .yo{:style => 'display:none'} #add_request_pane diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 18289b738..a5b4b5fc6 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -430,24 +430,21 @@ h1.big_text { #group ul > li.selected, #group ul > li.selected a { color: white; font-weight: bold; - font-size: 18px; - text-shadow: 0 2px 0px black; } + font-size: 18px; } #group a { color: #aaaaaa; font-weight: normal; } - #group #friend_pictures .add_new { + #group #friend_pictures .add_new_description { position: relative; - display: inline-block; height: 40px; - width: 40px; - background-color: black; - text-align: center; - font-size: 40px; + display: inline-block; + background-color: #222222; + color: #999999; + top: -16px; line-height: 40px; - top: -6px; } - #group #friend_pictures .add_new:hover { - background: #999999; - color: black; } + padding: 0 1em; + margin-bottom: -20px; + font-style: italic; } #group #friend_pictures img { height: 40px; } diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 0ac9dbfce..b41a1120a 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -546,21 +546,22 @@ h1.big_text :weight normal #friend_pictures - .add_new - :position relative - :display inline-block - :height 40px - :width 40px - :background - :color #000 - :text-align center - :font-size 40px - :line-height 40px - :top -6px - &:hover - :background #999 - :color #000 + .add_new_description + :position relative + :height 40px + :display inline-block + :background + :color #222 + :color #999 + :top -16px + :line + :height 40px + :padding 0 1em + :margin + :bottom -20px + :font + :style italic img :height 40px