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 nick { shift->{nick} }; |
---|
23 | sub subject { shift->{subject} }; |
---|
24 | sub status { shift->{status} } |
---|
25 | |
---|
26 | sub login_type { |
---|
27 | my $self = shift; |
---|
28 | my $type = $self->jtype; |
---|
29 | return " ($type)" if $type; |
---|
30 | } |
---|
31 | |
---|
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; |
---|
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 | } |
---|
51 | return $self->from; |
---|
52 | } |
---|
53 | |
---|
54 | sub context { |
---|
55 | return shift->room; |
---|
56 | } |
---|
57 | |
---|
58 | sub subcontext { |
---|
59 | return shift->subject || ""; |
---|
60 | } |
---|
61 | |
---|
62 | sub personal_context { |
---|
63 | my $self = shift; |
---|
64 | if($self->subject) { |
---|
65 | return "subject: " . $self->subject; |
---|
66 | } elsif ($self->is_incoming) { |
---|
67 | return "to " . $self->to; |
---|
68 | } else { |
---|
69 | return "from " . $self->from; |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | sub smartfilter { |
---|
74 | my $self = shift; |
---|
75 | my $inst = shift; |
---|
76 | |
---|
77 | my $filter; |
---|
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; |
---|
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 | } |
---|
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"; |
---|
112 | BarnOwl::command(qw[filter], $filter, qw[type ^jabber$], |
---|
113 | qw[and ( ( direction ^in$ and from], "^\Q$user\E(/.*)?\$", |
---|
114 | qw[) or ( direction ^out$ and to ], "^\Q$user\E(/.*)?\$", |
---|
115 | qw[ ) ) ]); |
---|
116 | return $filter; |
---|
117 | |
---|
118 | } |
---|
119 | |
---|
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; |
---|
136 | } else { |
---|
137 | # Unknown type |
---|
138 | return; |
---|
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) { |
---|
163 | my @cmd = ('jwrite', '-a', $account); |
---|
164 | if (defined $subject) { |
---|
165 | push @cmd, '-s', $subject; |
---|
166 | } |
---|
167 | push @cmd, '--', $recip; |
---|
168 | return BarnOwl::quote(@cmd); |
---|
169 | } else { |
---|
170 | return undef; |
---|
171 | } |
---|
172 | } |
---|
173 | |
---|
174 | sub log_filenames { |
---|
175 | return map { BarnOwl::compat_casefold($_) } BarnOwl::Message::log_filenames(@_); |
---|
176 | } |
---|
177 | |
---|
178 | =head1 SEE ALSO |
---|
179 | |
---|
180 | L<BarnOwl::Message> |
---|
181 | |
---|
182 | =cut |
---|
183 | |
---|
184 | 1; |
---|