aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/notifiers
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-09-16 12:45:02 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-09-16 12:45:02 +0100
commitf63d7076e52a8844f1cfe43e57330687d88e83b6 (patch)
treed22e5e9b25cb9bd4fbb2325231bacad5404f1cd0 /lib/mauve/notifiers
parentef42591e391efeee625ac139ed6e9c07a3c38eb0 (diff)
Robustificated the XMPP notifier not to crash mauve.
Diffstat (limited to 'lib/mauve/notifiers')
-rw-r--r--lib/mauve/notifiers/xmpp.rb22
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/mauve/notifiers/xmpp.rb b/lib/mauve/notifiers/xmpp.rb
index 77d6236..5ffe8f4 100644
--- a/lib/mauve/notifiers/xmpp.rb
+++ b/lib/mauve/notifiers/xmpp.rb
@@ -152,6 +152,7 @@ module Mauve
rescue StandardError => ex
logger.error "Connect failed #{ex.to_s}"
logger.debug ex.backtrace.join("\n")
+ self.close
@client = nil
end
@@ -173,6 +174,7 @@ module Mauve
end
@client.close!
end
+ @client = nil
end
def ready?
@@ -232,6 +234,8 @@ module Mauve
# Sends a message to the destionation.
def send_message(jid, msg, html_msg=nil, msg_type=:chat)
+ return false unless self.ready?
+
jid = JID.new(jid) unless jid.is_a?(JID)
message = Message.new(jid)
@@ -277,7 +281,11 @@ module Mauve
#
# Joins a chat, and returns the stripped JID of the chat joined.
#
- def join_muc(jid, password=nil)
+ def join_muc(jid, password=nil)
+ self.connect unless self.ready?
+
+ return unless self.ready?
+
if jid.is_a?(String) and jid =~ /^muc:(.*)/
jid = JID.new($1)
end
@@ -328,7 +336,7 @@ module Mauve
#
def is_muc?(jid)
(jid.is_a?(JID) and @mucs.keys.include?(jid.strip)) or
- (jid.is_a?(String) and jid =~ /^muc:(.*)/)
+ (jid.to_s =~ /^muc:(.*)/)
#
# It would be nice to use service discovery to determin this, but it
@@ -354,6 +362,10 @@ module Mauve
# is necessary to ensure both are true.
#
def ensure_roster_and_subscription!(jid)
+ self.connect unless self.ready?
+
+ return unless self.ready?
+
return jid if is_muc?(jid)
jid = JID.new(jid) unless jid.is_a?(JID)
@@ -643,11 +655,13 @@ EOF
# is met, false otherwise. Note that if the alerter can't see the alertee's
# presence, only 'unknown' will match - generally, you'll want [:online, :unknown]
def check_jid_has_presence(jid, presence_or_presences = [:online, :unknown])
+ return true if is_muc?(jid)
+
jid = JID.new(jid) unless jid.is_a?(JID)
- return true if is_muc?(jid)
+ self.connect unless self.ready?
- reconnect unless @client
+ return false unless self.ready?
presences = [presence_or_presences].flatten
roster_item = @roster.find(jid)