Commit 3d5db0e9 authored by Andrew Price's avatar Andrew Price

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);
parent 3222e3af
Pipeline #558 passed with stage
in 7 minutes and 39 seconds
......@@ -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;
......
......@@ -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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment