[mw-devel] [Git][arthur/mw][master] js-duk: Add a channel object to the message_received objects
Andrew Price
welshbyte at sucs.org
Fri Nov 16 20:33:49 GMT 2018
Andrew Price pushed to branch master at Justin Mitchell / mw
Commits:
652ee18c by Andrew Price at 2018-11-16T20:33:27+00:00
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);
- - - - -
2 changed files:
- src/client/js-duk.c
- src/rooms.c
Changes:
=====================================
src/client/js-duk.c
=====================================
--- a/src/client/js-duk.c
+++ b/src/client/js-duk.c
@@ -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");
=====================================
src/rooms.c
=====================================
--- a/src/rooms.c
+++ b/src/rooms.c
@@ -25,7 +25,7 @@ static int str2num(char *in)
if (in == NULL)
{
- return(-1);
+ return 0;
}
else
{
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/652ee18cd3abe23c90b173ffb47f688c1d19bc57
--
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/652ee18cd3abe23c90b173ffb47f688c1d19bc57
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/20181116/89c26e81/attachment-0001.html>
More information about the mw-devel
mailing list