[707] in BarnOwl Developers
[D-O-H] r764 - in trunk/owl/perl/modules/Jabber/lib: BarnOwl/Module BarnOwl/Module/Jabber Net/Jabber
daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:08:53 2009
Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: nelhage@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Wed, 12 Sep 2007 22:46:18 -0400 (EDT)
Author: nelhage
Date: 2007-09-12 22:46:17 -0400 (Wed, 12 Sep 2007)
New Revision: 764
Modified:
trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm
trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm
trunk/owl/perl/modules/Jabber/lib/Net/Jabber/MUC.pm
Log:
Show full JIDs for users in non-anonymous JIDs in :jmuc presence. closes #24
Modified: trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm
===================================================================
--- trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm 2007-09-13 01:54:51 UTC (rev 763)
+++ trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm 2007-09-13 02:46:17 UTC (rev 764)
@@ -51,6 +51,9 @@
Leave a MUC. The MUC is specified in the same form as L</FindMUC>
+Returns true if successful, false if this connection was not in the
+named MUC.
+
=cut
sub MUCLeave {
@@ -60,6 +63,7 @@
$muc->Leave();
$self->{_BARNOWL_MUCS} = [grep {$_->BaseJID ne $muc->BaseJID} $self->MUCs];
+ return 1;
}
=head2 FindMUC ARGS
Modified: trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm
===================================================================
--- trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm 2007-09-13 01:54:51 UTC (rev 763)
+++ trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm 2007-09-13 02:46:17 UTC (rev 764)
@@ -600,8 +600,11 @@
$muc = shift @args if scalar @args;
die("Usage: jmuc part MUC [-a account]") unless $muc;
- $conn->getConnectionFromJID($jid)->MUCLeave(JID => $muc);
- queue_admin_msg("$jid has left $muc.");
+ if($conn->getConnectionFromJID($jid)->MUCLeave(JID => $muc)) {
+ queue_admin_msg("$jid has left $muc.");
+ } else {
+ die("Error: Not joined to $muc");
+ }
}
sub jmuc_invite {
@@ -640,10 +643,27 @@
sub jmuc_presence_single {
my $m = shift;
my @jids = $m->Presence();
- return "JIDs present in " . $m->BaseJID . "\n\t"
- . join("\n\t", map {$_->GetResource}@jids) . "\n";
+
+ my $presence = "JIDs present in " . $m->BaseJID;
+ if($m->Anonymous) {
+ $presence .= " [anonymous MUC]";
+ }
+ $presence .= "\n\t";
+ $presence .= join("\n\t", map {pp_jid($m, $_);} @jids) . "\n";
+ return $presence;
}
+sub pp_jid {
+ my ($m, $jid) = @_;
+ my $nick = $jid->GetResource;
+ my $full = $m->GetFullJID($jid);
+ if($full && $full ne $nick) {
+ return "$nick ($full)";
+ } else {
+ return "$nick";
+ }
+}
+
sub jmuc_presence {
my ( $jid, $muc, @args ) = @_;
Modified: trunk/owl/perl/modules/Jabber/lib/Net/Jabber/MUC.pm
===================================================================
--- trunk/owl/perl/modules/Jabber/lib/Net/Jabber/MUC.pm 2007-09-13 01:54:51 UTC (rev 763)
+++ trunk/owl/perl/modules/Jabber/lib/Net/Jabber/MUC.pm 2007-09-13 02:46:17 UTC (rev 764)
@@ -63,6 +63,7 @@
$self->{CONNECTION} = $args{connection};
$self->{JID} = $args{jid};
$self->{PRESENCE} = { };
+ $self->{ANONYMOUS} = 1;
bless($self, $class);
@@ -187,7 +188,15 @@
if($type eq 'unavailable') {
delete $self->{PRESENCE}->{$from->GetJID('full')};
} elsif($type eq 'available') {
- $self->{PRESENCE}->{$from->GetJID('full')} = $from;
+ $self->{PRESENCE}->{$from->GetJID('full')} = {ROOMNICK => $from};
+ my $x = $presence->GetX('http://jabber.org/protocol/muc#user');
+ if($x && $x->DefinedItem()) {
+ my $item = $x->GetItem();
+ if($item->DefinedJID()) {
+ $self->{PRESENCE}->{$from->GetJID('full')}->{FULLJID} = $item->GetJID();
+ $self->{ANONYMOUS} = 0;
+ }
+ }
}
}
@@ -206,6 +215,24 @@
return exists $self->{PRESENCE}->{$jid};
}
+=head2 GetFullJID roomjid
+
+Given the roomnick of a user in the MUC, return their full NIC if the
+MUC makes it available. If the MUC is anonymous or the user does not
+exist in the MUC, return undef.
+
+=cut
+
+sub GetFullJID {
+ my $self = shift;
+ my $jid = shift;
+
+ $jid = $jid->GetJID('full') if UNIVERSAL::isa($jid, 'Net::Jabber::JID');
+ my $pres = $self->{PRESENCE}->{$jid};
+ return unless $pres;
+ return $pres->{FULLJID};
+}
+
=head2 Presence
Returns a list of JIDS in the MUC, as Net::Jabber::JID objects
@@ -214,7 +241,18 @@
sub Presence {
my $self = shift;
- return values %{$self->{PRESENCE}};
+ return map {$_->{ROOMNICK}} values %{$self->{PRESENCE}};
}
+=head2 Anonymous
+
+Returns true if the MUC is anonymous (hides participants real JIDs)
+
+=cut
+
+sub Anonymous {
+ my $self = shift;
+ return $self->{ANONYMOUS};
+}
+
1;