mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 05:15:04 +00:00
New functions notify_get() and notify_list().
This commit is contained in:
parent
211bedd497
commit
1a27e67ed9
3 changed files with 60 additions and 3 deletions
49
data.c
49
data.c
|
@ -1537,6 +1537,55 @@ void notify_add(snac *snac, const char *type, const char *utype,
|
|||
}
|
||||
|
||||
|
||||
xs_dict *notify_get(snac *snac, const char *id)
|
||||
/* gets a notification */
|
||||
{
|
||||
xs *fn = xs_fmt("%s/notify/%s.json", snac->basedir);
|
||||
FILE *f;
|
||||
xs_dict *out = NULL;
|
||||
|
||||
if ((f = fopen(fn, "r")) != NULL) {
|
||||
xs *j = xs_readall(f);
|
||||
fclose(f);
|
||||
|
||||
out = xs_json_loads(j);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
xs_list *notify_list(snac *snac, int new_only)
|
||||
/* returns a list of notifications, optionally only the new ones */
|
||||
{
|
||||
xs *t = NULL;
|
||||
|
||||
/* if only new ones are requested, get the last time */
|
||||
if (new_only)
|
||||
t = notify_check_time(snac, 0);
|
||||
|
||||
xs *spec = xs_fmt("%s/notify/" "*.json", snac->basedir);
|
||||
xs *lst = xs_glob(spec, 1, 0);
|
||||
xs_list *out = xs_list_new();
|
||||
xs_list *p = lst;
|
||||
xs_str *v;
|
||||
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
xs *id = xs_replace(v, ".json", "");
|
||||
|
||||
/* old? */
|
||||
if (t != NULL && strcmp(id, t) < 0)
|
||||
continue;
|
||||
|
||||
xs *noti = notify_get(snac, id);
|
||||
|
||||
out = xs_list_append(out, noti);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
/** the queue **/
|
||||
|
||||
static xs_dict *_enqueue_put(const char *fn, xs_dict *msg)
|
||||
|
|
|
@ -855,10 +855,16 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
|||
else
|
||||
if (strcmp(cmd, "/notifications") == 0) {
|
||||
/* TBD */
|
||||
if (logged_in) {
|
||||
xs *l = notify_list(&snac1, 0);
|
||||
|
||||
*body = xs_dup("[]");
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
else
|
||||
status = 401;
|
||||
}
|
||||
else
|
||||
if (strcmp(cmd, "/filters") == 0) {
|
||||
/* snac will never have filters */
|
||||
|
|
2
snac.h
2
snac.h
|
@ -140,6 +140,8 @@ void lastlog_write(snac *snac);
|
|||
xs_str *notify_check_time(snac *snac, int reset);
|
||||
void notify_add(snac *snac, const char *type, const char *utype,
|
||||
const char *actor, const char *objid);
|
||||
xs_dict *notify_get(snac *snac, const char *id);
|
||||
xs_list *notify_list(snac *snac, int new_only);
|
||||
|
||||
void inbox_add(const char *inbox);
|
||||
void inbox_add_by_actor(const xs_dict *actor);
|
||||
|
|
Loading…
Reference in a new issue