[mw-devel] [Git][arthur/mw][master] 4 commits: js-duk: Set to_name properly for .sayto/.whisper
Andrew Price
welshbyte at sucs.org
Wed Oct 17 08:41:08 BST 2018
Andrew Price pushed to branch master at Justin Mitchell / mw
Commits:
94ca2afd by Andrew Price at 2018-10-17T00:32:35+01:00
js-duk: Set to_name properly for .sayto/.whisper
Fixes #31
- - - - -
c6dd9d9a by Andrew Price at 2018-10-17T00:33:10+01:00
js-duk: Don't set excluded_name when no one is excluded
- - - - -
06d4bbf8 by Andrew Price at 2018-10-17T00:57:16+01:00
js-duk: Implement deletion for mw.store entries
- - - - -
2a4ad037 by Andrew Price at 2018-10-17T08:38:10+01:00
js-duk: Implement 'has' for mw.store
Adds support for things like 'if ("foo" in mw.store) ...'
- - - - -
3 changed files:
- src/client/js-duk.c
- src/client/sqlite.c
- src/client/sqlite.h
Changes:
=====================================
src/client/js-duk.c
=====================================
--- a/src/client/js-duk.c
+++ b/src/client/js-duk.c
@@ -150,6 +150,7 @@ static int js_push_username(int32_t id)
static int js_push_ipcmsg_event(ipc_message_t *msg)
{
+ const char *str;
duk_idx_t idx;
json_t *json;
json_t *val;
@@ -178,16 +179,18 @@ static int js_push_ipcmsg_event(ipc_message_t *msg)
js_push_username(msg->head.src);
duk_put_prop_string(ctx, idx, "from_name");
if (msg->head.type == IPC_SAYTOUSER) {
- js_push_username(msg->head.dst);
+ duk_push_string(ctx, json_getstring(json, "target"));
duk_put_prop_string(ctx, idx, "to_name");
}
duk_push_string(ctx, json_getstring(json, "type"));
duk_put_prop_string(ctx, idx, "type");
duk_push_string(ctx, json_getstring(json, "text"));
duk_put_prop_string(ctx, idx, "text");
- duk_push_string(ctx, json_getstring(json, "exclude"));
- duk_put_prop_string(ctx, idx, "excluded_name");
-
+ str = json_getstring(json, "exclude");
+ if (str != NULL) {
+ duk_push_string(ctx, str);
+ duk_put_prop_string(ctx, idx, "excluded_name");
+ }
val = json_object_get(json, "plural");
if (val != NULL && json_is_integer(val)) {
unsigned p = json_integer_value(val);
@@ -869,6 +872,7 @@ int stop_js(void)
return 0;
}
+/* x = mw.store.foo; */
static duk_ret_t js_store_get(duk_context *cx)
{
const char *key = duk_get_string(cx, 1);
@@ -880,6 +884,7 @@ static duk_ret_t js_store_get(duk_context *cx)
return 1;
}
+/* mw.store.foo = "bar"; */
static duk_ret_t js_store_set(duk_context *cx)
{
const char *key = duk_get_string(cx, 1);
@@ -888,9 +893,32 @@ static duk_ret_t js_store_set(duk_context *cx)
return 0;
}
+/* delete mw.store.foo; */
+static duk_ret_t js_store_delete(duk_context *cx)
+{
+ const char *key = duk_get_string(cx, 1);
+
+ userdb_set(USERDB_PUBLIC, user->record.name, key, NULL);
+ return 0;
+
+}
+
+/* "foo" in mw.store */
+static duk_ret_t js_store_has(duk_context *cx)
+{
+ const char *key = duk_get_string(cx, 1);
+ int exists;
+
+ exists = userdb_key_exists(USERDB_PUBLIC, user->record.name, key);
+ duk_push_boolean(cx, exists);
+ return 1;
+}
+
static const duk_function_list_entry store_handlers[] = {
{ "get", js_store_get, 3 },
{ "set", js_store_set, 4 },
+ { "has", js_store_has, 2 },
+ { "deleteProperty", js_store_delete, 2 },
{ NULL, NULL, 0 }
};
=====================================
src/client/sqlite.c
=====================================
--- a/src/client/sqlite.c
+++ b/src/client/sqlite.c
@@ -157,6 +157,24 @@ out_dbfree:
return out;
}
+int userdb_key_exists(const char *table, const char *user, const char *key)
+{
+ struct db_result *result;
+ char *query;
+ int nrows;
+
+ query = sqlite3_mprintf("SELECT * from %Q WHERE user=%Q AND opt=%Q", table, user, key);
+ result = db_query(USERSQL, query, 1);
+ sqlite3_free(query);
+
+ if (result == NULL)
+ return 0;
+ nrows = db_numrows(result);
+ db_free(result);
+ if (nrows < 1)
+ return 0;
+ return 1;
+}
void userdb_set(const char *table, const char *user, const char *opt, const char *arg)
{
struct db_result *old;
=====================================
src/client/sqlite.h
=====================================
--- a/src/client/sqlite.h
+++ b/src/client/sqlite.h
@@ -4,6 +4,7 @@
extern struct js_db_result* js_db_query(char *dbname, const char *query);
extern void js_db_free(struct js_db_result *result);
extern char * userdb_get(const char *table, const char *user, const char *opt);
+extern int userdb_key_exists(const char *table, const char *user, const char *key);
extern void userdb_set(const char *table, const char *user, const char *opt, const char *arg);
#endif /* CLIENT_SQLITE_H */
View it on GitLab: https://projects.sucs.org/arthur/mw/compare/1f28d11ef7fa9a66f4bc0e900b44516ecc531fef...2a4ad037b49d77baf220033c751eb8d81ae15357
--
View it on GitLab: https://projects.sucs.org/arthur/mw/compare/1f28d11ef7fa9a66f4bc0e900b44516ecc531fef...2a4ad037b49d77baf220033c751eb8d81ae15357
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/20181017/76af8592/attachment-0001.html>
More information about the mw-devel
mailing list