mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
Use the new hide API.
This commit is contained in:
parent
4553528507
commit
d215f8ce46
5 changed files with 24 additions and 50 deletions
48
data.c
48
data.c
|
@ -14,7 +14,7 @@
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
double db_layout = 2.2;
|
double db_layout = 2.3;
|
||||||
|
|
||||||
|
|
||||||
int db_upgrade(d_char **error);
|
int db_upgrade(d_char **error);
|
||||||
|
@ -913,50 +913,6 @@ void timeline_admire(snac *snac, char *id, char *admirer, int like)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int timeline_hide(snac *snac, char *id, int hide)
|
|
||||||
/* hides/unhides a timeline entry */
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
xs *fn = _timeline_find_fn(snac, id);
|
|
||||||
FILE *f;
|
|
||||||
|
|
||||||
if (fn != NULL && (f = fopen(fn, "r")) != NULL) {
|
|
||||||
xs *s1 = xs_readall(f);
|
|
||||||
xs *msg = xs_json_loads(s1);
|
|
||||||
xs *meta = xs_dup(xs_dict_get(msg, "_snac"));
|
|
||||||
xs *hdn = xs_val_new(hide ? XSTYPE_TRUE : XSTYPE_FALSE);
|
|
||||||
char *p, *v;
|
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
/* if it's already in this hidden state, we're done */
|
|
||||||
if ((v = xs_dict_get(meta, "hidden")) && xs_type(v) == xs_type(hdn))
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
meta = xs_dict_set(meta, "hidden", hdn);
|
|
||||||
msg = xs_dict_set(msg, "_snac", meta);
|
|
||||||
|
|
||||||
if ((f = fopen(fn, "w")) != NULL) {
|
|
||||||
xs *j1 = xs_json_dumps_pp(msg, 4);
|
|
||||||
|
|
||||||
fwrite(j1, strlen(j1), 1, f);
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
snac_debug(snac, 1, xs_fmt("timeline_hide %d %s", hide, id));
|
|
||||||
|
|
||||||
/* now hide the children */
|
|
||||||
p = xs_dict_get(meta, "children");
|
|
||||||
while (xs_list_iter(&p, &v))
|
|
||||||
timeline_hide(snac, v, hide);
|
|
||||||
|
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
d_char *_following_fn(snac *snac, char *actor)
|
d_char *_following_fn(snac *snac, char *actor)
|
||||||
{
|
{
|
||||||
xs *md5 = xs_md5_hex(actor, strlen(actor));
|
xs *md5 = xs_md5_hex(actor, strlen(actor));
|
||||||
|
@ -1109,7 +1065,7 @@ int is_muted(snac *snac, char *actor)
|
||||||
d_char *_hidden_fn(snac *snac, const char *id)
|
d_char *_hidden_fn(snac *snac, const char *id)
|
||||||
{
|
{
|
||||||
xs *md5 = xs_md5_hex(id, strlen(id));
|
xs *md5 = xs_md5_hex(id, strlen(id));
|
||||||
return xs_fmt("%s/hidden/%s.json", snac->basedir, md5);
|
return xs_fmt("%s/hidden/%s", snac->basedir, md5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
4
html.c
4
html.c
|
@ -497,7 +497,7 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, i
|
||||||
xs *s = xs_str_new(NULL);
|
xs *s = xs_str_new(NULL);
|
||||||
|
|
||||||
/* top wrap */
|
/* top wrap */
|
||||||
if ((v = xs_dict_get(meta, "hidden")) && xs_type(v) == XSTYPE_TRUE)
|
if (is_hidden(snac, id))
|
||||||
s = xs_str_cat(s, "<div style=\"display: none\">\n");
|
s = xs_str_cat(s, "<div style=\"display: none\">\n");
|
||||||
else
|
else
|
||||||
s = xs_str_cat(s, "<div>\n");
|
s = xs_str_cat(s, "<div>\n");
|
||||||
|
@ -1300,7 +1300,7 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(action, L("Hide")) == 0) {
|
if (strcmp(action, L("Hide")) == 0) {
|
||||||
timeline_hide(&snac, id, 1);
|
hide(&snac, id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(action, L("Follow")) == 0) {
|
if (strcmp(action, L("Follow")) == 0) {
|
||||||
|
|
1
snac.h
1
snac.h
|
@ -71,7 +71,6 @@ d_char *timeline_get(snac *snac, char *fn);
|
||||||
d_char *timeline_list(snac *snac, int max);
|
d_char *timeline_list(snac *snac, int max);
|
||||||
int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer);
|
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);
|
void timeline_admire(snac *snac, char *id, char *admirer, int like);
|
||||||
int timeline_hide(snac *snac, char *id, int hide);
|
|
||||||
|
|
||||||
d_char *local_list(snac *snac, int max);
|
d_char *local_list(snac *snac, int max);
|
||||||
|
|
||||||
|
|
19
upgrade.c
19
upgrade.c
|
@ -74,6 +74,25 @@ int db_upgrade(d_char **error)
|
||||||
|
|
||||||
nf = 2.2;
|
nf = 2.2;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
if (f < 2.3) {
|
||||||
|
xs *users = user_list();
|
||||||
|
char *p, *v;
|
||||||
|
|
||||||
|
p = users;
|
||||||
|
while (xs_list_iter(&p, &v)) {
|
||||||
|
snac snac;
|
||||||
|
|
||||||
|
if (user_open(&snac, v)) {
|
||||||
|
xs *dir = xs_fmt("%s/hidden", snac.basedir);
|
||||||
|
|
||||||
|
mkdir(dir, 0755);
|
||||||
|
user_free(&snac);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nf = 2.3;
|
||||||
|
}
|
||||||
|
|
||||||
if (f < nf) {
|
if (f < nf) {
|
||||||
f = nf;
|
f = nf;
|
||||||
|
|
2
utils.c
2
utils.c
|
@ -237,7 +237,7 @@ int adduser(char *uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *dirs[] = {
|
const char *dirs[] = {
|
||||||
"followers", "following", "local", "muted",
|
"followers", "following", "local", "muted", "hidden",
|
||||||
"queue", "static", "timeline", "history", NULL };
|
"queue", "static", "timeline", "history", NULL };
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue