| 1 | # | ||
| 2 | # $Id: Conversation.pm,v 0.16 2003/08/07 00:01:59 lawrence Exp $ | ||
| 3 | # | ||
| 4 | |||
| 5 | package Net::Msmgr::Conversation; | ||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | use Net::Msmgr::Object; | ||
| 9 | our @ISA = qw (Net::Msmgr::Object); | ||
| 10 | |||
| 11 | sub _fields | ||
| 12 | { | ||
| 13 | return shift->SUPER::_fields,( | ||
| 14 | session => undef, | ||
| 15 | switchboard => undef, | ||
| 16 | email => {}, | ||
| 17 | _state => 0, | ||
| 18 | ); | ||
| 19 | } | ||
| 20 | |||
| 21 | use constant Disconnected => 0; | ||
| 22 | use constant Connected => 1; | ||
| 23 | |||
| 24 | =pod | ||
| 25 | |||
| 26 | =head1 NAME | ||
| 27 | |||
| 28 | Net::Msmgr::Conversation -- A user-friendly manager for the myriad ways we can talk to other users | ||
| 29 | |||
| 30 | =head1 SYNOPSIS | ||
| 31 | |||
| 32 | =head1 DESCRIPTION | ||
| 33 | |||
| 34 | =head1 CONSTRUCTION OPTIONS | ||
| 35 | |||
| 36 | =head1 PUBLIC METHODS | ||
| 37 | |||
| 38 | =over | ||
| 39 | |||
| 40 | =item $conversation->shutdown(); | ||
| 41 | |||
| 42 | Terminate the session, close off switchboard connection | ||
| 43 | |||
| 44 | =cut | ||
| 45 | |||
| 46 | sub invite( $$ ) | ||
| 47 | { | ||
| 48 | my ($self, $email ) = @_; | ||
| 49 | { | ||
| 50 | my $command = new Net::Msmgr::Command | ||
| 51 | (type => Net::Msmgr::Command::Normal, | ||
| 52 | cmd => 'CAL', | ||
| 53 | params => [ $email ] ); | ||
| 54 | $command->send($self->switchboard); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | |||
| 59 | sub send_message( $$;$ ) | ||
| 60 | { | ||
| 61 | my ($self, $text) = splice(@_,0,2); | ||
| 62 | my $ack = shift || 'N'; | ||
| 63 | Net::Msmgr::Command->new(type => Net::Msmgr::Command::Payload, | ||
| 64 | cmd => 'MSG', | ||
| 65 | params => [ $ack ] , | ||
| 66 | body => $text)->send($self->switchboard); | ||
| 67 | } | ||
| 68 | |||
| 69 | sub shutdown( $ ) | ||
| 70 | { | ||
| 71 | my ($self) = @_; | ||
| 72 | $self->{switchboard}->shutdown if $self->{switchboard}; | ||
| 73 | $self->{email} = {}; | ||
| 74 | $self->{_state} = Disconnected; | ||
| 75 | } | ||
| 76 | |||
| 77 | =pod | ||
| 78 | |||
| 79 | =item $conversation->roster(); | ||
| 80 | |||
| 81 | Return a list of email addresses for people connected to this | ||
| 82 | conversation | ||
| 83 | |||
| 84 | =cut | ||
| 85 | |||
| 86 | sub roster( $ ) | ||
| 87 | { | ||
| 88 | my ($self) = @_; | ||
| 89 | |||
| 90 | return(keys(%{$self->{email}})); | ||
| 91 | } | ||
| 92 | |||
| 93 | =pod | ||
| 94 | |||
| 95 | =back | ||
| 96 | |||
| 97 | =cut | ||
| 98 | |||
| 99 | sub _handle_ans | ||
| 100 | { | ||
| 101 | my ($self, $command) = @_; | ||
| 102 | $self->_state(Connected); | ||
| 103 | } | ||
| 104 | |||
| 105 | sub _handle_usr | ||
| 106 | { | ||
| 107 | my ($self, $command) = @_; | ||
| 108 | $self->_state(Connected); | ||
| 109 | } | ||
| 110 | |||
| 111 | sub _handle_iro | ||
| 112 | { | ||
| 113 | my ($self, $command) = @_; | ||
| 114 | $self->{email}->{$command->params->[3]} = Connected; | ||
| 115 | } | ||
| 116 | |||
| 117 | sub _handle_joi | ||
| 118 | { | ||
| 119 | my ($self, $command) = @_; | ||
| 120 | $self->{email}->{$command->params->[0]} = 1; | ||
| 121 | |||
| 122 | } | ||
| 123 | |||
| 124 | sub _handle_bye | ||
| 125 | { | ||
| 126 | my ($self, $command) = @_; | ||
| 127 | delete $self->{email}->{$command->params->[0]}; | ||
| 128 | } | ||
| 129 | |||
| 130 | |||
| 131 | |||
| 132 | # | ||
| 133 | # $Log: Conversation.pm,v $ | ||
| 134 | # Revision 0.16 2003/08/07 00:01:59 lawrence | ||
| 135 | # Initial Release | ||
| 136 | # | ||
| 137 | # |