fix: clear badgge when Palaver device connects 1.2.1
authorKyle Fuller <redacted>
Sat, 18 Jul 2020 17:39:03 +0000 (18:39 +0100)
committerKyle Fuller <redacted>
Sat, 18 Jul 2020 18:11:36 +0000 (19:11 +0100)
CHANGELOG.md
palaver.cpp

index 3319bbee40a7be9f5f348e670676f312d67b8f48..e61288ff70c30df094b765542a6d7a373d5dc45c 100644 (file)
@@ -1,5 +1,12 @@
 # Changelog for Palaver ZNC Module
 
+## 1.2.1 (18/07/2020)
+
+### Bug Fixes
+
+- Fixes a case where the unread badge on send push notifications would not get
+  reset when reconnecting the same Palaver device.
+
 ## 1.2.0
 
 ### Enhancements
index 37d72d3c37f9b6f05bf9674d0af82808e8f4dc37..7a88d9d0c5691a503902ab45034869f896fcb9c5 100644 (file)
@@ -7,7 +7,7 @@
 
 #define REQUIRESSL
 
-#define ZNC_PALAVER_VERSION "1.2.0"
+#define ZNC_PALAVER_VERSION "1.2.1"
 
 #include <znc/Modules.h>
 #include <znc/User.h>
@@ -761,21 +761,23 @@ public:
                module.AddSocket(pSocket);
        }
 
-       void ClearBadges(CModule& module) {
+       void ClearBadges(CModule& module, bool bInformAPI) {
                if (m_uiBadge != 0) {
-                       MCString mcsHeaders;
+                       if (bInformAPI) {
+                               MCString mcsHeaders;
 
-                       CString token = GetPushToken();
-                       if (token.empty()) {
-                               token = GetIdentifier();
-                       }
-                       mcsHeaders["Authorization"] = CString("Bearer " + token);
-                       mcsHeaders["Content-Type"] = "application/json";
+                               CString token = GetPushToken();
+                               if (token.empty()) {
+                                       token = GetIdentifier();
+                               }
+                               mcsHeaders["Authorization"] = CString("Bearer " + token);
+                               mcsHeaders["Content-Type"] = "application/json";
 
-                       CString sJSON = "{\"badge\": 0}";
+                               CString sJSON = "{\"badge\": 0}";
 
-                       PLVHTTPSocket *pSocket = new PLVHTTPNotificationSocket(&module, token, "POST", GetPushEndpoint(), mcsHeaders, sJSON);
-                       module.AddSocket(pSocket);
+                               PLVHTTPSocket *pSocket = new PLVHTTPNotificationSocket(&module, token, "POST", GetPushEndpoint(), mcsHeaders, sJSON);
+                               module.AddSocket(pSocket);
+                       }
 
                        m_uiBadge = 0;
                }
@@ -965,8 +967,8 @@ public:
                                        it != m_vDevices.end(); ++it) {
                                CDevice& device = **it;
 
-                               if (device.HasClient(*m_pClient) == false && device.HasNetwork(*pNetwork)) {
-                                       device.ClearBadges(*this);
+                               if (device.HasNetwork(*pNetwork)) {
+                                       device.ClearBadges(*this, !device.HasClient(*m_pClient));
                                }
                        }
                }
git clone https://git.99rst.org/PROJECT