diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1095ae7249715974c623936f1085bc5e7e37b5d2..47172314e5aac818eab642ad38d4e634be5c535d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,8 +4,8 @@ class ApplicationController < ActionController::Base has_mobile_fu + helper_method :all_aspects protect_from_forgery :except => :receive - before_filter :ensure_http_referer_is_set before_filter :set_header_data, :except => [:create, :update] before_filter :set_invites @@ -29,10 +29,17 @@ class ApplicationController < ActionController::Base @unread_message_count = ConversationVisibility.sum(:unread, :conditions => "person_id = #{current_user.person.id}") end @object_aspect_ids = [] - @all_aspects = current_user.aspects + + end + end + + def all_aspects + if user_signed_in? + @all_aspects ||= current_user.aspects end end + def ensure_page params[:page] = params[:page] ? params[:page].to_i : 1 end diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 5a9770634e96e723ed5fb16ed8a456c55ac93d38..f5fcc865fd7b98a9ca3c92eee9810d88fa1b2e7a 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -134,7 +134,7 @@ class AspectsController < ApplicationController def manage @aspect = :manage @contacts = current_user.contacts.includes(:person => :profile) - @aspects = @all_aspects.includes(:contacts => {:person => :profile}) + @aspects = all_aspects.includes(:contacts => {:person => :profile}) end def update diff --git a/app/controllers/sockets_controller.rb b/app/controllers/sockets_controller.rb index 7ed70b1cb908b95387a09d135be358a30ee7c84a..2f9c0f471ecc8e6b629416505ed93df3d56af638 100644 --- a/app/controllers/sockets_controller.rb +++ b/app/controllers/sockets_controller.rb @@ -6,20 +6,34 @@ class SocketsController < ApplicationController include ApplicationHelper include SocketsHelper include Rails.application.routes.url_helpers - + helper_method :all_aspects + + def incoming(msg) Rails.logger.info("Socket received connection to: #{msg}") end def outgoing(user_or_id, object, opts={}) - if user_or_id.instance_of?(Fixnum) - user_id = user_or_id - else - user_id = user_or_id.id - @user = user_or_id - end + #this should be the actual params of the controller + @params = {:user_or_id => user_or_id, :object => object}.merge(opts) return unless Diaspora::WebSocket.is_connected?(user_id) @_request = ActionDispatch::Request.new({}) - Diaspora::WebSocket.queue_to_user(user_id, action_hash(@user || User.find(user_id), object, opts)) + Diaspora::WebSocket.queue_to_user(user_id, action_hash(user, object, opts)) + end + + def user_id + if @params[:user_or_id].instance_of?(Fixnum) + @user_id ||= @params[:user_or_id] + else + @user_id ||= @params[:user_or_id].id + end + end + + def user + @user ||= ((@params[:user_or_id].instance_of? User )? @params[:user_or_id] : User.find(user_id)) + end + + def all_aspects + @all_aspects ||= user.aspects end end diff --git a/app/helpers/sockets_helper.rb b/app/helpers/sockets_helper.rb index 175ed92b00fd28092a65b57ac02ca123234fc595..eeaf1943302b1d61a9938ca45f27994663bff166 100644 --- a/app/helpers/sockets_helper.rb +++ b/app/helpers/sockets_helper.rb @@ -34,17 +34,16 @@ module SocketsHelper } }, :current_user => user, - :all_aspects => user.aspects, + :all_aspects => all_aspects, } v = render_to_string(:partial => 'shared/stream_element', :locals => post_hash) elsif object.is_a? Person person_hash = { :single_aspect_form => opts["single_aspect_form"], :person => object, - :all_aspects => user.aspects, + :all_aspects => all_aspects, :contact => user.contact_for(object), :current_user => user} - @all_aspects = user.aspects v = render_to_string(:partial => 'people/person', :locals => person_hash) elsif object.is_a? Comment diff --git a/app/views/aspect_memberships/_aspect_dropdown.html.haml b/app/views/aspect_memberships/_aspect_dropdown.html.haml index bcb1aa0834726b8e46963f914e834dfaf2802ed0..264fd2d8301e2f74d6d12d1b04f9a0e42eae9227 100644 --- a/app/views/aspect_memberships/_aspect_dropdown.html.haml +++ b/app/views/aspect_memberships/_aspect_dropdown.html.haml @@ -9,7 +9,7 @@ .wrapper %ul.dropdown_list{:unSelectable => 'on', 'data-person_id' => ((person.id) if person)} - - for aspect in @all_aspects + - for aspect in all_aspects = aspect_dropdown_list_item(aspect, contact, person) - if defined?(@aspect) && ( @aspect == :profile || @aspect == :tag || @aspect == :search || @aspect == :notification) diff --git a/app/views/invitations/new.html.haml b/app/views/invitations/new.html.haml index 28b3d56fdd0ec6ebd6e0e9ed672c35b5319e30ac..89a086c7e963562239bdf59374f6dd0aa78eaa50 100644 --- a/app/views/invitations/new.html.haml +++ b/app/views/invitations/new.html.haml @@ -24,7 +24,7 @@ %h4 = t('.aspect') - = invite.select(:aspects, options_from_collection_for_select(@all_aspects, 'id', 'name')) + = invite.select(:aspects, options_from_collection_for_select(all_aspects, 'id', 'name')) %br %br diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index ff5524d06a7d6d83ffd40e320f07497539114fd5..5dddbce549380db99acfaa294679c4188b5c176b 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -51,7 +51,7 @@ %li{:class => ('selected' if @aspect == :all)} = link_to t('all_aspects'), aspects_path, :class => 'home_selector' - - for aspect in @all_aspects + - for aspect in all_aspects %li{:data=>{:guid=>aspect.id}, :class => ("selected" if @object_aspect_ids.include?(aspect.id))} = link_for_aspect(aspect, :class => 'aspect_selector name', :title => t('contacts', :count => aspect.contacts.size)) diff --git a/app/views/layouts/application.mobile.haml b/app/views/layouts/application.mobile.haml index f1ce759050536f47af280638563e3a485eacdf2e..62cc39de5892565b3a30e279c6bcf2b4d4ceacda 100644 --- a/app/views/layouts/application.mobile.haml +++ b/app/views/layouts/application.mobile.haml @@ -88,7 +88,7 @@ %ul{:data => {:role => 'listview', :inset => 'true'}} %li = link_to t('all_aspects'), aspects_path - - for aspect in @all_aspects + - for aspect in all_aspects %li = link_to aspect, aspects_path('a_ids[]' => aspect.id) diff --git a/app/views/services/_remote_friend.html.haml b/app/views/services/_remote_friend.html.haml index 6775a81133671a24ae2345c5a99f1a707a86a090..720a68ba998237916d598b19691dc7eaad07b316 100644 --- a/app/views/services/_remote_friend.html.haml +++ b/app/views/services/_remote_friend.html.haml @@ -14,7 +14,7 @@ - elsif current_user.invites > 0 = form_tag service_inviter_path(:provider => 'facebook') do - = select_tag(:aspect_id, options_from_collection_for_select(@all_aspects, 'id', 'name')) + = select_tag(:aspect_id, options_from_collection_for_select(all_aspects, 'id', 'name')) = hidden_field_tag :uid, friend.uid = submit_tag t('.invite') diff --git a/app/views/shared/_footer.mobile.haml b/app/views/shared/_footer.mobile.haml index 6746d51451b82885d6e5df340ff343f1f0242796..57975114890303ca9ab918686affeb14f6d8e1e5 100644 --- a/app/views/shared/_footer.mobile.haml +++ b/app/views/shared/_footer.mobile.haml @@ -3,7 +3,7 @@ .inset %b= t('.your_aspects') %div{:data => {:role => 'controlgroup', :type => 'horizontal'}} - - for aspect in @all_aspects + - for aspect in all_aspects = link_to aspect, aspects_path('a_ids[]' => aspect.id) | .ui-bar diff --git a/app/views/shared/_stream.haml b/app/views/shared/_stream.haml index 1b41adab56cf482e0b534d8e1ae5ad8c1be41526..95ee72a0f5eaa58665d3c453b2bd1470dd80db14 100644 --- a/app/views/shared/_stream.haml +++ b/app/views/shared/_stream.haml @@ -6,6 +6,5 @@ = render :partial => 'shared/stream_element', :collection => posts, :as => :post, - :locals => {:all_aspects => @all_aspects, - :commenting_disabled => defined?(@commenting_disabled)} + :locals => { :commenting_disabled => defined?(@commenting_disabled)} diff --git a/log/.gitkeep b/log/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/spec/controllers/sockets_controller_spec.rb b/spec/controllers/sockets_controller_spec.rb index bae64a43842b5f9bd16f09a98eadb49fabe6c534..b88946739bdd3aa8a110b3617b04df3335f21902 100644 --- a/spec/controllers/sockets_controller_spec.rb +++ b/spec/controllers/sockets_controller_spec.rb @@ -20,6 +20,7 @@ describe SocketsController do describe 'actionhash' do it 'actionhashes posts' do + @controller.instance_variable_set(:@params, {:user_or_id => @user, :object => @message}) json = @controller.action_hash(@user, @message) json.include?(@message.text).should be_true json.include?('status_message').should be_true @@ -52,4 +53,4 @@ describe SocketsController do @controller.outgoing(@user, @message) end end -end \ No newline at end of file +end