mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-09 19:50:26 +03:00
New function timeline_top_level() (untested).
This commit is contained in:
parent
4f261ec7b9
commit
159a591f45
53
data.c
53
data.c
@ -6,6 +6,7 @@
|
||||
#include "xs_json.h"
|
||||
#include "xs_openssl.h"
|
||||
#include "xs_glob.h"
|
||||
#include "xs_set.h"
|
||||
|
||||
#include "snac.h"
|
||||
|
||||
@ -1038,6 +1039,58 @@ int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer
|
||||
}
|
||||
|
||||
|
||||
d_char *timeline_top_level(snac *snac, const char *index)
|
||||
/* returns the top level entries from this index */
|
||||
{
|
||||
int max = 256;
|
||||
xs *list = index_list_desc(index, max);
|
||||
xs *tl = xs_list_new();
|
||||
xs_set seen;
|
||||
char *p, *v;
|
||||
|
||||
xs_set_init(&seen);
|
||||
|
||||
p = list;
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
char line[256] = "";
|
||||
|
||||
strcpy(line, v);
|
||||
|
||||
for (;;) {
|
||||
char line2[256];
|
||||
xs *fn = _object_fn_by_md5(line);
|
||||
fn = xs_replace_i(fn, ".json", "_p.idx");
|
||||
|
||||
/* if it doesn't have a parent, we got it */
|
||||
if (index_first(fn, line2, strlen(line2)) == 0) {
|
||||
strcpy(line, line2);
|
||||
break;
|
||||
}
|
||||
|
||||
xs *pfn = _object_fn_by_md5(line2);
|
||||
|
||||
/* well, there is a parent... if it's not here, we're done */
|
||||
if (mtime(pfn) == 0.0)
|
||||
break;
|
||||
|
||||
/* it's here! try again with its own parent */
|
||||
strcpy(line, line2);
|
||||
}
|
||||
|
||||
if (xs_set_add(&seen, line) == 1) {
|
||||
xs *obj = NULL;
|
||||
|
||||
if (valid_status(object_get(line, &obj, NULL)))
|
||||
tl = xs_list_append(tl, obj);
|
||||
}
|
||||
}
|
||||
|
||||
xs_set_free(&seen);
|
||||
|
||||
return tl;
|
||||
}
|
||||
|
||||
|
||||
void timeline_admire(snac *snac, char *id, char *admirer, int like)
|
||||
/* updates a timeline entry with a new admiration */
|
||||
{
|
||||
|
2
snac.h
2
snac.h
@ -76,6 +76,8 @@ d_char *timeline_list(snac *snac, int max);
|
||||
int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer);
|
||||
void timeline_admire(snac *snac, char *id, char *admirer, int like);
|
||||
|
||||
d_char *timeline_top_level(snac *snac, const char *index);
|
||||
|
||||
d_char *local_list(snac *snac, int max);
|
||||
|
||||
int following_add(snac *snac, char *actor, char *msg);
|
||||
|
Loading…
Reference in New Issue
Block a user