Skip to content

Commit

Permalink
Merge branch 'ripta/chat-state-notification'
Browse files Browse the repository at this point in the history
  • Loading branch information
mojodna committed Dec 2, 2008
2 parents bf26ee8 + 1002aae commit 28d60ea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/xmpp4r/message.rb
Expand Up @@ -148,10 +148,11 @@ def thread
end

##
# Returns the current chat state, or nil if no chat state is set
# Returns the current chat state, or :active if no chat state is set
def chat_state
each_elements(*CHAT_STATES) { |el| return el.name.to_sym }
return nil
set_chat_state(:active)
return :active
end

##
Expand All @@ -166,7 +167,7 @@ def chat_state=(s)
##
# Sets the message's chat state
def set_chat_state(s)
self.state = s
self.chat_state = s
self
end

Expand Down
7 changes: 4 additions & 3 deletions test/tc_message.rb
Expand Up @@ -86,11 +86,12 @@ def test_thread

def test_chat_state
x = Message.new
assert_equal(nil, x.chat_state)
chat_state = REXML::Element.new('active')
assert_equal(:active, x.chat_state)
chat_state = REXML::Element.new('inactive')
chat_state.add_namespace('http://jabber.org/protocol/chatstates')
x.delete_element('active')
x.add(chat_state)
assert_equal(:active, x.chat_state)
assert_equal(:inactive, x.chat_state)
x.chat_state = :gone
assert_equal(:gone, x.chat_state)
assert_raise(InvalidChatState) do
Expand Down

0 comments on commit 28d60ea

Please sign in to comment.