From fde63241aefcbbe0e2fb13bc46f20af66eae504f Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Fri, 13 Apr 2018 10:20:26 +0200 Subject: [PATCH] TT#35604 Implement silent flag for push If a user/room is in the mute list of a user, send silent push. Change-Id: Id41a998c795e6b3e3c8a57bc9d446cd2f5fd115c --- ...5604-mod_sipwise_pushd.lib-add-silent-push | 120 ++++++++++++++++++ debian/patches/series | 1 + 2 files changed, 121 insertions(+) create mode 100644 debian/patches/0009-TT-35604-mod_sipwise_pushd.lib-add-silent-push diff --git a/debian/patches/0009-TT-35604-mod_sipwise_pushd.lib-add-silent-push b/debian/patches/0009-TT-35604-mod_sipwise_pushd.lib-add-silent-push new file mode 100644 index 0000000..28c5cf3 --- /dev/null +++ b/debian/patches/0009-TT-35604-mod_sipwise_pushd.lib-add-silent-push @@ -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 diff --git a/debian/patches/series b/debian/patches/series index d0a5233..c201301 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -7,3 +7,4 @@ mod_auth_sql.path 0006-TT-9314-mod_mam-sipwise_archive.lib-support-emojis.patch 0007-TT-27653-mod_mam-sipwise_archive.lib-fix-uuid-trailing-garbage.patch 0008-TT-35053-mod_mam-sipwise_archive.lib-fix-retrieving-incoming.patch +0009-TT-35604-mod_sipwise_pushd.lib-add-silent-push