File: muc.rb

package info (click to toggle)
ruby-xmpp4r 0.5.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,384 kB
  • sloc: ruby: 17,382; xml: 74; sh: 12; makefile: 4
file content (70 lines) | stat: -rw-r--r-- 1,729 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# =XMPP4R - XMPP Library for Ruby
# License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
# Website::http://xmpp4r.github.io

require 'xmpp4r/muc/x/mucuseritem'
require 'xmpp4r/muc/x/mucuserinvite'

module Jabber
  module MUC
    ##
    # Class for <x/> elements
    # with namespace http://jabber.org/protocol/muc
    #
    # See JEP-0045 for details
    class XMUC < X
      name_xmlns 'x', 'http://jabber.org/protocol/muc'

      ##
      # Text content of the <tt><password/></tt> element
      def password
        first_element_text('password')
      end

      ##
      # Set the password for joining a room
      # (text content of the <tt><password/></tt> element)
      def password=(s)
        if s
          replace_element_text('password', s)
        else
          delete_elements('password')
        end
      end
    end

    ##
    # Class for <x/> elements
    # with namespace http://jabber.org/protocol/muc#user
    #
    # See JEP-0058 for details
    class XMUCUser < X
      name_xmlns 'x', 'http://jabber.org/protocol/muc#user'

      ##
      # Retrieve the three-digit code in
      # <tt><x xmlns='http://jabber.org/protocol/muc#user'><status code='...'/></x></tt>
      # result:: [Fixnum] or nil
      def status_code
        e = nil
        each_element('status') { |xe| e = xe }
        if e and e.attributes['code'].size == 3 and e.attributes['code'].to_i != 0
          e.attributes['code'].to_i
        else
          nil
        end
      end

      ##
      # Get all <item/> elements
      # result:: [Array] of [XMUCUserItem]
      def items
        res = []
        each_element('item') { |item|
          res << item
        }
        res
      end
    end
  end
end