Class: Jabber::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/lijab/xmpp4r/message.rb,
lib/lijab/xmpp4r/message.rb

Constant Summary collapse

CHAT_STATES =
%w(active composing gone inactive paused).freeze

Instance Method Summary collapse

Instance Method Details

#chat_stateObject



14
15
16
17
# File 'lib/lijab/xmpp4r/message.rb', line 14

def chat_state
   each_elements(*CHAT_STATES) { |el| return el.name.to_sym }
   return nil
end

#chat_state=(s) ⇒ Object

Sets the chat state :active, :composing, :gone, :inactive, :paused

Raises:

  • (InvalidChatState)


21
22
23
24
25
26
27
# File 'lib/lijab/xmpp4r/message.rb', line 21

def chat_state=(s)
   s = s.to_s
   raise InvalidChatState, 
      "Chat state must be one of #{CHAT_STATES.join(', ')}" unless CHAT_STATES.include?(s)
   CHAT_STATES.each { |state| delete_elements(state) }
   add_element(REXML::Element.new(s).add_namespace('http://jabber.org/protocol/chatstates'))
end

#each_elements(*els, &block) ⇒ Object

Returns the current chat state, or nil if no chat state is set



8
9
10
11
12
# File 'lib/lijab/xmpp4r/message.rb', line 8

def each_elements(*els, &block)
   els.inject([ ]) do |res, e|
      res + each_element(e, &block)
   end
end

#set_chat_state(s) ⇒ Object

Sets the message’s chat state



40
41
42
43
# File 'lib/lijab/xmpp4r/message.rb', line 40

def set_chat_state(s)
   self.chat_state = s
   self
end