Skip to content
12 changes: 10 additions & 2 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,14 @@ def akismet_attributes
# While we do have tag comments, those are from logged-in users with special
# access granted by admins, so we never spam check them, unlike comments on
# works or admin posts.
comment_type = ultimate_parent.is_a?(Work) ? "fanwork-comment" : "comment"
case ultimate_parent
when Work
comment_type = "fanwork-comment"
comment_post_modified_gmt = ultimate_parent.revised_at.iso8601
when AdminPost
comment_type = "comment"
comment_post_modified_gmt = ultimate_parent.created_at.iso8601
end

if pseud_id.nil?
user_role = "guest"
Expand All @@ -126,7 +133,8 @@ def akismet_attributes
user_role: user_role,
comment_author: comment_author,
comment_author_email: comment_owner_email,
comment_content: comment_content
comment_content: comment_content,
comment_post_modified_gmt: comment_post_modified_gmt
}

attributes[:recheck_reason] = "edit" if will_save_change_to_edited_at? && will_save_change_to_comment_content?
Expand Down
16 changes: 16 additions & 0 deletions spec/models/comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ def queue_adapter_for_test
it "has comment_type \"fanwork-comment\"" do
expect(subject.akismet_attributes[:comment_type]).to eq("fanwork-comment")
end

it "has comment_post_modified_gmt as the work's revision time" do
expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(subject.ultimate_parent.revised_at.iso8601)
end
end

context "when the commentable is an admin post" do
Expand All @@ -300,6 +304,10 @@ def queue_adapter_for_test
it "has comment_type \"comment\"" do
expect(subject.akismet_attributes[:comment_type]).to eq("comment")
end

it "has comment_post_modified_gmt as the admin post's creation time" do
expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(subject.ultimate_parent.created_at.iso8601)
end
end

context "when the commentable is a comment" do
Expand All @@ -309,6 +317,10 @@ def queue_adapter_for_test
it "has comment_type \"fanwork-comment\"" do
expect(subject.akismet_attributes[:comment_type]).to eq("fanwork-comment")
end

it "has comment_post_modified_gmt as the work's revision time" do
expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(subject.ultimate_parent.revised_at.iso8601)
end
end

context "when the comment is on an admin post" do
Expand All @@ -317,6 +329,10 @@ def queue_adapter_for_test
it "has comment_type \"comment\"" do
expect(subject.akismet_attributes[:comment_type]).to eq("comment")
end

it "has comment_post_modified_gmt as the admin post's creation time" do
expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(subject.ultimate_parent.created_at.iso8601)
end
end
end
end
Expand Down
Loading