Skip to content

Commit

Permalink
Implement notification uri keyword expansion
Browse files Browse the repository at this point in the history
Resolves #198.  Four keywords are supported: context, nick, datetime,
and unixtime.
  • Loading branch information
amyreese committed Mar 9, 2011
1 parent df891c0 commit 94ad557
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
14 changes: 13 additions & 1 deletion README.md
Expand Up @@ -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

Expand Down Expand Up @@ -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"

<!-- vim:set ft= expandtab tabstop=4 shiftwidth=4: -->
20 changes: 18 additions & 2 deletions notifo.cpp
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 94ad557

Please sign in to comment.