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;
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
$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') {
$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);
},
$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 {
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,
);
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,
);
}