Class: Message
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Message
- Defined in:
- lib/generators/kablam/templates/message.rb
Overview
require ‘rest-client’
Class Method Summary collapse
Instance Method Summary collapse
- #broadcast_self ⇒ Object
- #set_updated_at ⇒ Object
- #setup_status ⇒ Object
- #status(user_id) ⇒ Object
- #user ⇒ Object
- #user_time ⇒ Object
Class Method Details
.slack_hook ⇒ Object
8 9 10 11 |
# File 'lib/generators/kablam/templates/message.rb', line 8 def self.slack_hook # "http://insert-slack-hook-here" nil end |
.slack_message ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/generators/kablam/templates/message.rb', line 13 def self. {create: { pretext: "New Message from #{user.name}", author: "#{user.name}", title: "chat.subject", text: "#{content}" } } end |
Instance Method Details
#broadcast_self ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/generators/kablam/templates/message.rb', line 41 def broadcast_self ActionCable.server.broadcast "AdminChannel", {chat_id: "#{chat.id}_#{sender_id}" } chat.users.each do |u| ActionCable.server.broadcast "DotChannel_#{u}", {dot: "#{sender_id}" } end end |
#set_updated_at ⇒ Object
27 28 29 30 31 |
# File 'lib/generators/kablam/templates/message.rb', line 27 def set_updated_at @chat = self.chat @chat.update(updated_at: self.created_at) # @chat.save end |
#setup_status ⇒ Object
23 24 25 |
# File 'lib/generators/kablam/templates/message.rb', line 23 def setup_status MessageStatus.create(user_id: self.chat.user_id, message_id: self.id) end |
#status(user_id) ⇒ Object
33 34 35 |
# File 'lib/generators/kablam/templates/message.rb', line 33 def status(user_id) MessageStatus.find_by(user_id: user_id, message_id: self.id).read end |
#user ⇒ Object
37 38 39 |
# File 'lib/generators/kablam/templates/message.rb', line 37 def user User.find(self.sender_id.to_i) end |
#user_time ⇒ Object
49 50 51 52 |
# File 'lib/generators/kablam/templates/message.rb', line 49 def user_time u = User.find(self.sender_id.to_i) ActiveSupport::TimeZone[u.timezone].now if !u.timezone.nil? end |