@rmdes/indiekit-endpoint-activitypub 3.8.6 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/assets/css/base.css +144 -0
  2. package/assets/css/card.css +377 -0
  3. package/assets/css/compose.css +169 -0
  4. package/assets/css/dark-mode.css +94 -0
  5. package/assets/css/explore.css +530 -0
  6. package/assets/css/features.css +436 -0
  7. package/assets/css/federation.css +242 -0
  8. package/assets/css/interactions.css +236 -0
  9. package/assets/css/media.css +315 -0
  10. package/assets/css/messages.css +158 -0
  11. package/assets/css/moderation.css +119 -0
  12. package/assets/css/notifications.css +191 -0
  13. package/assets/css/profile.css +308 -0
  14. package/assets/css/responsive.css +33 -0
  15. package/assets/css/skeleton.css +74 -0
  16. package/assets/reader-interactions.js +115 -0
  17. package/assets/reader.css +20 -3439
  18. package/index.js +34 -694
  19. package/lib/batch-broadcast.js +98 -0
  20. package/lib/controllers/compose.js +5 -7
  21. package/lib/controllers/interactions-boost.js +8 -13
  22. package/lib/controllers/interactions-like.js +8 -13
  23. package/lib/federation-actions.js +70 -0
  24. package/lib/inbox-queue.js +16 -10
  25. package/lib/init-indexes.js +251 -0
  26. package/lib/item-processing.js +22 -2
  27. package/lib/lookup-cache.js +3 -0
  28. package/lib/mastodon/backfill-timeline.js +11 -2
  29. package/lib/mastodon/entities/sanitize.js +19 -88
  30. package/lib/mastodon/helpers/account-cache.js +3 -0
  31. package/lib/mastodon/helpers/enrich-accounts.js +42 -55
  32. package/lib/mastodon/router.js +31 -0
  33. package/lib/mastodon/routes/accounts.js +16 -49
  34. package/lib/mastodon/routes/media.js +6 -4
  35. package/lib/mastodon/routes/notifications.js +6 -24
  36. package/lib/mastodon/routes/oauth.js +91 -18
  37. package/lib/mastodon/routes/search.js +3 -1
  38. package/lib/mastodon/routes/statuses.js +14 -52
  39. package/lib/mastodon/routes/timelines.js +3 -6
  40. package/lib/og-unfurl.js +52 -33
  41. package/lib/storage/moderation.js +11 -2
  42. package/lib/syndicator.js +239 -0
  43. package/lib/timeline-store.js +11 -15
  44. package/package.json +2 -1
  45. package/views/activitypub-federation-mgmt.njk +2 -2
  46. package/views/activitypub-moderation.njk +1 -1
  47. package/views/activitypub-profile.njk +16 -76
  48. package/views/activitypub-reader.njk +2 -1
  49. package/views/layouts/ap-reader.njk +2 -0
  50. package/views/partials/ap-item-card.njk +14 -117
  51. package/views/partials/ap-item-content.njk +20 -0
  52. package/views/partials/ap-notification-card.njk +1 -1
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Card interaction Alpine.js component.
3
+ * Handles like, boost, and save-for-later actions with optimistic UI and
4
+ * rollback on failure.
5
+ *
6
+ * Configured via data-* attributes on the container element (the <footer>):
7
+ * data-item-uid="..." canonical AP UID used for like/boost API calls
8
+ * data-item-url="..." display URL used for saveLater and links
9
+ * data-csrf-token="..."
10
+ * data-mount-path="..."
11
+ * data-liked="true|false"
12
+ * data-boosted="true|false"
13
+ * data-like-count="N" omit or empty string for null
14
+ * data-boost-count="N" omit or empty string for null
15
+ */
16
+ document.addEventListener("alpine:init", () => {
17
+ Alpine.data("apCardInteraction", () => ({
18
+ liked: false,
19
+ boosted: false,
20
+ saved: false,
21
+ loading: false,
22
+ error: "",
23
+ likeCount: null,
24
+ boostCount: null,
25
+
26
+ init() {
27
+ this.liked = this.$el.dataset.liked === "true";
28
+ this.boosted = this.$el.dataset.boosted === "true";
29
+ const lc = this.$el.dataset.likeCount;
30
+ const bc = this.$el.dataset.boostCount;
31
+ this.likeCount = lc != null && lc !== "" ? Number(lc) : null;
32
+ this.boostCount = bc != null && bc !== "" ? Number(bc) : null;
33
+ },
34
+
35
+ async saveLater() {
36
+ if (this.saved) return;
37
+ const el = this.$el;
38
+ const itemUrl = el.dataset.itemUrl;
39
+ try {
40
+ const res = await fetch("/readlater/save", {
41
+ method: "POST",
42
+ headers: { "Content-Type": "application/json" },
43
+ body: JSON.stringify({
44
+ url: itemUrl,
45
+ title:
46
+ el.closest("article")?.querySelector("p")?.textContent?.substring(0, 80) ||
47
+ itemUrl,
48
+ source: "activitypub",
49
+ }),
50
+ credentials: "same-origin",
51
+ });
52
+ if (res.ok) this.saved = true;
53
+ else this.error = "Failed to save";
54
+ } catch (e) {
55
+ this.error = e.message;
56
+ }
57
+ if (this.error) setTimeout(() => (this.error = ""), 3000);
58
+ },
59
+
60
+ async interact(action) {
61
+ if (this.loading) return;
62
+ this.loading = true;
63
+ this.error = "";
64
+ const el = this.$el;
65
+ const itemUid = el.dataset.itemUid;
66
+ const csrfToken = el.dataset.csrfToken;
67
+ const basePath = el.dataset.mountPath;
68
+ const prev = {
69
+ liked: this.liked,
70
+ boosted: this.boosted,
71
+ boostCount: this.boostCount,
72
+ likeCount: this.likeCount,
73
+ };
74
+ if (action === "like") {
75
+ this.liked = true;
76
+ if (this.likeCount !== null) this.likeCount++;
77
+ } else if (action === "unlike") {
78
+ this.liked = false;
79
+ if (this.likeCount !== null && this.likeCount > 0) this.likeCount--;
80
+ } else if (action === "boost") {
81
+ this.boosted = true;
82
+ if (this.boostCount !== null) this.boostCount++;
83
+ } else if (action === "unboost") {
84
+ this.boosted = false;
85
+ if (this.boostCount !== null && this.boostCount > 0) this.boostCount--;
86
+ }
87
+ try {
88
+ const res = await fetch(basePath + "/admin/reader/" + action, {
89
+ method: "POST",
90
+ headers: {
91
+ "Content-Type": "application/json",
92
+ "X-CSRF-Token": csrfToken,
93
+ },
94
+ body: JSON.stringify({ url: itemUid }),
95
+ });
96
+ const data = await res.json();
97
+ if (!data.success) {
98
+ this.liked = prev.liked;
99
+ this.boosted = prev.boosted;
100
+ this.boostCount = prev.boostCount;
101
+ this.likeCount = prev.likeCount;
102
+ this.error = data.error || "Failed";
103
+ }
104
+ } catch (e) {
105
+ this.liked = prev.liked;
106
+ this.boosted = prev.boosted;
107
+ this.boostCount = prev.boostCount;
108
+ this.likeCount = prev.likeCount;
109
+ this.error = e.message;
110
+ }
111
+ this.loading = false;
112
+ if (this.error) setTimeout(() => (this.error = ""), 3000);
113
+ },
114
+ }));
115
+ });