diff options
| author | 2025-01-05 09:34:00 +0100 | |
|---|---|---|
| committer | 2025-01-05 09:34:00 +0100 | |
| commit | 3a1cae73265aebdbe678d94fbdc16edf3ccc643f (patch) | |
| tree | 3c50341495d370dfeb7bfe0312ad5644d9c8f865 | |
| parent | Use the site's CSS in the /share page. (diff) | |
| download | snac2-3a1cae73265aebdbe678d94fbdc16edf3ccc643f.tar.gz snac2-3a1cae73265aebdbe678d94fbdc16edf3ccc643f.tar.xz snac2-3a1cae73265aebdbe678d94fbdc16edf3ccc643f.zip | |
Moved post language setting to msg_note(), where it really belongs.
On the way, posting from the Mastodon API sets the language accordingly.
| -rw-r--r-- | activitypub.c | 19 | ||||
| -rw-r--r-- | html.c | 6 | ||||
| -rw-r--r-- | main.c | 17 | ||||
| -rw-r--r-- | mastoapi.c | 5 | ||||
| -rw-r--r-- | snac.h | 3 |
5 files changed, 26 insertions, 24 deletions
diff --git a/activitypub.c b/activitypub.c index e3a1f79..ea4d8ea 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -1422,7 +1422,8 @@ xs_dict *msg_follow(snac *snac, const char *q) | |||
| 1422 | 1422 | ||
| 1423 | 1423 | ||
| 1424 | xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, | 1424 | xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, |
| 1425 | const xs_str *in_reply_to, const xs_list *attach, int priv) | 1425 | const xs_str *in_reply_to, const xs_list *attach, |
| 1426 | int priv, const char *lang_str) | ||
| 1426 | /* creates a 'Note' message */ | 1427 | /* creates a 'Note' message */ |
| 1427 | { | 1428 | { |
| 1428 | xs *ntid = tid(0); | 1429 | xs *ntid = tid(0); |
| @@ -1584,6 +1585,20 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, | |||
| 1584 | if (xs_list_len(atls)) | 1585 | if (xs_list_len(atls)) |
| 1585 | msg = xs_dict_append(msg, "attachment", atls); | 1586 | msg = xs_dict_append(msg, "attachment", atls); |
| 1586 | 1587 | ||
| 1588 | /* set language content map */ | ||
| 1589 | if (xs_type(lang_str) == XSTYPE_STRING) { | ||
| 1590 | /* split at the first _ */ | ||
| 1591 | xs *l0 = xs_split(lang_str, "_"); | ||
| 1592 | const char *lang = xs_list_get(l0, 0); | ||
| 1593 | |||
| 1594 | if (xs_type(lang) == XSTYPE_STRING && strlen(lang) == 2) { | ||
| 1595 | /* a valid ISO language id */ | ||
| 1596 | xs *cmap = xs_dict_new(); | ||
| 1597 | cmap = xs_dict_set(cmap, lang, xs_dict_get(msg, "content")); | ||
| 1598 | msg = xs_dict_set(msg, "contentMap", cmap); | ||
| 1599 | } | ||
| 1600 | } | ||
| 1601 | |||
| 1587 | return msg; | 1602 | return msg; |
| 1588 | } | 1603 | } |
| 1589 | 1604 | ||
| @@ -1625,7 +1640,7 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach, | |||
| 1625 | const xs_list *opts, int multiple, int end_secs) | 1640 | const xs_list *opts, int multiple, int end_secs) |
| 1626 | /* creates a Question message */ | 1641 | /* creates a Question message */ |
| 1627 | { | 1642 | { |
| 1628 | xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0); | 1643 | xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0, NULL); |
| 1629 | int max = 8; | 1644 | int max = 8; |
| 1630 | xs_set seen; | 1645 | xs_set seen; |
| 1631 | 1646 | ||
| @@ -3515,7 +3515,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 3515 | const char *b64 = xs_dict_get(q_vars, "content"); | 3515 | const char *b64 = xs_dict_get(q_vars, "content"); |
| 3516 | int sz; | 3516 | int sz; |
| 3517 | xs *content = xs_base64_dec(b64, &sz); | 3517 | xs *content = xs_base64_dec(b64, &sz); |
| 3518 | xs *msg = msg_note(&snac, content, NULL, NULL, NULL, 0); | 3518 | xs *msg = msg_note(&snac, content, NULL, NULL, NULL, 0, NULL); |
| 3519 | xs *c_msg = msg_create(&snac, msg); | 3519 | xs *c_msg = msg_create(&snac, msg); |
| 3520 | 3520 | ||
| 3521 | timeline_add(&snac, xs_dict_get(msg, "id"), msg); | 3521 | timeline_add(&snac, xs_dict_get(msg, "id"), msg); |
| @@ -3661,7 +3661,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 3661 | enqueue_close_question(&snac, xs_dict_get(msg, "id"), end_secs); | 3661 | enqueue_close_question(&snac, xs_dict_get(msg, "id"), end_secs); |
| 3662 | } | 3662 | } |
| 3663 | else | 3663 | else |
| 3664 | msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv); | 3664 | msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv, NULL); |
| 3665 | 3665 | ||
| 3666 | if (sensitive != NULL) { | 3666 | if (sensitive != NULL) { |
| 3667 | msg = xs_dict_set(msg, "sensitive", xs_stock(XSTYPE_TRUE)); | 3667 | msg = xs_dict_set(msg, "sensitive", xs_stock(XSTYPE_TRUE)); |
| @@ -4095,7 +4095,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 4095 | int c = 0; | 4095 | int c = 0; |
| 4096 | 4096 | ||
| 4097 | while (xs_list_next(ls, &v, &c)) { | 4097 | while (xs_list_next(ls, &v, &c)) { |
| 4098 | xs *msg = msg_note(&snac, "", actor, irt, NULL, 1); | 4098 | xs *msg = msg_note(&snac, "", actor, irt, NULL, 1, NULL); |
| 4099 | 4099 | ||
| 4100 | /* set the option */ | 4100 | /* set the option */ |
| 4101 | msg = xs_dict_append(msg, "name", v); | 4101 | msg = xs_dict_append(msg, "name", v); |
| @@ -667,22 +667,7 @@ int main(int argc, char *argv[]) | |||
| 667 | else | 667 | else |
| 668 | content = xs_dup(url); | 668 | content = xs_dup(url); |
| 669 | 669 | ||
| 670 | msg = msg_note(&snac, content, NULL, NULL, attl, 0); | 670 | msg = msg_note(&snac, content, NULL, NULL, attl, 0, getenv("LANG")); |
| 671 | |||
| 672 | /* set a post language according the LANG environment variable */ | ||
| 673 | const char *lang_env = getenv("LANG"); | ||
| 674 | if (xs_type(lang_env) == XSTYPE_STRING) { | ||
| 675 | /* split at the first _ */ | ||
| 676 | xs *l0 = xs_split(lang_env, "_"); | ||
| 677 | const char *lang = xs_list_get(l0, 0); | ||
| 678 | |||
| 679 | if (xs_type(lang) == XSTYPE_STRING && strlen(lang) == 2) { | ||
| 680 | /* a valid ISO language id */ | ||
| 681 | xs *cmap = xs_dict_new(); | ||
| 682 | cmap = xs_dict_set(cmap, lang, xs_dict_get(msg, "content")); | ||
| 683 | msg = xs_dict_set(msg, "contentMap", cmap); | ||
| 684 | } | ||
| 685 | } | ||
| 686 | 671 | ||
| 687 | c_msg = msg_create(&snac, msg); | 672 | c_msg = msg_create(&snac, msg); |
| 688 | 673 | ||
| @@ -2600,6 +2600,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, | |||
| 2600 | const char *visibility = xs_dict_get(args, "visibility"); | 2600 | const char *visibility = xs_dict_get(args, "visibility"); |
| 2601 | const char *summary = xs_dict_get(args, "spoiler_text"); | 2601 | const char *summary = xs_dict_get(args, "spoiler_text"); |
| 2602 | const char *media_ids = xs_dict_get(args, "media_ids"); | 2602 | const char *media_ids = xs_dict_get(args, "media_ids"); |
| 2603 | const char *language = xs_dict_get(args, "language"); | ||
| 2603 | 2604 | ||
| 2604 | if (xs_is_null(media_ids)) | 2605 | if (xs_is_null(media_ids)) |
| 2605 | media_ids = xs_dict_get(args, "media_ids[]"); | 2606 | media_ids = xs_dict_get(args, "media_ids[]"); |
| @@ -2650,7 +2651,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, | |||
| 2650 | 2651 | ||
| 2651 | /* prepare the message */ | 2652 | /* prepare the message */ |
| 2652 | xs *msg = msg_note(&snac, content, NULL, irt, attach_list, | 2653 | xs *msg = msg_note(&snac, content, NULL, irt, attach_list, |
| 2653 | strcmp(visibility, "public") == 0 ? 0 : 1); | 2654 | strcmp(visibility, "public") == 0 ? 0 : 1, language); |
| 2654 | 2655 | ||
| 2655 | if (!xs_is_null(summary) && *summary) { | 2656 | if (!xs_is_null(summary) && *summary) { |
| 2656 | msg = xs_dict_set(msg, "sensitive", xs_stock(XSTYPE_TRUE)); | 2657 | msg = xs_dict_set(msg, "sensitive", xs_stock(XSTYPE_TRUE)); |
| @@ -3000,7 +3001,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, | |||
| 3000 | if (o) { | 3001 | if (o) { |
| 3001 | const char *name = xs_dict_get(o, "name"); | 3002 | const char *name = xs_dict_get(o, "name"); |
| 3002 | 3003 | ||
| 3003 | xs *msg = msg_note(&snac, "", atto, (char *)id, NULL, 1); | 3004 | xs *msg = msg_note(&snac, "", atto, (char *)id, NULL, 1, NULL); |
| 3004 | msg = xs_dict_append(msg, "name", name); | 3005 | msg = xs_dict_append(msg, "name", name); |
| 3005 | 3006 | ||
| 3006 | xs *c_msg = msg_create(&snac, msg); | 3007 | xs *c_msg = msg_create(&snac, msg); |
| @@ -314,7 +314,8 @@ xs_dict *msg_create(snac *snac, const xs_dict *object); | |||
| 314 | xs_dict *msg_follow(snac *snac, const char *actor); | 314 | xs_dict *msg_follow(snac *snac, const char *actor); |
| 315 | 315 | ||
| 316 | xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, | 316 | xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, |
| 317 | const xs_str *in_reply_to, const xs_list *attach, int priv); | 317 | const xs_str *in_reply_to, const xs_list *attach, |
| 318 | int priv, const char *lang); | ||
| 318 | 319 | ||
| 319 | xs_dict *msg_undo(snac *snac, const xs_val *object); | 320 | xs_dict *msg_undo(snac *snac, const xs_val *object); |
| 320 | xs_dict *msg_delete(snac *snac, const char *id); | 321 | xs_dict *msg_delete(snac *snac, const char *id); |