1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

fix display of a "list type" in a form if there's no value assigned yet

It is possible, that a server sends a form with a field as follows, which
has no (default) value assigned.

```
<field label="foo" type="list-single" var="bar">
  <option label="a"><value>a</value></option>
  <option label="b"><value>b</value></option>
  <option label="c"><value>c</value></option>
</field>
```

This patch fixes profanity to show that list. Before this patch
profanity showed nothing.

I stumbled over this while running the `/room config` command inside
a newly created muc on the `sure.im` XMPP server.

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
Steffen Jaeckel 2023-04-03 15:54:33 +02:00
parent 74415ae71d
commit 7271898541

View File

@ -215,8 +215,8 @@ _confwin_form_field(ProfWin* window, char* tag, FormField* field)
win_append(window, THEME_DEFAULT, ": "); win_append(window, THEME_DEFAULT, ": ");
} }
GSList* values = field->values; GSList* curr_value = field->values;
GSList* curr_value = values; GSList* curr_option;
switch (field->type_t) { switch (field->type_t) {
case FIELD_HIDDEN: case FIELD_HIDDEN:
@ -272,36 +272,30 @@ _confwin_form_field(ProfWin* window, char* tag, FormField* field)
} }
break; break;
case FIELD_LIST_SINGLE: case FIELD_LIST_SINGLE:
if (curr_value) { win_newline(window);
win_newline(window); char* value = curr_value ? curr_value->data : NULL;
char* value = curr_value->data; curr_option = field->options;
GSList* options = field->options; while (curr_option) {
GSList* curr_option = options; FormOption* option = curr_option->data;
while (curr_option) { if (g_strcmp0(option->value, value) == 0) {
FormOption* option = curr_option->data; win_println(window, THEME_ONLINE, "-", " [%s] %s", option->value, option->label);
if (g_strcmp0(option->value, value) == 0) { } else {
win_println(window, THEME_ONLINE, "-", " [%s] %s", option->value, option->label); win_println(window, THEME_OFFLINE, "-", " [%s] %s", option->value, option->label);
} else {
win_println(window, THEME_OFFLINE, "-", " [%s] %s", option->value, option->label);
}
curr_option = g_slist_next(curr_option);
} }
curr_option = g_slist_next(curr_option);
} }
break; break;
case FIELD_LIST_MULTI: case FIELD_LIST_MULTI:
if (curr_value) { win_newline(window);
win_newline(window); curr_option = field->options;
GSList* options = field->options; while (curr_option) {
GSList* curr_option = options; FormOption* option = curr_option->data;
while (curr_option) { if (g_slist_find_custom(curr_value, option->value, (GCompareFunc)g_strcmp0)) {
FormOption* option = curr_option->data; win_println(window, THEME_ONLINE, "-", " [%s] %s", option->value, option->label);
if (g_slist_find_custom(curr_value, option->value, (GCompareFunc)g_strcmp0)) { } else {
win_println(window, THEME_ONLINE, "-", " [%s] %s", option->value, option->label); win_println(window, THEME_OFFLINE, "-", " [%s] %s", option->value, option->label);
} else {
win_println(window, THEME_OFFLINE, "-", " [%s] %s", option->value, option->label);
}
curr_option = g_slist_next(curr_option);
} }
curr_option = g_slist_next(curr_option);
} }
break; break;
case FIELD_JID_SINGLE: case FIELD_JID_SINGLE: