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

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since dfaa47d was dfaa47d, checked in by Geoffrey Thomas <geofft@mit.edu>, 15 years ago
Display context for personals, so as to make <message,*,%me> usable. Signed-off-by: Geoffrey Thomas <geofft@mit.edu>
  • Property mode set to 100644
File size: 3.4 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 personal_context {
55    return "to " . shift->to;
56}
57
58sub smartfilter {
59    my $self = shift;
60    my $inst = shift;
61
62    my $filter;
63
64    if($self->jtype eq 'chat') {
65        my $user;
66        if($self->direction eq 'in') {
67            $user = $self->from;
68        } else {
69            $user = $self->to;
70        }
71        return smartfilter_user($user, $inst);
72    } elsif ($self->jtype eq 'groupchat') {
73        my $room = $self->room;
74        $filter = "jabber-room-$room";
75        BarnOwl::command(qw[filter], $filter,
76                         qw[type ^jabber$ and room], "^\Q$room\E\$");
77        return $filter;
78    } elsif ($self->login ne 'none') {
79        return smartfilter_user($self->from, $inst);
80    }
81}
82
83sub smartfilter_user {
84    my $user = shift;
85    my $inst = shift;
86
87    $user   = Net::Jabber::JID->new($user)->GetJID( $inst ? 'full' : 'base' );
88    my $filter = "jabber-user-$user";
89    BarnOwl::command(qw[filter], $filter, qw[type ^jabber$],
90                     qw[and ( ( direction ^in$ and from], "^\Q$user\E(/.*)?\$",
91                     qw[) or ( direction ^out$ and to ], "^\Q$user\E(/.*)?\$",
92                     qw[ ) ) ]);
93    return $filter;
94
95}
96
97sub replycmd {
98    my $self = shift;
99    my ($recip, $account, $subject);
100    if ($self->is_loginout) {
101        $recip   = $self->sender;
102        $account = $self->recipient;
103    } elsif ($self->jtype eq 'chat') {
104        return $self->replysendercmd;
105    } elsif ($self->jtype eq 'groupchat') {
106        $recip = $self->room;
107        if ($self->is_incoming) {
108            $account = $self->to;
109        } else {
110            $account = $self->from;
111        }
112        $subject = $self->subject;
113    } else {
114        # Unknown type
115        return;
116    }
117    return jwrite_cmd($recip, $account, $subject);
118}
119
120sub replysendercmd {
121    my $self = shift;
122    if($self->jtype eq 'groupchat'
123       || $self->jtype eq 'chat') {
124        my ($recip, $account);
125        if ($self->is_incoming) {
126            $recip   = $self->from;
127            $account = $self->to;
128        } else {
129            $recip   = $self->to;
130            $account = $self->from;
131        }
132        return jwrite_cmd($recip, $account);
133    }
134    return $self->replycmd;
135}
136
137sub jwrite_cmd {
138    my ($recip, $account, $subject) = @_;
139    if (defined $recip) {
140        $recip   = BarnOwl::quote($recip);
141        $account = BarnOwl::quote($account);
142        my $cmd = "jwrite $recip -a $account";
143        if (defined $subject) {
144            $cmd .= " -s " . BarnOwl::quote($subject);
145        }
146        return $cmd;
147    } else {
148        return undef;
149    }
150}
151
152=head1 SEE ALSO
153
154L<BarnOwl::Message>
155
156=cut
157
1581;
Note: See TracBrowser for help on using the repository browser.