mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-12-25 16:53:37 +00:00
More timeline work.
This commit is contained in:
parent
732654e73a
commit
9a01f731d7
3 changed files with 73 additions and 9 deletions
66
data.c
66
data.c
|
@ -246,12 +246,12 @@ d_char *follower_list(snac *snac)
|
|||
|
||||
if (glob(spec, 0, NULL, &globbuf) == 0) {
|
||||
int n;
|
||||
char *p;
|
||||
char *fn;
|
||||
|
||||
for (n = 0; (p = globbuf.gl_pathv[n]) != NULL; n++) {
|
||||
for (n = 0; (fn = globbuf.gl_pathv[n]) != NULL; n++) {
|
||||
FILE *f;
|
||||
|
||||
if ((f = fopen(p, "r")) != NULL) {
|
||||
if ((f = fopen(fn, "r")) != NULL) {
|
||||
xs *j = xs_readall(f);
|
||||
xs *o = xs_json_loads(j);
|
||||
|
||||
|
@ -269,7 +269,7 @@ d_char *follower_list(snac *snac)
|
|||
}
|
||||
|
||||
|
||||
d_char *_timeline_fn(snac *snac, char *id)
|
||||
d_char *_timeline_find_fn(snac *snac, char *id)
|
||||
/* returns the file name of a timeline entry by its id */
|
||||
{
|
||||
xs *md5 = xs_md5_hex(id, strlen(id));
|
||||
|
@ -288,10 +288,10 @@ d_char *_timeline_fn(snac *snac, char *id)
|
|||
}
|
||||
|
||||
|
||||
d_char *timeline_get(snac *snac, char *id)
|
||||
/* gets a message from the timeline */
|
||||
d_char *timeline_find(snac *snac, char *id)
|
||||
/* gets a message from the timeline by id */
|
||||
{
|
||||
xs *fn = _timeline_fn(snac, id);
|
||||
xs *fn = _timeline_find_fn(snac, id);
|
||||
xs *msg = NULL;
|
||||
|
||||
if (fn != NULL) {
|
||||
|
@ -312,7 +312,7 @@ d_char *timeline_get(snac *snac, char *id)
|
|||
void timeline_del(snac *snac, char *id)
|
||||
/* deletes a message from the timeline */
|
||||
{
|
||||
xs *fn = _timeline_fn(snac, id);
|
||||
xs *fn = _timeline_find_fn(snac, id);
|
||||
|
||||
if (fn != NULL) {
|
||||
xs *lfn = NULL;
|
||||
|
@ -327,3 +327,53 @@ void timeline_del(snac *snac, char *id)
|
|||
snac_debug(snac, 1, xs_fmt("timeline_del (local) %s", id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
d_char *timeline_get(snac *snac, char *fn)
|
||||
/* gets a timeline entry by file name */
|
||||
{
|
||||
d_char *d = NULL;
|
||||
FILE *f;
|
||||
|
||||
if ((f = fopen(fn, "r")) != NULL) {
|
||||
xs *j = xs_readall(f);
|
||||
|
||||
d = xs_json_loads(j);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
d_char *timeline_list(snac *snac)
|
||||
/* returns a list of the timeline filenames */
|
||||
{
|
||||
d_char *list;
|
||||
xs *spec = xs_fmt("%s/timeline/" "*.json", snac->basedir);
|
||||
glob_t globbuf;
|
||||
int max;
|
||||
|
||||
/* maximum number of items in the timeline */
|
||||
max = xs_number_get(xs_dict_get(srv_config, "max_timeline_entries"));
|
||||
|
||||
list = xs_list_new();
|
||||
|
||||
/* get the list in reverse order */
|
||||
if (glob(spec, 0, NULL, &globbuf) == 0) {
|
||||
int n;
|
||||
|
||||
if (max > globbuf.gl_matchc)
|
||||
max = globbuf.gl_matchc;
|
||||
|
||||
for (n = 0; n < max; n++) {
|
||||
char *fn = globbuf.gl_pathv[globbuf.gl_matchc - n - 1];
|
||||
|
||||
list = xs_list_append(list, fn);
|
||||
}
|
||||
}
|
||||
|
||||
globfree(&globbuf);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
|
12
main.c
12
main.c
|
@ -26,6 +26,18 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
xs *list = timeline_list(&snac);
|
||||
char *p, *fn;
|
||||
|
||||
p = list;
|
||||
while (xs_list_iter(&p, &fn)) {
|
||||
xs *tle = timeline_get(&snac, fn);
|
||||
|
||||
printf("%s\n", xs_dict_get(tle, "id"));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
xs *list = user_list();
|
||||
char *p, *uid;
|
||||
|
|
4
snac.h
4
snac.h
|
@ -45,5 +45,7 @@ int follower_del(snac *snac, char *actor);
|
|||
int follower_check(snac *snac, char *actor);
|
||||
d_char *follower_list(snac *snac);
|
||||
|
||||
d_char *timeline_get(snac *snac, char *id);
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue