Skip to content

Commit

Permalink
fix: clear badgge when Palaver device connects
Browse files Browse the repository at this point in the history
  • Loading branch information
kylef committed Jul 18, 2020
1 parent cb74b8f commit 825cb68
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 16 additions & 14 deletions palaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -761,21 +761,23 @@ class CDevice {
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;
}
Expand Down Expand Up @@ -965,8 +967,8 @@ class CPalaverMod : public CModule {
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));
}
}
}
Expand Down

0 comments on commit 825cb68

Please sign in to comment.