diff options
| -rw-r--r-- | mastoapi.c | 48 |
1 files changed, 37 insertions, 11 deletions
| @@ -440,7 +440,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 440 | /* the private timeline */ | 440 | /* the private timeline */ |
| 441 | if (logged_in) { | 441 | if (logged_in) { |
| 442 | const char *max_id = xs_dict_get(args, "max_id"); | 442 | const char *max_id = xs_dict_get(args, "max_id"); |
| 443 | // const char *since_id = xs_dict_get(args, "since_id"); | 443 | const char *since_id = xs_dict_get(args, "since_id"); |
| 444 | // const char *min_id = xs_dict_get(args, "min_id"); | 444 | // const char *min_id = xs_dict_get(args, "min_id"); |
| 445 | const char *limit_s = xs_dict_get(args, "limit"); | 445 | const char *limit_s = xs_dict_get(args, "limit"); |
| 446 | int limit = 20; | 446 | int limit = 20; |
| @@ -449,7 +449,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 449 | if (!xs_is_null(limit_s)) | 449 | if (!xs_is_null(limit_s)) |
| 450 | limit = atoi(limit_s); | 450 | limit = atoi(limit_s); |
| 451 | 451 | ||
| 452 | xs *timeline = timeline_list(&snac, "private", 0, XS_ALL); | 452 | xs *timeline = timeline_simple_list(&snac, "private", 0, XS_ALL); |
| 453 | 453 | ||
| 454 | xs *out = xs_list_new(); | 454 | xs *out = xs_list_new(); |
| 455 | xs_list *p = timeline; | 455 | xs_list *p = timeline; |
| @@ -466,11 +466,17 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 466 | continue; | 466 | continue; |
| 467 | } | 467 | } |
| 468 | 468 | ||
| 469 | /* only returns entries newer than since_id */ | ||
| 470 | if (since_id) { | ||
| 471 | if (strcmp(v, since_id) == 0) | ||
| 472 | break; | ||
| 473 | } | ||
| 474 | |||
| 469 | /* get the entry */ | 475 | /* get the entry */ |
| 470 | if (!valid_status(timeline_get_by_md5(&snac, v, &msg))) | 476 | if (!valid_status(timeline_get_by_md5(&snac, v, &msg))) |
| 471 | continue; | 477 | continue; |
| 472 | 478 | ||
| 473 | /* discard not-Notes */ | 479 | /* discard non-Notes */ |
| 474 | if (strcmp(xs_dict_get(msg, "type"), "Note") != 0) | 480 | if (strcmp(xs_dict_get(msg, "type"), "Note") != 0) |
| 475 | continue; | 481 | continue; |
| 476 | 482 | ||
| @@ -481,6 +487,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 481 | if (actor == NULL) | 487 | if (actor == NULL) |
| 482 | continue; | 488 | continue; |
| 483 | 489 | ||
| 490 | /** shave the yak converting an ActivityPub Note to a Mastodon status **/ | ||
| 491 | |||
| 484 | xs *acct = xs_dict_new(); | 492 | xs *acct = xs_dict_new(); |
| 485 | 493 | ||
| 486 | const char *display_name = xs_dict_get(actor, "name"); | 494 | const char *display_name = xs_dict_get(actor, "name"); |
| @@ -521,10 +529,13 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 521 | 529 | ||
| 522 | st = xs_dict_append(st, "id", v); | 530 | st = xs_dict_append(st, "id", v); |
| 523 | st = xs_dict_append(st, "uri", id); | 531 | st = xs_dict_append(st, "uri", id); |
| 532 | st = xs_dict_append(st, "url", id); | ||
| 524 | st = xs_dict_append(st, "created_at", xs_dict_get(msg, "published")); | 533 | st = xs_dict_append(st, "created_at", xs_dict_get(msg, "published")); |
| 525 | st = xs_dict_append(st, "account", acct); | 534 | st = xs_dict_append(st, "account", acct); |
| 526 | st = xs_dict_append(st, "content", xs_dict_get(msg, "content")); | 535 | st = xs_dict_append(st, "content", xs_dict_get(msg, "content")); |
| 527 | st = xs_dict_append(st, "visibility", "public"); | 536 | |
| 537 | st = xs_dict_append(st, "visibility", | ||
| 538 | is_msg_public(&snac, msg) ? "public" : "private"); | ||
| 528 | 539 | ||
| 529 | tmp = xs_dict_get(msg, "sensitive"); | 540 | tmp = xs_dict_get(msg, "sensitive"); |
| 530 | if (xs_is_null(tmp)) | 541 | if (xs_is_null(tmp)) |
| @@ -568,14 +579,29 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 568 | 579 | ||
| 569 | st = xs_dict_append(st, "replies_count", ixc); | 580 | st = xs_dict_append(st, "replies_count", ixc); |
| 570 | 581 | ||
| 571 | st = xs_dict_append(st, "url", id); | 582 | tmp = xs_dict_get(msg, "inReplyTo"); |
| 572 | 583 | if (xs_is_null(tmp)) { | |
| 573 | st = xs_dict_append(st, "in_reply_to_id", n); | 584 | st = xs_dict_append(st, "in_reply_to_id", n); |
| 574 | st = xs_dict_append(st, "in_reply_to_account_id", n); | 585 | st = xs_dict_append(st, "in_reply_to_account_id", n); |
| 575 | st = xs_dict_append(st, "reblog", n); | 586 | } |
| 576 | st = xs_dict_append(st, "poll", n); | 587 | else { |
| 577 | st = xs_dict_append(st, "card", n); | 588 | xs *irt_md5 = xs_md5_hex(tmp, strlen(tmp)); |
| 589 | st = xs_dict_append(st, "in_reply_to_id", irt_md5); | ||
| 590 | |||
| 591 | xs *irto = NULL; | ||
| 592 | char *at = NULL; | ||
| 593 | if (valid_status(object_get(tmp, &irto)) && | ||
| 594 | !xs_is_null(at = xs_dict_get(irto, "attributedTo"))) { | ||
| 595 | xs *at_md5 = xs_md5_hex(at, strlen(at)); | ||
| 596 | st = xs_dict_append(st, "in_reply_to_account_id", at_md5); | ||
| 597 | } | ||
| 598 | else | ||
| 599 | st = xs_dict_append(st, "in_reply_to_account_id", n); | ||
| 600 | } | ||
| 578 | 601 | ||
| 602 | st = xs_dict_append(st, "reblog", n); | ||
| 603 | st = xs_dict_append(st, "poll", n); | ||
| 604 | st = xs_dict_append(st, "card", n); | ||
| 579 | st = xs_dict_append(st, "language", n); | 605 | st = xs_dict_append(st, "language", n); |
| 580 | 606 | ||
| 581 | tmp = xs_dict_get(msg, "sourceContent"); | 607 | tmp = xs_dict_get(msg, "sourceContent"); |