MS DG; some stream refactoring; can comment now exists in base stream; default behavior is to allow you to comment on locals post, and then remote people if you are connected with them
This commit is contained in:
parent
01d7b9507b
commit
5a8024a71a
6 changed files with 75 additions and 39 deletions
|
|
@ -117,4 +117,13 @@ class Stream::Aspect< Stream::Base
|
||||||
Rails.application.routes.url_helpers.contacts_path(:a_id => aspect.id)
|
Rails.application.routes.url_helpers.contacts_path(:a_id => aspect.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This is perfomance optimization, as everyone in your aspect stream you have
|
||||||
|
# a contact.
|
||||||
|
#
|
||||||
|
# @param post [Post]
|
||||||
|
# @return [Boolean]
|
||||||
|
def can_comment?(post)
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,12 @@ class Stream::Base
|
||||||
self.order = opts[:order]
|
self.order = opts[:order]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [Person]
|
||||||
def random_featured_user
|
def random_featured_user
|
||||||
@random_featured_user ||= Person.find_by_diaspora_handle(featured_diaspora_id)
|
@random_featured_user ||= Person.find_by_diaspora_handle(featured_diaspora_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [Boolean]
|
||||||
def has_featured_users?
|
def has_featured_users?
|
||||||
random_featured_user.present?
|
random_featured_user.present?
|
||||||
end
|
end
|
||||||
|
|
@ -21,14 +23,18 @@ class Stream::Base
|
||||||
'change me in lib/base_stream.rb!'
|
'change me in lib/base_stream.rb!'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [Boolean]
|
||||||
def can_comment?(post)
|
def can_comment?(post)
|
||||||
true
|
return true if post.author.local?
|
||||||
|
post_is_from_contact?(post)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [String]
|
||||||
def title
|
def title
|
||||||
'a title'
|
'a title'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [ActiveRecord::Relation<Post>]
|
||||||
def posts
|
def posts
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
@ -39,23 +45,28 @@ class Stream::Base
|
||||||
Person.where(:id => people_ids).includes(:profile)
|
Person.where(:id => people_ids).includes(:profile)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [String]
|
||||||
def contacts_link_title
|
def contacts_link_title
|
||||||
I18n.translate('aspects.selected_contacts.view_all_contacts')
|
I18n.translate('aspects.selected_contacts.view_all_contacts')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [String]
|
||||||
def contacts_title
|
def contacts_title
|
||||||
'change me in lib/base_stream.rb!'
|
'change me in lib/base_stream.rb!'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [String]
|
||||||
def contacts_link
|
def contacts_link
|
||||||
'#'
|
'#'
|
||||||
end
|
end
|
||||||
|
|
||||||
#helpers
|
#helpers
|
||||||
|
# @return [Boolean]
|
||||||
def ajax_stream?
|
def ajax_stream?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [Boolean]
|
||||||
def for_all_aspects?
|
def for_all_aspects?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
@ -64,9 +75,10 @@ class Stream::Base
|
||||||
#NOTE: MBS bad bad methods the fact we need these means our views are foobared. please kill them and make them
|
#NOTE: MBS bad bad methods the fact we need these means our views are foobared. please kill them and make them
|
||||||
#private methods on the streams that need them
|
#private methods on the streams that need them
|
||||||
def aspects
|
def aspects
|
||||||
@user.aspects
|
user.aspects
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [Aspect] The first aspect in #aspects
|
||||||
def aspect
|
def aspect
|
||||||
aspects.first
|
aspects.first
|
||||||
end
|
end
|
||||||
|
|
@ -86,7 +98,24 @@ class Stream::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# Memoizes all Contacts present in the Stream
|
||||||
|
#
|
||||||
|
# @return [Array<Contact>]
|
||||||
|
def contacts_in_stream
|
||||||
|
@contacts_in_stream ||= Contact.where(:user_id => user.id, :person_id => people.map{|x| x.id}).all
|
||||||
|
end
|
||||||
|
|
||||||
def featured_diaspora_id
|
def featured_diaspora_id
|
||||||
@featured_diaspora_id ||= AppConfig[:featured_users].try(:sample, 1)
|
@featured_diaspora_id ||= AppConfig[:featured_users].try(:sample, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @param post [Post]
|
||||||
|
# @return [Boolean]
|
||||||
|
def post_is_from_contact?(post)
|
||||||
|
@can_comment_cache ||= {}
|
||||||
|
@can_comment_cache[post.id] ||= contacts_in_stream.find{|contact| contact.person_id == post.author.id}.present?
|
||||||
|
@can_comment_cache[post.id] ||= user.person.id == post.author.id
|
||||||
|
@can_comment_cache[post.id]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -22,16 +22,7 @@ class Stream::FollowedTag < Stream::Base
|
||||||
I18n.translate('streams.tags.contacts_title')
|
I18n.translate('streams.tags.contacts_title')
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_comment?(post)
|
|
||||||
@can_comment_cache ||= {}
|
|
||||||
@can_comment_cache[post.id] ||= contacts_in_stream.find{|contact| contact.person_id == post.author.id}.present?
|
|
||||||
@can_comment_cache[post.id] ||= user.person.id == post.author.id
|
|
||||||
@can_comment_cache[post.id]
|
|
||||||
end
|
|
||||||
|
|
||||||
def contacts_in_stream
|
|
||||||
@contacts_in_stream ||= Contact.where(:user_id => user.id, :person_id => people.map{|x| x.id}).all
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,40 @@ require 'spec_helper'
|
||||||
require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
|
require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
|
||||||
describe Stream::Base do
|
describe Stream::Base do
|
||||||
before do
|
before do
|
||||||
@stream = Stream::Base.new(stub)
|
@stream = Stream::Base.new(alice)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.can_comment?' do
|
||||||
|
before do
|
||||||
|
@person = Factory(:person)
|
||||||
|
@stream.stub(:people).and_return([bob.person, eve.person, @person])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns true if user is a contact of the post author' do
|
||||||
|
post = Factory(:status_message, :author => bob.person)
|
||||||
|
@stream.can_comment?(post).should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns true if a user is the author of the post' do
|
||||||
|
post = Factory(:status_message, :author => alice.person)
|
||||||
|
@stream.can_comment?(post).should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns true if the author of the post is local' do
|
||||||
|
post = Factory(:status_message, :author => eve.person)
|
||||||
|
@stream.can_comment?(post).should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns true if person is remote and is a contact' do
|
||||||
|
Contact.create!(:user => @stream.user, :person => @person)
|
||||||
|
post = Factory(:status_message, :author => @person)
|
||||||
|
@stream.can_comment?(post).should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false if person is remote and not a contact' do
|
||||||
|
post = Factory(:status_message, :author => @person)
|
||||||
|
@stream.can_comment?(post).should be_false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'shared behaviors' do
|
describe 'shared behaviors' do
|
||||||
|
|
|
||||||
|
|
@ -10,26 +10,4 @@ describe Stream::FollowedTag do
|
||||||
describe 'shared behaviors' do
|
describe 'shared behaviors' do
|
||||||
it_should_behave_like 'it is a stream'
|
it_should_behave_like 'it is a stream'
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.can_comment?' do
|
|
||||||
before do
|
|
||||||
@stream = Stream::FollowedTag.new(alice)
|
|
||||||
@stream.stub(:people).and_return([bob.person])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns true if user is a contact of the post author' do
|
|
||||||
post = Factory(:status_message, :author => bob.person)
|
|
||||||
@stream.can_comment?(post).should be_true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns true if a user is the author of the post' do
|
|
||||||
post = Factory(:status_message, :author => alice.person)
|
|
||||||
@stream.can_comment?(post).should be_true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns false otherwise' do
|
|
||||||
post = Factory(:status_message, :author => eve.person)
|
|
||||||
@stream.can_comment?(post).should be_false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,6 @@ describe 'Streams' do
|
||||||
@stream.order=nil
|
@stream.order=nil
|
||||||
@stream.order.should == 'created_at'
|
@stream.order.should == 'created_at'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should have can_comment?(post)' do
|
|
||||||
@stream.can_comment?(Factory(:status_message)).should_not be_nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue