Skip to content

Commit

Permalink
Merge branch 'release/0.6.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Feb 28, 2012
2 parents 7f3398b + 2093709 commit 69ed6ff
Show file tree
Hide file tree
Showing 13 changed files with 391 additions and 33 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
@@ -1,11 +1,13 @@
rvm:
- 1.9.2
- rbx
- rbx-2.0
- jruby
- 1.8.7
- ree
- ruby-head
- 1.9.2
- 1.9.3
- jruby-18mode
- jruby-19mode
- rbx-18mode
- rbx-19mode
- jruby

branches:
only:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG
@@ -1,5 +1,12 @@
develop

v0.6.2
Feature(benlangfeld): Add password support to MUCUser
Feature(benlangfeld): Add support for invitation elements to MUCUser messages
Feature(benlangfeld): Add support for MUC invite declines
Bugfix(benlangfeld): Don't implicitly create an invite node when checking invite status
Bugfix(benlangfeld): Ensure that form nodes are not duplicated on muc/muc_user presence stanzas

v0.6.1
Bugfix(benlangfeld): Ensure MUC presence nodes (joining) have a form element on creation

Expand Down
1 change: 1 addition & 0 deletions lib/blather.rb
Expand Up @@ -43,6 +43,7 @@
blather/stanza/disco/disco_items
blather/stanza/disco/capabilities
blather/stanza/message
blather/stanza/message/muc_user
blather/stanza/presence
blather/stanza/presence/c
blather/stanza/presence/status
Expand Down
4 changes: 4 additions & 0 deletions lib/blather/stanza/message.rb
Expand Up @@ -180,6 +180,10 @@ def self.import(node)
klass = class_from_registration(e.element_name, ns)
end

if klass == Blather::Stanza::Presence::MUCUser
klass = Blather::Stanza::Message::MUCUser
end

if klass && klass != self && ![Blather::Stanza::X, Blather::Stanza::Iq].include?(klass)
klass.import(node)
else
Expand Down
117 changes: 117 additions & 0 deletions lib/blather/stanza/message/muc_user.rb
@@ -0,0 +1,117 @@
require 'blather/stanza/muc/muc_user_base'

module Blather
class Stanza
class Message

class MUCUser < Message
include Blather::Stanza::MUC::MUCUserBase

def self.new(to = nil, body = nil, type = :normal)
super
end

def invite?
!!find_invite_node
end

def invite_decline?
!!find_decline_node
end

def invite
if invite = find_invite_node
Invite.new invite
else
muc_user << (invite = Invite.new nil, nil, nil, self.document)
invite
end
end

def find_invite_node
muc_user.find_first 'ns:invite', :ns => self.class.registered_ns
end

def decline
if decline = find_decline_node
Decline.new decline
else
muc_user << (decline = Decline.new nil, nil, nil, self.document)
decline
end
end

def find_decline_node
muc_user.find_first 'ns:decline', :ns => self.class.registered_ns
end

class InviteBase < XMPPNode
def self.new(element_name, to = nil, from = nil, reason = nil, document = nil)
new_node = super element_name, document

case to
when self
to.document ||= document
return to
when Nokogiri::XML::Node
new_node.inherit to
when Hash
new_node.to = to[:to]
new_node.from = to[:from]
new_node.reason = to[:reason]
else
new_node.to = to
new_node.from = from
new_node.reason = reason
end
new_node
end

def to
read_attr :to
end

def to=(val)
write_attr :to, val
end

def from
read_attr :from
end

def from=(val)
write_attr :from, val
end

def reason
reason_node.content.strip
end

def reason=(val)
reason_node.content = val
end

def reason_node
unless reason = find_first('ns:reason', :ns => MUCUser.registered_ns)
self << (reason = XMPPNode.new('reason', self.document))
end
reason
end
end

class Invite < InviteBase
def self.new(*args)
new_node = super :invite, *args
end
end

class Decline < InviteBase
def self.new(*args)
new_node = super :decline, *args
end
end
end # MUC

end # Presence
end # Stanza
end # Blather
53 changes: 53 additions & 0 deletions lib/blather/stanza/muc/muc_user_base.rb
@@ -0,0 +1,53 @@
module Blather
class Stanza
class MUC

module MUCUserBase
def self.included(klass)
klass.extend ClassMethods
klass.register :muc_user, :x, "http://jabber.org/protocol/muc#user"
end

module ClassMethods
def new(*args)
super.tap { |e| e.muc_user }
end
end

def inherit(node)
muc_user.remove
super
self
end

def password
find_password_node && password_node.content
end

def password=(var)
password_node.content = var
end

def muc_user
unless muc_user = find_first('ns:x', :ns => self.class.registered_ns)
self << (muc_user = XMPPNode.new('x', self.document))
muc_user.namespace = self.class.registered_ns
end
muc_user
end

def password_node
unless pw = find_password_node
muc_user << (pw = XMPPNode.new('password', self.document))
end
pw
end

def find_password_node
muc_user.find_first 'ns:password', :ns => self.class.registered_ns
end
end # MUCUserBase

end # MUC
end # Stanza
end # Blather
6 changes: 6 additions & 0 deletions lib/blather/stanza/presence/muc.rb
Expand Up @@ -11,6 +11,12 @@ def self.new(*args)
new_node
end

def inherit(node)
muc.remove
super
self
end

def muc
unless muc = find_first('ns:x', :ns => self.class.registered_ns)
self << (muc = XMPPNode.new('x', self.document))
Expand Down
35 changes: 14 additions & 21 deletions lib/blather/stanza/presence/muc_user.rb
@@ -1,9 +1,11 @@
require 'blather/stanza/muc/muc_user_base'

module Blather
class Stanza
class Presence

class MUCUser < Status
register :muc_user, :x, "http://jabber.org/protocol/muc#user"
include Blather::Stanza::MUC::MUCUserBase

def affiliation
item.affiliation
Expand Down Expand Up @@ -40,29 +42,20 @@ def status_codes=(val)
end
end

private
def muc_user
unless muc_user = find_first('ns:x', :ns => self.class.registered_ns)
self << (muc_user = XMPPNode.new('x', self.document))
muc_user.namespace = self.class.registered_ns
end
muc_user
end

def item
if item = muc_user.find_first('ns:item', :ns => self.class.registered_ns)
Item.new item
else
muc_user << (item = Item.new nil, nil, nil, self.document)
item
end
def item
if item = muc_user.find_first('ns:item', :ns => self.class.registered_ns)
Item.new item
else
muc_user << (item = Item.new nil, nil, nil, self.document)
item
end
end

def status
muc_user.find('ns:status', :ns => self.class.registered_ns).map do |status|
Status.new status
end
def status
muc_user.find('ns:status', :ns => self.class.registered_ns).map do |status|
Status.new status
end
end

class Item < XMPPNode
def self.new(affiliation = nil, role = nil, jid = nil, document = nil)
Expand Down
2 changes: 1 addition & 1 deletion lib/blather/version.rb
@@ -1,4 +1,4 @@
module Blather
# Blather version number
VERSION = '0.6.1'
VERSION = '0.6.2'
end

0 comments on commit 69ed6ff

Please sign in to comment.