TT#139550 improve vmnotify behaviour

* vmnotify() now accepts cli and uuid arguments
* API handling of voicemails is now improved to:
  - send a notify if the item's INBOX/Old has been changed
  - correctly process DELETE to send vmnotify after the
    item's removal

Change-Id: Ic00ae825cf091bce273e55aa37cd0a7ac80d8b0f
mr9.5.4
Kirill Solomko 4 years ago committed by Marco Capetta
parent e1efd6cc48
commit bdbb3fba6d

@ -17,7 +17,6 @@ sub allowed_methods{
#sub delete_item { #sub delete_item {
# my ($self, $c, $item) = @_; # my ($self, $c, $item) = @_;
# $item->delete; # $item->delete;
# NGCP::Panel::Utils::Subscriber::vmnotify( 'c' => $c, 'fax' => $item );
#} #}
1; 1;

@ -124,7 +124,11 @@ sub DELETE :Allow {
last unless $self->resource_exists($c, voicemail => $item); last unless $self->resource_exists($c, voicemail => $item);
$item->delete; $item->delete;
NGCP::Panel::Utils::Subscriber::vmnotify( 'c' => $c, 'voicemail' => $item );
my $cli = $item->mailboxuser->provisioning_voip_subscriber->username;
my $uuid = $item->mailboxuser->provisioning_voip_subscriber->username;
NGCP::Panel::Utils::Subscriber::vmnotify(c => $c, cli => $cli, uuid => $uuid);
$guard->commit; $guard->commit;
$c->response->status(HTTP_NO_CONTENT); $c->response->status(HTTP_NO_CONTENT);

@ -4187,6 +4187,10 @@ sub play_voicemail :Chained('voicemail') :PathPart('play') :Args(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
my $file = $c->stash->{voicemail}; my $file = $c->stash->{voicemail};
my $cli = $file->mailboxuser->provisioning_voip_subscriber->username;
my $uuid = $file->mailboxuser->provisioning_voip_subscriber->uuid;
my $dir = $file->dir;
my $data_ref; my $data_ref;
try { try {
@ -4202,9 +4206,10 @@ sub play_voicemail :Chained('voicemail') :PathPart('play') :Args(0) {
$c->uri_for_action('/subscriber/details', [$c->req->captures->[0]])); $c->uri_for_action('/subscriber/details', [$c->req->captures->[0]]));
} }
NGCP::Panel::Utils::Subscriber::mark_voicemail_read( 'c' => $c, 'voicemail' => $c->stash->{voicemail} ); NGCP::Panel::Utils::Subscriber::mark_voicemail_read(c => $c, dir => $dir);
NGCP::Panel::Utils::Subscriber::vmnotify( 'c' => $c, 'voicemail' => $c->stash->{voicemail} ); NGCP::Panel::Utils::Subscriber::vmnotify(c => $c, cli => $cli, uuid => $uuid);
my $filename = NGCP::Panel::Utils::Subscriber::get_voicemail_filename($c,$file);
my $filename = NGCP::Panel::Utils::Subscriber::get_voicemail_filename($c, $file);
$c->response->header('Content-Disposition' => 'attachment; filename="'.$filename.'"'); $c->response->header('Content-Disposition' => 'attachment; filename="'.$filename.'"');
$c->response->content_type('audio/x-wav'); $c->response->content_type('audio/x-wav');
$c->response->body($$data_ref); $c->response->body($$data_ref);

@ -120,8 +120,11 @@ sub update_item {
$item->update($upresource); $item->update($upresource);
if($dir_old =~/INBOX/ && $upresource->{dir} !~/INBOX/){ my $cli = $item->mailboxuser->provisioning_voip_subscriber->username;
NGCP::Panel::Utils::Subscriber::vmnotify( 'c' => $c, 'voicemail' => $item ); my $uuid = $item->mailboxuser->provisioning_voip_subscriber->uuid;
if ($dir_old ne $upresource->{dir}) {
NGCP::Panel::Utils::Subscriber::vmnotify(c => $c, cli => $cli, uuid => $uuid);
} }
return $item; return $item;

@ -2270,16 +2270,17 @@ sub update_voicemail_number {
return; return;
} }
sub vmnotify{ sub vmnotify {
my (%params) = @_; my (%params) = @_;
my ($c, $voicemail) = @params{qw(c voicemail)}; my ($c, $cli, $uuid) = @params{qw(c cli uuid)};
#1.although method is called after delete - DBIC still can access data in deleted row #1.although method is called after delete - DBIC still can access data in deleted row
#2.amount of the new messages should be selected after played update or delete, of course #2.amount of the new messages should be selected after played update or delete, of course
my $data = { $voicemail->get_inflated_columns }; my $data = {
$data->{cli} = $voicemail->mailboxuser->provisioning_voip_subscriber->username; cli => $cli,
$data->{uuid} = $voicemail->mailboxuser->provisioning_voip_subscriber->uuid; uuid => $uuid
};
$data->{context} = 'default'; $data->{context} = 'default';
$data->{old_messages} = 0; $data->{old_messages} = 0;
$data->{new_messages} = 0; $data->{new_messages} = 0;
@ -2306,17 +2307,19 @@ sub vmnotify{
my @cmd = ('ngcp-vmnotify', @$data{qw/context cli uuid new_messages old_messages/}); my @cmd = ('ngcp-vmnotify', @$data{qw/context cli uuid new_messages old_messages/});
my $output = capturex([0..3],@cmd); my $output = capturex([0..3],@cmd);
$c->log->debug("cmd=".join(" ", @cmd)."; output=$output;"); $c->log->debug("cmd=".join(" ", @cmd)."; output=$output;");
return; return;
} }
sub mark_voicemail_read{ sub mark_voicemail_read {
my (%params) = @_; my (%params) = @_;
my $c = $params{c}; my $c = $params{c};
my $voicemail = $params{voicemail}; my $voicemail = $params{voicemail};
my $dir = $voicemail->dir; my $dir = $voicemail->dir;
$dir =~s/INBOX$/Old/; $dir = ~s/INBOX$/Old/;
$voicemail->update({ dir => $dir }); $voicemail->update({ dir => $dir });
return; return;
} }

Loading…
Cancel
Save