2023-02-04 14:22:05 +01:00
|
|
|
class CountChannel < ApplicationCable::Channel
|
|
|
|
def subscribed
|
2023-02-05 21:01:07 +01:00
|
|
|
stream_from "counts"
|
2023-02-04 14:22:05 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def unsubscribed
|
|
|
|
# Any cleanup needed when channel is unsubscribed
|
|
|
|
end
|
2023-02-05 21:01:07 +01:00
|
|
|
|
|
|
|
def plus_one(params)
|
|
|
|
unless current_user.nil?
|
|
|
|
total = Total.find(params["id"])
|
|
|
|
unless total.nil?
|
|
|
|
total.update(count: total.count + 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def minus_one(params)
|
|
|
|
unless current_user.nil?
|
|
|
|
total = Total.find(params["id"])
|
|
|
|
unless total.nil?
|
|
|
|
total.update(count: total.count - 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.create(total)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.update(total)
|
|
|
|
ActionCable.server.broadcast("counts", {"update": total})
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.destroy(total)
|
|
|
|
ActionCable.server.broadcast("counts", {"destroy": total.id})
|
|
|
|
end
|
|
|
|
|
2023-02-04 14:22:05 +01:00
|
|
|
end
|