Remove aspect_ids parameter from publisher

closes #7683
This commit is contained in:
Benjamin Neff 2017-12-25 00:13:24 +01:00
parent 70c659192f
commit e0eb76eb2a
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
10 changed files with 23 additions and 55 deletions

View file

@ -3,6 +3,7 @@
## Bug fixes ## Bug fixes
* Ignore invalid `diaspora://` links [#7652](https://github.com/diaspora/diaspora/pull/7652) * Ignore invalid `diaspora://` links [#7652](https://github.com/diaspora/diaspora/pull/7652)
* Fix deformed avatar in hovercards [#7656](https://github.com/diaspora/diaspora/pull/7656) * Fix deformed avatar in hovercards [#7656](https://github.com/diaspora/diaspora/pull/7656)
* Fix default aspects on profile page and bookmarklet publisher [#7679](https://github.com/diaspora/diaspora/issues/7679)
## Features ## Features
* Add birthday notifications [#7624](https://github.com/diaspora/diaspora/pull/7624) * Add birthday notifications [#7624](https://github.com/diaspora/diaspora/pull/7624)

View file

@ -20,8 +20,6 @@ class StatusMessagesController < ApplicationController
@contact = current_user.contact_for(@person) @contact = current_user.contact_for(@person)
if @contact if @contact
@aspects_with_person = @contact.aspects.load @aspects_with_person = @contact.aspects.load
@aspect_ids = @aspects_with_person.map(&:id)
gon.aspect_ids = @aspect_ids
render layout: nil render layout: nil
else else
@aspects_with_person = [] @aspects_with_person = []
@ -29,8 +27,6 @@ class StatusMessagesController < ApplicationController
elsif request.format == :mobile elsif request.format == :mobile
@aspect = :all @aspect = :all
@aspects = current_user.aspects.load @aspects = current_user.aspects.load
@aspect_ids = @aspects.map(&:id)
gon.aspect_ids = @aspect_ids
else else
redirect_to stream_path redirect_to stream_path
end end
@ -38,7 +34,6 @@ class StatusMessagesController < ApplicationController
def bookmarklet def bookmarklet
@aspects = current_user.aspects @aspects = current_user.aspects
@aspect_ids = current_user.aspect_ids
gon.preloads[:bookmarklet] = { gon.preloads[:bookmarklet] = {
content: params[:content], content: params[:content],

View file

@ -17,14 +17,12 @@ module AspectGlobalHelper
if stream if stream
aspects = stream.aspects aspects = stream.aspects
aspect = stream.aspect aspect = stream.aspect
aspect_ids = stream.aspect_ids
elsif current_user elsif current_user
aspects = current_user.post_default_aspects aspects = current_user.post_default_aspects
aspect = aspects.first aspect = aspects.first
aspect_ids = current_user.aspect_ids
else else
return {} return {}
end end
{selected_aspects: aspects, aspect: aspect, aspect_ids: aspect_ids} {selected_aspects: aspects, aspect: aspect}
end end
end end

View file

@ -62,6 +62,4 @@
data: {toggle: "modal", target: "#publicExplainModal"}} data: {toggle: "modal", target: "#publicExplainModal"}}
%i.entypo-cog %i.entypo-cog
= link_to "", contacts_path(aspect_ids: aspect_ids), class: "selected_contacts_link hidden"
= render "shared/public_explain" = render "shared/public_explain"

View file

@ -2,6 +2,6 @@
-# licensed under the Affero General Public License version 3 or later. See -# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file. -# the COPYRIGHT file.
= render :partial => 'publisher/publisher', :locals => { :aspect => :profile, :selected_aspects => @aspects, :aspect_ids => @aspect_ids } = render partial: "publisher/publisher", locals: {aspect: :profile, selected_aspects: @aspects}
= javascript_include_tag "mobile/bookmarklet" = javascript_include_tag "mobile/bookmarklet"

View file

@ -1,6 +1,2 @@
= render :partial => 'publisher/publisher', = render partial: "publisher/publisher",
:locals => { :aspect => @aspect, locals: {aspect: @aspect, selected_aspects: @aspects_with_person, person: @person}
:aspect_ids => @aspect_ids,
:selected_aspects => @aspects_with_person,
:person => @person }

View file

@ -2,4 +2,4 @@
-# licensed under the Affero General Public License version 3 or later. See -# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file. -# the COPYRIGHT file.
= render :partial => 'publisher/publisher', :locals => {:aspect => @aspects.first, :aspect_ids => @aspect_ids, :selected_aspects => @aspects} = render partial: "publisher/publisher", locals: {aspect: @aspects.first, selected_aspects: @aspects}

View file

@ -30,13 +30,6 @@ class Stream::Aspect < Stream::Base
end.call end.call
end end
# Maps ids into an array from #aspects
#
# @return [Array<Integer>] Aspect ids
def aspect_ids
@aspect_ids ||= aspects.map { |a| a.id }
end
# @return [ActiveRecord::Association<Post>] AR association of posts # @return [ActiveRecord::Association<Post>] AR association of posts
def posts def posts
# NOTE(this should be something like Post.all_for_stream(@user, aspect_ids, {}) that calls visible_shareables # NOTE(this should be something like Post.all_for_stream(@user, aspect_ids, {}) that calls visible_shareables
@ -84,7 +77,7 @@ class Stream::Aspect < Stream::Base
# #
# @return [Boolean] # @return [Boolean]
def for_all_aspects? def for_all_aspects?
@all_aspects ||= aspect_ids.length == user.aspects.size @all_aspects ||= aspects.size == user.aspects.size
end end
# This is perfomance optimization, as everyone in your aspect stream you have # This is perfomance optimization, as everyone in your aspect stream you have
@ -95,4 +88,10 @@ class Stream::Aspect < Stream::Base
def can_comment?(post) def can_comment?(post)
true true
end end
private
def aspect_ids
@aspect_ids ||= aspects.map(&:id)
end
end end

View file

@ -67,10 +67,6 @@ class Stream::Base
aspects.first aspects.first
end end
def aspect_ids
aspects.map {|x| x.try(:id) }
end
def max_time=(time_string) def max_time=(time_string)
@max_time = Time.at(time_string.to_i) unless time_string.blank? @max_time = Time.at(time_string.to_i) unless time_string.blank?
@max_time ||= (Time.now + 1) @max_time ||= (Time.now + 1)

View file

@ -31,19 +31,6 @@ describe Stream::Aspect do
end end
end end
describe '#aspect_ids' do
it 'maps ids from aspects' do
alice = double.as_null_object
aspects = double.as_null_object
stream = Stream::Aspect.new(alice, [1,2])
expect(stream).to receive(:aspects).and_return(aspects)
expect(aspects).to receive(:map)
stream.aspect_ids
end
end
describe '#posts' do describe '#posts' do
before do before do
@alice = double.as_null_object @alice = double.as_null_object
@ -83,16 +70,14 @@ describe Stream::Aspect do
end end
end end
describe '#people' do describe "#people" do
it 'should call Person.all_from_aspects' do it "should call Person.all_from_aspects" do
class Person ; end
alice = double.as_null_object alice = double.as_null_object
aspect_ids = [1, 2, 3] aspect_ids = [1, 2, 3]
stream = Stream::Aspect.new(alice, []) stream = Stream::Aspect.new(alice, [])
allow(stream).to receive(:aspect_ids).and_return(aspect_ids) allow(stream).to receive(:aspect_ids).and_return(aspect_ids)
expect(Person).to receive(:unique_from_aspects).with(stream.aspect_ids, alice).and_return(double(:includes => :profile)) expect(Person).to receive(:unique_from_aspects).with(aspect_ids, alice).and_return(double(includes: :profile))
stream.people stream.people
end end
end end
@ -114,20 +99,20 @@ describe Stream::Aspect do
end end
end end
describe 'for_all_aspects?' do describe "for_all_aspects?" do
before do before do
alice = double.as_null_object alice = double.as_null_object
allow(alice.aspects).to receive(:size).and_return(2) allow(alice.aspects).to receive(:size).and_return(2)
@stream = Stream::Aspect.new(alice, [1, 2]) @stream = Stream::Aspect.new(alice, [1, 2])
end end
it "is true if the count of aspect_ids is equal to the size of the user's aspect count" do it "is true if the count of aspects is equal to the size of the user's aspect count" do
allow(@stream.aspect_ids).to receive(:length).and_return(2) allow(@stream).to receive(:aspects).and_return(double(size: 2))
expect(@stream).to be_for_all_aspects expect(@stream).to be_for_all_aspects
end end
it "is false if the count of aspect_ids is not equal to the size of the user's aspect count" do it "is false if the count of aspects is not equal to the size of the user's aspect count" do
allow(@stream.aspect_ids).to receive(:length).and_return(1) allow(@stream).to receive(:aspects).and_return(double(size: 1))
expect(@stream).not_to be_for_all_aspects expect(@stream).not_to be_for_all_aspects
end end
end end