Allows you to use Mastodon and Bluesky comments on your Lustre blog hexdocs.pm/chilp/
blog gleam lustre indieweb mastodon bluesky comments
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

And here we go again rc3


Signed-off-by: MLC Bloeiman <mar@strawmelonjuice.com>

+56 -44
+1 -1
gleam.toml
··· 1 1 name = "chilp" 2 2 description = "Allows you to use Mastodon and Bluesky comments on your Lustre blog." 3 - version = "2.0.0-rc2" 3 + version = "2.0.0-rc3" 4 4 gleam = ">= 1.15.0" 5 5 licences = ["Apache-2.0"] 6 6 repository = { type = "tangled", user = "did:plc:jgtfsmv25thfs4zmydtbccnn", repo = "chilp" }
+55 -43
src/chilp/widget.gleam
··· 415 415 bsky_op_profile: Option(String), 416 416 mastodon_op_profile: Option(String), 417 417 ) -> Element(Msg) { 418 - use <- bool.guard( 419 - when: { 420 - list.find(comment.children, fn(child) { 421 - child.author_profile_link 422 - == case comment.source, bsky_op_profile, mastodon_op_profile { 423 - "Mastodon", _, Some(op) -> op 424 - "Bluesky", Some(op), _ -> op 425 - _, _, _ -> "" 418 + let commands = 419 + list.filter_map(comment.children, fn(child) { 420 + case 421 + { 422 + case comment.source, bsky_op_profile, mastodon_op_profile { 423 + "Mastodon", _, Some(op) -> op == child.author_profile_link 424 + 425 + "Bluesky", Some(op), _ -> { 426 + // Had some mismatches here, but decided it is of no importance what hostname we use. 427 + { 428 + op 429 + |> string.replace("https://bsky.app", "") 430 + |> string.replace("https://bluesky.app", "") 431 + } 432 + == { 433 + child.author_profile_link 434 + |> string.replace("https://bsky.app", "") 435 + |> string.replace("https://bluesky.app", "") 436 + } 437 + } 438 + _, _, _ -> False 439 + } 440 + } 441 + { 442 + // Not by op 443 + False -> Error(Nil) 444 + True -> { 445 + let content = 446 + element.to_readable_string(child.content) |> string.lowercase() 447 + case string.starts_with(content, "-chilp ") { 448 + True -> Ok(content) 449 + False -> Error(Nil) 450 + } 426 451 } 427 - && child.content |> element.to_readable_string() == "-chilp hide" 428 - }) 429 - // If this is ok, that means a hide command by the op was found. We return this thread and don't need to process anything else in it. 430 - |> result.is_ok() 431 - }, 432 - return: element.none(), 433 - ) 452 + } 453 + }) 454 + let is_hidden = list.any(commands, string.starts_with(_, "-chilp hide")) 455 + let is_silenced = list.any(commands, string.starts_with(_, "-chilp silence")) 456 + // Is the comment we're currently trying to parse a command? Even unauthorised commands will not be rendered. 457 + let is_command = { 458 + string.starts_with( 459 + element.to_readable_string(comment.content) |> string.lowercase(), 460 + "-chilp ", 461 + ) 462 + } 463 + use <- bool.guard(when: is_hidden, return: element.none()) 464 + use <- bool.guard(when: is_command, return: element.none()) 434 465 html.article([attribute.class("comment mt-2")], [ 435 466 html.header([attribute.class("flex")], [ 436 467 html.img([ ··· 534 565 ), 535 566 ]), 536 567 html.br([attribute.class("border-b-2 border-dotted")]), 537 - case comment.children { 538 - [] -> element.none() 539 - _ -> 568 + case comment.children, is_silenced { 569 + [], _ | _, True -> element.none() 570 + _, False -> 540 571 html.section( 541 572 [ 542 573 attribute.class( 543 574 "pl-5 border-s-4 border-default bg-neutral-secondary-soft", 544 575 ), 545 576 ], 546 - case 547 - { 548 - list.find(comment.children, fn(child) { 549 - child.author_profile_link 550 - == case comment.source, bsky_op_profile, mastodon_op_profile { 551 - "Mastodon", _, Some(op) -> op 552 - "Bluesky", Some(op), _ -> op 553 - _, _, _ -> "" 554 - } 555 - && child.content |> element.to_readable_string() 556 - == "-chilp silence" 557 - }) 558 - // If this is ok, that means a hide command by the op was found. We return this thread and don't need to process anything else in it. 559 - |> result.is_ok() 560 - } 561 - { 562 - True -> 563 - list.sort(comment.children, sort_comments) 564 - |> list.map(view_rendered_comment( 565 - _, 566 - bsky_op_profile, 567 - mastodon_op_profile, 568 - )) 569 - False -> [element.text("Comments on this comment are hidden.")] 570 - }, 577 + list.sort(comment.children, sort_comments) 578 + |> list.map(view_rendered_comment( 579 + _, 580 + bsky_op_profile, 581 + mastodon_op_profile, 582 + )), 571 583 ) 572 584 }, 573 585 ]),