Chatroom invitations

Martin Atkins mart at
Wed Nov 7 20:27:11 UTC 2007

Clive Holloway wrote:
> This snippet allows chatroom members to send invites to other users.
>         if ($stanza->isa("DJabberd::Message")
>             && $stanza->{children}[0]{element} eq 'x'
>             && $stanza->{children}[0]{children}[0]{element} eq 'invite') {

This seems risky, since I believe <message> stanzas can come with a 
<body> in them for fallback in clients without MUC support, like this:

<message ...>
     <subject>Conference Invitation</subject>
     <body>Please join me in the conference room "blah"
     <x xmlns="jabber:x:conference">
         <invite ... />

Probably should also verify the namespace of that "x" element, too. The 
MUC spec seems to suggest that it should be:

You can support this succinctly as follows:

     use List::Util qw(first);

     # ...

     my $invite_elem = first {
         $_->element eq "{}x"
     } $stanza->children_elements;

DJabberd::Bot uses this technique to extract "body" and 
"{}html" elements from incoming messages.

> Is there a cleaner way of calling attributes like this?
> $stanza->{children}[0]{element}

I believe that you could also write this as 
$stanza->first_element->element, but this will return the name qualified 
with its namespace as in the example above, rather than the bare local 
name as in your example.

See DJabberd::XMLElement for further accessor methods.

More information about the Djabberd mailing list