Skip to content

Commit

Permalink
handle Flag activities received to inbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Floppy committed Nov 22, 2024
1 parent e3217f6 commit 545fb85
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/models/report.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'fediverse/inbox'

class Report
def self.handle_flag(activity)
Rails.logger.debug activity.inspect
end
end

Fediverse::Inbox.register_handler 'Flag', '*', Report, :handle_flag
25 changes: 25 additions & 0 deletions spec/requests/reports_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "rails_helper"

RSpec.describe "Reports" do
let(:user) { create :user }
let(:report_body) {
<<-EOF
{
"@context":"https://www.w3.org/ns/activitystreams",
"id":"https://mastodon.me.uk/d977f377-214b-4efd-8a47-70a37fb7ea20",
"type":"Flag",
"actor":"https://mastodon.me.uk/actor",
"content":"Test, please ignore",
"object":[
"https://example.com/models/abc123"
]
}
EOF
}

it "should call registered Report handler when a flag is received by Federails" do
expect(Report).to receive(:handle_flag).once.and_call_original
post user.actor.inbox_url, params: report_body, headers: { content_type: "application/activity" }
end

end

0 comments on commit 545fb85

Please sign in to comment.