From b887eb4c82b4c6f17f193a97fd49475b90255e13 Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Sun, 30 Oct 2016 12:16:49 -0600 Subject: [PATCH] Update message_waiting.lua --- .../resources/functions/message_waiting.lua | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/resources/install/scripts/app/voicemail/resources/functions/message_waiting.lua b/resources/install/scripts/app/voicemail/resources/functions/message_waiting.lua index ef26819104..76ff31fce6 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/message_waiting.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/message_waiting.lua @@ -1,5 +1,5 @@ -- Part of FusionPBX --- Copyright (C) 2013-2015 Mark J Crane +-- Copyright (C) 2013-2016 Mark J Crane -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without @@ -12,7 +12,7 @@ -- notice, this list of conditions and the following disclaimer in the -- documentation and/or other materials provided with the distribution. -- --- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, +-- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, -- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, @@ -25,39 +25,44 @@ --voicemail count if zero new messages set the mwi to no function message_waiting(voicemail_id, domain_uuid) + --initialize the array and add the voicemail_id local accounts = {} + + --add the current voicemail id to the accounts array table.insert(accounts, voicemail_id); + --get the voicemail id and all related mwi accounts local sql = [[SELECT extension, number_alias from v_extensions WHERE domain_uuid = ']] .. domain_uuid ..[[' - AND (mwi_account = ']]..voicemail_id..[[' or mwi_account = ']]..voicemail_id..[[@]]..domain_name..[[')]]; + AND ( + mwi_account = ']]..voicemail_id..[[' + or mwi_account = ']]..voicemail_id..[[@]]..domain_name..[[' + or number_alias = ']]..voicemail_id..[[' + )]]; if (debug["sql"]) then freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n"); end dbh:query(sql, function(row) - if (string.len(row["number_alias"]) > 0) then - table.insert(accounts, row["number_alias"]); - else - table.insert(accounts, row["extension"]); - end + table.insert(accounts, row["extension"]); end); --get new and saved message counts - local new_messages, saved_messages = message_count_by_id( - voicemail_id, domain_uuid - ) + local new_messages, saved_messages = message_count_by_id(voicemail_id, domain_uuid); --send the message waiting event for _,value in ipairs(accounts) do - local account = value.."@"..domain_name - mwi_notify(account, new_messages, saved_messages) - if (debug["info"]) then - if new_messages == "0" then - freeswitch.consoleLog("notice", "[voicemail] mailbox: "..account.." messages: no new messages\n"); - else - freeswitch.consoleLog("notice", "[voicemail] mailbox: "..account.." messages: " .. new_messages .. " new message(s)\n"); + --add the domain to voicemail id + local account = value.."@"..domain_name; + --send the message waiting notifications + mwi_notify(account, new_messages, saved_messages); + --send information to the console + if (debug["info"]) then + if new_messages == "0" then + freeswitch.consoleLog("notice", "[voicemail] mailbox: "..account.." messages: no new messages\n"); + else + freeswitch.consoleLog("notice", "[voicemail] mailbox: "..account.." messages: " .. new_messages .. " new message(s)\n"); + end end - end end end