From: Kyle Fuller Date: Fri, 13 Sep 2013 17:11:38 +0000 (+0100) Subject: Reset the badge when another client connects X-Git-Tag: 1.0.0~19 X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=f7b20097bf260c9a4e3b7923a856ec26c59ea5b0;p=znc-palaver.git Reset the badge when another client connects --- diff --git a/palaver.cpp b/palaver.cpp index 088d16f..1269b01 100644 --- a/palaver.cpp +++ b/palaver.cpp @@ -83,6 +83,7 @@ public: CDevice(const CString &sToken) { m_sToken = sToken; m_bInNegotiation = false; + m_uiBadge = 0; } CString GetVersion() const { @@ -239,6 +240,8 @@ public: m_vIgnoreKeywords.clear(); m_vIgnoreChannels.clear(); m_vIgnoreNicks.clear(); + + m_uiBadge = 0; } void AddMentionKeyword(const CString& sKeyword) { @@ -483,13 +486,16 @@ public: #pragma mark - Notifications void SendNotification(CModule& module, const CString& sSender, const CString& sNotification, const CChan *pChannel) { + ++m_uiBadge; + MCString mcsHeaders; mcsHeaders["Authorization"] = CString("Bearer " + GetToken()); mcsHeaders["Content-Type"] = "application/json"; CString sJSON = "{"; - sJSON += "\"message\": \"" + sNotification.Replace_n("\"", "\\\"") + "\""; + sJSON += "\"badge\": " + m_uiBadge; + sJSON += ",\"message\": \"" + sNotification.Replace_n("\"", "\\\"") + "\""; sJSON += ",\"sender\": \"" + sSender.Replace_n("\"", "\\\"") + "\""; if (pChannel) { sJSON += ",\"channel\": \"" + pChannel->GetName().Replace_n("\"", "\\\"") + "\""; @@ -500,6 +506,22 @@ public: module.AddSocket(pSocket); } + void ClearBadges(CModule& module) { + if (m_uiBadge != 0) { + MCString mcsHeaders; + + mcsHeaders["Authorization"] = CString("Bearer " + GetToken()); + mcsHeaders["Content-Type"] = "application/json"; + + CString sJSON = "{\"badge\": 0}"; + + PLVHTTPSocket *pSocket = new PLVHTTPSocket(&module, "POST", GetPushEndpoint(), mcsHeaders, sJSON); + module.AddSocket(pSocket); + + m_uiBadge = 0; + } + } + std::map GetNetworks() const { return m_msvsNetworks; } @@ -522,6 +544,7 @@ private: VCString m_vIgnoreNicks; bool m_bInNegotiation; + unsigned int m_uiBadge; }; class CPalaverMod : public CModule { @@ -630,6 +653,19 @@ public: Save(); } } + + if (m_pNetwork) { + // Let's reset any other devices for this client + + for (std::vector::const_iterator it = m_vDevices.begin(); + it != m_vDevices.end(); ++it) { + CDevice& device = **it; + + if (device.HasClient(*m_pClient) == false && device.HasNetwork(*m_pNetwork)) { + device.ClearBadges(*this); + } + } + } } virtual void OnClientDisconnect() { @@ -904,4 +940,4 @@ template<> void TModInfo(CModInfo& Info) { Info.SetWikiPage("palaver"); } -GLOBALMODULEDEFS(CPalaverMod, "Palaver support module") \ No newline at end of file +GLOBALMODULEDEFS(CPalaverMod, "Palaver support module")