source: perl/modules/Jabber/lib/BarnOwl/Message/Jabber.pm @ 38a7f22

debianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 38a7f22 was 38a7f22, checked in by Nelson Elhage <nelhage@mit.edu>, 16 years ago
Convert Message::IRC and Message::Jabber to use the new BarnOwl::command() We should now be able to properly narrow to MUCs and users and channels containing whitespace or quotation marks.
  • Property mode set to 100644
File size: 1.9 KB
Line 
1use warnings;
2use strict;
3
4=head1 NAME
5
6BarnOwl::Message::Jabber
7
8=head1 DESCRIPTION
9
10A subclass of BarnOwl::Message for Jabber messages
11
12=cut
13
14package BarnOwl::Message::Jabber;
15
16use base qw( BarnOwl::Message );
17
18sub jtype { shift->{jtype} };
19sub from { shift->{from} };
20sub to { shift->{to} };
21sub room { shift->{room} };
22sub subject { shift->{subject} };
23sub status { shift->{status} }
24
25sub login_type {
26    my $self = shift;
27    my $type = $self->jtype;
28    return " ($type)" if $type;
29}
30
31sub 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
41sub long_sender {
42    my $self = shift;
43    return $self->from;
44}
45
46sub context {
47    return shift->room;
48}
49
50sub subcontext {
51    return shift->subject || "";
52}
53
54sub 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
79sub 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
96L<BarnOwl::Message>
97
98=cut
99
1001;
Note: See TracBrowser for help on using the repository browser.