Class: Message

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
lib/generators/kablam/templates/message.rb

Overview

require ‘rest-client’

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.slack_hookObject



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_messageObject



13
14
15
16
17
18
19
20
21
# File 'lib/generators/kablam/templates/message.rb', line 13

def self.slack_message
  {create: {
    pretext: "New Message from #{user.name}",
    author: "#{user.name}",
    title: "chat.subject",
    text: "#{content}"
    }
  }
end

Instance Method Details

#broadcast_selfObject



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_atObject



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_statusObject



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

#userObject



37
38
39
# File 'lib/generators/kablam/templates/message.rb', line 37

def user
  User.find(self.sender_id.to_i)
end

#user_timeObject



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