[mw-devel] [Git][milliways/mw][master] Give onoff mwjs objects a timestamp

Andrew Price welshbyte at sucs.org
Sat Apr 6 22:43:04 BST 2019


Andrew Price pushed to branch master at milliways / mw


Commits:
3d5db0e9 by Andrew Price at 2019-04-06T21:31:11Z
Give onoff mwjs objects a timestamp

function handler(ev)
{
	switch (ev.type) {
        case "mw_logon":
        case "mw_logoff":
        case "talker_join":
        case "talker_leave":
                onoff = ev.data;
		t = new Date(onoff.unixtime * 1000);
		mw.print("onoff event at: " + t);
		break;
	}
	return true;
}
mw.onevent.push(handler);

- - - - -


2 changed files:

- src/client/js-duk.c
- src/client/onoff.c


Changes:

=====================================
src/client/js-duk.c
=====================================
@@ -343,12 +343,14 @@ static int (*js_push_onoff_func[ONOFF_SIZE])(json_t*, duk_idx_t, int) = {
 
 /* Pushes the event object and attaches the common bits to it before calling
  * the onoff action type-specific function to fill in the rest */
-static int js_push_onoff_event(json_t *j, int action)
+static int js_push_onoff_event(json_t *j, int action, int64_t unixtime)
 {
 	duk_idx_t idx = duk_push_bare_object(ctx);
 	int type = json_getint(j, "type");
 	int ret;
 
+	duk_push_number(ctx, unixtime);
+	duk_put_prop_string(ctx, idx, "unixtime");
 	duk_push_boolean(ctx, json_is_true(json_object_get(j, "quiet")));
 	duk_put_prop_string(ctx, idx, "quiet");
 	duk_push_string(ctx, json_getstring(j, "user"));
@@ -925,7 +927,7 @@ static int js_push_event(struct mwevent *ev)
 			break;
 		duk_push_string(ctx, onoff_action_name[action]);
 		duk_put_prop_string(ctx, idx, "type");
-		ret = js_push_onoff_event(j, action);
+		ret = js_push_onoff_event(j, action, ev->ev_data.onoff->head.when);
 		if (ret == 0)
 			duk_put_prop_string(ctx, idx, "data");
 		break;


=====================================
src/client/onoff.c
=====================================
@@ -25,6 +25,7 @@ int announce_logon(const char *usr, int type, int quiet)
 	ipcmsg_destination(msg, SYSTEM_USER);
 	ipcmsg_json_encode(msg, j);
 	json_decref(j);
+	msg->head.when = time(NULL);
 	ipcmsg_transmit(msg);
 	return 0;
 }
@@ -48,6 +49,7 @@ int announce_logoff(const char *usr, int type, const char *agent, const char *re
 	ipcmsg_destination(msg, SYSTEM_USER);
 	ipcmsg_json_encode(msg, j);
 	json_decref(j);
+	msg->head.when = time(NULL);
 	ipcmsg_transmit(msg);
 	return 0;
 }
@@ -70,6 +72,7 @@ int announce_join(const char *usr, int channel, int type, const char *agent, int
 	ipcmsg_destination(msg, SYSTEM_USER);
 	ipcmsg_json_encode(msg, j);
 	json_decref(j);
+	msg->head.when = time(NULL);
 	ipcmsg_transmit(msg);
 	return 0;
 }
@@ -94,6 +97,7 @@ int announce_leave(const char *usr, int channel, int type, const char *agent, co
 	ipcmsg_destination(msg, SYSTEM_USER);
 	ipcmsg_json_encode(msg, j);
 	json_decref(j);
+	msg->head.when = time(NULL);
 	ipcmsg_transmit(msg);
 	return 0;
 }



View it on GitLab: https://projects.sucs.org/milliways/mw/commit/3d5db0e9544516cdf710c984ac92679ebd414b98

-- 
View it on GitLab: https://projects.sucs.org/milliways/mw/commit/3d5db0e9544516cdf710c984ac92679ebd414b98
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20190406/1bd3b9fe/attachment-0001.html>


More information about the mw-devel mailing list