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} }; |
---|
22 | sub subject { shift->{subject} }; |
---|
23 | sub status { shift->{status} } |
---|
24 | |
---|
25 | sub login_type { |
---|
26 | my $self = shift; |
---|
27 | my $type = $self->jtype; |
---|
28 | return " ($type)" if $type; |
---|
29 | } |
---|
30 | |
---|
31 | sub login_extra { |
---|
32 | my $self = shift; |
---|
33 | my $show = $self->{show}; |
---|
34 | my $status = $self->status; |
---|
35 | my $s = ""; |
---|
36 | $s .= $show if $show; |
---|
37 | $s .= ", $status" if $status; |
---|
38 | return $s; |
---|
39 | } |
---|
40 | |
---|
41 | sub long_sender { |
---|
42 | my $self = shift; |
---|
43 | return $self->from; |
---|
44 | } |
---|
45 | |
---|
46 | sub context { |
---|
47 | return shift->room; |
---|
48 | } |
---|
49 | |
---|
50 | sub subcontext { |
---|
51 | return shift->subject || ""; |
---|
52 | } |
---|
53 | |
---|
54 | sub smartfilter { |
---|
55 | my $self = shift; |
---|
56 | my $inst = shift; |
---|
57 | |
---|
58 | my $filter; |
---|
59 | |
---|
60 | if($self->jtype eq 'chat') { |
---|
61 | my $user; |
---|
62 | if($self->direction eq 'in') { |
---|
63 | $user = $self->from; |
---|
64 | } else { |
---|
65 | $user = $self->to; |
---|
66 | } |
---|
67 | return smartfilter_user($user, $inst); |
---|
68 | } elsif ($self->jtype eq 'groupchat') { |
---|
69 | my $room = $self->room; |
---|
70 | $filter = "jabber-room-$room"; |
---|
71 | BarnOwl::command(qw[filter], $filter, |
---|
72 | qw[type ^jabber$ and room], "^$room\$"); |
---|
73 | return $filter; |
---|
74 | } elsif ($self->login ne 'none') { |
---|
75 | return smartfilter_user($self->from, $inst); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | sub smartfilter_user { |
---|
80 | my $user = shift; |
---|
81 | my $inst = shift; |
---|
82 | |
---|
83 | $user = Net::Jabber::JID->new($user)->GetJID( $inst ? 'full' : 'base' ); |
---|
84 | my $filter = "jabber-user-$user"; |
---|
85 | BarnOwl::command(qw[filter], $filter, qw[type ^jabber$], |
---|
86 | qw[and ( ( direction ^in$ and from], "^$user", |
---|
87 | qw[) or ( direction ^out$ and to ], "^$user", |
---|
88 | qw[ ) ) ]); |
---|
89 | return $filter; |
---|
90 | |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | =head1 SEE ALSO |
---|
95 | |
---|
96 | L<BarnOwl::Message> |
---|
97 | |
---|
98 | =cut |
---|
99 | |
---|
100 | 1; |
---|