Skip to content

Commit ae3b780

Browse files
committed
Merge pull request #8441 from SuperTux88/fix-fetch-comments
Allow fetching comments
2 parents 7cc48be + 9e61693 commit ae3b780

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ We recommend setting up new pods using Ruby 3.1, and updating existing pods to t
8383
* Add a more detailed modal when reporting a post or a comment [#8035](https://github.com/diaspora/diaspora/pull/8035)
8484
* Re-introduce likes on comments [#8203](https://github.com/diaspora/diaspora/pull/8203)
8585
* New redesigned registration page [#8285](https://github.com/diaspora/diaspora/pull/8285)
86+
* Allow comments to be fetched [#8441](https://github.com/diaspora/diaspora/pull/8441)
8687

8788
# 0.7.18.2
8889

app/models/comment.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ class Comment < ApplicationRecord
3737
scope :including_author, -> { includes(:author => :profile) }
3838
scope :for_a_stream, -> { including_author.merge(order('created_at ASC')) }
3939

40+
scope :all_public, -> {
41+
where("commentable_type = 'Post' AND EXISTS(
42+
SELECT 1 FROM posts WHERE posts.id = commentable_id AND posts.public = true
43+
)")
44+
}
45+
4046
before_save do
4147
self.text.strip! unless self.text.nil?
4248
end

config/initializers/diaspora_federation.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@
120120
on :fetch_public_entity do |entity_type, guid|
121121
entity = Diaspora::Federation::Mappings.model_class_for(entity_type).all_public.find_by(guid: guid)
122122
case entity
123-
when Post
124-
Diaspora::Federation::Entities.post(entity)
125123
when Poll
126124
Diaspora::Federation::Entities.status_message(entity.status_message)
125+
else
126+
Diaspora::Federation::Entities.build(entity) if entity
127127
end
128128
end
129129

spec/federation_callbacks_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,33 @@
465465
DiasporaFederation.callbacks.trigger(:fetch_public_entity, "Post", "unknown-guid")
466466
).to be_nil
467467
end
468+
469+
context "comment" do
470+
it "fetches a Comment" do
471+
post = FactoryBot.create(:status_message, author: alice.person, public: true)
472+
comment = FactoryBot.create(:comment, author: alice.person, commentable: post)
473+
entity = DiasporaFederation.callbacks.trigger(:fetch_public_entity, "Comment", comment.guid)
474+
475+
expect(entity.guid).to eq(comment.guid)
476+
expect(entity.author).to eq(alice.diaspora_handle)
477+
expect(entity.parent.public).to be_truthy
478+
end
479+
480+
it "does not fetch a Comment from a private post" do
481+
post = FactoryBot.create(:status_message, author: alice.person, public: false)
482+
comment = FactoryBot.create(:comment, author: alice.person, commentable: post)
483+
484+
expect(
485+
DiasporaFederation.callbacks.trigger(:fetch_public_entity, "Comment", comment.guid)
486+
).to be_nil
487+
end
488+
489+
it "returns nil, if the comment is unknown" do
490+
expect(
491+
DiasporaFederation.callbacks.trigger(:fetch_public_entity, "Comment", "unknown-guid")
492+
).to be_nil
493+
end
494+
end
468495
end
469496

470497
describe ":fetch_person_url_to" do

0 commit comments

Comments
 (0)