Commit 652ee18c authored by Andrew Price's avatar Andrew Price
Browse files

js-duk: Add a channel object to the message_received objects

    function handler(ev)
    {
        switch (ev.type) {
        case "message_received":
                msg = ev.data;
                ...
                mw.print("msg.channel.id: " + msg.channel.id);
                mw.print("msg.channel.name: " + msg.channel.name);
                mw.print("msg.channel.topic: " + msg.channel.topic);
                mw.print("msg.channel.soundproof: " + msg.channel.soundproof);
                ...
    }
    mw.onevent.push(handler);
parent 2dcaa5fa
Loading
Loading
Loading
Loading
Loading
+37 −1
Original line number Diff line number Diff line
@@ -148,6 +148,31 @@ static int js_push_username(int32_t id)
	return ret;
}

static int js_push_channel(uint32_t dst)
{
	struct room room = {0};
	duk_idx_t idx;

	if (!LoadRoom(&room, dst))
		return 1;

	idx = duk_push_bare_object(ctx); /* The channel object */

	duk_push_number(ctx, dst);
	duk_put_prop_string(ctx, idx, "id");
	if (room.name != NULL) {
		duk_push_string(ctx, room.name);
		duk_put_prop_string(ctx, idx, "name");
	}
	if (room.desc != NULL) {
		duk_push_string(ctx, room.desc);
		duk_put_prop_string(ctx, idx, "topic");
	}
	duk_push_boolean(ctx, room.sproof);
	duk_put_prop_string(ctx, idx, "soundproof");
	return 0;
}

static int js_push_ipcmsg_event(ipc_message_t *msg)
{
	const char *str;
@@ -178,9 +203,20 @@ static int js_push_ipcmsg_event(ipc_message_t *msg)
	duk_put_prop_string(ctx, idx, "ipc_type");
	js_push_username(msg->head.src);
	duk_put_prop_string(ctx, idx, "from_name");
	if (msg->head.type == IPC_SAYTOUSER) {
	switch (msg->head.type) {
	case IPC_SAYTOROOM:
		if (js_push_channel(msg->head.dst)) {
			duk_pop(ctx);
			return -1;
		}
		duk_put_prop_string(ctx, idx, "channel");
		break;
	case IPC_SAYTOUSER:
		duk_push_string(ctx, json_getstring(json, "target"));
		duk_put_prop_string(ctx, idx, "to_name");
		break;
	default:
		break;
	}
	duk_push_string(ctx, json_getstring(json, "type"));
	duk_put_prop_string(ctx, idx, "type");
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ static int str2num(char *in)

	if (in == NULL)
	{
		return(-1);
		return 0;
	}
	else
	{