Changeset 2ce12de


Ignore:
Timestamp:
Jul 28, 2009, 10:53:47 PM (15 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
57ba9f1
Parents:
c1d9441
git-author:
Alejandro R. Sedeño <asedeno@mit.edu> (07/28/09 22:45:22)
git-committer:
Alejandro R. Sedeño <asedeno@mit.edu> (07/28/09 22:53:47)
Message:
Tab Completion for jwrite
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm

    r004d683 r2ce12de  
    1919use BarnOwl::Module::Jabber::Connection;
    2020use BarnOwl::Module::Jabber::ConnectionManager;
     21use BarnOwl::Completion::Util qw(complete_flags);
    2122
    2223use Authen::SASL qw(Perl);
     
    6263$conn ||= BarnOwl::Module::Jabber::ConnectionManager->new;
    6364our %vars;
     65our %completion_jids;
    6466
    6567sub onStart {
     
    164166
    165167    $blistStr .= sprintf '%-15s %s', $name, $buddy->GetJID();
     168    $completion_jids{$name} = 1;
     169    $completion_jids{$buddy->GetJID()} = 1;
    166170
    167171    if ($res) {
     
    427431                BarnOwl::error( "Error in connect: " . join( " ", @result ) );
    428432            } else {
    429                 $conn->getRosterFromJID($jidStr)->fetch();
     433                my $roster = $conn->getRosterFromJID($jidStr);
     434                $roster->fetch();
    430435                $client->PresenceSend( priority => 1 );
    431436                my $fullJid = $client->{SESSION}->{FULLJID} || $jidStr;
     
    437442                #queue_admin_msg("Connected to jabber as $fullJid ($client->{fileno})");
    438443                BarnOwl::add_dispatch($client->{fileno}, sub { $client->OwlProcess() });
     444
     445                # populate completion from roster.
     446                for my $buddy ( $roster->jids('all') ) {
     447                    my %jq  = $roster->query($buddy);
     448                    my $name = $jq{name} || $buddy->GetUserID();
     449                    $completion_jids{$name} = 1;
     450                    $completion_jids{$buddy->GetJID()} = 1;
     451                }
    439452            }
    440453        }
     
    647660                                                   MaxChars => 0
    648661                                                  });
     662    $completion_jids{$muc} = 1;
    649663    return;
    650664}
     
    701715
    702716    my $presence = "JIDs present in " . $m->BaseJID;
     717    $completion_jids{$m->BaseJID} = 1;
    703718    if($m->Anonymous) {
    704719        $presence .= " [anonymous MUC]";
     
    875890    $name = "" unless (1 == scalar(@ARGV));
    876891
     892    $completion_jids{$baseJID} = 1;
     893    $completion_jids{$name} = 1 if $name;
     894
    877895    foreach my $to (@ARGV) {
    878896        my %jq  = $roster->query($to);
     
    10571075
    10581076sub process_presence_available {
    1059     return unless (BarnOwl::getvar('jabber:show_logins') eq 'on');
    10601077    my ( $sid, $p ) = @_;
    10611078    my $from = $p->GetFrom('jid')->GetJID('base');
     1079    $completion_jids{$from} = 1;
     1080    return unless (BarnOwl::getvar('jabber:show_logins') eq 'on');
    10621081    my $to = $p->GetTo();
    10631082    my $type = $p->GetType();
     
    12091228              if ($connection->FindMUC(jid => $to));
    12101229        }
     1230
     1231        # Populate completion.
     1232        if ($dir eq 'in') {
     1233            $completion_jids{ $props{sender} }= 1;
     1234        }
     1235        else {
     1236            $completion_jids{ $props{recipient} } = 1;
     1237        }
    12111238    }
    12121239    elsif ( $jtype eq 'groupchat' ) {
    12131240        my $nick = $props{nick} = $from->GetResource();
    12141241        my $room = $props{room} = $from->GetJID('base');
     1242        $completion_jids{$room} = 1;
    12151243
    12161244        $props{sender} = $nick || $room;
     
    13841412}
    13851413
     1414################################################################################
     1415### Completion
     1416
     1417sub complete_user_or_muc { return keys %completion_jids; }
     1418sub complete_account { return $conn->getJIDs(); }
     1419
     1420sub complete_jwrite {
     1421    my $ctx = shift;
     1422    return complete_flags($ctx,
     1423                          [qw(-t -i -s)],
     1424                          {
     1425                              "-a" => \&complete_account,
     1426                          },
     1427                          \&complete_user_or_muc }
     1428        );
     1429}
     1430
     1431BarnOwl::Completion::register_completer(jwrite => sub { BarnOwl::Module::Jabber::complete_jwrite(@_));
     1432
    138614331;
Note: See TracChangeset for help on using the changeset viewer.