|
|
|
|
@ -342,7 +342,7 @@ int chat_feedback_command(struct UTUN_INSTANCE* inst, const char* command, char*
|
|
|
|
|
answer.count = n; bytes = chat_answer_encode(&answer, data, sizeof(data)); kind = CHAT_FEEDBACK_ANSWER; |
|
|
|
|
if (!poll_answer_allowed(&poll, &answer)) return poll_command_error("Answer violates poll rules", result); |
|
|
|
|
} else if (!strcmp(cmd, "react")) { |
|
|
|
|
uint8_t ids[CHAT_REACTION_SELECTED_MAX + 1]; size_t count = 0; |
|
|
|
|
uint8_t ids[CHAT_REACTION_SELECTED_MAX]; size_t count = 0; |
|
|
|
|
int clear = poll_field_bool(inst, command, "$.clear", 0); if (clear < 0) return poll_command_error("Invalid clear flag", result); |
|
|
|
|
if (!clear) { |
|
|
|
|
struct chat_feedback_record old; |
|
|
|
|
@ -359,13 +359,11 @@ int chat_feedback_command(struct UTUN_INSTANCE* inst, const char* command, char*
|
|
|
|
|
ok = type && (!strcmp(type, "integer") || !strcmp(type, "text")) && emoji >= 0 && emoji < CHAT_REACTION_COUNT; |
|
|
|
|
sqlite3_finalize(st); |
|
|
|
|
if (!ok) return poll_command_error("Invalid emoji", result); |
|
|
|
|
size_t at = 0; while (at < count && ids[at] != emoji) at++; |
|
|
|
|
int on = poll_field_bool(inst, command, "$.on", at == count); |
|
|
|
|
int selected = count == 1 && ids[0] == emoji; |
|
|
|
|
int on = poll_field_bool(inst, command, "$.on", !selected); |
|
|
|
|
if (on < 0) return poll_command_error("Invalid reaction state", result); |
|
|
|
|
if (on && at == count) { |
|
|
|
|
if (count == CHAT_REACTION_SELECTED_MAX) return poll_command_error("Too many reactions", result); |
|
|
|
|
ids[count++] = emoji; |
|
|
|
|
} else if (!on && at < count) { memmove(ids + at, ids + at + 1, count - at - 1); count--; } |
|
|
|
|
if (on) { ids[0] = (uint8_t)emoji; count = 1; } |
|
|
|
|
else if (selected) count = 0; |
|
|
|
|
} |
|
|
|
|
bytes = chat_reactions_encode(ids, count, data, sizeof(data)); kind = CHAT_FEEDBACK_REACTION; |
|
|
|
|
} else return poll_command_error("Unknown interaction command", result); |
|
|
|
|
|