Ignore:
Timestamp:
Dec 22, 2009, 6:37:38 PM (10 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
a2a5236
Parents:
6396c1e
git-author:
Alejandro R. Sedeño <asedeno@mit.edu> (12/22/09 01:15:39)
git-committer:
Alejandro R. Sedeño <asedeno@mit.edu> (12/22/09 18:37:38)
Message:
Factor out some common jabber connect-time code

Call it upon successful connection and reconnection.
File:
1 edited

Legend:

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

    r8590774 r0dbb7d2  
    163163}
    164164
     165=head2 OnConnect
     166
     167Actions to perform on connecting and reconnecting.
     168
     169=cut
     170
     171sub onConnect {
     172    my $self = shift;
     173    my $conn = shift;
     174    my $jidStr = shift;
     175
     176    my $fullJid = $self->{SESSION}->{FULLJID} || $jidStr;
     177    my $roster = $conn->getRosterFromJID($jidStr);
     178
     179    $roster->fetch();
     180    $self->PresenceSend( priority => 1 );
     181
     182    $conn->renameConnection($jidStr, $fullJid);
     183    BarnOwl::admin_message('Jabber', "Connected to jabber as $fullJid");
     184    # The remove_io_dispatch() method is called from the
     185    # ConnectionManager's removeConnection() method.
     186    $self->{fileno} = $self->getSocket()->fileno();
     187    BarnOwl::add_io_dispatch($self->{fileno}, 'r', sub { $self->OwlProcess($fullJid) });
     188
     189    # populate completion from roster.
     190    for my $buddy ( $roster->jids('all') ) {
     191        my %jq  = $roster->query($buddy);
     192        my $name = $jq{name} || $buddy->GetUserID();
     193        $BarnOwl::Module::Jabber::completion_jids{$name} = 1;
     194        $BarnOwl::Module::Jabber::completion_jids{$buddy->GetJID()} = 1;
     195    }
     196    $BarnOwl::Module::Jabber::vars{idletime} |= BarnOwl::getidletime();
     197    unless (exists $BarnOwl::Module::Jabber::vars{keepAliveTimer}) {
     198        $BarnOwl::Module::Jabber::vars{keepAliveTimer} =
     199            BarnOwl::Timer->new({
     200                'after' => 5,
     201                'interval' => 5,
     202                'cb' => sub { BarnOwl::Module::Jabber::do_keep_alive_and_auto_away(@_) }
     203                                });
     204    }
     205}
     206
    165207=head1 SEE ALSO
    166208
Note: See TracChangeset for help on using the changeset viewer.