Sha256: 878f6b684c78a6b1f4054d13658650f6028258192d49880b46d9924dad8c8b77

Contents?: true

Size: 1.08 KB

Versions: 27

Compression:

Stored size: 1.08 KB

Contents

# encoding: UTF-8

module Vines
  class Stanza
    class PubSub
      class Delete < PubSub
        NS = NAMESPACES[:pubsub]

        register "/iq[@id and @type='set']/ns:pubsub/ns:delete", 'ns' => NS

        def process
          return if route_iq || !allowed?
          validate_to_address

          node = self.xpath('ns:pubsub/ns:delete', 'ns' => NS)
          raise StanzaErrors::BadRequest.new(self, 'modify') if node.size != 1
          node = node.first

          id = node['node']
          raise StanzaErrors::ItemNotFound.new(self, 'cancel') unless pubsub.node?(id)

          pubsub.publish(id, message(id))
          pubsub.delete_node(id)
          stream.write(to_result)
        end

        private

        def message(id)
          doc = Document.new
          doc.create_element('message') do |node|
            node << node.document.create_element('event') do |event|
              event.default_namespace = NAMESPACES[:pubsub_event]
              event << node.document.create_element('delete', 'node' => id)
            end
          end
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 4 rubygems

Version Path
diaspora-vines-0.2.0.develop.4 lib/vines/stanza/pubsub/delete.rb
diaspora-vines-0.2.0.develop.3 lib/vines/stanza/pubsub/delete.rb
diaspora-vines-0.2.0.develop.2 lib/vines/stanza/pubsub/delete.rb
diaspora-vines-0.2.0.develop.1 lib/vines/stanza/pubsub/delete.rb
diaspora-vines-0.1.28 lib/vines/stanza/pubsub/delete.rb
lygneo-vines-0.1.5 lib/vines/stanza/pubsub/delete.rb
lygneo-vines-0.1.1 lib/vines/stanza/pubsub/delete.rb
diaspora-vines-0.1.27 lib/vines/stanza/pubsub/delete.rb
diaspora-vines-0.1.26 lib/vines/stanza/pubsub/delete.rb
diaspora-vines-0.1.25 lib/vines/stanza/pubsub/delete.rb
diaspora-vines-0.1.24 lib/vines/stanza/pubsub/delete.rb
vines-0.4.10 lib/vines/stanza/pubsub/delete.rb
diaspora-vines-0.1.22 lib/vines/stanza/pubsub/delete.rb
diaspora-vines-0.1.21 lib/vines/stanza/pubsub/delete.rb
diaspora-vines-0.1.2 lib/vines/stanza/pubsub/delete.rb
vines-0.4.9 lib/vines/stanza/pubsub/delete.rb
vines-0.4.8 lib/vines/stanza/pubsub/delete.rb
vines-0.4.7 lib/vines/stanza/pubsub/delete.rb
vines-0.4.6 lib/vines/stanza/pubsub/delete.rb
vinesmod-0.4.5.2 lib/vines/stanza/pubsub/delete.rb