From 94ad55784e043564ed38f4f84d76d8b1bfa2d7ef Mon Sep 17 00:00:00 2001 From: John Reese Date: Wed, 9 Mar 2011 10:59:51 -0500 Subject: [PATCH] Implement notification uri keyword expansion Resolves #198. Four keywords are supported: context, nick, datetime, and unixtime. --- README.md | 14 +++++++++++++- notifo.cpp | 20 ++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8190849..e4ad91d 100644 --- a/README.md +++ b/README.md @@ -202,7 +202,18 @@ Configuration * `message_url = ""` URI that will be sent with the notification to Notifo. This could be a web address or a - local scheme to access a mobile application. + local scheme to access a mobile application. Keyword expansion is performed on this + value each time a notification is sent; the following keywords will be replaced with + the appropriate value: + + * `{context}`: the channel or query window context + * `{nick}`: the nick that sent the message + * `{datetime}`: [ISO 8601][] date string, in server-local time + * `{unixtime}`: unix-style integer timestamp + + As an example, a value of "http://domain/{context}/{datetime}" would be expanded to + something similar to "http://domain/#channel/2011-03-09 14:25:09", or + "http://domain/{nick}/{unixtime}" to "http://domain/somenick/1299685136". ### Advanced @@ -256,5 +267,6 @@ This project is licensed under the MIT license. See the `LICENSE` file for deta [mantis]: http://leetcode.net/mantis [Notifo]: http://notifo.com "Notifo, Mobile Notifications for Everything" [ZNC]: http://en.znc.in "ZNC, an advanced IRC bouncer" +[ISO 8601]: http://en.wikipedia.org/wiki/ISO_8601 "ISO 8601 Date Format" diff --git a/notifo.cpp b/notifo.cpp index ce92bf5..79d5d51 100644 --- a/notifo.cpp +++ b/notifo.cpp @@ -167,7 +167,7 @@ class CNotifoMod : public CModule * @param title Message title to use * @param context Channel or nick context */ - void send_message(const CString& message, const CString& title="New Message", const CString& context="") + void send_message(const CString& message, const CString& title="New Message", const CString& context="*notifo", const CNick& nick=CString("*notifo")) { // Set the last notification time last_notification_time[context] = time(NULL); @@ -180,12 +180,28 @@ class CNotifoMod : public CModule short_message = message.Ellipsize(message_length); } + // Generate an ISO8601 date string + time_t rawtime; + struct tm * timeinfo; + time(&rawtime); + timeinfo = localtime(&rawtime); + char iso8601 [20]; + strftime(iso8601, 20, "%Y-%m-%d %H:%M:%S", timeinfo); + + // URI string replacements + MCString replace; + replace["{context}"] = context; + replace["{nick}"] = nick.GetNick(); + replace["{datetime}"] = CString(iso8601); + replace["{unixtime}"] = CString(time(NULL)); + CString uri = expand(options["message_uri"], replace); + // POST body parameters for the request CString post = "to=" + urlencode(options["username"]); post += "&msg=" + urlencode(short_message); post += "&label=" + urlencode(app); post += "&title=" + urlencode(title); - post += "&uri=" + urlencode(options["message_uri"]); + post += "&uri=" + urlencode(uri); // Request headers and POST body CString request = "POST " + notifo_url + " HTTP/1.1" + crlf;