Merge pull request #8390 from cmrd-senya/improve-public-fetch
Improve public posts fetch on account search
This commit is contained in:
commit
7c450b4446
3 changed files with 59 additions and 51 deletions
|
|
@ -51,6 +51,7 @@ We use yarn to install the frontend dependencies now, so you need to have that i
|
|||
* Fix multiple photos upload progress bar [#7655](https://github.com/diaspora/diaspora/pull/7655)
|
||||
* Photo-upload file picker now correctly restricts possible file types [#8205](https://github.com/diaspora/diaspora/pull/8205)
|
||||
* Make inline code inside links show the link color [#8387](https://github.com/diaspora/diaspora/pull/8387)
|
||||
* Fix fetching public posts on first account search was missing some data [#8390](https://github.com/diaspora/diaspora/pull/8390)
|
||||
|
||||
## Features
|
||||
* Add client-side cropping of profile image uploads [#7581](https://github.com/diaspora/diaspora/pull/7581)
|
||||
|
|
|
|||
|
|
@ -104,16 +104,13 @@ module Diaspora; module Fetcher; class Public
|
|||
|
||||
logger.debug "post: #{post.to_s[0..250]}"
|
||||
|
||||
entry = StatusMessage.diaspora_initialize(
|
||||
author: @person,
|
||||
public: true,
|
||||
guid: post["guid"],
|
||||
text: post["text"],
|
||||
provider_display_name: post["provider_display_name"],
|
||||
created_at: ActiveSupport::TimeZone.new("UTC").parse(post["created_at"]).to_datetime,
|
||||
DiasporaFederation::Federation::Fetcher.fetch_public(
|
||||
@person.diaspora_handle,
|
||||
:post,
|
||||
post["guid"]
|
||||
)
|
||||
entry.save
|
||||
|
||||
rescue DiasporaFederation::Federation::Fetcher::NotFetchable => e
|
||||
logger.warn e.message
|
||||
end
|
||||
set_fetch_status Public::Status_Processed
|
||||
end
|
||||
|
|
@ -131,9 +128,8 @@ module Diaspora; module Fetcher; class Public
|
|||
# @see check_existing
|
||||
# @see check_author
|
||||
# @see check_public
|
||||
# @see check_type
|
||||
def validate post
|
||||
check_existing(post) && check_author(post) && check_public(post) && check_type(post)
|
||||
check_existing(post) && check_author(post) && check_public(post)
|
||||
end
|
||||
|
||||
# hopefully there is no post with the same guid somewhere already...
|
||||
|
|
@ -166,13 +162,4 @@ module Diaspora; module Fetcher; class Public
|
|||
|
||||
ispublic
|
||||
end
|
||||
|
||||
# see, if the type of the given post is something we can handle
|
||||
def check_type post
|
||||
type_ok = (post['post_type'] == "StatusMessage")
|
||||
|
||||
logger.warn "the post (#{post['guid']}) has a type, which cannot be handled (#{post['post_type']})" unless type_ok
|
||||
|
||||
type_ok
|
||||
end
|
||||
end; end; end
|
||||
|
|
|
|||
|
|
@ -4,13 +4,21 @@
|
|||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require "integration/federation/federation_helper"
|
||||
|
||||
# Tests fetching public posts of a person on a remote server
|
||||
describe Diaspora::Fetcher::Public do
|
||||
let(:fixture) do
|
||||
File.read(Rails.root.join("spec/fixtures/public_posts.json"))
|
||||
end
|
||||
let(:fixture_data) do
|
||||
JSON.parse(fixture)
|
||||
end
|
||||
|
||||
before do
|
||||
# the fixture is taken from an actual json request.
|
||||
# it contains 10 StatusMessages and 5 Reshares, all of them public
|
||||
# the guid of the person is "7445f9a0a6c28ebb"
|
||||
@fixture = File.read(Rails.root.join("spec/fixtures/public_posts.json"))
|
||||
@fetcher = Diaspora::Fetcher::Public.new
|
||||
@person = FactoryBot.create(:person, guid: "7445f9a0a6c28ebb",
|
||||
pod: Pod.find_or_create_by(url: "https://remote-testpod.net"),
|
||||
|
|
@ -21,7 +29,7 @@ describe Diaspora::Fetcher::Public do
|
|||
"Accept" => "application/json",
|
||||
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
|
||||
"User-Agent" => "diaspora-fetcher"
|
||||
}).to_return(body: @fixture)
|
||||
}).to_return(body: fixture)
|
||||
end
|
||||
|
||||
describe "#queue_for" do
|
||||
|
|
@ -62,28 +70,54 @@ describe Diaspora::Fetcher::Public do
|
|||
@data
|
||||
}
|
||||
expect(data).not_to be_nil
|
||||
expect(data.size).to eql JSON.parse(@fixture).size
|
||||
expect(data.size).to eq(fixture_data.size)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#process_posts" do
|
||||
before do
|
||||
person = @person
|
||||
data = JSON.parse(@fixture)
|
||||
data = fixture_data
|
||||
|
||||
@fetcher.instance_eval {
|
||||
@person = person
|
||||
@data = data
|
||||
}
|
||||
|
||||
fixture_data.each do |post_data|
|
||||
post = if post_data["post_type"] == "StatusMessage"
|
||||
FactoryBot.build(
|
||||
:status_message,
|
||||
guid: post_data["guid"],
|
||||
text: post_data["text"],
|
||||
created_at: post_data["created_at"],
|
||||
public: true,
|
||||
author: eve.person
|
||||
)
|
||||
else
|
||||
reshare = FactoryBot.build(
|
||||
:reshare,
|
||||
guid: post_data["guid"],
|
||||
created_at: post_data["created_at"],
|
||||
public: true,
|
||||
author: eve.person
|
||||
)
|
||||
reshare.root.save
|
||||
reshare
|
||||
end
|
||||
payload = generate_payload(Diaspora::Federation::Entities.post(post), eve)
|
||||
|
||||
stub_request(:get, "https://remote-testpod.net/fetch/post/#{post_data['guid']}")
|
||||
.to_return(status: 200, body: payload)
|
||||
end
|
||||
end
|
||||
|
||||
it "creates 10 new posts in the database" do
|
||||
before_count = Post.count
|
||||
@fetcher.instance_eval {
|
||||
process_posts
|
||||
}
|
||||
after_count = Post.count
|
||||
expect(after_count).to eql(before_count + 10)
|
||||
it "creates 15 new posts in the database" do
|
||||
expect {
|
||||
@fetcher.instance_eval {
|
||||
process_posts
|
||||
}
|
||||
}.to change(Post, :count).by(15)
|
||||
end
|
||||
|
||||
it "sets the operation status on the person" do
|
||||
|
|
@ -100,7 +134,6 @@ describe Diaspora::Fetcher::Public do
|
|||
before do
|
||||
Timecop.freeze
|
||||
@now = DateTime.now.utc
|
||||
@data = JSON.parse(@fixture).select {|item| item["post_type"] == "StatusMessage" }
|
||||
|
||||
# save posts to db
|
||||
@fetcher.instance_eval {
|
||||
|
|
@ -113,26 +146,26 @@ describe Diaspora::Fetcher::Public do
|
|||
end
|
||||
|
||||
it "applies the date from JSON to the record" do
|
||||
@data.each do |post|
|
||||
fixture_data.each do |post|
|
||||
date = ActiveSupport::TimeZone.new("UTC").parse(post["created_at"]).to_i
|
||||
|
||||
entry = StatusMessage.find_by(guid: post["guid"])
|
||||
entry = Post.find_by(guid: post["guid"])
|
||||
expect(entry.created_at.to_i).to eql(date)
|
||||
end
|
||||
end
|
||||
|
||||
it "copied the text correctly" do
|
||||
@data.each do |post|
|
||||
it "copied the text of status messages correctly" do
|
||||
fixture_data.select {|item| item["post_type"] == "StatusMessage" }.each do |post|
|
||||
entry = StatusMessage.find_by(guid: post["guid"])
|
||||
expect(entry.text).to eql(post["text"])
|
||||
end
|
||||
end
|
||||
|
||||
it "applies now to interacted_at on the record" do
|
||||
@data.each do |post|
|
||||
fixture_data.each do |post|
|
||||
date = @now.to_i
|
||||
|
||||
entry = StatusMessage.find_by(guid: post["guid"])
|
||||
entry = Post.find_by(guid: post["guid"])
|
||||
expect(entry.interacted_at.to_i).to eql(date)
|
||||
end
|
||||
end
|
||||
|
|
@ -208,7 +241,6 @@ describe Diaspora::Fetcher::Public do
|
|||
expect(public_fetcher).to receive(:check_existing).and_return(true)
|
||||
expect(public_fetcher).to receive(:check_author).and_return(true)
|
||||
expect(public_fetcher).to receive(:check_public).and_return(true)
|
||||
expect(public_fetcher).to receive(:check_type).and_return(true)
|
||||
|
||||
expect(public_fetcher.instance_eval { validate({}) }).to be true
|
||||
end
|
||||
|
|
@ -256,17 +288,5 @@ describe Diaspora::Fetcher::Public do
|
|||
expect(public_fetcher.instance_eval { check_public post }).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe "#check_type" do
|
||||
it "returns false if the type is anything other that 'StatusMessage'" do
|
||||
post = {"post_type"=>"Reshare"}
|
||||
expect(public_fetcher.instance_eval { check_type post }).to be false
|
||||
end
|
||||
|
||||
it "returns true if the type is 'StatusMessage'" do
|
||||
post = {"post_type"=>"StatusMessage"}
|
||||
expect(public_fetcher.instance_eval { check_type post }).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue