AnyEvent-XMPP
view release on metacpan or search on metacpan
lib/AnyEvent/XMPP/IM/Contact.pm view on Meta::CPAN
unless ($error) { $con = $self }
$cb->($con, $error) if $cb
}
);
}
=item B<send_subscribe ()>
This method sends this contact a subscription request.
=cut
sub send_subscribe {
my ($self) = @_;
$self->{connection}->send_presence ('subscribe', undef, to => $self->jid);
}
=item B<send_subscribed ()>
This method accepts a contact's subscription request.
=cut
sub send_subscribed {
my ($self) = @_;
$self->{connection}->send_presence ('subscribed', undef, to => $self->jid);
}
=item B<send_unsubscribe ()>
This method sends this contact a unsubscription request.
=cut
sub send_unsubscribe {
my ($self) = @_;
$self->{connection}->send_presence ('unsubscribe', undef, to => $self->jid);
}
=item B<send_unsubscribed ()>
This method sends this contact a unsubscription request which unsubscribes
ones own presence from him (he wont get any further presence from us).
=cut
sub send_unsubscribed {
my ($self) = @_;
$self->{connection}->send_presence ('unsubscribed', undef, to => $self->jid);
}
=item B<update ($item)>
This method wants a L<AnyEvent::XMPP::Node> in C<$item> which
should be a roster item received from the server. The method will
update the contact accordingly and return it self.
=cut
sub update {
my ($self, $item) = @_;
my ($jid, $name, $subscription, $ask) =
(
$item->attr ('jid'),
$item->attr ('name'),
$item->attr ('subscription'),
$item->attr ('ask')
);
$self->{name} = $name;
$self->{subscription} = $subscription;
$self->{groups} = [ map { $_->text } $item->find_all ([qw/roster group/]) ];
$self->{ask} = $ask;
$self
}
=item B<update_presence ($presence)>
This method updates the presence of contacts on the roster.
C<$presence> must be a L<AnyEvent::XMPP::Node> object and should be
a presence packet.
=cut
sub update_presence {
my ($self, $node) = @_;
my $type = $node->attr ('type');
my $jid = $node->attr ('from');
# XXX: should check whether C<$jid> is nice JID.
$self->touch_presence ($jid);
my $old;
my $new;
if ($type eq 'unavailable') {
$old = $self->remove_presence ($jid);
} else {
$old = $self->touch_presence ($jid)->update ($node);
$new = $self->touch_presence ($jid);
}
($self, $old, $new)
}
sub remove_presence {
my ($self, $jid) = @_;
my $sjid = AnyEvent::XMPP::Util::stringprep_jid ($jid);
delete $self->{presences}->{$sjid}
}
sub touch_presence {
my ($self, $jid) = @_;
my $sjid = AnyEvent::XMPP::Util::stringprep_jid ($jid);
unless (exists $self->{presences}->{$sjid}) {
$self->{presences}->{$sjid} =
AnyEvent::XMPP::IM::Presence->new (connection => $self->{connection}, jid => $jid);
}
$self->{presences}->{$sjid}
}
=item B<get_presence ($jid)>
This method returns a presence of this contact if
it is available. The return value is an instance of L<AnyEvent::XMPP::IM::Presence>
or undef if no such presence exists.
=cut
sub get_presence {
my ($self, $jid) = @_;
my $sjid = AnyEvent::XMPP::Util::stringprep_jid ($jid);
$self->{presences}->{$sjid}
}
=item B<get_presences>
Returns all presences of this contact in form of
L<AnyEvent::XMPP::IM::Presence> objects.
=cut
sub get_presences { values %{$_[0]->{presences}} }
( run in 1.069 second using v1.01-cache-2.11-cpan-39bf76dae61 )