Class: Livechat::Message

Inherits:
ApplicationRecord show all
Defined in:
app/models/livechat/message.rb

Overview

One chat entry. Three kinds of author: the visitor, a named agent, or the system (resolve/reopen events, so a thread worked by several teammates stays legible). Agent attribution is stored as loose fields — agent_id plus a label resolved at write time — no foreign key to the host's users.

Constant Summary collapse

AUTHOR_TYPES =
%w[visitor agent system].freeze
EVENTS =
%w[resolved reopened].freeze
MAX_BODY_LENGTH =
5_000

Instance Method Summary collapse

Instance Method Details

#as_widget_jsonObject



42
43
44
45
46
47
48
49
50
51
# File 'app/models/livechat/message.rb', line 42

def as_widget_json
  {
    id: id,
    author: author_type,
    label: public_label,
    body: system? ? nil : body,
    event: event,
    at: created_at.iso8601
  }
end

#public_labelObject

What the widget shows as the sender of an agent message — run through config.agent_display_name, so hosts control how much of the team's identity visitors see.



38
39
40
# File 'app/models/livechat/message.rb', line 38

def public_label
  agent? ? Livechat.display_name_for(agent_label) : nil
end

#read?Boolean

Returns:

  • (Boolean)


33
# File 'app/models/livechat/message.rb', line 33

def read? = read_at.present?