AnyEvent::XMPP::Ext::MUC::Message - A room message


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

Index


Code Index:

NAME

Top

AnyEvent::XMPP::Ext::MUC::Message - A room message

SYNOPSIS

Top

DESCRIPTION

Top

This message represents a message from a MUC room. It is derived from AnyEvent::XMPP::IM::Message. (You can use the methods from that class to access it for example).

Also the methods like eg. make_reply return a AnyEvent::XMPP::Ext::MUC::Message.

METHODS

Top

new (%args)

This constructor takes the same arguments that the constructor for AnyEvent::XMPP::IM::Message takes.

room

Returns the chatroom in which' context this message was sent.

send ([$room])

This method send this message. If $room is defined it will set the connection of this message object before it is send.

make_reply ([$msg])

This method returns a new instance of AnyEvent::XMPP::Ext::MUC::Message. The destination address, connection and type of the returned message object will be set.

If $msg is defined and an instance of AnyEvent::XMPP::Ext::MUC::Message the destination address, connection and type of $msg will be changed and this method will not return a new instance of AnyEvent::XMPP::Ext::MUC::Message.

If $self is a message of type 'groupchat' the to attribute will be set to the bare JID of the room for the reply.

from_nick

This method returns the nickname of the source of this message.

is_private

This method returns true when the message was not directed to the room, but privately to you.

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::Message;
use strict;
use AnyEvent::XMPP::Namespaces qw/xmpp_ns/;
use AnyEvent::XMPP::Util qw/bare_jid res_jid/;
use AnyEvent::XMPP::IM::Message;

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

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

sub from_node {
   my ($self, $node) = @_;
   $self->SUPER::from_node ($node);
}

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

sub send {
   my ($self, $room) = @_;

   if ($room) {
      $self->{room} = $room;
      $self->{connection} = $self->{room}->{connection};
   }

   my @add;
   push @add, (subject => $self->{subjects})
      if %{$self->{subjects} || {}};
   push @add, (thread => $self->thread)
      if $self->thread;
   push @add, (from => $self->from)
      if defined $self->from;

   $self->{connection}->send_message (
      $self->to, $self->type, undef,
      body => $self->{bodies},
      @add
   );
}

sub make_reply {
   my ($self, $msg) = @_;

   unless ($msg) {
      $msg = $self->new (room => $self->room);
   }

   $msg->{connection} = $self->{connection};
   $msg->{room}       = $self->{room};

   if ($self->type eq 'groupchat') {
      $msg->to (bare_jid $self->from);

   } else {
      $msg->to ($self->from);
   }
   $msg->type ($self->type);

   $msg
}

sub from_nick {
   my ($self) = @_;
   res_jid ($self->from)
}

sub is_private {
   my ($self) = @_;
   $self->type ne 'groupchat'
}

1;