Adds a local-public tag on the sidebar that shows all posts local to this pod
This commit is contained in:
parent
e8442021b6
commit
ddee980426
13 changed files with 109 additions and 13 deletions
|
|
@ -24,6 +24,7 @@ app.Router = Backbone.Router.extend({
|
||||||
"posts/:id(/)": "singlePost",
|
"posts/:id(/)": "singlePost",
|
||||||
"profile/edit(/)": "settings",
|
"profile/edit(/)": "settings",
|
||||||
"public(/)": "stream",
|
"public(/)": "stream",
|
||||||
|
"local_public(/)": "stream",
|
||||||
"stream(/)": "stream",
|
"stream(/)": "stream",
|
||||||
"tags/:name(/)": "followed_tags",
|
"tags/:name(/)": "followed_tags",
|
||||||
"u/:name(/)": "profile",
|
"u/:name(/)": "profile",
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,10 @@ class StreamsController < ApplicationController
|
||||||
stream_responder(Stream::Public)
|
stream_responder(Stream::Public)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def local_public
|
||||||
|
stream_responder(Stream::LocalPublic)
|
||||||
|
end
|
||||||
|
|
||||||
def activity
|
def activity
|
||||||
stream_responder(Stream::Activity)
|
stream_responder(Stream::Activity)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ module StreamHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
# rubocop:disable Rails/HelperInstanceVariable
|
||||||
def next_stream_path
|
def next_stream_path
|
||||||
if current_page?(:stream)
|
if current_page?(:stream)
|
||||||
stream_path(max_time: time_for_scroll(@stream))
|
stream_path(max_time: time_for_scroll(@stream))
|
||||||
|
|
@ -30,6 +30,8 @@ module StreamHelper
|
||||||
activity_stream_path(max_time: time_for_scroll(@stream))
|
activity_stream_path(max_time: time_for_scroll(@stream))
|
||||||
elsif current_page?(:aspects_stream)
|
elsif current_page?(:aspects_stream)
|
||||||
aspects_stream_path(max_time: time_for_scroll(@stream), a_ids: session[:a_ids])
|
aspects_stream_path(max_time: time_for_scroll(@stream), a_ids: session[:a_ids])
|
||||||
|
elsif current_page?(:local_public_stream)
|
||||||
|
local_public_stream_path(max_time: time_for_scroll(@stream))
|
||||||
elsif current_page?(:public_stream)
|
elsif current_page?(:public_stream)
|
||||||
public_stream_path(max_time: time_for_scroll(@stream))
|
public_stream_path(max_time: time_for_scroll(@stream))
|
||||||
elsif current_page?(:commented_stream)
|
elsif current_page?(:commented_stream)
|
||||||
|
|
@ -44,6 +46,7 @@ module StreamHelper
|
||||||
raise "in order to use pagination for this new stream, update next_stream_path in stream helper"
|
raise "in order to use pagination for this new stream, update next_stream_path in stream helper"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Rails/HelperInstanceVariable
|
||||||
|
|
||||||
def time_for_scroll(stream)
|
def time_for_scroll(stream)
|
||||||
if stream.stream_posts.empty?
|
if stream.stream_posts.empty?
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,12 @@ class Post < ApplicationRecord
|
||||||
|
|
||||||
scope :all_public, -> { where(public: true) }
|
scope :all_public, -> { where(public: true) }
|
||||||
|
|
||||||
|
scope :all_local_public, -> {
|
||||||
|
left_outer_joins(author: [:pod])
|
||||||
|
.where("pods.host is null") # local posts have no host in pods
|
||||||
|
.where(public: true)
|
||||||
|
}
|
||||||
|
|
||||||
scope :commented_by, ->(person) {
|
scope :commented_by, ->(person) {
|
||||||
select('DISTINCT posts.*')
|
select('DISTINCT posts.*')
|
||||||
.joins(:comments)
|
.joins(:comments)
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@
|
||||||
= render "aspects/aspect_listings", stream: @stream
|
= render "aspects/aspect_listings", stream: @stream
|
||||||
%li.nested-list
|
%li.nested-list
|
||||||
= render "tags/followed_tags_listings"
|
= render "tags/followed_tags_listings"
|
||||||
|
%li{data: {stream: "local_public"}}
|
||||||
|
= link_to t("streams.local_public.title"), local_public_stream_path, rel: "backbone", class: "hoverable"
|
||||||
%li{data: {stream: "public"}}
|
%li{data: {stream: "public"}}
|
||||||
= link_to t("streams.public.title"), public_stream_path, rel: "backbone", class: "hoverable"
|
= link_to t("streams.public.title"), public_stream_path, rel: "backbone", class: "hoverable"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1245,6 +1245,8 @@ de:
|
||||||
title: "Stream"
|
title: "Stream"
|
||||||
public:
|
public:
|
||||||
title: "Öffentliche Aktivität"
|
title: "Öffentliche Aktivität"
|
||||||
|
local_public:
|
||||||
|
title: "Lokale Posts"
|
||||||
tags:
|
tags:
|
||||||
title: "Getaggte Beiträge: %{tags}"
|
title: "Getaggte Beiträge: %{tags}"
|
||||||
tag_followings:
|
tag_followings:
|
||||||
|
|
|
||||||
|
|
@ -1249,6 +1249,9 @@ en:
|
||||||
public:
|
public:
|
||||||
title: "Public activity"
|
title: "Public activity"
|
||||||
|
|
||||||
|
local_public:
|
||||||
|
title: "Local posts"
|
||||||
|
|
||||||
multi:
|
multi:
|
||||||
title: "Stream"
|
title: "Stream"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ Rails.application.routes.draw do
|
||||||
get "activity" => "streams#activity", :as => "activity_stream"
|
get "activity" => "streams#activity", :as => "activity_stream"
|
||||||
get "stream" => "streams#multi", :as => "stream"
|
get "stream" => "streams#multi", :as => "stream"
|
||||||
get "public" => "streams#public", :as => "public_stream"
|
get "public" => "streams#public", :as => "public_stream"
|
||||||
|
get "local_public" => "streams#local_public", :as => "local_public_stream"
|
||||||
get "followed_tags" => "streams#followed_tags", :as => "followed_tags_stream"
|
get "followed_tags" => "streams#followed_tags", :as => "followed_tags_stream"
|
||||||
get "mentions" => "streams#mentioned", :as => "mentioned_stream"
|
get "mentions" => "streams#mentioned", :as => "mentioned_stream"
|
||||||
get "liked" => "streams#liked", :as => "liked_stream"
|
get "liked" => "streams#liked", :as => "liked_stream"
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Stream
|
module Stream
|
||||||
require 'stream/activity'
|
require "stream/activity"
|
||||||
require 'stream/aspect'
|
require "stream/aspect"
|
||||||
require 'stream/comments'
|
require "stream/comments"
|
||||||
require 'stream/followed_tag'
|
require "stream/followed_tag"
|
||||||
require 'stream/likes'
|
require "stream/likes"
|
||||||
require 'stream/mention'
|
require "stream/mention"
|
||||||
require 'stream/multi'
|
require "stream/multi"
|
||||||
require 'stream/person'
|
require "stream/person"
|
||||||
require 'stream/public'
|
require "stream/public"
|
||||||
require 'stream/tag'
|
require "stream/local_public"
|
||||||
|
require "stream/tag"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
29
lib/stream/local_public.rb
Normal file
29
lib/stream/local_public.rb
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
class Stream::LocalPublic < Stream::Base
|
||||||
|
def link(opts={})
|
||||||
|
Rails.application.routes.url_helpers.local_public_stream_path(opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
def title
|
||||||
|
I18n.translate("streams.local_public.title")
|
||||||
|
end
|
||||||
|
|
||||||
|
# @return [ActiveRecord::Association<Post>] AR association of posts
|
||||||
|
def posts
|
||||||
|
@posts ||= Post.all_local_public
|
||||||
|
end
|
||||||
|
|
||||||
|
def can_comment?(post)
|
||||||
|
post.author.local?
|
||||||
|
end
|
||||||
|
|
||||||
|
# Override base class method
|
||||||
|
def aspects
|
||||||
|
["public"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -20,6 +20,13 @@ describe StreamHelper, type: :helper do
|
||||||
expect(helper.next_page_path).to include "/public"
|
expect(helper.next_page_path).to include "/public"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "works for local-public page when current page is local-public stream" do
|
||||||
|
allow(helper).to receive(:current_page?).and_return(false)
|
||||||
|
expect(helper).to receive(:current_page?).with(:local_public_stream).and_return(true)
|
||||||
|
allow(helper).to receive(:controller).and_return(build_controller(StreamsController))
|
||||||
|
expect(helper.next_page_path).to include "/local-public"
|
||||||
|
end
|
||||||
|
|
||||||
it "works for stream page when current page is stream" do
|
it "works for stream page when current page is stream" do
|
||||||
allow(helper).to receive(:current_page?).and_return(false)
|
allow(helper).to receive(:current_page?).and_return(false)
|
||||||
expect(helper).to receive(:current_page?).with(:stream).and_return(true)
|
expect(helper).to receive(:current_page?).with(:stream).and_return(true)
|
||||||
|
|
|
||||||
20
spec/lib/stream/local_public_spec.rb
Normal file
20
spec/lib/stream/local_public_spec.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require Rails.root.join('spec', 'shared_behaviors', 'stream')
|
||||||
|
|
||||||
|
describe Stream::LocalPublic do
|
||||||
|
before do
|
||||||
|
@stream = Stream::LocalPublic.new(alice)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'shared behaviors' do
|
||||||
|
it_should_behave_like 'it is a stream'
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#posts" do
|
||||||
|
it "calls Post#all_local_public" do
|
||||||
|
expect(Post).to receive(:all_local_public)
|
||||||
|
@stream.posts
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -58,8 +58,25 @@ describe Post, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".for_a_stream" do
|
describe ".all_local_public" do
|
||||||
it "calls #for_visible_shareable_sql" do
|
it "includes all public posts from local" do
|
||||||
|
post1 = FactoryBot.create(:status_message, author: alice.person, public: true)
|
||||||
|
post2 = FactoryBot.create(:status_message, author: bob.person, public: true)
|
||||||
|
expect(Post.all_local_public.ids).to match_array([post1.id, post2.id])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't include any posts from other pods" do
|
||||||
|
pod = FactoryBot.create(:pod)
|
||||||
|
external_person = FactoryBot.create(:person, pod: pod)
|
||||||
|
FactoryBot.create(:status_message, author: alice.person, public: true)
|
||||||
|
FactoryBot.create(:status_message, author: bob.person, public: true)
|
||||||
|
post_from_extern = FactoryBot.create(:status_message, author: external_person, public: true)
|
||||||
|
expect(Post.all_local_public.ids).not_to match_array([post_from_extern.id])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.for_a_stream' do
|
||||||
|
it 'calls #for_visible_shareable_sql' do
|
||||||
time = double
|
time = double
|
||||||
order = double
|
order = double
|
||||||
expect(Post).to receive(:for_visible_shareable_sql).with(time, order).and_return(Post)
|
expect(Post).to receive(:for_visible_shareable_sql).with(time, order).and_return(Post)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue