Chatroom invitations

Clive Holloway clive.holloway at gmail.com
Mon Oct 29 22:31:53 UTC 2007


I *think* I've got this written correctly, but would appreciate a
style commentary before I go further.

This snippet allows chatroom members to send invites to other users.

I've added this code to MUC.pm, line 97:

        # chatroom invites
        if ($stanza->isa("DJabberd::Message")
            && $stanza->{children}[0]{element} eq 'x'
            && $stanza->{children}[0]{children}[0]{element} eq 'invite') {

            my $room = $stanza->{attrs}{"{}to"};
            my $from = $stanza->{attrs}{"{}from"};

            my $x = $stanza->{children}[0];
            my $invite = $x->{children}[0];
            my $invited = $invite->{attrs}{"{}to"};

            # rebuild stanza for delivery
            $stanza->set_to($invited);
            $stanza->set_from($room);
            $invite->set_attr( "{}from" => $from );

            # add conference xmlns to stanza
            my $jabber_x_conference =
DJabberd::XMLElement->new("",'x', { xmlns => "jabber:x:conference",
jid => $room });
            $stanza->push_child($jabber_x_conference);
            $logger->debug("$from invited user $invited to chatroom $room");
        }

---------------------------------

Is there a cleaner way of calling attributes like this?

$stanza->{children}[0]{element}

(etc), because if there is, it's eluded me so far.

If that looks correct, can someone commit it. If it doesn't can
someone correct me?

cLive ;-)


More information about the Djabberd mailing list