diff options
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 38 |
1 files changed, 34 insertions, 4 deletions
| @@ -1982,10 +1982,40 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1982 | } | 1982 | } |
| 1983 | else | 1983 | else |
| 1984 | if (strcmp(cmd, "/v1/announcements") == 0) { /** **/ | 1984 | if (strcmp(cmd, "/v1/announcements") == 0) { /** **/ |
| 1985 | /* snac has no announcements (yet?) */ | 1985 | if (logged_in) { |
| 1986 | *body = xs_dup("[]"); | 1986 | xs *resp = xs_list_new(); |
| 1987 | *ctype = "application/json"; | 1987 | double la = 0.0; |
| 1988 | status = HTTP_STATUS_OK; | 1988 | xs *user_la = xs_dup(xs_dict_get(snac1.config, "last_announcement")); |
| 1989 | if (user_la != NULL) | ||
| 1990 | la = xs_number_get(user_la); | ||
| 1991 | xs *val_date = xs_str_utctime(la, ISO_DATE_SPEC); | ||
| 1992 | |||
| 1993 | /* contrary to html, we always send the announcement and set the read flag instead */ | ||
| 1994 | |||
| 1995 | const t_announcement *annce = announcement(la); | ||
| 1996 | if (annce != NULL && annce->text != NULL) { | ||
| 1997 | xs *an = xs_dict_new(); | ||
| 1998 | an = xs_dict_set(an, "id", xs_fmt("%d", annce->timestamp)); | ||
| 1999 | an = xs_dict_set(an, "content", xs_fmt("<p>%s</p>", annce->text)); | ||
| 2000 | an = xs_dict_set(an, "starts_at", xs_stock(XSTYPE_NULL)); | ||
| 2001 | an = xs_dict_set(an, "ends_at", xs_stock(XSTYPE_NULL)); | ||
| 2002 | an = xs_dict_set(an, "all_day", xs_stock(XSTYPE_TRUE)); | ||
| 2003 | an = xs_dict_set(an, "published_at", val_date); | ||
| 2004 | an = xs_dict_set(an, "updated_at", val_date); | ||
| 2005 | an = xs_dict_set(an, "read", (annce->timestamp >= la) | ||
| 2006 | ? xs_stock(XSTYPE_FALSE) : xs_stock(XSTYPE_TRUE)); | ||
| 2007 | an = xs_dict_set(an, "mentions", xs_stock(XSTYPE_LIST)); | ||
| 2008 | an = xs_dict_set(an, "statuses", xs_stock(XSTYPE_LIST)); | ||
| 2009 | an = xs_dict_set(an, "tags", xs_stock(XSTYPE_LIST)); | ||
| 2010 | an = xs_dict_set(an, "emojis", xs_stock(XSTYPE_LIST)); | ||
| 2011 | an = xs_dict_set(an, "reactions", xs_stock(XSTYPE_LIST)); | ||
| 2012 | resp = xs_list_append(resp, an); | ||
| 2013 | } | ||
| 2014 | |||
| 2015 | *body = xs_json_dumps(resp, 4); | ||
| 2016 | *ctype = "application/json"; | ||
| 2017 | status = HTTP_STATUS_OK; | ||
| 2018 | } | ||
| 1989 | } | 2019 | } |
| 1990 | else | 2020 | else |
| 1991 | if (strcmp(cmd, "/v1/custom_emojis") == 0) { /** **/ | 2021 | if (strcmp(cmd, "/v1/custom_emojis") == 0) { /** **/ |