diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index b3e826077..e7437c454 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -28,9 +28,12 @@ class GroupsController < ApplicationController end def show - @people_ids = @group.people.map {|p| p.id} - @posts = Post.paginate :person_id => @people_ids, :order => 'created_at DESC' + @people_ids = @group.person_ids + @group = Group.first(:id => params[:id]) + + @posts = current_user.posts_for( :group => @group ).paginate :order => 'created_at DESC' + #@posts = Post.paginate :person_id => @people_ids, :order => 'created_at DESC' end def edit diff --git a/app/controllers/sockets_controller.rb b/app/controllers/sockets_controller.rb index 802aa9cb5..fd966afeb 100644 --- a/app/controllers/sockets_controller.rb +++ b/app/controllers/sockets_controller.rb @@ -4,7 +4,7 @@ class SocketsController < ApplicationController include Rails.application.routes.url_helpers def incoming(msg) - puts "Got a connection to: #{msg}" + Rails.logger.info("Socket received connection to: #{msg}") end def outgoing(uid,object) diff --git a/app/helpers/requests_helper.rb b/app/helpers/requests_helper.rb index 9eed63e91..37a5485c4 100644 --- a/app/helpers/requests_helper.rb +++ b/app/helpers/requests_helper.rb @@ -30,7 +30,7 @@ module RequestsHelper url = nil local_person = Person.by_webfinger identifier if local_person - action = (local_person == current_user.local_person ? :none : :friend) + action = (local_person == current_user.person ? :none : :friend) url = local_person.receive_url elsif !(identifier.include?(request.host) || identifier.include?("localhost")) f = Redfinger.finger(identifier) diff --git a/app/models/user.rb b/app/models/user.rb index 197fc4ea0..53cde243e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -53,10 +53,24 @@ class User model_class = class_name.to_s.camelize.constantize post = model_class.instantiate(options) post.creator_signature = post.sign_with_key(encryption_key) + post.save post.notify_people - post.socket_to_uid owner.id if (owner_id && post.respond_to?( :socket_to_uid)) + post.socket_to_uid owner.id if (owner_id && post.respond_to?(:socket_to_uid)) + + self.posts << post + self.save + post - end ######### Posts and Such ############### + end + + def posts_for( opts = {} ) + if opts[:group] + group = self.groups.find_by_id( opts[:group].id ) + self.posts.find_all_by_person_id( (group.person_ids + [self.person.id] ), :order => "created_at desc") + end + end + + ######### Posts and Such ############### def retract( post ) retraction = Retraction.for(post) diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb index 0f4e68f7b..381d1f6c2 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -12,7 +12,7 @@ require "lib/diaspora/websocket" sid = Diaspora::WebSocket.subscribe(ws.request['Path'].gsub('/',''), ws) - ws.onmessage { |msg| SocketsController.new.incoming(msg) }#@channel.push msg; puts msg} + ws.onmessage { |msg| SocketsController.new.incoming(msg) } ws.onclose { Diaspora::WebSocket.unsubscribe(ws.request['Path'].gsub('/',''), sid) } } diff --git a/lib/message_handler.rb b/lib/message_handler.rb index 4bc54b4c9..8f97e53c3 100644 --- a/lib/message_handler.rb +++ b/lib/message_handler.rb @@ -31,8 +31,9 @@ class MessageHandler end http.errback { - puts http.response - puts "failure from #{query.destination}, retrying" + Rails.logger.info(http.response) + Rails.logger.info("Failure from #{query.destination}, retrying...") + query.try_count +=1 @queue.push query unless query.try_count >= NUM_TRIES process diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index fd78af0a3..26381c311 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -269,6 +269,12 @@ describe User do @user.posts.count.should == 0 end + + it "should add the post to that user's posts when a user posts it" do + status_message = @user.post :status_message, :message => "hi" + @user.reload + @user.posts.include?(status_message).should be true + end it 'should be removed on unfriending' do status_message = @user2.post :status_message, :message => "hi" @@ -326,7 +332,7 @@ describe User do it 'should not override userrefs on receive by another person' do @user3 = Factory.create :user - @user3.activate_friend(@user2, @group3) + @user3.activate_friend(@user2.person, @group3) status_message = @user2.post :status_message, :message => "hi" @user.receive status_message.to_diaspora_xml @@ -351,6 +357,39 @@ describe User do Post.count.should be 1 end + describe 'group streams' do + before do + @group = @user.group(:name => 'heroes') + @group2 = @user.group(:name => 'stuff') + @user2 = Factory.create :user + @user.activate_friend(@user2.person, @group) + + @user3 = Factory.create :user + @user.activate_friend(@user3.person, @group2) + + @user4 = Factory.create :user + @user.activate_friend(@user4.person, @group2) + end + + it 'should generate a valid stream for a group of people' do + status_message1 = @user2.post :status_message, :message => "hi" + status_message2 = @user3.post :status_message, :message => "heyyyy" + status_message3 = @user4.post :status_message, :message => "yooo" + + @user.receive status_message1.to_diaspora_xml + @user.receive status_message2.to_diaspora_xml + @user.receive status_message3.to_diaspora_xml + @user.reload + + @user.posts_for(:group => @group).include?(status_message1).should be true + @user.posts_for(:group => @group).include?(status_message2).should be false + @user.posts_for(:group => @group).include?(status_message3).should be false + + @user.posts_for(:group => @group2).include?(status_message1).should be false + @user.posts_for(:group => @group2).include?(status_message2).should be true + @user.posts_for(:group => @group2).include?(status_message3).should be true + end + end end end