From a996f3bd05fc480247fd112f23fa3e67f7d5d7b5 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 7 Dec 2024 15:54:39 -0500 Subject: Added support for liking blog posts via webmention --- app/models/concerns/votable.rb | 8 ++++++++ app/models/vote.rb | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/concerns/votable.rb b/app/models/concerns/votable.rb index ba6e6d5..40b3a2a 100644 --- a/app/models/concerns/votable.rb +++ b/app/models/concerns/votable.rb @@ -39,5 +39,13 @@ module Votable save! end end + + def like!(url, name) + return false unless votes.where(liker_url: url).empty? + + votes.create(liker_url: url, liker_name: name, upvote: 1).save + self.upvotes += 1 + save! + end end end diff --git a/app/models/vote.rb b/app/models/vote.rb index e2d8386..fced5bd 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -2,5 +2,4 @@ class Vote < ApplicationRecord belongs_to :votable, polymorphic: true validates :upvote, presence: true, inclusion: { in: [0, 1] } - validates :ip, presence: true end -- cgit 1.4.1