Skip to content

Commit 792b851

Browse files
François-Simon Fauteux-Chapleauaberaud
authored andcommitted
dht_proxy_server: fix Android push notifications
This commit updates the format of the push notification requests sent by the DHT proxy server to conform to FCM's HTTP v1 API. (The previously used API was deprecated in 2023, see: https://firebase.google.com/docs/cloud-messaging/migrate-v1) The "priority" and "ttl" (time to live) options are specific to Android and therefore need to be put in the "android" block, as documented here: https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages
1 parent 9da832c commit 792b851

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/dht_proxy_server.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,10 +1107,14 @@ DhtProxyServer::sendPushNotification(const std::string& token, Json::Value&& jso
11071107
notification["tokens"] = std::move(tokens);
11081108
notification["platform"] = type == PushType::Android ? 2 : 1;
11091109
notification["data"] = std::move(json);
1110-
notification["priority"] = highPriority ? "high" : "normal";
1111-
if (type == PushType::Android)
1112-
notification["time_to_live"] = 3600 * 24; // 24 hours
1113-
else {
1110+
auto priority = highPriority ? "high" : "normal";
1111+
if (type == PushType::Android) {
1112+
Json::Value androidConfig(Json::objectValue);
1113+
androidConfig["priority"] = priority;
1114+
androidConfig["ttl"] = "86400s"; // time to live = 24 hours
1115+
notification["android"] = std::move(androidConfig);
1116+
} else {
1117+
notification["priority"] = priority;
11141118
const auto expiration = std::chrono::system_clock::now() + std::chrono::hours(24);
11151119
uint32_t exp = std::chrono::duration_cast<std::chrono::seconds>(expiration.time_since_epoch()).count();
11161120
notification["expiration"] = exp;

0 commit comments

Comments
 (0)