Class: EtherpadLite::ChatMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/etherpad-lite/models/chat_message.rb

Overview

An Etherpad Lite Chat message

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance, attrs) ⇒ ChatMessage

Instantiate a ChatMessage



18
19
20
21
22
23
24
25
# File 'lib/etherpad-lite/models/chat_message.rb', line 18

def initialize(instance, attrs)
  @instance = instance
  @pad_id = attrs[:padID]
  @text = attrs[:text]
  @user_id = attrs[:userId]
  @timestamp = attrs[:time] / 1000 if attrs[:time]
  @user_name = attrs[:userName]
end

Instance Attribute Details

#instanceObject (readonly)

The EtherpadLite::Instance object



5
6
7
# File 'lib/etherpad-lite/models/chat_message.rb', line 5

def instance
  @instance
end

#pad_idObject (readonly)

The pad id



7
8
9
# File 'lib/etherpad-lite/models/chat_message.rb', line 7

def pad_id
  @pad_id
end

#textObject (readonly)

The message text



9
10
11
# File 'lib/etherpad-lite/models/chat_message.rb', line 9

def text
  @text
end

#timestampObject (readonly)

Unix timestamp



13
14
15
# File 'lib/etherpad-lite/models/chat_message.rb', line 13

def timestamp
  @timestamp
end

#user_idObject (readonly)

User/Author id



11
12
13
# File 'lib/etherpad-lite/models/chat_message.rb', line 11

def user_id
  @user_id
end

#user_nameObject (readonly)

User/Author name



15
16
17
# File 'lib/etherpad-lite/models/chat_message.rb', line 15

def user_name
  @user_name
end

Instance Method Details

#authorObject Also known as: user

Returns the Author that sent this message



37
38
39
40
41
42
43
# File 'lib/etherpad-lite/models/chat_message.rb', line 37

def author
  if user_id
    @author ||= Author.new(instance, user_id)
  else
    nil
  end
end

#padObject

Returns this message’s Pad



28
29
30
31
32
33
34
# File 'lib/etherpad-lite/models/chat_message.rb', line 28

def pad
  if pad_id
    @pad ||= Pad.new(instance, pad_id)
  else
    nil
  end
end

#timeObject

Time object



48
49
50
51
52
53
54
# File 'lib/etherpad-lite/models/chat_message.rb', line 48

def time
  if timestamp
    @time ||= Time.at(timestamp)
  else
    nil
  end
end

#to_sObject

Returns the message text



57
58
59
# File 'lib/etherpad-lite/models/chat_message.rb', line 57

def to_s
  text.to_s
end