nuke unneeded comments
[scpubgit/Clifton.git] / lib / App / Clifton / Tower / Jabber.pm
index 1798f46..c55bbb1 100644 (file)
@@ -27,6 +27,8 @@ has chain_set => (
   default => sub { ChainSet->new }
 );
 
+has full_jid => (is => 'rw');
+
 sub _build_xmpp_client {
   my ($self) = @_;
   $self->_login_xmpp_client($self->_new_child(XMPP_Client, {
@@ -50,9 +52,19 @@ sub handle_message {
 
   my $me = $self->jabber_config->user;
 
+  return log_info {
+    "Received error message"
+  } if $msg->type eq 'error';
+
   return log_debug {
     "Received message for ${\$msg->to} instead of $me - ignoring"
-  } unless $msg->to eq $me;
+  } unless $msg->to =~ /^\Q$me/; # may be foo@gmail.com or .../gsklgsh
+
+  if (!$self->full_jid
+      or ($self->full_jid !~ m{/} and $msg->to =~ m{/})
+    ) {
+    $self->full_jid($msg->to); # need foo@gmail.com/skldshgsdg here
+  }
 
   (my $from = $msg->from) =~ s/\/.*//;
 
@@ -93,6 +105,8 @@ sub handle_message {
 
 sub send_xmpp_message {
   my ($self, $args) = @_;
+  s/&/&amp;/g, s/"/&quot;/g, s/</&lt;/g, s/>/&gt;/g for $args->{body};
+  $args->{from} = $self->full_jid;
   $self->xmpp_client->compose(%$args)->send;
 }
 
@@ -110,19 +124,3 @@ sub start_chain_for {
 }
 
 1;
-
-# and later
-
-# package App::Clifton::Tower::IRC;
-
-# has irc_client
-
-# has irc_server_name
-
-# has user_config
-
-# has chain_set
-
-# package App::Clifton::Chain
-
-#