Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/assets/javascripts/app/router.js1
-rw-r--r--app/controllers/streams_controller.rb4
-rw-r--r--app/helpers/stream_helper.rb5
-rw-r--r--app/models/post.rb6
-rw-r--r--app/views/streams/main_stream.html.haml2
-rw-r--r--config/locales/diaspora/de.yml2
-rw-r--r--config/locales/diaspora/en.yml3
-rw-r--r--config/routes.rb1
-rw-r--r--lib/stream.rb21
-rw-r--r--lib/stream/local_public.rb29
-rw-r--r--spec/helpers/stream_helper_spec.rb7
-rw-r--r--spec/lib/stream/local_public_spec.rb20
-rw-r--r--spec/models/post_spec.rb21
13 files changed, 109 insertions, 13 deletions
diff --git a/app/assets/javascripts/app/router.js b/app/assets/javascripts/app/router.js
index 265b3cd48..f7bd8a440 100644
--- a/app/assets/javascripts/app/router.js
+++ b/app/assets/javascripts/app/router.js
@@ -24,6 +24,7 @@ app.Router = Backbone.Router.extend({
"posts/:id(/)": "singlePost",
"profile/edit(/)": "settings",
"public(/)": "stream",
+ "local_public(/)": "stream",
"stream(/)": "stream",
"tags/:name(/)": "followed_tags",
"u/:name(/)": "profile",
diff --git a/app/controllers/streams_controller.rb b/app/controllers/streams_controller.rb
index 0d0947616..57133e5c8 100644
--- a/app/controllers/streams_controller.rb
+++ b/app/controllers/streams_controller.rb
@@ -25,6 +25,10 @@ class StreamsController < ApplicationController
stream_responder(Stream::Public)
end
+ def local_public
+ stream_responder(Stream::LocalPublic)
+ end
+
def activity
stream_responder(Stream::Activity)
end
diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb
index cada31f8b..503580dd6 100644
--- a/app/helpers/stream_helper.rb
+++ b/app/helpers/stream_helper.rb
@@ -22,7 +22,7 @@ module StreamHelper
end
private
-
+ # rubocop:disable Rails/HelperInstanceVariable
def next_stream_path
if current_page?(:stream)
stream_path(max_time: time_for_scroll(@stream))
@@ -30,6 +30,8 @@ module StreamHelper
activity_stream_path(max_time: time_for_scroll(@stream))
elsif current_page?(:aspects_stream)
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)
public_stream_path(max_time: time_for_scroll(@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"
end
end
+ # rubocop:enable Rails/HelperInstanceVariable
def time_for_scroll(stream)
if stream.stream_posts.empty?
diff --git a/app/models/post.rb b/app/models/post.rb
index 76f829f23..1905854fa 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -51,6 +51,12 @@ class Post < ApplicationRecord
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) {
select('DISTINCT posts.*')
.joins(:comments)
diff --git a/app/views/streams/main_stream.html.haml b/app/views/streams/main_stream.html.haml
index 56be82d92..11663651a 100644
--- a/app/views/streams/main_stream.html.haml
+++ b/app/views/streams/main_stream.html.haml
@@ -37,6 +37,8 @@
= render "aspects/aspect_listings", stream: @stream
%li.nested-list
= 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"}}
= link_to t("streams.public.title"), public_stream_path, rel: "backbone", class: "hoverable"
diff --git a/config/locales/diaspora/de.yml b/config/locales/diaspora/de.yml
index 745af609a..38a92f6fa 100644
--- a/config/locales/diaspora/de.yml
+++ b/config/locales/diaspora/de.yml
@@ -1245,6 +1245,8 @@ de:
title: "Stream"
public:
title: "Öffentliche Aktivität"
+ local_public:
+ title: "Lokale Posts"
tags:
title: "Getaggte Beiträge: %{tags}"
tag_followings:
diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml
index 12379c1b6..2e8a21915 100644
--- a/config/locales/diaspora/en.yml
+++ b/config/locales/diaspora/en.yml
@@ -1249,6 +1249,9 @@ en:
public:
title: "Public activity"
+ local_public:
+ title: "Local posts"
+
multi:
title: "Stream"
diff --git a/config/routes.rb b/config/routes.rb
index 9a5782a41..e776cbb04 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -52,6 +52,7 @@ Rails.application.routes.draw do
get "activity" => "streams#activity", :as => "activity_stream"
get "stream" => "streams#multi", :as => "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 "mentions" => "streams#mentioned", :as => "mentioned_stream"
get "liked" => "streams#liked", :as => "liked_stream"
diff --git a/lib/stream.rb b/lib/stream.rb
index 27cb67e25..51c7512e6 100644
--- a/lib/stream.rb
+++ b/lib/stream.rb
@@ -1,14 +1,15 @@
# frozen_string_literal: true
module Stream
- require 'stream/activity'
- require 'stream/aspect'
- require 'stream/comments'
- require 'stream/followed_tag'
- require 'stream/likes'
- require 'stream/mention'
- require 'stream/multi'
- require 'stream/person'
- require 'stream/public'
- require 'stream/tag'
+ require "stream/activity"
+ require "stream/aspect"
+ require "stream/comments"
+ require "stream/followed_tag"
+ require "stream/likes"
+ require "stream/mention"
+ require "stream/multi"
+ require "stream/person"
+ require "stream/public"
+ require "stream/local_public"
+ require "stream/tag"
end
diff --git a/lib/stream/local_public.rb b/lib/stream/local_public.rb
new file mode 100644
index 000000000..be729c4ff
--- /dev/null
+++ b/lib/stream/local_public.rb
@@ -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
diff --git a/spec/helpers/stream_helper_spec.rb b/spec/helpers/stream_helper_spec.rb
index dac0196cb..979bc609d 100644
--- a/spec/helpers/stream_helper_spec.rb
+++ b/spec/helpers/stream_helper_spec.rb
@@ -20,6 +20,13 @@ describe StreamHelper, type: :helper do
expect(helper.next_page_path).to include "/public"
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
allow(helper).to receive(:current_page?).and_return(false)
expect(helper).to receive(:current_page?).with(:stream).and_return(true)
diff --git a/spec/lib/stream/local_public_spec.rb b/spec/lib/stream/local_public_spec.rb
new file mode 100644
index 000000000..431e0a134
--- /dev/null
+++ b/spec/lib/stream/local_public_spec.rb
@@ -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
diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb
index 3e77e142f..36440e650 100644
--- a/spec/models/post_spec.rb
+++ b/spec/models/post_spec.rb
@@ -58,8 +58,25 @@ describe Post, type: :model do
end
end
- describe ".for_a_stream" do
- it "calls #for_visible_shareable_sql" do
+ describe ".all_local_public" 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
order = double
expect(Post).to receive(:for_visible_shareable_sql).with(time, order).and_return(Post)