More work in the people page.

This commit is contained in:
default 2022-11-02 10:49:16 +01:00
parent 1fd14a850d
commit 773be130ed
3 changed files with 62 additions and 16 deletions

35
data.c
View File

@ -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));

42
html.c
View File

@ -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("<h2>%s</h2>\n", header);
char *p, *v;
s = html_user_header(snac, s, 0);
s = xs_str_cat(s, h);
s = xs_str_cat(s, "<h2>");
s = xs_str_cat(s, L("People you follow"));
s = xs_str_cat(s, "</h2>\n");
s = xs_str_cat(s, "<h2>");
s = xs_str_cat(s, L("People that follows you"));
s = xs_str_cat(s, "</h2>\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, "<div class=\"snac-post\">\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, "</body>\n</html>\n");

1
snac.h
View File

@ -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);