From 374fdd6cc9ade267b13b12a7ca43eb5e0c16e91f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Fri, 13 Dec 2019 22:42:39 -0500
Subject: [PATCH] proxy: send normal priority push message for value expiration

---
 include/opendht/dht_proxy_server.h | 2 +-
 src/dht_proxy_server.cpp           | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/opendht/dht_proxy_server.h b/include/opendht/dht_proxy_server.h
index 195f8206..bcb83405 100644
--- a/include/opendht/dht_proxy_server.h
+++ b/include/opendht/dht_proxy_server.h
@@ -281,7 +281,7 @@ private:
      * @param key of the device
      * @param json, the content to send
      */
-    void sendPushNotification(const std::string& key, Json::Value&& json, bool isAndroid);
+    void sendPushNotification(const std::string& key, Json::Value&& json, bool isAndroid, bool highPriority);
 
     /**
      * Send push notification with an expire timeout.
diff --git a/src/dht_proxy_server.cpp b/src/dht_proxy_server.cpp
index 07b9f89c..8ec8df66 100644
--- a/src/dht_proxy_server.cpp
+++ b/src/dht_proxy_server.cpp
@@ -706,7 +706,7 @@ DhtProxyServer::subscribe(restinio::request_handle_t request,
                     }
                     json["exp"] = ss.str();
                 }
-                sendPushNotification(pushToken, std::move(json), isAndroid);
+                sendPushNotification(pushToken, std::move(json), isAndroid, !expired);
                 return true;
             }
         );
@@ -802,7 +802,7 @@ DhtProxyServer::handleNotifyPushListenExpire(const asio::error_code &ec, const s
     }
     if (logger_)
         logger_->d("[proxy:server] [subscribe] sending put refresh to %s token", pushToken.c_str());
-    sendPushNotification(pushToken, std::move(json), isAndroid);
+    sendPushNotification(pushToken, std::move(json), isAndroid, false);
 }
 
 void
@@ -844,7 +844,7 @@ DhtProxyServer::handleCancelPushListen(const asio::error_code &ec, const std::st
 }
 
 void
-DhtProxyServer::sendPushNotification(const std::string& token, Json::Value&& json, bool isAndroid)
+DhtProxyServer::sendPushNotification(const std::string& token, Json::Value&& json, bool isAndroid, bool highPriority)
 {
     if (pushServer_.empty())
         return;
@@ -868,7 +868,7 @@ DhtProxyServer::sendPushNotification(const std::string& token, Json::Value&& jso
         notification["tokens"] = std::move(tokens);
         notification["platform"] = isAndroid ? 2 : 1;
         notification["data"] = std::move(json);
-        notification["priority"] = "high";
+        notification["priority"] = highPriority ? "high" : "normal";
         notification["time_to_live"] = 600;
 
         Json::Value notifications(Json::arrayValue);
-- 
GitLab