diff --git a/data.c b/data.c index 5e1be8e..e8e4f9f 100644 --- a/data.c +++ b/data.c @@ -699,6 +699,41 @@ int following_get(snac *snac, char *actor, d_char **data) } +d_char *following_list(snac *snac) +/* returns the list of people being followed */ +{ + xs *spec = xs_fmt("%s/following/" "*.json", snac->basedir); + xs *glist = xs_glob(spec, 0, 0); + char *p, *v; + d_char *list = xs_list_new(); + + /* iterate the list of files */ + p = glist; + while (xs_list_iter(&p, &v)) { + FILE *f; + + /* load the follower data */ + if ((f = fopen(v, "r")) != NULL) { + xs *j = xs_readall(f); + fclose(f); + + if (j != NULL) { + xs *o = xs_json_loads(j); + + if (o != NULL) { + char *type = xs_dict_get(o, "type"); + + if (!xs_is_null(type) && strcmp(type, "Accept") == 0) + list = xs_list_append(list, o); + } + } + } + } + + return list; +} + + d_char *_muted_fn(snac *snac, char *actor) { xs *md5 = xs_md5_hex(actor, strlen(actor)); diff --git a/html.c b/html.c index 80b7f43..b20b0d0 100644 --- a/html.c +++ b/html.c @@ -820,28 +820,19 @@ d_char *html_timeline(snac *snac, char *list, int local) } -d_char *html_people(snac *snac) +d_char *html_people_list(snac *snac, d_char *os, d_char *list, const char *header) { - d_char *s = xs_str_new(NULL); - xs *wers = NULL; - xs *wing = NULL; + xs *s = xs_str_new(NULL); + xs *h = xs_fmt("

%s

\n", header); char *p, *v; - s = html_user_header(snac, s, 0); + s = xs_str_cat(s, h); - s = xs_str_cat(s, "

"); - s = xs_str_cat(s, L("People you follow")); - s = xs_str_cat(s, "

\n"); - - s = xs_str_cat(s, "

"); - s = xs_str_cat(s, L("People that follows you")); - s = xs_str_cat(s, "

\n"); - - p = wers = follower_list(snac); + p = list; while (xs_list_iter(&p, &v)) { char *actor_id = xs_dict_get(v, "actor"); xs *md5 = xs_md5_hex(actor_id, strlen(actor_id)); - xs *actor; + xs *actor = NULL; if (valid_status(actor_get(snac, actor_id, &actor))) { s = xs_str_cat(s, "
\n"); @@ -888,7 +879,10 @@ d_char *html_people(snac *snac) ); s = xs_str_cat(s, s1); - s = html_button(s, "unfollow", L("Unfollow")); + if (following_check(snac, actor_id)) + s = html_button(s, "unfollow", L("Unfollow")); + else + s = html_button(s, "follow", L("Follow")); if (is_muted(snac, actor_id)) s = html_button(s, "unmute", L("Unmute")); @@ -922,6 +916,22 @@ d_char *html_people(snac *snac) } } + return xs_str_cat(os, s); +} + + +d_char *html_people(snac *snac) +{ + d_char *s = xs_str_new(NULL); + xs *wing = following_list(snac); + xs *wers = follower_list(snac); + + s = html_user_header(snac, s, 0); + + s = html_people_list(snac, s, wing, L("People you follow")); + + s = html_people_list(snac, s, wers, L("People that follows you")); + s = html_user_footer(snac, s); s = xs_str_cat(s, "\n\n"); diff --git a/snac.h b/snac.h index 7a3a5f3..79e5453 100644 --- a/snac.h +++ b/snac.h @@ -72,6 +72,7 @@ int following_add(snac *snac, char *actor, char *msg); int following_del(snac *snac, char *actor); int following_check(snac *snac, char *actor); int following_get(snac *snac, char *actor, d_char **data); +d_char *following_list(snac *snac); void mute(snac *snac, char *actor); void unmute(snac *snac, char *actor);