summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--html.c72
1 files changed, 32 insertions, 40 deletions
diff --git a/html.c b/html.c
index 2146c93..a2dfb79 100644
--- a/html.c
+++ b/html.c
@@ -398,6 +398,37 @@ xs_html *html_msg_icon(snac *user, const char *actor_id, const xs_dict *msg,
398 return actor_icon; 398 return actor_icon;
399} 399}
400 400
401void html_note_render_visibility(snac* user, xs_html *form, const int scope)
402{
403 // scopes aren't sorted by value unfortunately, so simple math won't work to limit them. using map-like thing here
404 static const int public_scopes[5] = {SCOPE_PUBLIC, SCOPE_UNLISTED, SCOPE_FOLLOWERS, SCOPE_MENTIONED, -1};
405 static const int unlisted_scopes[4] = {SCOPE_UNLISTED, SCOPE_FOLLOWERS, SCOPE_MENTIONED, -1};
406 static const int followers_scopes[3] = {SCOPE_FOLLOWERS, SCOPE_MENTIONED, -1};
407 static const int mentioned_scopes[2] = {SCOPE_MENTIONED, -1};
408 static const int * const scopes[4] = { public_scopes, mentioned_scopes, unlisted_scopes, followers_scopes};
409 static const char * const scopes_tags[4] = { "public", "mentioned", "unlisted", "followers"};
410 static const char * const scopes_names[4] = { "Public", "Direct Message", "Unlisted", "Followers-only"};
411
412 xs_html *paragraph = xs_html_tag("p", xs_html_text(L("Visibility: ")));
413 const int* to_render = scopes[scope];
414 for( int i = 0; to_render[i] != -1; i++ ){
415 const int scope_i = to_render[i];
416 const char* value = scopes_tags[scope_i];
417 const char* name = scopes_names[scope_i];
418 xs_html_add(paragraph,
419 xs_html_tag("label",
420 xs_html_sctag("input",
421 xs_html_attr("type", "radio"),
422 xs_html_attr("name", "visibility"),
423 xs_html_attr("value", value),
424 xs_html_attr(scope == scope_i ? "checked" : "", NULL)),
425 xs_html_text(" "),
426 xs_html_text(L(name)),
427 xs_html_text(" "))
428 );
429 }
430 xs_html_add(form, paragraph);
431}
401 432
402xs_html *html_note(snac *user, const char *summary, 433xs_html *html_note(snac *user, const char *summary,
403 const char *div_id, const char *form_id, 434 const char *div_id, const char *form_id,
@@ -455,46 +486,7 @@ xs_html *html_note(snac *user, const char *summary,
455 xs_html_attr("type", "hidden"), 486 xs_html_attr("type", "hidden"),
456 xs_html_attr("name", "to"), 487 xs_html_attr("name", "to"),
457 xs_html_attr("value", actor_id))); 488 xs_html_attr("value", actor_id)));
458 else { 489 html_note_render_visibility(user, form, scope);
459 xs_html_add(form,
460 xs_html_tag("p",
461 xs_html_text(L("Visibility: ")),
462 xs_html_tag("label",
463 xs_html_sctag("input",
464 xs_html_attr("type", "radio"),
465 xs_html_attr("name", "visibility"),
466 xs_html_attr("value", "public"),
467 xs_html_attr(scope == SCOPE_PUBLIC ? "checked" : "", NULL)),
468 xs_html_text(" "),
469 xs_html_text(L("Public"))),
470 xs_html_text(" "),
471 xs_html_tag("label",
472 xs_html_sctag("input",
473 xs_html_attr("type", "radio"),
474 xs_html_attr("name", "visibility"),
475 xs_html_attr("value", "unlisted"),
476 xs_html_attr(scope == SCOPE_UNLISTED ? "checked" : "", NULL)),
477 xs_html_text(" "),
478 xs_html_text(L("Unlisted"))),
479 xs_html_text(" "),
480 xs_html_tag("label",
481 xs_html_sctag("input",
482 xs_html_attr("type", "radio"),
483 xs_html_attr("name", "visibility"),
484 xs_html_attr("value", "followers"),
485 xs_html_attr(scope == SCOPE_FOLLOWERS ? "checked" : "", NULL)),
486 xs_html_text(" "),
487 xs_html_text(L("Followers-only"))),
488 xs_html_text(" "),
489 xs_html_tag("label",
490 xs_html_sctag("input",
491 xs_html_attr("type", "radio"),
492 xs_html_attr("name", "visibility"),
493 xs_html_attr("value", "mentioned"),
494 xs_html_attr(scope == SCOPE_MENTIONED ? "checked" : "", NULL)),
495 xs_html_text(" "),
496 xs_html_text(L("Direct Message")))));
497 }
498 490
499 if (redir) 491 if (redir)
500 xs_html_add(form, 492 xs_html_add(form,