diff options
| author | 2026-01-27 10:46:57 +0100 | |
|---|---|---|
| committer | 2026-01-27 10:46:57 +0100 | |
| commit | 2a65e135cf7ea00e8eb3e436c77a11115816c477 (patch) | |
| tree | 3504382b467717aa3c474aafa2e8f10427d1f4a7 /data.c | |
| parent | Merge pull request 'po/de_DE.po aktualisiert' (#538) from zen/snac2:master in... (diff) | |
| parent | style (diff) | |
| download | snac2-2a65e135cf7ea00e8eb3e436c77a11115816c477.tar.gz snac2-2a65e135cf7ea00e8eb3e436c77a11115816c477.tar.xz snac2-2a65e135cf7ea00e8eb3e436c77a11115816c477.zip | |
Merge pull request 'notifications filter' (#524) from byte/snac2:notif_filter into master
Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/524
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 66 |
1 files changed, 65 insertions, 1 deletions
| @@ -3503,11 +3503,75 @@ xs_list *notify_list(snac *snac, int skip, int show) | |||
| 3503 | } | 3503 | } |
| 3504 | 3504 | ||
| 3505 | 3505 | ||
| 3506 | xs_list *notify_filter_list(snac *snac, xs_list *notifs) | ||
| 3507 | /* apply user-defined notification filter to IDs */ | ||
| 3508 | { | ||
| 3509 | const xs_dict *n_filter = xs_dict_get(snac->config, "notify_filter"); | ||
| 3510 | if (!n_filter) { | ||
| 3511 | return xs_dup(notifs); | ||
| 3512 | } | ||
| 3513 | const xs_val *n_def = xs_stock( XSTYPE_TRUE ); | ||
| 3514 | int n_likes_on = xs_is_true(xs_dict_get_def(n_filter, "likes", n_def)); | ||
| 3515 | int n_reacts_on = xs_is_true(xs_dict_get_def(n_filter, "reacts", n_def)); | ||
| 3516 | int n_ments_on = xs_is_true(xs_dict_get_def(n_filter, "mentions", n_def)); | ||
| 3517 | int n_ann_on = xs_is_true(xs_dict_get_def(n_filter, "announces", n_def)); | ||
| 3518 | int n_fol_on = xs_is_true(xs_dict_get_def(n_filter, "follows", n_def)); | ||
| 3519 | int n_unfol_on = xs_is_true(xs_dict_get_def(n_filter, "unfollows", n_def)); | ||
| 3520 | int n_folreq_on = xs_is_true(xs_dict_get_def(n_filter, "folreqs", n_def)); | ||
| 3521 | int n_blocks_on = xs_is_true(xs_dict_get_def(n_filter, "blocks", n_def)); | ||
| 3522 | int n_polls_on = xs_is_true(xs_dict_get_def(n_filter, "polls", n_def)); | ||
| 3523 | |||
| 3524 | const xs_str *v; | ||
| 3525 | xs_list *flt = xs_list_new(); | ||
| 3526 | |||
| 3527 | xs_list_foreach(notifs, v) { | ||
| 3528 | xs *noti = notify_get(snac, v); | ||
| 3529 | |||
| 3530 | if (noti == NULL) | ||
| 3531 | continue; | ||
| 3532 | |||
| 3533 | const char *type = xs_dict_get(noti, "type"); | ||
| 3534 | const char *utype = xs_dict_get(noti, "utype"); | ||
| 3535 | const char *actor_id = xs_dict_get(noti, "actor"); | ||
| 3536 | if (strcmp(type, "EmojiReact") == 0 && xs_is_true(xs_dict_get(srv_config, "disable_emojireact"))) | ||
| 3537 | continue; | ||
| 3538 | if (strcmp(type, "Create") == 0 && !n_ments_on) | ||
| 3539 | continue; | ||
| 3540 | if (strcmp(type, "Update") == 0 && strcmp(utype, "Question") == 0 && !n_polls_on) | ||
| 3541 | continue; | ||
| 3542 | if (strcmp(type, "Undo") == 0 && strcmp(utype, "Follow") == 0 && !n_unfol_on) | ||
| 3543 | continue; | ||
| 3544 | if (strcmp(type, "EmojiReact") == 0 || strcmp(type, "Like") == 0) { | ||
| 3545 | if (strcmp(type, "Like") == 0 && !n_likes_on) | ||
| 3546 | continue; | ||
| 3547 | if (strcmp(type, "EmojiReact") == 0 && !n_reacts_on) | ||
| 3548 | continue; | ||
| 3549 | } | ||
| 3550 | if (strcmp(type, "Follow") == 0) { | ||
| 3551 | if (pending_check(snac, actor_id)) { | ||
| 3552 | if (!n_folreq_on) | ||
| 3553 | continue; | ||
| 3554 | } | ||
| 3555 | else | ||
| 3556 | if (!n_fol_on) | ||
| 3557 | continue; | ||
| 3558 | } | ||
| 3559 | if (strcmp(type, "Block") == 0 && !n_blocks_on) | ||
| 3560 | continue; | ||
| 3561 | if (strcmp(type, "Announce") == 0 && !n_ann_on) | ||
| 3562 | continue; | ||
| 3563 | flt = xs_list_append(flt, v); | ||
| 3564 | } | ||
| 3565 | return flt; | ||
| 3566 | } | ||
| 3567 | |||
| 3568 | |||
| 3506 | int notify_new_num(snac *snac) | 3569 | int notify_new_num(snac *snac) |
| 3507 | /* counts the number of new notifications */ | 3570 | /* counts the number of new notifications */ |
| 3508 | { | 3571 | { |
| 3509 | xs *t = notify_check_time(snac, 0); | 3572 | xs *t = notify_check_time(snac, 0); |
| 3510 | xs *lst = notify_list(snac, 0, XS_ALL); | 3573 | xs *lst_unfilt = notify_list(snac, 0, XS_ALL); |
| 3574 | xs *lst = notify_filter_list(snac, lst_unfilt); | ||
| 3511 | int cnt = 0; | 3575 | int cnt = 0; |
| 3512 | 3576 | ||
| 3513 | xs_list *p = lst; | 3577 | xs_list *p = lst; |