AnyEvent::XMPP::IM::Presence - XMPP presence


AnyEvent-XMPP documentation Contained in the AnyEvent-XMPP distribution.

Index


Code Index:

NAME

Top

AnyEvent::XMPP::IM::Presence - XMPP presence

SYNOPSIS

Top

DESCRIPTION

Top

This module represents an XMPP presence. It stores the full JID of the contact, the show value, status value and priority.

AnyEvent::XMPP::IM::Presence is derived from AnyEvent::XMPP::IM::Delayed, use the interface described there to find out whether this presence was delayed.

METHODS

Top

jid

Returns the full JID of this presence.

priority

Returns the priority of this presence.

status_all_lang

Returns all language tags of available status descriptions. See also status.

show

Returns the show value of this presence, which is one of:

   'away', 'chat', 'dnd', 'xa'

or the empty string if the presence is 'available'.

status ([$lang])

Returns the presence description. $lang is optional can should be one of the tags returned by status_all_lang.

make_message (%args)

Returns a AnyEvent::XMPP::IM::Message object with the to field set to this presence full JID.

%args are further arguments to the constructor of the message.

AUTHOR

Top

Robin Redeker, <elmex at ta-sa.org>, JID: <elmex at jabber.org>

COPYRIGHT & LICENSE

Top


AnyEvent-XMPP documentation Contained in the AnyEvent-XMPP distribution.
package AnyEvent::XMPP::IM::Presence;
use strict;
use AnyEvent::XMPP::Util;
use AnyEvent::XMPP::IM::Message;
use AnyEvent::XMPP::IM::Delayed;

our @ISA = qw/AnyEvent::XMPP::IM::Delayed/;

sub new {
   my $this = shift;
   my $class = ref($this) || $this;
   bless { @_ }, $class;
}

sub clone {
   my ($self) = @_;
   my $p = $self->new (connection => $self->{connection});
   $p->{$_} = $self->{$_} for qw/show jid priority status/;
   $p
}

sub update {
   my ($self, $node) = @_;

   $self->fetch_delay_from_node ($node);

   my $type       = $node->attr ('type');
   my ($show)     = $node->find_all ([qw/client show/]);
   my ($priority) = $node->find_all ([qw/client priority/]);

   my %stati;
   $stati{$_->attr ('lang') || ''} = $_->text
      for $node->find_all ([qw/client status/]);

   my $old = $self->clone;

   $self->{show}     = $show     ? $show->text     : undef;
   $self->{priority} = $priority ? $priority->text : undef;
   $self->{status}   = \%stati;
   $self->{type}     = $type;

   $old
}

sub jid { $_[0]->{jid} }

sub priority { $_[0]->{priority} }

sub status_all_lang {
   my ($self, $jid) = @_;
   keys %{$self->{status} || []}
}

sub show { $_[0]->{show} }

sub status {
   my ($self, $lang) = @_;

   if (defined $lang) {
      return $self->{status}->{$lang}
   } else {
      return $self->{status}->{''}
         if defined $self->{status}->{''};
      return $self->{status}->{en}
         if defined $self->{status}->{en};
   }

   undef
}

sub message_class { 'AnyEvent::XMPP::IM::Message' }

sub make_message {
   my ($self, %args) = @_;
   $self->message_class ()->new (
      connection => $self->{connection},
      to         => $self->jid,
      %args
   );
}

sub debug_dump {
   my ($self) = @_;
   printf "   * %-30s [%-5s] (%3d)          {%s}\n",
      $self->jid,
      $self->show     || '',
      $self->priority || 0,
      $self->status   || '',
}

1;