summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2022-11-02 10:49:16 +0100
committerGravatar default2022-11-02 10:49:16 +0100
commit773be130ed4557c95fef2d54799a170ffea9e0de (patch)
tree4144e8c5b13108efc851dc5465718bf168074982
parentPeople page started. (diff)
downloadpenes-snac2-773be130ed4557c95fef2d54799a170ffea9e0de.tar.gz
penes-snac2-773be130ed4557c95fef2d54799a170ffea9e0de.tar.xz
penes-snac2-773be130ed4557c95fef2d54799a170ffea9e0de.zip
More work in the people page.
-rw-r--r--data.c35
-rw-r--r--html.c42
-rw-r--r--snac.h1
3 files changed, 62 insertions, 16 deletions
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)
699} 699}
700 700
701 701
702d_char *following_list(snac *snac)
703/* returns the list of people being followed */
704{
705 xs *spec = xs_fmt("%s/following/" "*.json", snac->basedir);
706 xs *glist = xs_glob(spec, 0, 0);
707 char *p, *v;
708 d_char *list = xs_list_new();
709
710 /* iterate the list of files */
711 p = glist;
712 while (xs_list_iter(&p, &v)) {
713 FILE *f;
714
715 /* load the follower data */
716 if ((f = fopen(v, "r")) != NULL) {
717 xs *j = xs_readall(f);
718 fclose(f);
719
720 if (j != NULL) {
721 xs *o = xs_json_loads(j);
722
723 if (o != NULL) {
724 char *type = xs_dict_get(o, "type");
725
726 if (!xs_is_null(type) && strcmp(type, "Accept") == 0)
727 list = xs_list_append(list, o);
728 }
729 }
730 }
731 }
732
733 return list;
734}
735
736
702d_char *_muted_fn(snac *snac, char *actor) 737d_char *_muted_fn(snac *snac, char *actor)
703{ 738{
704 xs *md5 = xs_md5_hex(actor, strlen(actor)); 739 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)
820} 820}
821 821
822 822
823d_char *html_people(snac *snac) 823d_char *html_people_list(snac *snac, d_char *os, d_char *list, const char *header)
824{ 824{
825 d_char *s = xs_str_new(NULL); 825 xs *s = xs_str_new(NULL);
826 xs *wers = NULL; 826 xs *h = xs_fmt("<h2>%s</h2>\n", header);
827 xs *wing = NULL;
828 char *p, *v; 827 char *p, *v;
829 828
830 s = html_user_header(snac, s, 0); 829 s = xs_str_cat(s, h);
831
832 s = xs_str_cat(s, "<h2>");
833 s = xs_str_cat(s, L("People you follow"));
834 s = xs_str_cat(s, "</h2>\n");
835 830
836 s = xs_str_cat(s, "<h2>"); 831 p = list;
837 s = xs_str_cat(s, L("People that follows you"));
838 s = xs_str_cat(s, "</h2>\n");
839
840 p = wers = follower_list(snac);
841 while (xs_list_iter(&p, &v)) { 832 while (xs_list_iter(&p, &v)) {
842 char *actor_id = xs_dict_get(v, "actor"); 833 char *actor_id = xs_dict_get(v, "actor");
843 xs *md5 = xs_md5_hex(actor_id, strlen(actor_id)); 834 xs *md5 = xs_md5_hex(actor_id, strlen(actor_id));
844 xs *actor; 835 xs *actor = NULL;
845 836
846 if (valid_status(actor_get(snac, actor_id, &actor))) { 837 if (valid_status(actor_get(snac, actor_id, &actor))) {
847 s = xs_str_cat(s, "<div class=\"snac-post\">\n"); 838 s = xs_str_cat(s, "<div class=\"snac-post\">\n");
@@ -888,7 +879,10 @@ d_char *html_people(snac *snac)
888 ); 879 );
889 s = xs_str_cat(s, s1); 880 s = xs_str_cat(s, s1);
890 881
891 s = html_button(s, "unfollow", L("Unfollow")); 882 if (following_check(snac, actor_id))
883 s = html_button(s, "unfollow", L("Unfollow"));
884 else
885 s = html_button(s, "follow", L("Follow"));
892 886
893 if (is_muted(snac, actor_id)) 887 if (is_muted(snac, actor_id))
894 s = html_button(s, "unmute", L("Unmute")); 888 s = html_button(s, "unmute", L("Unmute"));
@@ -922,6 +916,22 @@ d_char *html_people(snac *snac)
922 } 916 }
923 } 917 }
924 918
919 return xs_str_cat(os, s);
920}
921
922
923d_char *html_people(snac *snac)
924{
925 d_char *s = xs_str_new(NULL);
926 xs *wing = following_list(snac);
927 xs *wers = follower_list(snac);
928
929 s = html_user_header(snac, s, 0);
930
931 s = html_people_list(snac, s, wing, L("People you follow"));
932
933 s = html_people_list(snac, s, wers, L("People that follows you"));
934
925 s = html_user_footer(snac, s); 935 s = html_user_footer(snac, s);
926 936
927 s = xs_str_cat(s, "</body>\n</html>\n"); 937 s = xs_str_cat(s, "</body>\n</html>\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);
72int following_del(snac *snac, char *actor); 72int following_del(snac *snac, char *actor);
73int following_check(snac *snac, char *actor); 73int following_check(snac *snac, char *actor);
74int following_get(snac *snac, char *actor, d_char **data); 74int following_get(snac *snac, char *actor, d_char **data);
75d_char *following_list(snac *snac);
75 76
76void mute(snac *snac, char *actor); 77void mute(snac *snac, char *actor);
77void unmute(snac *snac, char *actor); 78void unmute(snac *snac, char *actor);