Skip to content

Commit 825cb68

Browse files
committed
fix: clear badgge when Palaver device connects
1 parent cb74b8f commit 825cb68

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog for Palaver ZNC Module
22

3+
## 1.2.1 (18/07/2020)
4+
5+
### Bug Fixes
6+
7+
- Fixes a case where the unread badge on send push notifications would not get
8+
reset when reconnecting the same Palaver device.
9+
310
## 1.2.0
411

512
### Enhancements

palaver.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#define REQUIRESSL
99

10-
#define ZNC_PALAVER_VERSION "1.2.0"
10+
#define ZNC_PALAVER_VERSION "1.2.1"
1111

1212
#include <znc/Modules.h>
1313
#include <znc/User.h>
@@ -761,21 +761,23 @@ class CDevice {
761761
module.AddSocket(pSocket);
762762
}
763763

764-
void ClearBadges(CModule& module) {
764+
void ClearBadges(CModule& module, bool bInformAPI) {
765765
if (m_uiBadge != 0) {
766-
MCString mcsHeaders;
766+
if (bInformAPI) {
767+
MCString mcsHeaders;
767768

768-
CString token = GetPushToken();
769-
if (token.empty()) {
770-
token = GetIdentifier();
771-
}
772-
mcsHeaders["Authorization"] = CString("Bearer " + token);
773-
mcsHeaders["Content-Type"] = "application/json";
769+
CString token = GetPushToken();
770+
if (token.empty()) {
771+
token = GetIdentifier();
772+
}
773+
mcsHeaders["Authorization"] = CString("Bearer " + token);
774+
mcsHeaders["Content-Type"] = "application/json";
774775

775-
CString sJSON = "{\"badge\": 0}";
776+
CString sJSON = "{\"badge\": 0}";
776777

777-
PLVHTTPSocket *pSocket = new PLVHTTPNotificationSocket(&module, token, "POST", GetPushEndpoint(), mcsHeaders, sJSON);
778-
module.AddSocket(pSocket);
778+
PLVHTTPSocket *pSocket = new PLVHTTPNotificationSocket(&module, token, "POST", GetPushEndpoint(), mcsHeaders, sJSON);
779+
module.AddSocket(pSocket);
780+
}
779781

780782
m_uiBadge = 0;
781783
}
@@ -965,8 +967,8 @@ class CPalaverMod : public CModule {
965967
it != m_vDevices.end(); ++it) {
966968
CDevice& device = **it;
967969

968-
if (device.HasClient(*m_pClient) == false && device.HasNetwork(*pNetwork)) {
969-
device.ClearBadges(*this);
970+
if (device.HasNetwork(*pNetwork)) {
971+
device.ClearBadges(*this, !device.HasClient(*m_pClient));
970972
}
971973
}
972974
}

0 commit comments

Comments
 (0)