summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--data.c100
1 files changed, 90 insertions, 10 deletions
diff --git a/data.c b/data.c
index 22ea7b0..1aac759 100644
--- a/data.c
+++ b/data.c
@@ -41,6 +41,20 @@ int srv_open(const char *basedir, int auto_upgrade)
41 FILE *f; 41 FILE *f;
42 xs_str *error = NULL; 42 xs_str *error = NULL;
43 43
44 /* MUST be three letters */
45 months[0] = LL("Jan");
46 months[1] = LL("Feb");
47 months[2] = LL("Mar");
48 months[3] = LL("Apr");
49 months[4] = LL("May");
50 months[5] = LL("Jun");
51 months[6] = LL("Jul");
52 months[7] = LL("Aug");
53 months[8] = LL("Sep");
54 months[9] = LL("Oct");
55 months[10] = LL("Nov");
56 months[11] = LL("Dec");
57
44 pthread_mutex_init(&data_mutex, NULL); 58 pthread_mutex_init(&data_mutex, NULL);
45 59
46 srv_basedir = xs_str_new(basedir); 60 srv_basedir = xs_str_new(basedir);
@@ -86,12 +100,12 @@ int srv_open(const char *basedir, int auto_upgrade)
86 100
87 if (auto_upgrade) 101 if (auto_upgrade)
88 ret = snac_upgrade(&error); 102 ret = snac_upgrade(&error);
89 else { 103 else if (xs_number_get(xs_dict_get(srv_config, "layout")) < disk_layout)
90 if (xs_number_get(xs_dict_get(srv_config, "layout")) < disk_layout) 104 error = xs_fmt("ERROR: disk layout changed - execute 'snac upgrade' first");
91 error = xs_fmt("ERROR: disk layout changed - execute 'snac upgrade' first"); 105 else if (!check_strip_tool())
92 else 106 error = xs_fmt("ERROR: strip_exif enabled but commands not found or working");
93 ret = 1; 107 else
94 } 108 ret = 1;
95 } 109 }
96 110
97 } 111 }
@@ -2368,9 +2382,9 @@ void tag_index(const char *id, const xs_dict *obj)
2368 if (*name == '\0') 2382 if (*name == '\0')
2369 continue; 2383 continue;
2370 2384
2371 name = xs_utf8_to_lower((xs_str *)name); 2385 xs* name_cased = xs_utf8_to_lower((xs_str *)name);
2372 2386
2373 xs *md5_tag = xs_md5_hex(name, strlen(name)); 2387 xs *md5_tag = xs_md5_hex(name_cased, strlen(name_cased));
2374 xs *tag_dir = xs_fmt("%s/%c%c", g_tag_dir, md5_tag[0], md5_tag[1]); 2388 xs *tag_dir = xs_fmt("%s/%c%c", g_tag_dir, md5_tag[0], md5_tag[1]);
2375 mkdirx(tag_dir); 2389 mkdirx(tag_dir);
2376 2390
@@ -2382,7 +2396,7 @@ void tag_index(const char *id, const xs_dict *obj)
2382 FILE *f; 2396 FILE *f;
2383 xs *g_tag_name = xs_replace(g_tag_idx, ".idx", ".tag"); 2397 xs *g_tag_name = xs_replace(g_tag_idx, ".idx", ".tag");
2384 if ((f = fopen(g_tag_name, "w")) != NULL) { 2398 if ((f = fopen(g_tag_name, "w")) != NULL) {
2385 fprintf(f, "%s\n", name); 2399 fprintf(f, "%s\n", name_cased);
2386 fclose(f); 2400 fclose(f);
2387 } 2401 }
2388 2402
@@ -2710,6 +2724,8 @@ void static_put(snac *snac, const char *id, const char *data, int size)
2710 if (fn && (f = fopen(fn, "wb")) != NULL) { 2724 if (fn && (f = fopen(fn, "wb")) != NULL) {
2711 fwrite(data, size, 1, f); 2725 fwrite(data, size, 1, f);
2712 fclose(f); 2726 fclose(f);
2727
2728 strip_media(fn);
2713 } 2729 }
2714} 2730}
2715 2731
@@ -3494,11 +3510,75 @@ xs_list *notify_list(snac *snac, int skip, int show)
3494} 3510}
3495 3511
3496 3512
3513xs_list *notify_filter_list(snac *snac, xs_list *notifs)
3514/* apply user-defined notification filter to IDs */
3515{
3516 const xs_dict *n_filter = xs_dict_get(snac->config, "notify_filter");
3517 if (!n_filter) {
3518 return xs_dup(notifs);
3519 }
3520 const xs_val *n_def = xs_stock( XSTYPE_TRUE );
3521 int n_likes_on = xs_is_true(xs_dict_get_def(n_filter, "likes", n_def));
3522 int n_reacts_on = xs_is_true(xs_dict_get_def(n_filter, "reacts", n_def));
3523 int n_ments_on = xs_is_true(xs_dict_get_def(n_filter, "mentions", n_def));
3524 int n_ann_on = xs_is_true(xs_dict_get_def(n_filter, "announces", n_def));
3525 int n_fol_on = xs_is_true(xs_dict_get_def(n_filter, "follows", n_def));
3526 int n_unfol_on = xs_is_true(xs_dict_get_def(n_filter, "unfollows", n_def));
3527 int n_folreq_on = xs_is_true(xs_dict_get_def(n_filter, "folreqs", n_def));
3528 int n_blocks_on = xs_is_true(xs_dict_get_def(n_filter, "blocks", n_def));
3529 int n_polls_on = xs_is_true(xs_dict_get_def(n_filter, "polls", n_def));
3530
3531 const xs_str *v;
3532 xs_list *flt = xs_list_new();
3533
3534 xs_list_foreach(notifs, v) {
3535 xs *noti = notify_get(snac, v);
3536
3537 if (noti == NULL)
3538 continue;
3539
3540 const char *type = xs_dict_get(noti, "type");
3541 const char *utype = xs_dict_get(noti, "utype");
3542 const char *actor_id = xs_dict_get(noti, "actor");
3543 if (strcmp(type, "EmojiReact") == 0 && xs_is_true(xs_dict_get(srv_config, "disable_emojireact")))
3544 continue;
3545 if (strcmp(type, "Create") == 0 && !n_ments_on)
3546 continue;
3547 if (strcmp(type, "Update") == 0 && strcmp(utype, "Question") == 0 && !n_polls_on)
3548 continue;
3549 if (strcmp(type, "Undo") == 0 && strcmp(utype, "Follow") == 0 && !n_unfol_on)
3550 continue;
3551 if (strcmp(type, "EmojiReact") == 0 || strcmp(type, "Like") == 0) {
3552 if (strcmp(type, "Like") == 0 && !n_likes_on)
3553 continue;
3554 if (strcmp(type, "EmojiReact") == 0 && !n_reacts_on)
3555 continue;
3556 }
3557 if (strcmp(type, "Follow") == 0) {
3558 if (pending_check(snac, actor_id)) {
3559 if (!n_folreq_on)
3560 continue;
3561 }
3562 else
3563 if (!n_fol_on)
3564 continue;
3565 }
3566 if (strcmp(type, "Block") == 0 && !n_blocks_on)
3567 continue;
3568 if (strcmp(type, "Announce") == 0 && !n_ann_on)
3569 continue;
3570 flt = xs_list_append(flt, v);
3571 }
3572 return flt;
3573}
3574
3575
3497int notify_new_num(snac *snac) 3576int notify_new_num(snac *snac)
3498/* counts the number of new notifications */ 3577/* counts the number of new notifications */
3499{ 3578{
3500 xs *t = notify_check_time(snac, 0); 3579 xs *t = notify_check_time(snac, 0);
3501 xs *lst = notify_list(snac, 0, XS_ALL); 3580 xs *lst_unfilt = notify_list(snac, 0, XS_ALL);
3581 xs *lst = notify_filter_list(snac, lst_unfilt);
3502 int cnt = 0; 3582 int cnt = 0;
3503 3583
3504 xs_list *p = lst; 3584 xs_list *p = lst;