[2cedb7a] | 1 | use warnings; |
---|
| 2 | use strict; |
---|
| 3 | |
---|
| 4 | =head1 NAME |
---|
| 5 | |
---|
| 6 | BarnOwl::Message::Jabber |
---|
| 7 | |
---|
| 8 | =head1 DESCRIPTION |
---|
| 9 | |
---|
| 10 | A subclass of BarnOwl::Message for Jabber messages |
---|
| 11 | |
---|
| 12 | =cut |
---|
| 13 | |
---|
| 14 | package BarnOwl::Message::Jabber; |
---|
| 15 | |
---|
| 16 | use base qw( BarnOwl::Message ); |
---|
| 17 | |
---|
| 18 | sub jtype { shift->{jtype} }; |
---|
| 19 | sub from { shift->{from} }; |
---|
| 20 | sub to { shift->{to} }; |
---|
| 21 | sub room { shift->{room} }; |
---|
[2f25537] | 22 | sub nick { shift->{nick} }; |
---|
[693c8f2] | 23 | sub subject { shift->{subject} }; |
---|
[2cedb7a] | 24 | sub status { shift->{status} } |
---|
| 25 | |
---|
[a1a2036] | 26 | sub login_type { |
---|
| 27 | my $self = shift; |
---|
| 28 | my $type = $self->jtype; |
---|
| 29 | return " ($type)" if $type; |
---|
| 30 | } |
---|
| 31 | |
---|
[2cedb7a] | 32 | sub login_extra { |
---|
| 33 | my $self = shift; |
---|
| 34 | my $show = $self->{show}; |
---|
| 35 | my $status = $self->status; |
---|
| 36 | my $s = ""; |
---|
| 37 | $s .= $show if $show; |
---|
| 38 | $s .= ", $status" if $status; |
---|
| 39 | return $s; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | sub long_sender { |
---|
| 43 | my $self = shift; |
---|
[2f25537] | 44 | if ($self->jtype eq 'groupchat' && $self->nick) { |
---|
| 45 | my $from_jid = Net::Jabber::JID->new($self->from); |
---|
| 46 | if ($from_jid->GetJID('base') eq $self->room && |
---|
| 47 | $from_jid->GetResource() eq $self->nick) { |
---|
| 48 | return $self->nick; |
---|
| 49 | } |
---|
| 50 | } |
---|
[2cedb7a] | 51 | return $self->from; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | sub context { |
---|
| 55 | return shift->room; |
---|
| 56 | } |
---|
| 57 | |
---|
[693c8f2] | 58 | sub subcontext { |
---|
| 59 | return shift->subject || ""; |
---|
| 60 | } |
---|
| 61 | |
---|
[dfaa47d] | 62 | sub personal_context { |
---|
[cdaf294] | 63 | my $self = shift; |
---|
[b401ef2] | 64 | if($self->subject) { |
---|
| 65 | return "subject: " . $self->subject; |
---|
| 66 | } elsif ($self->is_incoming) { |
---|
[cdaf294] | 67 | return "to " . $self->to; |
---|
| 68 | } else { |
---|
| 69 | return "from " . $self->from; |
---|
| 70 | } |
---|
[dfaa47d] | 71 | } |
---|
| 72 | |
---|
[2cedb7a] | 73 | sub smartfilter { |
---|
| 74 | my $self = shift; |
---|
| 75 | my $inst = shift; |
---|
| 76 | |
---|
[38a7f22] | 77 | my $filter; |
---|
[2cedb7a] | 78 | |
---|
| 79 | if($self->jtype eq 'chat') { |
---|
| 80 | my $user; |
---|
| 81 | if($self->direction eq 'in') { |
---|
| 82 | $user = $self->from; |
---|
| 83 | } else { |
---|
| 84 | $user = $self->to; |
---|
| 85 | } |
---|
| 86 | return smartfilter_user($user, $inst); |
---|
| 87 | } elsif ($self->jtype eq 'groupchat') { |
---|
| 88 | my $room = $self->room; |
---|
[8278543] | 89 | if ($inst) { |
---|
| 90 | my $subject = $self->subject; |
---|
| 91 | $filter = "jabber-room-$room-subject-$subject"; |
---|
| 92 | BarnOwl::command(qw[filter], $filter, |
---|
| 93 | qw[type ^jabber$ and room], "^\Q$room\E\$", |
---|
| 94 | qw[and subject], "^\Q$subject\E\$"); |
---|
| 95 | } else { |
---|
| 96 | $filter = "jabber-room-$room"; |
---|
| 97 | BarnOwl::command(qw[filter], $filter, |
---|
| 98 | qw[type ^jabber$ and room], "^\Q$room\E\$"); |
---|
| 99 | } |
---|
[2cedb7a] | 100 | return $filter; |
---|
| 101 | } elsif ($self->login ne 'none') { |
---|
| 102 | return smartfilter_user($self->from, $inst); |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | sub smartfilter_user { |
---|
| 107 | my $user = shift; |
---|
| 108 | my $inst = shift; |
---|
| 109 | |
---|
| 110 | $user = Net::Jabber::JID->new($user)->GetJID( $inst ? 'full' : 'base' ); |
---|
| 111 | my $filter = "jabber-user-$user"; |
---|
[38a7f22] | 112 | BarnOwl::command(qw[filter], $filter, qw[type ^jabber$], |
---|
[9375f8c] | 113 | qw[and ( ( direction ^in$ and from], "^\Q$user\E(/.*)?\$", |
---|
| 114 | qw[) or ( direction ^out$ and to ], "^\Q$user\E(/.*)?\$", |
---|
[38a7f22] | 115 | qw[ ) ) ]); |
---|
[2cedb7a] | 116 | return $filter; |
---|
| 117 | |
---|
| 118 | } |
---|
| 119 | |
---|
[d5dcd7c] | 120 | sub replycmd { |
---|
| 121 | my $self = shift; |
---|
| 122 | my ($recip, $account, $subject); |
---|
| 123 | if ($self->is_loginout) { |
---|
| 124 | $recip = $self->sender; |
---|
| 125 | $account = $self->recipient; |
---|
| 126 | } elsif ($self->jtype eq 'chat') { |
---|
| 127 | return $self->replysendercmd; |
---|
| 128 | } elsif ($self->jtype eq 'groupchat') { |
---|
| 129 | $recip = $self->room; |
---|
| 130 | if ($self->is_incoming) { |
---|
| 131 | $account = $self->to; |
---|
| 132 | } else { |
---|
| 133 | $account = $self->from; |
---|
| 134 | } |
---|
| 135 | $subject = $self->subject; |
---|
[96134cb] | 136 | } else { |
---|
| 137 | # Unknown type |
---|
| 138 | return; |
---|
[d5dcd7c] | 139 | } |
---|
| 140 | return jwrite_cmd($recip, $account, $subject); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | sub replysendercmd { |
---|
| 144 | my $self = shift; |
---|
| 145 | if($self->jtype eq 'groupchat' |
---|
| 146 | || $self->jtype eq 'chat') { |
---|
| 147 | my ($recip, $account); |
---|
| 148 | if ($self->is_incoming) { |
---|
| 149 | $recip = $self->from; |
---|
| 150 | $account = $self->to; |
---|
| 151 | } else { |
---|
| 152 | $recip = $self->to; |
---|
| 153 | $account = $self->from; |
---|
| 154 | } |
---|
| 155 | return jwrite_cmd($recip, $account); |
---|
| 156 | } |
---|
| 157 | return $self->replycmd; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | sub jwrite_cmd { |
---|
| 161 | my ($recip, $account, $subject) = @_; |
---|
| 162 | if (defined $recip) { |
---|
[c854e74] | 163 | my @cmd = ('jwrite', $recip, '-a', $account); |
---|
[d5dcd7c] | 164 | if (defined $subject) { |
---|
[c854e74] | 165 | push @cmd, '-s', $subject; |
---|
[d5dcd7c] | 166 | } |
---|
[c854e74] | 167 | return BarnOwl::quote(@cmd); |
---|
[d5dcd7c] | 168 | } else { |
---|
| 169 | return undef; |
---|
| 170 | } |
---|
| 171 | } |
---|
[2cedb7a] | 172 | |
---|
| 173 | =head1 SEE ALSO |
---|
| 174 | |
---|
| 175 | L<BarnOwl::Message> |
---|
| 176 | |
---|
| 177 | =cut |
---|
| 178 | |
---|
| 179 | 1; |
---|