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


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

Index


Code Index:

NAME

Top

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

SYNOPSIS

Top

DESCRIPTION

Top

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

METHODS

Top

new (%args)
nick

The nickname of the MUC user.

affiliation

The affiliation of the user.

role

The role of the user.

room

The AnyEvent::XMPP::Ext::MUD::Room this user is in.

in_room_jid

The room local JID of the user.

real_jid

The real JID of the user, this might be undef if it is an anonymous room.

make_message (%args)

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

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

did_create_room

This method returns true if the user created a room.

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::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/;

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}
}

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

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

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

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

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

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

sub message_class { 'AnyEvent::XMPP::Ext::MUC::Message' }


sub did_create_room { $_[0]->{stati}->{'201'} }

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

sub is_in_nick_change {
   $_[0]->{stati}->{'303'}
}

sub nick_change_old_nick {
   $_[0]->{old_nick}
}

1;