MS DG DC Participate stream that has things bubble to the top

This commit is contained in:
Dennis Collinson 2012-02-03 14:31:11 -08:00
parent c301f80ca9
commit 3991903b56
15 changed files with 92 additions and 26 deletions

View file

@ -152,8 +152,6 @@ group :development do
gem 'ruby-debug', :platforms => :mri_18 gem 'ruby-debug', :platforms => :mri_18
gem 'yard', :require => false gem 'yard', :require => false
# speed up development requests (already pulled into rails 3.2)
gem 'active_reload'
# for tracing AR object instantiation and memory usage per request # for tracing AR object instantiation and memory usage per request
gem 'oink' gem 'oink'

View file

@ -61,7 +61,6 @@ GEM
rack-mount (~> 0.6.14) rack-mount (~> 0.6.14)
rack-test (~> 0.5.7) rack-test (~> 0.5.7)
tzinfo (~> 0.3.23) tzinfo (~> 0.3.23)
active_reload (0.6.1)
activemodel (3.0.11) activemodel (3.0.11)
activesupport (= 3.0.11) activesupport (= 3.0.11)
builder (~> 2.1.2) builder (~> 2.1.2)
@ -431,7 +430,6 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
SystemTimer (= 1.2.3) SystemTimer (= 1.2.3)
active_reload
activerecord-import activerecord-import
acts-as-taggable-on! acts-as-taggable-on!
acts_as_api acts_as_api

View file

@ -32,6 +32,7 @@ class StreamsController < ApplicationController
end end
def participate def participate
puts params.inspect
stream_responder(Stream::Participate) stream_responder(Stream::Participate)
end end

View file

@ -70,6 +70,7 @@ Please do the following:
HELP HELP
Process.exit(1) Process.exit(1)
end end
self.setup!
end end
def self.setup! def self.setup!

View file

@ -55,6 +55,15 @@ class Post < ActiveRecord::Base
#scopes #scopes
scope :includes_for_a_stream, includes(:o_embed_cache, {:author => :profile}, :mentions => {:person => :profile}) #note should include root and photos, but i think those are both on status_message scope :includes_for_a_stream, includes(:o_embed_cache, {:author => :profile}, :mentions => {:person => :profile}) #note should include root and photos, but i think those are both on status_message
scope :commented_by, lambda { |person|
select('DISTINCT posts.*').joins(:comments).where(:comments => {:author_id => person.id})
}
scope :liked_by, lambda { |person|
joins(:likes).where(:likes => {:author_id => person.id})
}
def post_type def post_type
self.class.name self.class.name
end end

View file

@ -32,14 +32,6 @@ class StatusMessage < Post
joins(:mentions).where(:mentions => {:person_id => person.id}) joins(:mentions).where(:mentions => {:person_id => person.id})
} }
scope :commented_by, lambda { |person|
select('DISTINCT posts.*').joins(:comments).where(:comments => {:author_id => person.id})
}
scope :liked_by, lambda { |person|
joins(:likes).where(:likes => {:author_id => person.id})
}
def self.guids_for_author(person) def self.guids_for_author(person)
Post.connection.select_values(Post.where(:author_id => person.id).select('posts.guid').to_sql) Post.connection.select_values(Post.where(:author_id => person.id).select('posts.guid').to_sql)
end end

View file

@ -0,0 +1,9 @@
class AddInteractedAtToPosts < ActiveRecord::Migration
def self.up
add_column :posts, :interacted_at, :datetime
end
def self.down
remove_column :posts, :interacted_at
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120202190701) do ActiveRecord::Schema.define(:version => 20120203220932) do
create_table "account_deletions", :force => true do |t| create_table "account_deletions", :force => true do |t|
t.string "diaspora_handle" t.string "diaspora_handle"
@ -316,6 +316,7 @@ ActiveRecord::Schema.define(:version => 20120202190701) do
t.integer "comments_count", :default => 0 t.integer "comments_count", :default => 0
t.integer "o_embed_cache_id" t.integer "o_embed_cache_id"
t.integer "reshares_count", :default => 0 t.integer "reshares_count", :default => 0
t.datetime "interacted_at"
end end
add_index "posts", ["author_id", "root_guid"], :name => "index_posts_on_author_id_and_root_guid", :unique => true add_index "posts", ["author_id", "root_guid"], :name => "index_posts_on_author_id_and_root_guid", :unique => true
@ -336,8 +337,8 @@ ActiveRecord::Schema.define(:version => 20120202190701) do
t.date "birthday" t.date "birthday"
t.string "gender" t.string "gender"
t.text "bio" t.text "bio"
t.boolean "searchable", :default => true, :null => false t.boolean "searchable", :default => true, :null => false
t.integer "person_id", :null => false t.integer "person_id", :null => false
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "location" t.string "location"

View file

@ -18,6 +18,11 @@ module Diaspora
validate :author_is_not_ignored validate :author_is_not_ignored
delegate :public?, :to => :parent delegate :public?, :to => :parent
after_create do
parent.touch(:interacted_at) if parent.respond_to?(:interacted_at)
end
end end
end end

View file

@ -19,8 +19,7 @@ module EvilQuery
def posts def posts
liked_post_ids = fetch_ids!(LikedPosts.new(@user).posts, "posts.id") liked_post_ids = fetch_ids!(LikedPosts.new(@user).posts, "posts.id")
commented_post_ids = fetch_ids!(CommentedPosts.new(@user).posts, "posts.id") commented_post_ids = fetch_ids!(CommentedPosts.new(@user).posts, "posts.id")
Post.where(:id => liked_post_ids + commented_post_ids).order("posts.interacted_at DESC")
Post.where(:id => liked_post_ids + commented_post_ids)
end end
end end
@ -30,7 +29,7 @@ module EvilQuery
end end
def posts def posts
StatusMessage.liked_by(@user.person) Post.liked_by(@user.person)
end end
end end
@ -40,7 +39,7 @@ module EvilQuery
end end
def posts def posts
StatusMessage.commented_by(@user.person) Post.commented_by(@user.person)
end end
end end

View file

@ -3,6 +3,10 @@ class Stream::Participate < Stream::Base
Rails.application.routes.url_helpers.participate_stream_path(opts) Rails.application.routes.url_helpers.participate_stream_path(opts)
end end
def order
"interacted_at"
end
def title def title
I18n.translate("streams.participate.title") I18n.translate("streams.participate.title")
end end
@ -11,5 +15,4 @@ class Stream::Participate < Stream::Base
def posts def posts
@posts ||= EvilQuery::Participation.new(user).posts @posts ||= EvilQuery::Participation.new(user).posts
end end
end end

View file

@ -8,9 +8,5 @@ app.collections.Posts = Backbone.Collection.extend({
parse: function(resp){ parse: function(resp){
return resp.posts; return resp.posts;
},
comparator : function(post) {
return -post.createdAt();
} }
}); });

View file

@ -14,4 +14,48 @@ describe EvilQuery::Participation do
alice.comment!(@status_message, "hey") alice.comment!(@status_message, "hey")
EvilQuery::Participation.new(alice).posts.should include(@status_message) EvilQuery::Participation.new(alice).posts.should include(@status_message)
end end
it "should include your statusMessages" do
pending
end
describe "ordering" do
before do
@status_messageA = Factory(:status_message, :author => bob.person)
@status_messageB = Factory(:status_message, :author => bob.person)
@photoC = Factory(:activity_streams_photo, :author => bob.person)
@status_messageD = Factory(:status_message, :author => bob.person)
@status_messageE = Factory(:status_message, :author => bob.person)
time = Time.now
Timecop.freeze do
Timecop.travel time += 1.month
alice.comment!(@status_messageB, "party")
Timecop.travel time += 1.month
Factory(:like, :target => @status_messageA, :author => alice.person)
Timecop.travel time += 1.month
alice.comment!(@photoC, "party")
Timecop.travel time += 1.month
alice.comment!(@status_messageE, "party")
end
Timecop.return
end
let(:posts) {EvilQuery::Participation.new(alice).posts}
it "doesn't include Posts that aren't acted on" do
posts.map(&:id).should_not include(@status_messageD.id)
posts.map(&:id).should =~ [@status_messageA.id, @status_messageB.id, @photoC.id, @status_messageE.id]
end
it "returns the posts that the user has commented on or liked with the most recently acted on ones first" do
posts.map(&:id).should == [@status_messageE.id, @photoC.id, @status_messageA.id, @status_messageB.id]
end
end
end end

View file

@ -7,6 +7,16 @@ require 'spec_helper'
describe Diaspora::Relayable do describe Diaspora::Relayable do
shared_examples_for "it is relayable" do shared_examples_for "it is relayable" do
describe 'interacted_at' do
it 'sets the interacted at of the parent to the created at of the relayable post' do
relayable = build_object
relayable.save
if relayable.parent.respond_to?(:interacted_at) #I'm sorry.
relayable.parent.interacted_at.to_i.should == relayable.created_at.to_i
end
end
end
describe 'validations' do describe 'validations' do
describe 'on :author_id' do describe 'on :author_id' do
context "the author is on the parent object author's ignore list when object is created" do context "the author is on the parent object author's ignore list when object is created" do

View file

@ -32,9 +32,9 @@ describe 'Streams' do
@stream.max_time.should be_a(Time) @stream.max_time.should be_a(Time)
end end
it 'should default order to created_at' do it 'should always have an order (default created_at)' do
@stream.order=nil @stream.order=nil
@stream.order.should == 'created_at' @stream.order.should_not be_nil
end end
it 'initializes a publisher' do it 'initializes a publisher' do