mirror of https://github.com/sipwise/prosody.git
If a user/room is in the mute list of a user, send silent push. Change-Id: Id41a998c795e6b3e3c8a57bc9d446cd2f5fd115cchanges/53/20453/1
parent
c17d29512c
commit
fde63241ae
@ -0,0 +1,120 @@
|
||||
--- a/plugins/mod_sipwise_pushd.lua
|
||||
+++ b/plugins/mod_sipwise_pushd.lua
|
||||
@@ -61,6 +61,18 @@
|
||||
WHERE vp.attribute = 'mobile_push_enable'
|
||||
AND vd.domain = ?;
|
||||
]];
|
||||
+
|
||||
+local push_silent_query = [[
|
||||
+SELECT "1" FROM provisioning.voip_preferences vp
|
||||
+ LEFT JOIN provisioning.voip_usr_preferences vup ON vup.attribute_id = vp.id
|
||||
+ LEFT JOIN provisioning.voip_subscribers vs ON vs.id = vup.subscriber_id
|
||||
+ LEFT JOIN provisioning.voip_domains vd ON vd.id = vs.domain_id
|
||||
+WHERE vp.attribute = 'mobile_push_silent_list'
|
||||
+ AND vs.username = ?
|
||||
+ AND vd.domain = ?
|
||||
+ AND vup.value = ?;
|
||||
+]];
|
||||
+
|
||||
local engine;
|
||||
|
||||
-- luacheck: ignore request
|
||||
@@ -74,6 +86,21 @@
|
||||
end
|
||||
end
|
||||
|
||||
+local function push_silent(username, domain, other)
|
||||
+ -- Reconnect to DB if necessary
|
||||
+ if not engine.conn:ping() then
|
||||
+ engine.conn = nil;
|
||||
+ engine:connect();
|
||||
+ end
|
||||
+ for row in engine:select(push_silent_query, username, domain, other) do
|
||||
+ if row[1] == "1" then
|
||||
+ module:log("debug", "silent push preference mobile_push_silent_list matches");
|
||||
+ return true;
|
||||
+ end
|
||||
+ end
|
||||
+ return false;
|
||||
+end
|
||||
+
|
||||
local function push_enable(username, domain)
|
||||
-- Reconnect to DB if necessary
|
||||
if not engine.conn:ping() then
|
||||
@@ -303,20 +330,25 @@
|
||||
msg.data_sender_name = tostring(caller_info.display_name);
|
||||
return msg;
|
||||
end
|
||||
- local function build_push_apns_query(msg, muc)
|
||||
- if msg.data_type ~= 'invite' then
|
||||
- msg.apns_alert = string.format("message received from %s\n",
|
||||
- caller_info.display_name) .. msg.data_message;
|
||||
+ local function build_push_apns_query(msg, muc, silent)
|
||||
+ if silent then
|
||||
+ msg['apns_content-available'] = '1';
|
||||
else
|
||||
- msg.apns_alert = muc['invite'];
|
||||
+ if msg.data_type ~= 'invite' then
|
||||
+ msg.apns_alert = string.format("Message from %s:\n",
|
||||
+ caller_info.display_name) .. msg.data_message;
|
||||
+ else
|
||||
+ msg.apns_alert = muc['invite'];
|
||||
+ end
|
||||
+ msg.apns_sound = pushd_config.msg_sound or '';
|
||||
+ msg.apns_badge = tostring(get_callee_badge(to));
|
||||
end
|
||||
- msg.apns_sound = pushd_config.msg_sound or '';
|
||||
- msg.apns_badge = tostring(get_callee_badge(to));
|
||||
return msg;
|
||||
end
|
||||
local function build_push_query(msg)
|
||||
local muc;
|
||||
local caller_jid;
|
||||
+ local silent;
|
||||
if stanza.attr.type == 'groupchat' then
|
||||
msg.data_type = 'groupchat'
|
||||
caller_jid = get_muc_caller(stanza.attr.from);
|
||||
@@ -325,6 +357,7 @@
|
||||
caller_info = get_caller_info(caller_jid, caller_defaults) or
|
||||
caller_defaults;
|
||||
muc = get_muc_info(stanza, caller_info);
|
||||
+ silent = push_silent(msg.callee, msg.domain, muc['jid']);
|
||||
else
|
||||
msg.data_type = 'message';
|
||||
caller_jid = format("%s@%s",
|
||||
@@ -340,13 +373,19 @@
|
||||
caller_info = get_caller_info(caller_jid, caller_defaults) or
|
||||
caller_defaults;
|
||||
muc = get_muc_info(stanza, caller_info);
|
||||
+ silent = push_silent(msg.callee, msg.domain, caller_jid);
|
||||
+ end
|
||||
+ if silent then
|
||||
+ msg.data_silent = '1';
|
||||
+ else
|
||||
+ msg.data_silent = '0';
|
||||
end
|
||||
msg.data_sender_jid = caller_jid;
|
||||
msg.data_sender_sip = jid_bare(caller_jid);
|
||||
msg.push_id = uuid.generate();
|
||||
msg = build_push_common_query(msg, muc);
|
||||
if pushd_config.apns then
|
||||
- msg = build_push_apns_query(msg, muc);
|
||||
+ msg = build_push_apns_query(msg, muc, silent);
|
||||
end
|
||||
return msg;
|
||||
end
|
||||
@@ -445,6 +484,7 @@
|
||||
end
|
||||
|
||||
local function handle_msg(event)
|
||||
+ module:log("debug", "handle_msg");
|
||||
local stanza = event.stanza;
|
||||
local room_jid = stanza.attr.to;
|
||||
|
||||
@@ -529,5 +569,5 @@
|
||||
sql_config = module:get_option("auth_sql", sql_config);
|
||||
engine = mod_sql:create_engine(sql_config);
|
||||
engine:execute("SET NAMES 'utf8' COLLATE 'utf8_bin';");
|
||||
- module:log("info", "load OK");
|
||||
+ module:log("debug", "load OK");
|
||||
end
|
||||
Loading…
Reference in new issue