[2925] in BarnOwl Developers
[PATCH v2] Sort the output of :irc-names
daemon@ATHENA.MIT.EDU (Nelson Elhage)
Wed Feb 23 21:12:41 2011
From: Nelson Elhage <nelhage@ksplice.com>
To: barnowl-dev@MIT.EDU
Cc: Nelson Elhage <nelhage@MIT.EDU>
Date: Wed, 23 Feb 2011 21:12:35 -0500
In-Reply-To: <alpine.DEB.2.02.1102232107510.10886@dr-wily.mit.edu>
---
This should fix the "unitialized" warnings.
.../IRC/lib/BarnOwl/Module/IRC/Connection.pm | 15 ++++++++++++++-
1 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm b/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
index ba4f0c3..f15644d 100644
--- a/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
+++ b/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
@@ -259,11 +259,24 @@ sub on_namreply {
$self->names_tmp([@{$self->names_tmp}, split(' ', [$evt->args]->[3])]);
}
+sub cmp_user {
+ my ($lhs, $rhs) = (@_);
+ my ($sigil_l) = ($lhs =~ m{^[+@]}g);
+ my ($sigil_r) = ($rhs =~ m{^[+@]}g);
+ my %rank = (
+ '@' => 2,
+ '+' => 1,
+ '' => -1
+ );
+ return (($rank{$sigil_r||""}) <=> ($rank{$sigil_l||""})) ||
+ $rhs cmp $lhs;
+}
+
sub on_endofnames {
my ($self, $evt) = @_;
return unless $self->names_tmp;
my $names = BarnOwl::Style::boldify("Members of " . [$evt->args]->[1] . ":\n");
- for my $name (@{$self->names_tmp}) {
+ for my $name (sort {cmp_user($a, $b)} @{$self->names_tmp}) {
$names .= " $name\n";
}
BarnOwl::popless_ztext($names);
--
1.7.2.43.g36c08.dirty