diff options
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 70 |
1 files changed, 61 insertions, 9 deletions
| @@ -333,6 +333,7 @@ int user_open_by_md5(snac *snac, const char *md5) | |||
| 333 | return 0; | 333 | return 0; |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | |||
| 336 | int user_persist(snac *snac, int publish) | 337 | int user_persist(snac *snac, int publish) |
| 337 | /* store user */ | 338 | /* store user */ |
| 338 | { | 339 | { |
| @@ -348,7 +349,7 @@ int user_persist(snac *snac, int publish) | |||
| 348 | 349 | ||
| 349 | if (old != NULL) { | 350 | if (old != NULL) { |
| 350 | int nw = 0; | 351 | int nw = 0; |
| 351 | const char *fields[] = { "header", "avatar", "name", "bio", | 352 | const char *fields[] = { "header", "avatar", "name", "bio", "alias", "alias_raw", |
| 352 | "metadata", "latitude", "longitude", NULL }; | 353 | "metadata", "latitude", "longitude", NULL }; |
| 353 | 354 | ||
| 354 | for (int n = 0; fields[n]; n++) { | 355 | for (int n = 0; fields[n]; n++) { |
| @@ -1391,7 +1392,7 @@ xs_str *timeline_fn_by_md5(snac *snac, const char *md5) | |||
| 1391 | } | 1392 | } |
| 1392 | 1393 | ||
| 1393 | 1394 | ||
| 1394 | int timeline_here(snac *snac, const char *md5) | 1395 | int timeline_here_by_md5(snac *snac, const char *md5) |
| 1395 | /* checks if an object is in the user cache */ | 1396 | /* checks if an object is in the user cache */ |
| 1396 | { | 1397 | { |
| 1397 | xs *fn = timeline_fn_by_md5(snac, md5); | 1398 | xs *fn = timeline_fn_by_md5(snac, md5); |
| @@ -1400,6 +1401,14 @@ int timeline_here(snac *snac, const char *md5) | |||
| 1400 | } | 1401 | } |
| 1401 | 1402 | ||
| 1402 | 1403 | ||
| 1404 | int timeline_here(snac *user, const char *id) | ||
| 1405 | { | ||
| 1406 | xs *md5 = xs_md5_hex(id, strlen(id)); | ||
| 1407 | |||
| 1408 | return timeline_here_by_md5(user, md5); | ||
| 1409 | } | ||
| 1410 | |||
| 1411 | |||
| 1403 | int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg) | 1412 | int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg) |
| 1404 | /* gets a message from the timeline */ | 1413 | /* gets a message from the timeline */ |
| 1405 | { | 1414 | { |
| @@ -1515,7 +1524,7 @@ xs_list *timeline_top_level(snac *snac, const xs_list *list) | |||
| 1515 | break; | 1524 | break; |
| 1516 | 1525 | ||
| 1517 | /* well, there is a parent... but is it here? */ | 1526 | /* well, there is a parent... but is it here? */ |
| 1518 | if (!timeline_here(snac, line2)) | 1527 | if (!timeline_here_by_md5(snac, line2)) |
| 1519 | break; | 1528 | break; |
| 1520 | 1529 | ||
| 1521 | /* it's here! try again with its own parent */ | 1530 | /* it's here! try again with its own parent */ |
| @@ -2217,7 +2226,7 @@ void tag_index(const char *id, const xs_dict *obj) | |||
| 2217 | if (*name == '\0') | 2226 | if (*name == '\0') |
| 2218 | continue; | 2227 | continue; |
| 2219 | 2228 | ||
| 2220 | name = xs_tolower_i((xs_str *)name); | 2229 | name = xs_utf8_to_lower((xs_str *)name); |
| 2221 | 2230 | ||
| 2222 | xs *md5_tag = xs_md5_hex(name, strlen(name)); | 2231 | xs *md5_tag = xs_md5_hex(name, strlen(name)); |
| 2223 | xs *tag_dir = xs_fmt("%s/%c%c", g_tag_dir, md5_tag[0], md5_tag[1]); | 2232 | xs *tag_dir = xs_fmt("%s/%c%c", g_tag_dir, md5_tag[0], md5_tag[1]); |
| @@ -2235,7 +2244,7 @@ void tag_index(const char *id, const xs_dict *obj) | |||
| 2235 | fclose(f); | 2244 | fclose(f); |
| 2236 | } | 2245 | } |
| 2237 | 2246 | ||
| 2238 | srv_debug(0, xs_fmt("tagged %s #%s (#%s)", id, name, md5_tag)); | 2247 | srv_debug(1, xs_fmt("tagged %s #%s (#%s)", id, name, md5_tag)); |
| 2239 | } | 2248 | } |
| 2240 | } | 2249 | } |
| 2241 | } | 2250 | } |
| @@ -2247,7 +2256,7 @@ xs_str *tag_fn(const char *tag) | |||
| 2247 | if (*tag == '#') | 2256 | if (*tag == '#') |
| 2248 | tag++; | 2257 | tag++; |
| 2249 | 2258 | ||
| 2250 | xs *lw_tag = xs_tolower_i(xs_dup(tag)); | 2259 | xs *lw_tag = xs_utf8_to_lower(tag); |
| 2251 | xs *md5 = xs_md5_hex(lw_tag, strlen(lw_tag)); | 2260 | xs *md5 = xs_md5_hex(lw_tag, strlen(lw_tag)); |
| 2252 | 2261 | ||
| 2253 | return xs_fmt("%s/tag/%c%c/%s.idx", srv_basedir, md5[0], md5[1], md5); | 2262 | return xs_fmt("%s/tag/%c%c/%s.idx", srv_basedir, md5[0], md5[1], md5); |
| @@ -2832,9 +2841,9 @@ int content_match(const char *file, const xs_dict *msg) | |||
| 2832 | srv_debug(1, xs_fmt("content_match: loading regexes from %s", fn)); | 2841 | srv_debug(1, xs_fmt("content_match: loading regexes from %s", fn)); |
| 2833 | 2842 | ||
| 2834 | /* massage content (strip HTML tags, etc.) */ | 2843 | /* massage content (strip HTML tags, etc.) */ |
| 2835 | xs *c = xs_regex_replace(v, "<[^>]+>", " "); | 2844 | xs *c1 = xs_regex_replace(v, "<[^>]+>", " "); |
| 2836 | c = xs_regex_replace_i(c, " {2,}", " "); | 2845 | c1 = xs_regex_replace_i(c1, " {2,}", " "); |
| 2837 | c = xs_tolower_i(c); | 2846 | xs *c = xs_utf8_to_lower(c1); |
| 2838 | 2847 | ||
| 2839 | while (!r && !feof(f)) { | 2848 | while (!r && !feof(f)) { |
| 2840 | xs *rx = xs_strip_i(xs_readline(f)); | 2849 | xs *rx = xs_strip_i(xs_readline(f)); |
| @@ -3158,6 +3167,9 @@ void notify_add(snac *snac, const char *type, const char *utype, | |||
| 3158 | 3167 | ||
| 3159 | pthread_mutex_unlock(&data_mutex); | 3168 | pthread_mutex_unlock(&data_mutex); |
| 3160 | } | 3169 | } |
| 3170 | |||
| 3171 | if (!xs_is_true(xs_dict_get(srv_config, "disable_notify_webhook"))) | ||
| 3172 | enqueue_notify_webhook(snac, noti, 0); | ||
| 3161 | } | 3173 | } |
| 3162 | 3174 | ||
| 3163 | 3175 | ||
| @@ -3513,6 +3525,46 @@ void enqueue_webmention(const xs_dict *msg) | |||
| 3513 | } | 3525 | } |
| 3514 | 3526 | ||
| 3515 | 3527 | ||
| 3528 | void enqueue_notify_webhook(snac *user, const xs_dict *noti, int retries) | ||
| 3529 | /* enqueues a notification webhook */ | ||
| 3530 | { | ||
| 3531 | const char *webhook = xs_dict_get(user->config, "notify_webhook"); | ||
| 3532 | |||
| 3533 | if (xs_is_string(webhook) && xs_match(webhook, "https://*|http://*")) { /** **/ | ||
| 3534 | xs *msg = xs_dup(noti); | ||
| 3535 | |||
| 3536 | /* add more data */ | ||
| 3537 | msg = xs_dict_set(msg, "target", user->actor); | ||
| 3538 | msg = xs_dict_set(msg, "uid", user->uid); | ||
| 3539 | msg = xs_dict_set(msg, "basedir", srv_basedir); | ||
| 3540 | msg = xs_dict_set(msg, "baseurl", srv_baseurl); | ||
| 3541 | |||
| 3542 | xs *actor_obj = NULL; | ||
| 3543 | |||
| 3544 | if (valid_status(object_get(xs_dict_get(noti, "actor"), &actor_obj)) && actor_obj) | ||
| 3545 | msg = xs_dict_set(msg, "account", actor_obj); | ||
| 3546 | |||
| 3547 | /* if this post is a reply, also add the inReplyTo object */ | ||
| 3548 | const char *in_reply_to = xs_dict_get_path(msg, "msg.object.inReplyTo"); | ||
| 3549 | |||
| 3550 | if (xs_is_string(in_reply_to)) { | ||
| 3551 | xs *irt_obj = NULL; | ||
| 3552 | |||
| 3553 | if (valid_status(object_get(in_reply_to, &irt_obj))) | ||
| 3554 | msg = xs_dict_set(msg, "reply", irt_obj); | ||
| 3555 | } | ||
| 3556 | |||
| 3557 | xs *qmsg = _new_qmsg("notify_webhook", msg, retries); | ||
| 3558 | const char *ntid = xs_dict_get(qmsg, "ntid"); | ||
| 3559 | xs *fn = xs_fmt("%s/queue/%s.json", user->basedir, ntid); | ||
| 3560 | |||
| 3561 | qmsg = _enqueue_put(fn, qmsg); | ||
| 3562 | |||
| 3563 | snac_debug(user, 1, xs_fmt("notify_webhook")); | ||
| 3564 | } | ||
| 3565 | } | ||
| 3566 | |||
| 3567 | |||
| 3516 | int was_question_voted(snac *user, const char *id) | 3568 | int was_question_voted(snac *user, const char *id) |
| 3517 | /* returns true if the user voted in this poll */ | 3569 | /* returns true if the user voted in this poll */ |
| 3518 | { | 3570 | { |