xmpp4r-hipchat 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/xmpp4r/hipchat.rb +1 -2
- data/lib/xmpp4r/hipchat/version.rb +3 -5
- data/lib/xmpp4r/muc/helper/hipchat_client.rb +224 -0
- data/xmpp4r-hipchat.gemspec +5 -9
- metadata +8 -35
- data/lib/xmpp4r/hipchat/client.rb +0 -226
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f64323e247f6260a6a671ee3ea2b4762d8ec1765
|
4
|
+
data.tar.gz: c71fab69793bf8a902f8deb3e30c3c503943c679
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d9489b6a5ed86a130c9cdbb6fca83175e657f96b247db59a378aa38bb12f8e9ff0fee35e8c9d7c853e5289114a7ab1554f69a966677019d707a08430e54bd5c
|
7
|
+
data.tar.gz: 8abbeab174c7e7df994e981c699b1739eaeebfb39a433fe3fd012e9ba382a9ee1b3b809e40c407f6675d4b73a2e7d9a024460e64a36931360eb9cb20f959eaec
|
data/lib/xmpp4r/hipchat.rb
CHANGED
@@ -0,0 +1,224 @@
|
|
1
|
+
module Jabber
|
2
|
+
module MUC
|
3
|
+
class HipchatClient
|
4
|
+
attr_accessor :my_jid, :chat_domain, :conference_domain, :stream
|
5
|
+
|
6
|
+
def initialize(jid)
|
7
|
+
self.my_jid = JID.new(jid)
|
8
|
+
self.stream = Client.new(my_jid.strip) # TODO: Error Handling
|
9
|
+
Jabber::debuglog "Stream initialized"
|
10
|
+
self.chat_domain = my_jid.domain
|
11
|
+
|
12
|
+
@callbacks = Hash.new { |hash, key| hash[key] = CallbackList.new }
|
13
|
+
end
|
14
|
+
|
15
|
+
def join(jid, password = nil, opts = { history: false })
|
16
|
+
room_jid = JID.new(jid)
|
17
|
+
xmuc = XMUC.new
|
18
|
+
xmuc.password = password
|
19
|
+
|
20
|
+
if !opts[:history]
|
21
|
+
history = REXML::Element.new('history').tap{ |h| h.add_attribute('maxstanzas','0') }
|
22
|
+
xmuc.add_element history
|
23
|
+
end
|
24
|
+
|
25
|
+
room_jid.resource = name
|
26
|
+
set_presence(:available, room_jid, nil, xmuc) # TODO: Handle all join responses
|
27
|
+
end
|
28
|
+
|
29
|
+
def exit(jid, reason = nil)
|
30
|
+
room_jid = JID.new(jid)
|
31
|
+
Jabber::debuglog "Exiting #{jid}"
|
32
|
+
set_presence(:unavailable, room_jid, reason)
|
33
|
+
end
|
34
|
+
|
35
|
+
def keep_alive password
|
36
|
+
if stream.is_disconnected?
|
37
|
+
connect(password)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def name
|
42
|
+
my_jid.resource
|
43
|
+
end
|
44
|
+
|
45
|
+
def name= resource
|
46
|
+
my_jid.resource = resource
|
47
|
+
end
|
48
|
+
|
49
|
+
%w(lobby_presence room_presence room_message private_message invite).each do |callback_name|
|
50
|
+
define_method("on_#{callback_name}") do |prio = 0, ref = nil, &block|
|
51
|
+
@callbacks[callback_name.to_sym].add(prio, ref) do |*args|
|
52
|
+
block.call(*args)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_presence(type, to = nil, reason = nil, xmuc = nil, &block)
|
58
|
+
pres = Presence.new(:chat, reason)
|
59
|
+
pres.type = type
|
60
|
+
pres.to = to if to
|
61
|
+
pres.from = my_jid
|
62
|
+
pres.add(xmuc) if xmuc
|
63
|
+
stream.send(pres) { |r| block.call(r) }
|
64
|
+
end
|
65
|
+
|
66
|
+
def kick(recipients, room_jid)
|
67
|
+
iq = Iq.new(:set, room_jid)
|
68
|
+
iq.from = my_jid
|
69
|
+
iq.add(IqQueryMUCAdmin.new)
|
70
|
+
recipients.each do |recipient|
|
71
|
+
item = IqQueryMUCAdminItem.new
|
72
|
+
item.nick = recipient
|
73
|
+
item.role = :none
|
74
|
+
iq.query.add(item)
|
75
|
+
end
|
76
|
+
stream.send_with_id(iq)
|
77
|
+
end
|
78
|
+
|
79
|
+
def invite(recipients, room_jid)
|
80
|
+
msg = Message.new
|
81
|
+
msg.from = my_jid
|
82
|
+
msg.to = room_jid
|
83
|
+
x = msg.add(XMUCUser.new)
|
84
|
+
recipients.each do |jid|
|
85
|
+
x.add(XMUCUserInvite.new(jid))
|
86
|
+
end
|
87
|
+
stream.send(msg)
|
88
|
+
end
|
89
|
+
|
90
|
+
def send_message(type, jid, text, subject = nil)
|
91
|
+
message = Message.new(JID.new(jid), text.to_s)
|
92
|
+
message.type = type
|
93
|
+
message.from = my_jid
|
94
|
+
message.subject = subject
|
95
|
+
|
96
|
+
@send_thread.join if !@send_thread.nil? && @send_thread.alive?
|
97
|
+
@send_thread = Thread.new do
|
98
|
+
stream.send(message)
|
99
|
+
sleep(0.2)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def connect password
|
104
|
+
stream.connect
|
105
|
+
Jabber::debuglog "Connected to stream"
|
106
|
+
stream.auth(password)
|
107
|
+
Jabber::debuglog "Authenticated"
|
108
|
+
@muc_browser = MUCBrowser.new(stream)
|
109
|
+
Jabber::debuglog "MUCBrowser initialized"
|
110
|
+
self.conference_domain = @muc_browser.muc_rooms(chat_domain).keys.first
|
111
|
+
Jabber::debuglog "No conference domain found" if conference_domain.nil?
|
112
|
+
@roster = Roster::Helper.new(stream) # TODO: Error handling
|
113
|
+
@vcard = Vcard::Helper.new(stream) # TODO: Error handling
|
114
|
+
true
|
115
|
+
end
|
116
|
+
|
117
|
+
def activate_callbacks
|
118
|
+
stream.add_presence_callback(150, self){ |presence| handle_presence(presence) }
|
119
|
+
stream.add_message_callback(150, self){ |message| handle_message(message) }
|
120
|
+
Jabber::debuglog "Callbacks activated"
|
121
|
+
end
|
122
|
+
|
123
|
+
def get_rooms
|
124
|
+
iq = Iq.new(:get, conference_domain)
|
125
|
+
iq.from = stream.jid
|
126
|
+
iq.add(Discovery::IqQueryDiscoItems.new)
|
127
|
+
|
128
|
+
rooms = []
|
129
|
+
stream.send_with_id(iq) do |answer|
|
130
|
+
answer.query.each_element('item') do |item|
|
131
|
+
details = {}
|
132
|
+
item.first.children.each{ |c| details[c.name] = c.text }
|
133
|
+
rooms << {
|
134
|
+
item: item,
|
135
|
+
details: details
|
136
|
+
}
|
137
|
+
end
|
138
|
+
end
|
139
|
+
rooms
|
140
|
+
end
|
141
|
+
|
142
|
+
def get_users
|
143
|
+
@roster.wait_for_roster
|
144
|
+
@roster.items.map do |jid, item|
|
145
|
+
{
|
146
|
+
jid: item.jid.to_s,
|
147
|
+
name: item.iname,
|
148
|
+
mention: item.attributes['mention_name'],
|
149
|
+
}
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def get_user_details user_jid
|
154
|
+
vcard = @vcard.get(user_jid)
|
155
|
+
{
|
156
|
+
email: vcard['EMAIL/USERID'],
|
157
|
+
title: vcard['TITLE'],
|
158
|
+
photo: vcard['PHOTO'],
|
159
|
+
}
|
160
|
+
end
|
161
|
+
|
162
|
+
def deactivate_callbacks
|
163
|
+
stream.delete_presence_callback(self)
|
164
|
+
stream.delete_message_callback(self)
|
165
|
+
Jabber::debuglog "Callbacks deactivated"
|
166
|
+
end
|
167
|
+
|
168
|
+
private
|
169
|
+
|
170
|
+
def handle_presence(presence)
|
171
|
+
from_jid = presence.from.strip.to_s
|
172
|
+
presence_type = presence.type.to_s
|
173
|
+
user_name = presence.from.resource
|
174
|
+
if user_name.nil?
|
175
|
+
@callbacks[:lobby_presence].process(from_jid, presence_type)
|
176
|
+
else
|
177
|
+
@callbacks[:room_presence].process(from_jid, user_name, presence_type)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def handle_message(message)
|
182
|
+
if is_invite?(message)
|
183
|
+
handle_invite(message)
|
184
|
+
elsif message.type == :chat
|
185
|
+
handle_private_message(message)
|
186
|
+
elsif message.type == :groupchat
|
187
|
+
handle_group_message(message)
|
188
|
+
elsif message.type == :error
|
189
|
+
handle_error(message)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def handle_invite(message)
|
194
|
+
room_name = message.children.last.first_element_text('name')
|
195
|
+
topic = message.children.last.first_element_text('topic')
|
196
|
+
room_jid = message.from.strip.to_s
|
197
|
+
user_name = message.from.resource
|
198
|
+
@callbacks[:invite].process(room_jid, user_name, room_name, topic)
|
199
|
+
end
|
200
|
+
|
201
|
+
def handle_private_message(message)
|
202
|
+
user_jid = message.from.strip.to_s
|
203
|
+
message_body = message.body.to_s
|
204
|
+
@callbacks[:private_message].process(user_jid, message_body)
|
205
|
+
end
|
206
|
+
|
207
|
+
def handle_group_message(message)
|
208
|
+
room_jid = message.from.strip.to_s
|
209
|
+
user_name = message.from.resource
|
210
|
+
message_body = message.body.to_s
|
211
|
+
topic = message.subject.to_s
|
212
|
+
@callbacks[:room_message].process(room_jid, user_name, message_body, topic)
|
213
|
+
end
|
214
|
+
|
215
|
+
def handle_error(message)
|
216
|
+
false
|
217
|
+
end
|
218
|
+
|
219
|
+
def is_invite?(message)
|
220
|
+
!message.x.nil? && message.x.kind_of?(XMUCUser) && message.x.first.kind_of?(XMUCUserInvite)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
data/xmpp4r-hipchat.gemspec
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'xmpp4r/hipchat/version'
|
2
|
+
require File.expand_path('../lib/xmpp4r/hipchat/version', __FILE__)
|
5
3
|
|
6
4
|
Gem::Specification.new do |spec|
|
7
5
|
spec.name = 'xmpp4r-hipchat'
|
8
|
-
spec.version =
|
6
|
+
spec.version = XMPP4R::HipChat::VERSION
|
9
7
|
spec.authors = ['Bartosz Kopiński']
|
10
8
|
spec.email = ['bartosz.kopinski@gmail.com']
|
11
|
-
spec.description = 'HipChat client extension to
|
12
|
-
spec.summary = 'HipChat client extension to
|
13
|
-
spec.homepage = ''
|
9
|
+
spec.description = 'HipChat client extension to XMPP4R'
|
10
|
+
spec.summary = 'HipChat client extension to XMPP4R'
|
11
|
+
spec.homepage = 'https://github.com/bartoszkopinski/xmpp4r-hipchat'
|
14
12
|
spec.license = 'MIT'
|
15
13
|
|
16
14
|
spec.files = `git ls-files`.split($/)
|
@@ -18,6 +16,4 @@ Gem::Specification.new do |spec|
|
|
18
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
17
|
spec.require_paths = ['lib']
|
20
18
|
spec.add_runtime_dependency 'xmpp4r', ['~> 0.5']
|
21
|
-
spec.add_development_dependency 'bundler', '~> 1.4'
|
22
|
-
spec.add_development_dependency 'rake'
|
23
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xmpp4r-hipchat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bartosz Kopiński
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xmpp4r
|
@@ -24,35 +24,7 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.5'
|
27
|
-
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ~>
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.4'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.4'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '>='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
description: HipChat client extension to xmpp4r
|
27
|
+
description: HipChat client extension to XMPP4R
|
56
28
|
email:
|
57
29
|
- bartosz.kopinski@gmail.com
|
58
30
|
executables: []
|
@@ -65,10 +37,10 @@ files:
|
|
65
37
|
- README.md
|
66
38
|
- Rakefile
|
67
39
|
- lib/xmpp4r/hipchat.rb
|
68
|
-
- lib/xmpp4r/hipchat/client.rb
|
69
40
|
- lib/xmpp4r/hipchat/version.rb
|
41
|
+
- lib/xmpp4r/muc/helper/hipchat_client.rb
|
70
42
|
- xmpp4r-hipchat.gemspec
|
71
|
-
homepage:
|
43
|
+
homepage: https://github.com/bartoszkopinski/xmpp4r-hipchat
|
72
44
|
licenses:
|
73
45
|
- MIT
|
74
46
|
metadata: {}
|
@@ -88,8 +60,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
60
|
version: '0'
|
89
61
|
requirements: []
|
90
62
|
rubyforge_project:
|
91
|
-
rubygems_version: 2.
|
63
|
+
rubygems_version: 2.1.10
|
92
64
|
signing_key:
|
93
65
|
specification_version: 4
|
94
|
-
summary: HipChat client extension to
|
66
|
+
summary: HipChat client extension to XMPP4R
|
95
67
|
test_files: []
|
68
|
+
has_rdoc:
|
@@ -1,226 +0,0 @@
|
|
1
|
-
module Jabber
|
2
|
-
module MUC
|
3
|
-
module Hipchat
|
4
|
-
class Client
|
5
|
-
attr_accessor :my_jid, :chat_domain, :conference_domain, :stream
|
6
|
-
|
7
|
-
def initialize(jid)
|
8
|
-
self.my_jid = JID.new(jid)
|
9
|
-
self.stream = Client.new(my_jid.strip) # TODO: Error Handling
|
10
|
-
Jabber::debuglog "Stream initialized"
|
11
|
-
self.chat_domain = my_jid.domain
|
12
|
-
|
13
|
-
@callbacks = Hash.new { |hash, key| hash[key] = CallbackList.new }
|
14
|
-
end
|
15
|
-
|
16
|
-
def join(jid, password = nil, opts = { history: false })
|
17
|
-
room_jid = JID.new(jid)
|
18
|
-
xmuc = XMUC.new
|
19
|
-
xmuc.password = password
|
20
|
-
|
21
|
-
if !opts[:history]
|
22
|
-
history = REXML::Element.new('history').tap{ |h| h.add_attribute('maxstanzas','0') }
|
23
|
-
xmuc.add_element history
|
24
|
-
end
|
25
|
-
|
26
|
-
room_jid.resource = name
|
27
|
-
set_presence(:available, room_jid, nil, xmuc) # TODO: Handle all join responses
|
28
|
-
end
|
29
|
-
|
30
|
-
def exit(jid, reason = nil)
|
31
|
-
room_jid = JID.new(jid)
|
32
|
-
Jabber::debuglog "Exiting #{jid}"
|
33
|
-
set_presence(:unavailable, room_jid, reason)
|
34
|
-
end
|
35
|
-
|
36
|
-
def keep_alive password
|
37
|
-
if stream.is_disconnected?
|
38
|
-
connect(password)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def name
|
43
|
-
my_jid.resource
|
44
|
-
end
|
45
|
-
|
46
|
-
def name= resource
|
47
|
-
my_jid.resource = resource
|
48
|
-
end
|
49
|
-
|
50
|
-
%w(lobby_presence room_presence room_message private_message invite).each do |callback_name|
|
51
|
-
define_method("on_#{callback_name}") do |prio = 0, ref = nil, &block|
|
52
|
-
@callbacks[callback_name.to_sym].add(prio, ref) do |*args|
|
53
|
-
block.call(*args)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def set_presence(type, to = nil, reason = nil, xmuc = nil, &block)
|
59
|
-
pres = Presence.new(:chat, reason)
|
60
|
-
pres.type = type
|
61
|
-
pres.to = to if to
|
62
|
-
pres.from = my_jid
|
63
|
-
pres.add(xmuc) if xmuc
|
64
|
-
stream.send(pres) { |r| block.call(r) }
|
65
|
-
end
|
66
|
-
|
67
|
-
def kick(recipients, room_jid)
|
68
|
-
iq = Iq.new(:set, room_jid)
|
69
|
-
iq.from = my_jid
|
70
|
-
iq.add(IqQueryMUCAdmin.new)
|
71
|
-
recipients.each do |recipient|
|
72
|
-
item = IqQueryMUCAdminItem.new
|
73
|
-
item.nick = recipient
|
74
|
-
item.role = :none
|
75
|
-
iq.query.add(item)
|
76
|
-
end
|
77
|
-
stream.send_with_id(iq)
|
78
|
-
end
|
79
|
-
|
80
|
-
def invite(recipients, room_jid)
|
81
|
-
msg = Message.new
|
82
|
-
msg.from = my_jid
|
83
|
-
msg.to = room_jid
|
84
|
-
x = msg.add(XMUCUser.new)
|
85
|
-
recipients.each do |jid|
|
86
|
-
x.add(XMUCUserInvite.new(jid))
|
87
|
-
end
|
88
|
-
stream.send(msg)
|
89
|
-
end
|
90
|
-
|
91
|
-
def send_message(type, jid, text, subject = nil)
|
92
|
-
message = Message.new(JID.new(jid), text.to_s)
|
93
|
-
message.type = type
|
94
|
-
message.from = my_jid
|
95
|
-
message.subject = subject
|
96
|
-
|
97
|
-
@send_thread.join if !@send_thread.nil? && @send_thread.alive?
|
98
|
-
@send_thread = Thread.new do
|
99
|
-
stream.send(message)
|
100
|
-
sleep(0.2)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def connect password
|
105
|
-
stream.connect
|
106
|
-
Jabber::debuglog "Connected to stream"
|
107
|
-
stream.auth(password)
|
108
|
-
Jabber::debuglog "Authenticated"
|
109
|
-
@muc_browser = MUCBrowser.new(stream)
|
110
|
-
Jabber::debuglog "MUCBrowser initialized"
|
111
|
-
self.conference_domain = @muc_browser.muc_rooms(chat_domain).keys.first
|
112
|
-
Jabber::debuglog "No conference domain found" if conference_domain.nil?
|
113
|
-
@roster = Roster::Helper.new(stream) # TODO: Error handling
|
114
|
-
@vcard = Vcard::Helper.new(stream) # TODO: Error handling
|
115
|
-
true
|
116
|
-
end
|
117
|
-
|
118
|
-
def activate_callbacks
|
119
|
-
stream.add_presence_callback(150, self){ |presence| handle_presence(presence) }
|
120
|
-
stream.add_message_callback(150, self){ |message| handle_message(message) }
|
121
|
-
Jabber::debuglog "Callbacks activated"
|
122
|
-
end
|
123
|
-
|
124
|
-
def get_rooms
|
125
|
-
iq = Iq.new(:get, conference_domain)
|
126
|
-
iq.from = stream.jid
|
127
|
-
iq.add(Discovery::IqQueryDiscoItems.new)
|
128
|
-
|
129
|
-
rooms = []
|
130
|
-
stream.send_with_id(iq) do |answer|
|
131
|
-
answer.query.each_element('item') do |item|
|
132
|
-
details = {}
|
133
|
-
item.first.children.each{ |c| details[c.name] = c.text }
|
134
|
-
rooms << {
|
135
|
-
item: item,
|
136
|
-
details: details
|
137
|
-
}
|
138
|
-
end
|
139
|
-
end
|
140
|
-
rooms
|
141
|
-
end
|
142
|
-
|
143
|
-
def get_users
|
144
|
-
@roster.wait_for_roster
|
145
|
-
@roster.items.map do |jid, item|
|
146
|
-
{
|
147
|
-
jid: item.jid.to_s,
|
148
|
-
name: item.iname,
|
149
|
-
mention: item.attributes['mention_name'],
|
150
|
-
}
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def get_user_details user_jid
|
155
|
-
vcard = @vcard.get(user_jid)
|
156
|
-
{
|
157
|
-
email: vcard['EMAIL/USERID'],
|
158
|
-
title: vcard['TITLE'],
|
159
|
-
photo: vcard['PHOTO'],
|
160
|
-
}
|
161
|
-
end
|
162
|
-
|
163
|
-
def deactivate_callbacks
|
164
|
-
stream.delete_presence_callback(self)
|
165
|
-
stream.delete_message_callback(self)
|
166
|
-
Jabber::debuglog "Callbacks deactivated"
|
167
|
-
end
|
168
|
-
|
169
|
-
private
|
170
|
-
|
171
|
-
def handle_presence(presence)
|
172
|
-
from_jid = presence.from.strip.to_s
|
173
|
-
presence_type = presence.type.to_s
|
174
|
-
user_name = presence.from.resource
|
175
|
-
if user_name.nil?
|
176
|
-
@callbacks[:lobby_presence].process(from_jid, presence_type)
|
177
|
-
else
|
178
|
-
@callbacks[:room_presence].process(from_jid, user_name, presence_type)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
def handle_message(message)
|
183
|
-
if is_invite?(message)
|
184
|
-
handle_invite(message)
|
185
|
-
elsif message.type == :chat
|
186
|
-
handle_private_message(message)
|
187
|
-
elsif message.type == :groupchat
|
188
|
-
handle_group_message(message)
|
189
|
-
elsif message.type == :error
|
190
|
-
handle_error(message)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
def handle_invite(message)
|
195
|
-
room_name = message.children.last.first_element_text('name')
|
196
|
-
topic = message.children.last.first_element_text('topic')
|
197
|
-
room_jid = message.from.strip.to_s
|
198
|
-
user_name = message.from.resource
|
199
|
-
@callbacks[:invite].process(room_jid, user_name, room_name, topic)
|
200
|
-
end
|
201
|
-
|
202
|
-
def handle_private_message(message)
|
203
|
-
user_jid = message.from.strip.to_s
|
204
|
-
message_body = message.body.to_s
|
205
|
-
@callbacks[:private_message].process(user_jid, message_body)
|
206
|
-
end
|
207
|
-
|
208
|
-
def handle_group_message(message)
|
209
|
-
room_jid = message.from.strip.to_s
|
210
|
-
user_name = message.from.resource
|
211
|
-
message_body = message.body.to_s
|
212
|
-
topic = message.subject.to_s
|
213
|
-
@callbacks[:room_message].process(room_jid, user_name, message_body, topic)
|
214
|
-
end
|
215
|
-
|
216
|
-
def handle_error(message)
|
217
|
-
false
|
218
|
-
end
|
219
|
-
|
220
|
-
def is_invite?(message)
|
221
|
-
!message.x.nil? && message.x.kind_of?(XMUCUser) && message.x.first.kind_of?(XMUCUserInvite)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|