From: Kyle Fuller Date: Thu, 13 Apr 2017 15:16:39 +0000 (+0100) Subject: feat: Support disabling message previews X-Git-Tag: 1.1.0~1 X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=8dd283f63dfb27fc00beec664f5a68e0b93ae42b;p=znc-palaver.git feat: Support disabling message previews --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 723124b..7f296f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,9 @@ - We no longer mention you with private NOTICEs, these are usually server or service notices and rarely from a real user. +- You can now disable showing message previews in the Palaver app which will + prevent the message contents from being sent as a push notification. + ### Bug Fixes - We now detect when building the module with an unsupported compiler and will diff --git a/palaver.cpp b/palaver.cpp index 2907f61..8a59243 100644 --- a/palaver.cpp +++ b/palaver.cpp @@ -40,6 +40,7 @@ const char *kPLVMentionNickKey = "MENTION-NICK"; const char *kPLVIgnoreKeywordKey = "IGNORE-KEYWORD"; const char *kPLVIgnoreChannelKey = "IGNORE-CHANNEL"; const char *kPLVIgnoreNickKey = "IGNORE-NICK"; +const char *kPLVShowMessagePreviewKey = "SHOW-MESSAGE-PREVIEW"; #ifdef HAS_REGEX @@ -245,6 +246,14 @@ public: return m_sPushEndpoint; } + void SetShowMessagePreview(bool bShowMessagePreview) { + m_bShowMessagePreview = bShowMessagePreview; + } + + bool GetShowMessagePreview() const { + return m_bShowMessagePreview; + } + bool HasClient(const CClient& client) const { bool bHasClient = false; @@ -392,6 +401,7 @@ public: m_bInNegotiation = false; m_sVersion = ""; m_sPushEndpoint = ""; + m_bShowMessagePreview = true; m_vMentionKeywords.clear(); m_vMentionChannels.clear(); @@ -570,6 +580,8 @@ public: SetVersion(sValue); } else if (sKey.Equals(kPLVPushEndpointKey)) { SetPushEndpoint(sValue); + } else if (sKey.Equals(kPLVShowMessagePreviewKey)) { + SetShowMessagePreview(sValue.Equals("true")); } } else if (sCommand.Equals("ADD")) { CString sKey = sLine.Token(1); @@ -607,6 +619,12 @@ public: File.Write("SET VERSION " + GetVersion() + "\n"); } + if (GetShowMessagePreview()) { + File.Write("SET " + CString(kPLVShowMessagePreviewKey) + " true\n"); + } else { + File.Write("SET " + CString(kPLVShowMessagePreviewKey) + " false\n"); + } + if (GetPushEndpoint().empty() == false) { File.Write("SET " + CString(kPLVPushEndpointKey) + " " + GetPushEndpoint() + "\n"); } @@ -681,7 +699,13 @@ public: CString sJSON = "{"; sJSON += "\"badge\": " + CString(m_uiBadge); - sJSON += ",\"message\": \"" + sNotification.Replace_n("\"", "\\\"") + "\""; + + if (GetShowMessagePreview()) { + sJSON += ",\"message\": \"" + sNotification.Replace_n("\"", "\\\"") + "\""; + } else { + sJSON += ",\"private\": true"; + } + sJSON += ",\"sender\": \"" + sSender.Replace_n("\"", "\\\"") + "\""; if (pChannel) { sJSON += ",\"channel\": \"" + pChannel->GetName().Replace_n("\"", "\\\"") + "\""; @@ -737,6 +761,7 @@ private: VCString m_vIgnoreChannels; VCString m_vIgnoreNicks; + bool m_bShowMessagePreview; bool m_bInNegotiation; unsigned int m_uiBadge; };