@@ -12,36 +12,63 @@ int main(int argc, char *argv[])
1212
1313 std::ifstream f1(argv[1]);
1414 std::ofstream f2(argv[2]);
15− json jf1 = json::parse(f1);
16− json jf2;
15+ json js1 = json::parse(f1);
16+ json js2;
1717
18− std::string mtype = jf1["message"]["type"].get<std::string>();
19− bool popup = (jf1["message"]["devices"][0]["tweaks"]["sound"].get<std::string>() != "");
20− int unread_count = jf1["message"]["counts"]["unread"];
21− if (mtype == "m.room.message")
18+ std::string mtype = js1["message"]["type"].get<std::string>();
19+ std::string summary = "";
20+ std::string body = "";
21+ std::string icon = "";
22+
23+ int unread_count = 0;
24+ bool alert = false;
25+ bool popup = false;
26+
27+ if (js1["message"]["room_name"] != nullptr)
2228 {
23− jf2["notification"]["card"]["summary"] = (jf1["message"]["room_name"] != nullptr) ? jf1["message"]["room_name"] : jf1["message"]["sender_display_name"];
24− jf2["notification"]["card"]["body"] = jf1["message"]["sender_display_name"].get<std::string>() + ": " + jf1["message"]["content"]["body"].get<std::string>();
25− jf2["notification"]["card"]["icon"] = "contact-group";
29+ summary = js1["message"]["room_name"];
2630 }
27− if (mtype == "m.room.encrypted")
31+ else
2832 {
29− jf2["notification"]["card"]["summary"] = (jf1["message"]["room_name"] != nullptr) ? jf1["message"]["room_name"] : jf1["message"]["sender_display_name"];
30− jf2["notification"]["card"]["body"] = N_("New message");
33+ summary = js1["message"]["sender_display_name"];
34+ }
35+ if (mtype == "m.room.encrypted") {
36+ body = N_("New Message");
37+ }
38+ else {
39+ body = js1["message"]["sender_display_name"].get<std::string>() + ": " + js1["message"]["content"]["body"].get<std::string>();
40+ }
41+
42+ if (js1["message"]["room_name"] == nullptr) {
43+ icon = "contact";
44+ }
45+ else {
46+ icon = "contact-group";
47+ }
48+
49+ if (js1["message"]["devices"][0]["tweaks"]["sound"].get<std::string>() != "") {
50+ alert = true;
3151 }
32− if (popup)
33− {
3452
35− jf2["notification"]["vibrate"] = true;
36− jf2["notification"]["sound"] = true;
37− jf2["notification"]["card"]["persist"] = true;
38− jf2["notification"]["card"]["popup"] = true;
39− jf2["notification"]["card"]["icon"] = "contact-group";
40− jf2["notification"]["card"]["actions"] = {"cinny:\/\/" + jf1["message"]["room_id"].get<std::string>()};
53+ if(summary != "" && body != ""){
54+ popup = true;
4155 }
42− jf2["notification"]["emblem-counter"]["count"] = unread_count;
43− jf2["notification"]["emblem-counter"]["visible"] = (unread_count > 0);
4456
45− f2 << jf2;
57+ unread_count = js1["message"]["counts"]["unread"];
58+
59+ js2["notification"]["card"]["actions"] = {"cinny://" + js1["message"]["room_id"].get<std::string>()};
60+ js2["notification"]["card"]["summary"] = summary;
61+ js2["notification"]["card"]["body"] = body;
62+ js2["notification"]["card"]["icon"] = icon;
63+ js2["notification"]["card"]["persist"] = popup;
64+ js2["notification"]["card"]["popup"] = popup;
65+
66+ js2["notification"]["emblem-counter"]["count"] = unread_count;
67+ js2["notification"]["emblem-counter"]["visible"] = unread_count > 0;
68+
69+ js2["notification"]["sound"] = alert;
70+ js2["notification"]["vibrate"] = alert;
71+ f2 << js2;
72+
4673 return 0;
4774}