mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
Disallow empty or repeated options in msg_question().
This commit is contained in:
parent
af88b78478
commit
e66b3ff8da
1 changed files with 21 additions and 10 deletions
|
@ -1057,6 +1057,7 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach,
|
||||||
xs *ntid = tid(0);
|
xs *ntid = tid(0);
|
||||||
xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0);
|
xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0);
|
||||||
int max = 8;
|
int max = 8;
|
||||||
|
xs_set seen;
|
||||||
|
|
||||||
msg = xs_dict_set(msg, "type", "Question");
|
msg = xs_dict_set(msg, "type", "Question");
|
||||||
|
|
||||||
|
@ -1068,7 +1069,10 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach,
|
||||||
xs_str *v;
|
xs_str *v;
|
||||||
xs *replies = xs_json_loads("{\"type\":\"Collection\",\"totalItems\":0}");
|
xs *replies = xs_json_loads("{\"type\":\"Collection\",\"totalItems\":0}");
|
||||||
|
|
||||||
while (max-- && xs_list_iter(&p, &v)) {
|
xs_set_init(&seen);
|
||||||
|
|
||||||
|
while (max && xs_list_iter(&p, &v)) {
|
||||||
|
if (*v) {
|
||||||
xs *v2 = xs_dup(v);
|
xs *v2 = xs_dup(v);
|
||||||
xs *d = xs_dict_new();
|
xs *d = xs_dict_new();
|
||||||
|
|
||||||
|
@ -1077,10 +1081,17 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach,
|
||||||
v2 = xs_str_cat(v2, "...");
|
v2 = xs_str_cat(v2, "...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (xs_set_add(&seen, v2) == 1) {
|
||||||
d = xs_dict_append(d, "name", v2);
|
d = xs_dict_append(d, "name", v2);
|
||||||
d = xs_dict_append(d, "replies", replies);
|
d = xs_dict_append(d, "replies", replies);
|
||||||
o = xs_list_append(o, d);
|
o = xs_list_append(o, d);
|
||||||
|
|
||||||
|
max--;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xs_set_free(&seen);
|
||||||
|
|
||||||
msg = xs_dict_append(msg, multiple ? "anyOf" : "oneOf", o);
|
msg = xs_dict_append(msg, multiple ? "anyOf" : "oneOf", o);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue