diff --git a/src/base_page.c b/src/base_page.c index 11fc123..07e3bf0 100644 --- a/src/base_page.c +++ b/src/base_page.c @@ -43,17 +43,7 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t* struct mstdnt_notification* notifs = NULL; size_t notifs_len; - if (!ssn->config.changed && cookie) - { - if (ssn->cookies.theme) - ssn->config.theme = ssn->cookies.theme; - if (ssn->cookies.logged_in) - login_string = ""; - if (ssn->cookies.themeclr) - ssn->config.themeclr = ssn->cookies.themeclr; - if (ssn->cookies.background_url) - ssn->config.background_url = ssn->cookies.background_url; - } + read_config(ssn); if (ssn->config.background_url) { diff --git a/src/cookie.c b/src/cookie.c index 5e72a3f..7e156d0 100644 --- a/src/cookie.c +++ b/src/cookie.c @@ -56,6 +56,9 @@ char* read_cookies_env(struct cookie_values* cookies) { "instance_url", &(cookies->instance_url), key_string }, { "background_url", &(cookies->background_url), key_string }, { "themeclr", &(cookies->themeclr), key_int }, + { "jsactions", &(cookies->jsactions), key_int }, + { "jsreply", &(cookies->jsreply), key_int }, + { "jslive", &(cookies->jslive), key_int }, }; do diff --git a/src/cookie.h b/src/cookie.h index c996071..8c74c7a 100644 --- a/src/cookie.h +++ b/src/cookie.h @@ -28,6 +28,9 @@ struct cookie_values char* instance_url; char* background_url; int themeclr; + int jsactions; + int jsreply; + int jslive; }; struct http_cookie_info diff --git a/src/local_config_set.c b/src/local_config_set.c index d2980f9..7b8f258 100644 --- a/src/local_config_set.c +++ b/src/local_config_set.c @@ -51,7 +51,7 @@ int set_config_int(int* ssn, if (ssn) { *ssn = str_l; - printf("Set-Cookie: %s=%ld; HttpOnly; Path=/; SameSite=Strict;\r\n", + printf("Set-Cookie: %s=%ld; HttpOnly; Path=/; Max-Age=31536000; SameSite=Strict;\r\n", cookie_name, str_l); } @@ -79,3 +79,30 @@ void load_config(struct session* ssn, mastodont_t* api) set_config_int(&(ssn->config.jsreply), "jsreply", ssn->post.jsreply); set_config_int(&(ssn->config.jslive), "jslive", ssn->post.jslive); } + +#define SET_COOKIE_CONFIG(post, cookie, config) do{ \ + if (cookie && !post) \ + config = cookie; \ + } while(0); + +void read_config(struct session* ssn) +{ + SET_COOKIE_CONFIG(ssn->post.theme, + ssn->cookies.theme, + ssn->config.theme); + SET_COOKIE_CONFIG(ssn->post.themeclr, + ssn->cookies.themeclr, + ssn->config.themeclr); + SET_COOKIE_CONFIG(ssn->post.jsactions, + ssn->cookies.jsactions, + ssn->config.jsactions); + SET_COOKIE_CONFIG(ssn->post.jsreply, + ssn->cookies.jsreply, + ssn->config.jsreply); + SET_COOKIE_CONFIG(ssn->post.jslive, + ssn->cookies.jslive, + ssn->config.jslive); + SET_COOKIE_CONFIG((ssn->post.files.content && ssn->post.files.content[0].content), + ssn->cookies.background_url, + ssn->config.background_url); +}