New function queue().

This commit is contained in:
default 2022-09-20 12:43:49 +02:00
parent 5d843a488e
commit e923a4f5ec
3 changed files with 48 additions and 0 deletions

33
data.c
View File

@ -554,3 +554,36 @@ void enqueue(snac *snac, char *actor, char *msg, int retries)
snac_debug(snac, 2, xs_fmt("enqueue %s %s %d", actor, fn, retries));
}
}
d_char *queue(snac *snac)
/* returns a list with filenames that can be dequeued */
{
xs *spec = xs_fmt("%s/queue/" "*.json", snac->basedir);
d_char *list = xs_list_new();
glob_t globbuf;
time_t t = time(NULL);
/* get the list in reverse order */
if (glob(spec, 0, NULL, &globbuf) == 0) {
int n;
char *p;
for (n = 0; (p = globbuf.gl_pathv[n]) != NULL; n++) {
/* get the retry time from the basename */
char *bn = strrchr(p, '/');
time_t t2 = atol(bn + 1);
if (t2 > t)
snac_debug(snac, 2, xs_fmt("queue not yet time for %s", p));
else {
list = xs_list_append(list, p);
snac_debug(snac, 2, xs_fmt("queue ready for %s", p));
}
}
}
globfree(&globbuf);
return list;
}

12
main.c
View File

@ -15,6 +15,17 @@ int main(int argc, char *argv[])
user_open(&snac, "mike");
{
xs *list = queue(&snac);
char *p, *fn;
p = list;
while (xs_list_iter(&p, &fn)) {
printf("%s\n", fn);
}
}
#if 0
{
xs *list = follower_list(&snac);
char *p, *obj;
@ -50,6 +61,7 @@ int main(int argc, char *argv[])
}
}
}
#endif
return 0;
}

3
snac.h
View File

@ -57,3 +57,6 @@ int following_check(snac *snac, char *actor);
void mute(snac *snac, char *actor);
void unmute(snac *snac, char *actor);
int is_muted(snac *snac, char *actor);
void enqueue(snac *snac, char *actor, char *msg, int retries);
d_char *queue(snac *snac);