AnyEvent-XMPP

 view release on metacpan or  search on metacpan

lib/AnyEvent/XMPP/Ext/MUC/User.pm  view on Meta::CPAN

package AnyEvent::XMPP::Ext::MUC::User;
use strict;
use AnyEvent::XMPP::Namespaces qw/xmpp_ns/;
use AnyEvent::XMPP::IM::Presence;
use AnyEvent::XMPP::Ext::MUC::Message;
use AnyEvent::XMPP::Util qw/split_jid/;

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

=head1 NAME

AnyEvent::XMPP::Ext::MUC::User - User class

=head1 SYNOPSIS

=head1 DESCRIPTION

This module represents a user (occupant) handle for a MUC.
This class is derived from L<AnyEvent::XMPP::Presence> as a user has
also a presence within a room.

=head1 METHODS

=over 4

=item B<new (%args)>

=cut

sub new {
   my $this = shift;
   my $class = ref($this) || $this;
   my $self = $class->SUPER::new (@_);
   $self->init;
   $self
}

sub update {
   my ($self, $node) = @_;
   $self->SUPER::update ($node);
   my ($xuser) = $node->find_all ([qw/muc_user x/]);
   my $from = $node->attr ('from');
   my ($room, $srv, $nick) = split_jid ($from);

   my ($aff, $role, $stati, $jid, $new_nick);
   $self->{stati} ||= {};
   $stati = $self->{stati};

   delete $self->{stati}->{'303'}; # nick change

   if ($xuser) {
      if (my ($item) = $xuser->find_all ([qw/muc_user item/])) {
         $aff      = $item->attr ('affiliation');
         $role     = $item->attr ('role');
         $jid      = $item->attr ('jid');
         $new_nick = $item->attr ('nick');
      }

      for ($xuser->find_all ([qw/muc_user status/])) {
         $stati->{$_->attr ('code')}++;
      }
   }

   $self->{jid}         = $from;
   $self->{nick}        = $nick;
   $self->{affiliation} = $aff;
   $self->{real_jid}    = $jid if defined $jid && $jid ne '';
   $self->{role}        = $role;

   if ($self->is_in_nick_change) {
      $self->{old_nick} = $self->{nick};
      $self->{nick} = $new_nick;
   }
}

sub init {
   my ($self) = @_;
   $self->{connection} = $self->{room}->{muc}->{connection}
}

=item B<nick>

The nickname of the MUC user.

=cut

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

=item B<affiliation>

The affiliation of the user.

=cut

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

=item B<role>



( run in 2.147 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )