commit:24433ac00c6fbf57a6f869708e7b53a3f1dceb58
author:Chip Black
committer:Chip Black
date:Wed Jul 22 01:51:42 2015 -0500
parents:3ba37ed703feae16d90e4c62ac3d6880dbb8c27a
Adjust messages to work with client; normalize JIDs.
diff --git a/server/ChatNoir/Client.pm b/server/ChatNoir/Client.pm
line changes: +9/-15
index 4b97b18..24fab08
--- a/server/ChatNoir/Client.pm
+++ b/server/ChatNoir/Client.pm
@@ -2,7 +2,7 @@ package ChatNoir::Client;
 use Class::Accessor 'moose-like';
 use AnyEvent::XMPP::IM::Connection;
 
-use ChatNoir::Util qw/pretty_presence/;
+use ChatNoir::Util qw/pretty_presence short_jid/;
 
 use strict;
 use v5.10;
@@ -43,11 +43,11 @@ sub attach_controller_events {
                 if ($self->xmpp && $self->xmpp->is_connected) {
                     # If we're reattaching, check that the new password matches the original
                     if ($password ne $self->password) {
-                        $self->ws_send('logged-out', reason => 'unauthorized');
+                        $self->ws_send('login-failed', reason => 'unauthorized');
                         return;
                     }
                     $self->{active} = 1;
-                    $self->ws_send('logged-in');
+                    $self->ws_send('login-successful');
                     $self->app->log->debug("reattaching " . $self->jid);
                 } else {
                     # Otherwise, attempt a new connection with the given password
@@ -66,7 +66,7 @@ sub attach_controller_events {
                 $self->guard_connected || return;
                 $self->xmpp->disconnect;
                 delete $self->{xmpp};
-                $self->ws_send('logged-out', reason => 'user requested');
+                $self->ws_send('login-failed', reason => 'user requested');
                 $self->app->log->debug($self->jid . " logged out");
             }
             when ('message') {
@@ -104,13 +104,13 @@ sub attach_xmpp_events {
 
     $self->xmpp->reg_cb(
         session_ready => sub {
-            $self->ws_send('logged-in');
+            $self->ws_send('login-successful');
             $self->{active} = 1;
             $self->app->log->debug("Session ready for " . $self->xmpp->jid);
         },
         session_error => sub {
             my ($err) = @_;
-            $self->ws_send('logged-out', reason => 'error', error => $err->string);
+            $self->ws_send('login-failed', reason => 'error', error => $err->string);
             $self->{active} = undef;
             $self->app->log->error("Session error: " . $err->string);
         },
@@ -119,7 +119,7 @@ sub attach_xmpp_events {
             $self->{active} = undef;
             $self->app->log->error($err->string);
             if ($err->string =~ /not-authorized/) {
-                $self->ws_send('logged-out', reason => 'unauthorized');
+                $self->ws_send('login-failed', reason => 'unauthorized');
             }
         },
         roster_update => sub {
@@ -128,7 +128,7 @@ sub attach_xmpp_events {
         presence_update => sub {
             my ($connection, $roster, $contact, $old_presence, $new_presence) = @_;
             $self->ws_send('presence',
-                jid => $new_presence->jid,
+                jid => short_jid($new_presence->jid),
                 status => pretty_presence($new_presence),
                 priority => $new_presence->priority,
             );
@@ -136,14 +136,8 @@ sub attach_xmpp_events {
         message => sub {
             my ($connection, $msg) = @_;
 
-            AnyEvent::XMPP::IM::Message->new(
-                from => $self->jid,
-                to => $msg->from,
-                body => $msg->body,
-            )->send($self->xmpp);
-
             $self->ws_send('message',
-                from => $msg->from,
+                from => short_jid($msg->from),
                 body => $msg->body,
             );
         }

diff --git a/server/ChatNoir/Util.pm b/server/ChatNoir/Util.pm
line changes: +8/-1
index 8da814b..3cc414d
--- a/server/ChatNoir/Util.pm
+++ b/server/ChatNoir/Util.pm
@@ -1,6 +1,6 @@
 package ChatNoir::Util;
 use Exporter 'import';
-@EXPORT_OK = qw/pretty_presence/;
+@EXPORT_OK = qw/pretty_presence short_jid/;
 
 sub pretty_presence {
     my ($presence) = @_;
@@ -9,4 +9,11 @@ sub pretty_presence {
             "offline");
 }
 
+sub short_jid {
+    my ($jid) = @_;
+
+    $jid =~ s'/.*$'';
+    return $jid;
+}
+
 1;