diff --git a/app/models/comment.rb b/app/models/comment.rb index 9415aaa55e..da15453ef3 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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" @@ -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? diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index d10be853ea..5242b09e8e 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -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 @@ -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 @@ -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 @@ -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