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
|
# File 'lib/hipchat_bot/muc_client.rb', line 8
def join(jid, password=nil)
if active?
raise "MUCClient already active"
end
@jid = (jid.kind_of?(JID) ? jid : JID.new(jid))
activate
pres = Presence.new
pres.to = @jid
pres.from = @my_jid
xmuc = XMUC.new
xmuc.password = password
pres.add(xmuc)
history = XMPPElement.new('history')
history.add_attributes({'maxstanzas' => '0'})
xmuc.add(history)
error = nil
@stream.send(pres) { |r|
if from_room?(r.from) and r.kind_of?(Presence) and r.type == :error
error = r.error
true
elsif r.from == jid and r.kind_of?(Presence) and r.type != :unavailable
if r.x(XMUCUser) and (i = r.x(XMUCUser).items.first)
@affiliation = i.affiliation @role = i.role end
handle_presence(r, false)
true
else
false
end
}
if error
deactivate
raise ServerError.new(error)
end
self
end
|