lib/blather/stanza/presence/subscription.rb in sprsquish-blather-0.3.4 vs lib/blather/stanza/presence/subscription.rb in sprsquish-blather-0.4.0
- old
+ new
@@ -3,14 +3,15 @@
class Presence
class Subscription < Presence
register :subscription, :subscription
- def initialize(to = nil, type = nil)
- super()
- self.to = to
- self.type = type
+ def self.new(to = nil, type = nil)
+ node = super()
+ node.to = to
+ node.type = type
+ node
end
def inherit(node)
inherit_attrs node.attributes
self
@@ -22,51 +23,45 @@
##
# Create an approve stanza
def approve!
self.type = :subscribed
- morph_to_reply
+ reply_if_needed!
end
##
# Create a refuse stanza
def refuse!
self.type = :unsubscribed
- morph_to_reply
+ reply_if_needed!
end
##
# Create an unsubscribe stanza
def unsubscribe!
self.type = :unsubscribe
- morph_to_reply
+ reply_if_needed!
end
##
# Create a cancel stanza
def cancel!
self.type = :unsubscribed
- morph_to_reply
+ reply_if_needed!
end
##
# Create a request stanza
def request!
self.type = :subscribe
- morph_to_reply
+ reply_if_needed!
end
def request?
self.type == :subscribe
end
- private
- def morph_to_reply
- self.to = self.from if self.from
- self.from = nil
- self
- end
end #Subscription
end #Presence
end #Stanza
-end
\ No newline at end of file
+end