AnyEvent-XMPP
view release on metacpan or search on metacpan
lib/AnyEvent/XMPP/Ext/MUC/Room.pm view on Meta::CPAN
my ($n, $e) = @_;
if ($e) {
$cb->(undef, $e);
} else {
$cb->(1, undef);
}
},
to => $self->jid
);
}
sub message_class { 'AnyEvent::XMPP::Ext::MUC::Message' }
=item B<make_message (%args)>
This method constructs a L<AnyEvent::XMPP::Ext::MUC::Message> with
a connection to this room.
C<%args> are further arguments for the constructor of L<AnyEvent::XMPP::Ext::MUC::Message>.
The default C<to> argument for the message is the room and the
C<type> will be 'groupchat'.
=cut
sub make_message {
my ($self, %args) = @_;
$self->message_class ()->new (
room => $self,
to => $self->jid,
type => 'groupchat',
%args
)
}
=item B<send_part ($msg, $cb, $timeout)>
This lets you part the room, C<$msg> is an optional part message
and can be undef if no custom message should be generated.
C<$cb> is called when we successfully left the room or after
C<$timeout> seconds. The default for C<$timeout> is 60.
The first argument to the call of C<$cb> will be undef if
we successfully parted, or a true value when the timeout hit.
Even if we timeout we consider ourself parted (and a 'leave' event
is generated).
=cut
sub send_part {
my ($self, $msg, $cb, $timeout) = @_;
$self->check_online or return;
$timeout ||= 60;
my $con = $self->{connection};
my $timeouted = 0;
if ($cb) {
$self->{_part_timeout} =
AnyEvent->timer (after => $timeout, cb => sub {
delete $self->{_part_timeout};
$timeouted = 1;
$self->event ('leave', $self->get_me);
});
$self->{muc}->reg_cb (ext_after_leave => sub {
my ($muc, $room) = @_;
return unless cmp_jid ($room->nick_jid, $self->nick_jid);
delete $self->{_part_timeout};
$cb->($timeouted) if $cb;
$muc->unreg_me;
});
}
$con->send_presence (
'unavailable', undef,
(defined $msg ? (status => $msg) : ()),
to => $self->{nick_jid}
);
}
=item B<users>
Returns a list of L<AnyEvent::XMPP::Ext::MUC::User> objects
which are in this room.
=cut
sub users {
my ($self) = @_;
values %{$self->{users}}
}
=item B<jid>
Returns the bare JID of this room.
=cut
sub jid { $_[0]->{jid} }
=item B<nick_jid>
Returns the full JID of yourself in the room.
=cut
sub nick_jid { $_[0]->{nick_jid} }
=item B<is_connected>
Returns true if this room is still connected (but maybe not joined (yet)).
=cut
sub is_connected {
my ($self) = @_;
$self->{muc} && $self->{connection} && $self->{connection}->is_connected
}
( run in 1.813 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )