mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-09 19:50:26 +03:00
Add following code.
This commit is contained in:
parent
f6b34ce539
commit
591613a49e
51
data.c
51
data.c
@ -426,3 +426,54 @@ void timeline_add(snac *snac, char *id, char *msg, char *parent)
|
||||
snac_debug(snac, 1, xs_fmt("timeline_add (local) %s %s", id, lfn));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
d_char *_following_fn(snac *snac, char *actor)
|
||||
{
|
||||
xs *md5 = xs_md5_hex(actor, strlen(actor));
|
||||
return xs_fmt("%s/following/%s.json", snac->basedir, md5);
|
||||
}
|
||||
|
||||
|
||||
int following_add(snac *snac, char *actor, char *msg)
|
||||
/* adds to the following list */
|
||||
{
|
||||
int ret = 201; /* created */
|
||||
xs *fn = _following_fn(snac, actor);
|
||||
FILE *f;
|
||||
|
||||
if ((f = fopen(fn, "w")) != NULL) {
|
||||
xs *j = xs_json_dumps_pp(msg, 4);
|
||||
|
||||
fwrite(j, 1, strlen(j), f);
|
||||
fclose(f);
|
||||
}
|
||||
else
|
||||
ret = 500;
|
||||
|
||||
snac_debug(snac, 2, xs_fmt("following_add %s %s", actor, fn));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int following_del(snac *snac, char *actor)
|
||||
/* someone is no longer following us */
|
||||
{
|
||||
xs *fn = _following_fn(snac, actor);
|
||||
|
||||
unlink(fn);
|
||||
|
||||
snac_debug(snac, 2, xs_fmt("following_del %s %s", actor, fn));
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
||||
|
||||
int following_check(snac *snac, char *actor)
|
||||
/* checks if someone is following us */
|
||||
{
|
||||
xs *fn = _following_fn(snac, actor);
|
||||
|
||||
return !!(mtime(fn) != 0.0);
|
||||
}
|
||||
|
5
snac.h
5
snac.h
@ -49,3 +49,8 @@ d_char *timeline_find(snac *snac, char *id);
|
||||
void timeline_del(snac *snac, char *id);
|
||||
d_char *timeline_get(snac *snac, char *fn);
|
||||
d_char *timeline_list(snac *snac);
|
||||
|
||||
int following_add(snac *snac, char *actor, char *msg);
|
||||
int following_del(snac *snac, char *actor);
|
||||
int following_check(snac *snac, char *actor);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user