pups-client 0.4.0 → 0.5.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.
- package/README.md +35 -0
- package/dist/discovery.d.ts +5 -0
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +2 -0
- package/dist/discovery.js.map +1 -1
- package/dist/feed.d.ts +96 -4
- package/dist/feed.d.ts.map +1 -1
- package/dist/feed.js +135 -8
- package/dist/feed.js.map +1 -1
- package/dist/handles.d.ts +34 -0
- package/dist/handles.d.ts.map +1 -0
- package/dist/handles.js +91 -0
- package/dist/handles.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/mentions.d.ts +222 -0
- package/dist/mentions.d.ts.map +1 -0
- package/dist/mentions.js +341 -0
- package/dist/mentions.js.map +1 -0
- package/dist/session.d.ts +6 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +9 -0
- package/dist/session.js.map +1 -1
- package/dist/util.d.ts +2 -0
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +2 -0
- package/dist/util.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/discovery.ts +7 -0
- package/src/feed.ts +182 -12
- package/src/handles.ts +101 -0
- package/src/index.ts +7 -0
- package/src/mentions.ts +443 -0
- package/src/session.ts +10 -0
- package/src/util.ts +4 -0
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -145,6 +145,8 @@ console.log(post.item.url) // the post's
|
|
|
145
145
|
await feed.editPost(post.id, { title: 'Hello, world' }) // wherever the post is now, sets date_modified
|
|
146
146
|
await feed.deletePost(post.id, { deleteMedia: true }) // also deletes media no other post uses
|
|
147
147
|
await feed.updateSettings({ description: 'Longer notes', _podcast: { explicit: false } })
|
|
148
|
+
if (feed.commentsAvailable && feed.comments(state.feed) == 'off')
|
|
149
|
+
await feed.enableComments({ policy: { maxLength: 1000 } }) // comments go into the owner's inbox
|
|
148
150
|
|
|
149
151
|
for await (const item of feed.posts()) console.log(item.id) // newest first, through all archives
|
|
150
152
|
const feeds = await session.listFeeds() // the feeds registered in host-meta.json
|
|
@@ -153,9 +155,42 @@ const feeds = await session.listFeeds() // the feeds r
|
|
|
153
155
|
- **Archives.** Every post goes into the newest archive, `feed.000000.json`, `feed.000001.json`, … in the feed directory, 20 posts each, linked with `next_url`; posts never move. The feed file holds a copy of the newest 30 posts and points to the newest archive with `_pups.archive_url`; archives point back with `_pups.updates_url`. `session.feed(name, { maxItems, archiveSize, maxBytes })` changes the sizes. Archives are optional in RFC-7: with `{ startArchives: false }`, a feed without archives stays a plain feed file with the newest posts; a feed that has archives always keeps them.
|
|
154
156
|
- **Concurrency.** Every change is a read-modify-write with ETags, repeated when another app or the owner wrote in between. The archive is always written before the feed file, so no post is ever lost, and the next post repairs a feed file that an interrupted post didn't reach.
|
|
155
157
|
- **Post URLs.** `addPost()` returns `url`, the post's archive URL plus `#<id>`. It never changes, so it can be the `source` of an RFC-4 webmention. If the site has a homepage that shows single posts, such as webpup, `host-meta.json` declares their URLs with the property `https://bigwide.net/ns/post-url-template` (`POST_URL_TEMPLATE`), e.g. `https://tim.example/p/{feed}/post/{index}`. Posts of a feed with archives then get the URL of their page as `url`, unless the app sets one; `editPost()` adds it to older posts that have none. Show `post.item.url` as the post's link; `session.feed(name, { postUrls: false })` turns this off.
|
|
158
|
+
- **Comments on your feed.** If the server has a `comment_endpoint` (RFC-6 "Built-in receiver"), `feed.enableComments({ policy, tos })` opens the feed for RFC-4 comments: it writes `_submissions` into the feed file, with the endpoint as `url`, a `comments` policy and `republish: "no"`, and the server puts the comments into the owner's inbox. `feed.disableComments()` removes it, `feed.comments(doc)` tells whether comments go to this server (`pups`), another service (`other`) or nowhere (`off`). Archives don't copy `_submissions`: the feed file alone decides. Single posts are closed with `_commenting: { allowComments: false }`.
|
|
156
159
|
- **Indexes.** Every post gets an index, `_pups.index` (also `PostResult.index`, or `itemIndex(item)`): 0 for the first post, then counting up, never changed and never given out again, with the counter `_pups.next_index` in the newest archive. Readers can number the posts and load only the archives they need. A feed written before indexes existed is indexed on its next post, or with `feed.assignIndexes()`; posts of apps that don't know indexes get theirs on the next post.
|
|
157
160
|
- Errors: `not_pups_controlled` for feeds without the marker, `invalid_feed` for files that aren't JSON Feeds, `not_found` for a missing feed or post.
|
|
158
161
|
|
|
162
|
+
### Mentions and submissions
|
|
163
|
+
|
|
164
|
+
A feed can tell the people a post names or answers ([RFC-11](https://github.com/bigwide-net/RFCs/blob/main/RFC-11-Mentions.md)), and submit comments to other feeds ([RFC-4](https://github.com/bigwide-net/RFCs/blob/main/RFC-4-Feed-Submissions.md)):
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
const feed = session.feed(undefined, { mentions: true })
|
|
168
|
+
const post = await feed.addPost({ content_html: '<p>Great talk by <a href="https://alice.example/">@alice.example</a></p>' })
|
|
169
|
+
for (const r of await post.mentions ?? []) console.log(r.account, r.status) // @alice.example accepted
|
|
170
|
+
|
|
171
|
+
const comment = await feed.addPost({ content_text: 'Agreed!', _source: { inReplyTo: 'https://rm.example/groups/g/posts.json#a8Kd03' } })
|
|
172
|
+
const submission = await feed.submit(comment.id) // to the target feed's _submissions.url
|
|
173
|
+
await session.mentions.submissionStatus(submission.statusUrl!) // { status: 'success', pubUrl: … }
|
|
174
|
+
|
|
175
|
+
await session.mentions.notify(source, '@alice.example') // the generic interface: any source, any account
|
|
176
|
+
await session.mentions.reply(source, 'https://bob.example/feed.json#p-12')
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
- **Asking first.** `feed.planMentions(input)` lists the accounts a post would notify, without sending anything, so the app can ask before posting. Each write takes `{ mentions }`: `true`, `false` (post without mentions), or the confirmed list:
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
const planned = await feed.planMentions(input) // [{ account: '@alice.example', kind: 'mention', target }]
|
|
183
|
+
const confirmed = planned.length && await confirmDialog(planned) ? planned : false
|
|
184
|
+
await feed.addPost(input, { mentions: confirmed })
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
For an edit, plan with the new version and `{ previous: oldItem }`; for a delete, `planMentions(undefined, { previous: oldItem })`. `{ discover: true }` leaves out the domains without an endpoint, but looks them up before the post is published, which tells them that it names them.
|
|
188
|
+
- **Automatic mentions.** With `{ mentions: true }`, `addPost()`, `editPost()` and `deletePost()` find the handles in the post's title and visible text, e.g. `@alice.example`, also lists like `@alice.example/@bob.example`, but not e-mail addresses, fediverse addresses, names without a dot or paths. The author of the item a post answers (`_source.inReplyTo`) gets a reply mention. Each account is notified once, never the owner, at most 20 per post; after an edit or delete, everyone the old or the new version named.
|
|
189
|
+
- **After the upload.** The mentions are sent in the background, once the post is visible at its public URL (so that a CDN doesn't hand the receiver an old copy), with the archive URL plus `#<id>` as `source`. `post.mentions` resolves to one report per account (`accepted`, `rejected`, `failed`, `unknown` or `no-endpoint`) and never rejects; a failed mention never fails the post. Network errors, `5xx` and `429` are retried a few times; `feed.sendMentions(id)` sends again later.
|
|
190
|
+
- **Discovery.** The endpoint is the link `https://bigwide.net/ns/mention` in the domain's `host-meta.json`, cached for a day, failures for an hour. A domain without one, or whose `host-meta.json` doesn't allow CORS, gets nothing. An endpoint without CORS headers still receives the mention; its report says `unknown`.
|
|
191
|
+
- **Replies to RFC-4 feeds** are submissions, not mentions: if the answered feed has `_submissions`, no mentions are sent (the RFC-4 server sends them once it republishes the comment). Submitting is never automatic, because the app must first show the target's terms of service and what `republish` means: call `feed.submit(id)` after `addPost()`, and again after `editPost()` or `deletePost()`.
|
|
192
|
+
- `new Mentions({ fetch })` works without a session. `findHandles()`, `itemHandles()` and `visibleText()` are exported too.
|
|
193
|
+
|
|
159
194
|
### What the library does for you
|
|
160
195
|
|
|
161
196
|
- **Discovery** through `/.well-known/host-meta.json` and the configuration document.
|
package/dist/discovery.d.ts
CHANGED
|
@@ -35,6 +35,11 @@ export interface PupsServer {
|
|
|
35
35
|
hostMetaEndpoint?: string;
|
|
36
36
|
/** Present only if the server can't accept `PUT` and `DELETE`; all writes then go here. */
|
|
37
37
|
postEndpoint?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Present if the server accepts RFC-4 comments on posts of the owner's feeds and writes them into the owner's inbox
|
|
40
|
+
* (RFC-6 "Built-in receiver"). Feeds opt in with `feed.enableComments()`.
|
|
41
|
+
*/
|
|
42
|
+
commentEndpoint?: string;
|
|
38
43
|
maxUploadBytes: number;
|
|
39
44
|
specVersion: string;
|
|
40
45
|
/** The configuration document as fetched, including fields this library doesn't know. */
|
package/dist/discovery.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAGA,wHAAwH;AACxH,eAAO,MAAM,QAAQ,4CAA4C,CAAA;AAEjE,yDAAyD;AACzD,eAAO,MAAM,uBAAuB,EAAE,SAAS,MAAM,EAAY,CAAA;AAIjE,iEAAiE;AACjE,MAAM,WAAW,aAAa;IAC5B,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAA;IACZ,wFAAwF;IACxF,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,4EAA4E;IAC5E,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,0EAA0E;IAC1E,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,uFAAuF;IACvF,cAAc,EAAE,MAAM,EAAE,CAAA;CACzB;AAED,wHAAwH;AACxH,MAAM,WAAW,UAAU;IACzB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAA;IACd,yGAAyG;IACzG,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,qBAAqB,EAAE,MAAM,CAAA;IAC7B,aAAa,EAAE,MAAM,CAAA;IACrB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,0CAA0C;IAC1C,WAAW,EAAE,MAAM,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AED,wHAAwH;AACxH,MAAM,WAAW,UAAU;IACzB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAA;IACd,yGAAyG;IACzG,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,qBAAqB,EAAE,MAAM,CAAA;IAC7B,aAAa,EAAE,MAAM,CAAA;IACrB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,0CAA0C;IAC1C,WAAW,EAAE,MAAM,CAAA;IACnB,gDAAgD;IAChD,UAAU,EAAE,MAAM,CAAA;IAClB,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,cAAc,EAAE,aAAa,EAAE,CAAA;IAC/B,6EAA6E;IAC7E,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,2FAA2F;IAC3F,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,cAAc,EAAE,MAAM,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;IACnB,yFAAyF;IACzF,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC7B;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUrD;AAoBD;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAmB/G;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,UAAU,CAkE9F"}
|
package/dist/discovery.js
CHANGED
|
@@ -118,6 +118,7 @@ export function parseConfig(json, domain, identityHosts) {
|
|
|
118
118
|
});
|
|
119
119
|
const hostMetaEndpoint = optionalHttps('host_meta_endpoint');
|
|
120
120
|
const postEndpoint = optionalHttps('post_endpoint');
|
|
121
|
+
const commentEndpoint = optionalHttps('comment_endpoint');
|
|
121
122
|
return {
|
|
122
123
|
domain,
|
|
123
124
|
identityHosts,
|
|
@@ -131,6 +132,7 @@ export function parseConfig(json, domain, identityHosts) {
|
|
|
131
132
|
wellKnownPaths,
|
|
132
133
|
...hostMetaEndpoint ? { hostMetaEndpoint } : {},
|
|
133
134
|
...postEndpoint ? { postEndpoint } : {},
|
|
135
|
+
...commentEndpoint ? { commentEndpoint } : {},
|
|
134
136
|
maxUploadBytes: maxUploadBytes,
|
|
135
137
|
specVersion,
|
|
136
138
|
raw,
|
package/dist/discovery.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEtD,wHAAwH;AACxH,MAAM,CAAC,MAAM,QAAQ,GAAG,yCAAyC,CAAA;AAEjE,yDAAyD;AACzD,MAAM,CAAC,MAAM,uBAAuB,GAAsB,CAAC,KAAK,CAAC,CAAA;AAEjE,MAAM,kBAAkB,GAAG,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEtD,wHAAwH;AACxH,MAAM,CAAC,MAAM,QAAQ,GAAG,yCAAyC,CAAA;AAEjE,yDAAyD;AACzD,MAAM,CAAC,MAAM,uBAAuB,GAAsB,CAAC,KAAK,CAAC,CAAA;AAEjE,MAAM,kBAAkB,GAAG,MAAM,CAAA;AA+CjC;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,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AgB,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE;QAC/C,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE;QACvC,GAAG,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE;QAC7C,cAAc,EAAE,cAAwB;QACxC,WAAW;QACX,GAAG;KACJ,CAAA;AACH,CAAC"}
|
package/dist/feed.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Mentions, MentionReport, MentionSource, PlannedMention, Submission } from './mentions.js';
|
|
1
2
|
import type { Scope } from './scopes.js';
|
|
2
3
|
import type { Body, PupsSession } from './session.js';
|
|
3
4
|
/** The link relation that registers a feed in `host-meta.json` (RFC-7). A placeholder in RFC-7. */
|
|
@@ -96,6 +97,24 @@ export interface FeedSettings {
|
|
|
96
97
|
expired?: boolean;
|
|
97
98
|
[extension: `_${string}`]: unknown;
|
|
98
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* The rules for comments of RFC-4 "Policies". Missing rules have RFC-4's defaults; servers may add others. The PUPS
|
|
102
|
+
* server's receiver enforces `title`, `minLength`, `maxLength`, `requireSocialSpec`, `allowEdit` and `allowDelete`.
|
|
103
|
+
*/
|
|
104
|
+
export interface CommentPolicy {
|
|
105
|
+
title?: 'required' | 'allowed' | 'none';
|
|
106
|
+
minLength?: number;
|
|
107
|
+
maxLength?: number;
|
|
108
|
+
requireSocialSpec?: boolean;
|
|
109
|
+
allowEdit?: boolean;
|
|
110
|
+
allowDelete?: boolean;
|
|
111
|
+
[rule: string]: unknown;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Whether a feed accepts comments (RFC-4 `_submissions`): `pups` through the PUPS server's receiver, `other`
|
|
115
|
+
* through another service, such as an rssmention server, or `off`.
|
|
116
|
+
*/
|
|
117
|
+
export type CommentsState = 'pups' | 'other' | 'off';
|
|
99
118
|
/** Changes to the settings: a value sets the field, `null` removes it, `undefined` leaves it unchanged. */
|
|
100
119
|
export type FeedSettingsChanges = {
|
|
101
120
|
[K in keyof FeedSettings]?: FeedSettings[K] | null;
|
|
@@ -157,6 +176,11 @@ export interface PostResult {
|
|
|
157
176
|
* as the `source` of an RFC-4 webmention. In a feed without archives, the feed file's URL plus `#<id>`.
|
|
158
177
|
*/
|
|
159
178
|
url: string;
|
|
179
|
+
/**
|
|
180
|
+
* With the option `mentions`: the RFC-11 mentions, sent once the post is visible at its public URL. Never
|
|
181
|
+
* rejects. Missing if the post names and answers no one.
|
|
182
|
+
*/
|
|
183
|
+
mentions?: Promise<MentionReport[]>;
|
|
160
184
|
}
|
|
161
185
|
export interface MediaResult {
|
|
162
186
|
path: string;
|
|
@@ -209,6 +233,12 @@ export interface FeedOptions {
|
|
|
209
233
|
* declares one and the post has no `url` (RFC-7 "Post URLs"). Default true.
|
|
210
234
|
*/
|
|
211
235
|
postUrls?: boolean;
|
|
236
|
+
/**
|
|
237
|
+
* Whether to send RFC-11 mentions after `addPost()`, `editPost()` and `deletePost()`: to the domains a post names
|
|
238
|
+
* (`@tim.example.com`) and to the author of the item it answers. `true` uses `session.mentions`. Default false.
|
|
239
|
+
* Each write can decide otherwise with its own option `mentions`, e.g. with the accounts the author confirmed.
|
|
240
|
+
*/
|
|
241
|
+
mentions?: boolean | Mentions;
|
|
212
242
|
}
|
|
213
243
|
/** A feed registered in `host-meta.json`. */
|
|
214
244
|
export interface FeedLink {
|
|
@@ -221,6 +251,14 @@ export interface FeedLink {
|
|
|
221
251
|
type Signal = {
|
|
222
252
|
signal?: AbortSignal;
|
|
223
253
|
};
|
|
254
|
+
/**
|
|
255
|
+
* Which RFC-11 mentions a write sends: `true` all of them, `false` none, or a list from `planMentions()`, e.g. the
|
|
256
|
+
* accounts the author confirmed. Default: the feed's option `mentions`.
|
|
257
|
+
*/
|
|
258
|
+
export type MentionChoice = boolean | PlannedMention[];
|
|
259
|
+
type WithMentions = Signal & {
|
|
260
|
+
mentions?: MentionChoice;
|
|
261
|
+
};
|
|
224
262
|
/** The scopes an app needs to write a feed: the feed file and the feed directory (RFC-7 "Server requirements"). */
|
|
225
263
|
export declare function feedScopes(name?: string): Scope[];
|
|
226
264
|
/** The index of an item (RFC-7 "Indexes"), or undefined if it has none. */
|
|
@@ -284,6 +322,24 @@ export declare class PupsFeed {
|
|
|
284
322
|
setIcon(media: MediaInput | null, options?: Signal): Promise<FeedDocument>;
|
|
285
323
|
/** Uploads a new favicon (64 × 64) to the icons directory, like `setIcon()`, or removes it with `null`. */
|
|
286
324
|
setFavicon(media: MediaInput | null, options?: Signal): Promise<FeedDocument>;
|
|
325
|
+
/** Whether the PUPS server can receive comments on the feed's posts (`comment_endpoint`, RFC-6 "Built-in receiver"). */
|
|
326
|
+
get commentsAvailable(): boolean;
|
|
327
|
+
/** Whether the feed accepts comments, and through whom; `doc` is the feed file, e.g. from `load()`. */
|
|
328
|
+
comments(doc: FeedDocument): CommentsState;
|
|
329
|
+
/**
|
|
330
|
+
* Lets readers comment on the feed's posts through the PUPS server, which puts the comments into the owner's inbox
|
|
331
|
+
* (RFC-6 "Built-in receiver"): writes RFC-4 `_submissions` into the feed file, with `comment_endpoint` as `url`,
|
|
332
|
+
* the comments policy (RFC-4's defaults for `title`, `minLength` and `maxLength`, overridden by `policy`) and
|
|
333
|
+
* `republish: "no"`. Replaces the `_submissions` of another service; check `comments()` first and ask the owner.
|
|
334
|
+
* Single posts are closed with `_commenting: { allowComments: false }` (RFC-4).
|
|
335
|
+
* @throws {PupsError} `unsupported` if the server has no `comment_endpoint`.
|
|
336
|
+
*/
|
|
337
|
+
enableComments(settings?: {
|
|
338
|
+
policy?: CommentPolicy;
|
|
339
|
+
tos?: string;
|
|
340
|
+
}, options?: Signal): Promise<FeedDocument>;
|
|
341
|
+
/** Closes the feed for comments: removes `_submissions` from the feed file, whichever service it names. */
|
|
342
|
+
disableComments(options?: Signal): Promise<FeedDocument>;
|
|
287
343
|
/**
|
|
288
344
|
* Uploads an image, audio or video file into the feed directory under a new, unique name, by default
|
|
289
345
|
* `images/<year>/…` for images and `media/<year>/…` for everything else. Reference it from a post by its `url`.
|
|
@@ -299,11 +355,13 @@ export declare class PupsFeed {
|
|
|
299
355
|
* media with `uploadMedia()` before posting.
|
|
300
356
|
* In a feed with archives, a post without `url` gets one from the site's post URL template, if `host-meta.json`
|
|
301
357
|
* has one and `postUrls` isn't false: the page that shows the post (RFC-7 "Post URLs").
|
|
358
|
+
* With the option `mentions`, the domains the post names and the author of the item it answers are notified
|
|
359
|
+
* (RFC-11) once the post is visible; see `PostResult.mentions`.
|
|
302
360
|
* @returns the post, with `url`: its archive's URL plus `#<id>`, which never changes; for a feed without
|
|
303
361
|
* archives, the feed file's URL plus `#<id>`, valid while the post is among the newest. The post's page, if it
|
|
304
362
|
* has one, is `item.url`.
|
|
305
363
|
*/
|
|
306
|
-
addPost(input: PostInput, options?:
|
|
364
|
+
addPost(input: PostInput, options?: WithMentions): Promise<PostResult>;
|
|
307
365
|
/**
|
|
308
366
|
* Gives every item of the feed without an index one (RFC-7 "Indexing an existing feed"), and sets the counter.
|
|
309
367
|
* `addPost()` does this by itself before the first post to a feed that hasn't been indexed yet; call it to
|
|
@@ -326,11 +384,12 @@ export declare class PupsFeed {
|
|
|
326
384
|
* a function that gets a copy of the item and returns the new item, or `undefined` to leave it unchanged. The
|
|
327
385
|
* function may run more than once.
|
|
328
386
|
*
|
|
329
|
-
* Apps should edit posts only when the owner asks them to, whichever app created them.
|
|
387
|
+
* Apps should edit posts only when the owner asks them to, whichever app created them. With the option
|
|
388
|
+
* `mentions`, everyone the old or the new version mentions is notified. A post of a feed with
|
|
330
389
|
* archives that has no `url`, and had none before, gets one from the post URL template, as in `addPost()`.
|
|
331
390
|
* @throws {PupsError} `not_found`
|
|
332
391
|
*/
|
|
333
|
-
editPost(id: string, changes: PostChanges | ((item: FeedItem) => FeedItem | undefined | Promise<FeedItem | undefined>), options?:
|
|
392
|
+
editPost(id: string, changes: PostChanges | ((item: FeedItem) => FeedItem | undefined | Promise<FeedItem | undefined>), options?: WithMentions): Promise<PostResult>;
|
|
334
393
|
/**
|
|
335
394
|
* Deletes a post from its archive and from the feed file, which is then filled up again with the newest items
|
|
336
395
|
* from the archives. With `deleteMedia`, it also deletes the files in the feed directory that the post references
|
|
@@ -338,12 +397,45 @@ export declare class PupsFeed {
|
|
|
338
397
|
* @returns the deleted item, and the public URLs of the deleted media files.
|
|
339
398
|
* @throws {PupsError} `not_found`
|
|
340
399
|
*/
|
|
341
|
-
deletePost(id: string, options?:
|
|
400
|
+
deletePost(id: string, options?: WithMentions & {
|
|
342
401
|
deleteMedia?: boolean;
|
|
343
402
|
}): Promise<{
|
|
344
403
|
item: FeedItem;
|
|
345
404
|
deletedMedia: string[];
|
|
405
|
+
mentions?: Promise<MentionReport[]>;
|
|
346
406
|
}>;
|
|
407
|
+
/**
|
|
408
|
+
* Sends the RFC-11 mentions of a post now, e.g. to try again those that failed (see `Mentions.notifyAll()`). With
|
|
409
|
+
* `previous`, the version before an edit, also to the accounts that one mentioned.
|
|
410
|
+
* @throws {PupsError} `not_found`
|
|
411
|
+
*/
|
|
412
|
+
sendMentions(id: string, options?: Signal & {
|
|
413
|
+
previous?: FeedItem;
|
|
414
|
+
}): Promise<MentionReport[]>;
|
|
415
|
+
/**
|
|
416
|
+
* Submits a post that answers an item of an RFC-4 feed, e.g. a comment, to that feed's `_submissions.url`
|
|
417
|
+
* (RFC-4 "Submitting"): `source` is the post's archive URL plus `#<id>`, `target` its `_source.inReplyTo`. Call it
|
|
418
|
+
* after `addPost()` or `editPost()`, also to submit an edit or a delete again. Show the target's terms of service
|
|
419
|
+
* and what its `republish` means before the first submission.
|
|
420
|
+
* @throws {PupsError} `not_found`; `invalid_request` if the post answers nothing; `unsupported` if the target
|
|
421
|
+
* feed takes no submissions.
|
|
422
|
+
*/
|
|
423
|
+
submit(id: string, options?: Signal): Promise<Submission>;
|
|
424
|
+
/**
|
|
425
|
+
* The RFC-11 mentions a post would send (see `Mentions.plan()`), e.g. to ask the author before posting:
|
|
426
|
+
*
|
|
427
|
+
* ```ts
|
|
428
|
+
* const planned = await feed.planMentions(input)
|
|
429
|
+
* const confirmed = planned.length && await askToNotify(planned) ? planned : false // the app's dialog
|
|
430
|
+
* await feed.addPost(input, { mentions: confirmed })
|
|
431
|
+
* ```
|
|
432
|
+
*
|
|
433
|
+
* For an edit, pass the post as it will be and the current version as `previous`; for a delete, only `previous`.
|
|
434
|
+
*/
|
|
435
|
+
planMentions(post: MentionSource | undefined, options?: Signal & {
|
|
436
|
+
previous?: MentionSource;
|
|
437
|
+
discover?: boolean;
|
|
438
|
+
}): Promise<PlannedMention[]>;
|
|
347
439
|
}
|
|
348
440
|
/** The feeds registered in the owner's `host-meta.json` (RFC-7 "Registering feeds"). */
|
|
349
441
|
export declare function listFeeds(session: PupsSession, options?: Signal & FeedOptions): Promise<FeedLink[]>;
|
package/dist/feed.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feed.d.ts","sourceRoot":"","sources":["../src/feed.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"feed.d.ts","sourceRoot":"","sources":["../src/feed.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AACvG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAGrD,mGAAmG;AACnG,eAAO,MAAM,QAAQ,gCAAgC,CAAA;AAErD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,6CAA6C,CAAA;AAE3E,qGAAqG;AACrG,eAAO,MAAM,cAAc,qFAAqF,CAAA;AAuBhH,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM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Q,CAAC;QAAC,YAAY,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,CAAA;KAAE,CAAC;IAmC9K;;;;OAIG;IACG,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,EAAE,QAAQ,CAAA;KAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAMxG;;;;;;;OAOG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,MAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAQnE;;;;;;;;;;OAUG;IACH,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,EAAE,OAAO,GAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,EAAE,aAAa,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;CAyflJ;AAED,wFAAwF;AACxF,wBAAsB,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,GAAE,MAAM,GAAG,WAAgB,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAgB7G"}
|
package/dist/feed.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isPupsError, PupsError } from './errors.js';
|
|
2
2
|
import { fileTypes } from './file-types.js';
|
|
3
3
|
import { pathFromPublicUrl } from './paths.js';
|
|
4
|
-
import {
|
|
4
|
+
import { itemHandles } from './handles.js';
|
|
5
|
+
import { isObject, randomString } from './util.js';
|
|
5
6
|
/** The link relation that registers a feed in `host-meta.json` (RFC-7). A placeholder in RFC-7. */
|
|
6
7
|
export const FEED_REL = 'https://bigwide.net/ns/feed';
|
|
7
8
|
/**
|
|
@@ -12,6 +13,7 @@ export const POST_URL_TEMPLATE = 'https://bigwide.net/ns/post-url-template';
|
|
|
12
13
|
/** The `about` of the `_pups` object: RFC-7. Not its final location; readers must not rely on it. */
|
|
13
14
|
export const PUPS_FEED_SPEC = 'https://github.com/bigwide-net/RFCs/blob/main/RFC-7-Feed-Publishing-with-PUPS.md';
|
|
14
15
|
const RFC1_URL = 'https://github.com/bigwide-net/RFCs/blob/main/RFC-1-Source-for-JSON-Feeds.md';
|
|
16
|
+
const RFC4_URL = 'https://github.com/bigwide-net/RFCs/blob/main/RFC-4-Feed-Submissions.md';
|
|
15
17
|
const JSON_FEED_VERSION = 'https://jsonfeed.org/version/1.1';
|
|
16
18
|
const FEED_CONTENT_TYPE = 'application/feed+json';
|
|
17
19
|
const maxArchiveNumber = 999_999;
|
|
@@ -39,7 +41,6 @@ function feedPaths(name) {
|
|
|
39
41
|
throw new PupsError('invalid_request', `"${name}" can't be a feed name: /feed/${name}/ and its files belong to the main feed (RFC-7, Named feeds).`);
|
|
40
42
|
return { path: `/feed/${name}.json`, directory: `/feed/${name}/` };
|
|
41
43
|
}
|
|
42
|
-
const isObject = (value) => !!value && typeof value == 'object' && !Array.isArray(value);
|
|
43
44
|
const isFeedDocument = (value) => isObject(value) && typeof value.version == 'string' && value.version.startsWith('https://jsonfeed.org/version/1')
|
|
44
45
|
&& Array.isArray(value.items) && value.items.every(i => isObject(i) && typeof i.id == 'string');
|
|
45
46
|
const isControlled = (doc) => doc._pups?.pupsControlled === true;
|
|
@@ -136,6 +137,7 @@ export class PupsFeed {
|
|
|
136
137
|
#maxBytes;
|
|
137
138
|
#maxAttempts;
|
|
138
139
|
#postUrls;
|
|
140
|
+
#mentions;
|
|
139
141
|
#template;
|
|
140
142
|
/** @internal Use `session.feed()`. */
|
|
141
143
|
constructor(session, name, options = {}) {
|
|
@@ -150,6 +152,7 @@ export class PupsFeed {
|
|
|
150
152
|
this.#maxBytes = options.maxBytes;
|
|
151
153
|
this.#maxAttempts = options.maxAttempts ?? 8;
|
|
152
154
|
this.#postUrls = options.postUrls ?? true;
|
|
155
|
+
this.#mentions = options.mentions === true ? session.mentions : options.mentions || undefined;
|
|
153
156
|
if (!(this.#archiveSize >= 1 && this.#maxItems >= 1))
|
|
154
157
|
throw new PupsError('invalid_request', 'Feed options: maxItems and archiveSize must be at least 1.');
|
|
155
158
|
}
|
|
@@ -279,6 +282,49 @@ export class PupsFeed {
|
|
|
279
282
|
setFavicon(media, options = {}) {
|
|
280
283
|
return this.#setImage('favicon', media, options.signal);
|
|
281
284
|
}
|
|
285
|
+
/** Whether the PUPS server can receive comments on the feed's posts (`comment_endpoint`, RFC-6 "Built-in receiver"). */
|
|
286
|
+
get commentsAvailable() {
|
|
287
|
+
return !!this.#session.server.commentEndpoint;
|
|
288
|
+
}
|
|
289
|
+
/** Whether the feed accepts comments, and through whom; `doc` is the feed file, e.g. from `load()`. */
|
|
290
|
+
comments(doc) {
|
|
291
|
+
const submissions = doc._submissions;
|
|
292
|
+
if (!isObject(submissions))
|
|
293
|
+
return 'off';
|
|
294
|
+
const endpoint = this.#session.server.commentEndpoint;
|
|
295
|
+
return endpoint && submissions.url == endpoint ? 'pups' : 'other';
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Lets readers comment on the feed's posts through the PUPS server, which puts the comments into the owner's inbox
|
|
299
|
+
* (RFC-6 "Built-in receiver"): writes RFC-4 `_submissions` into the feed file, with `comment_endpoint` as `url`,
|
|
300
|
+
* the comments policy (RFC-4's defaults for `title`, `minLength` and `maxLength`, overridden by `policy`) and
|
|
301
|
+
* `republish: "no"`. Replaces the `_submissions` of another service; check `comments()` first and ask the owner.
|
|
302
|
+
* Single posts are closed with `_commenting: { allowComments: false }` (RFC-4).
|
|
303
|
+
* @throws {PupsError} `unsupported` if the server has no `comment_endpoint`.
|
|
304
|
+
*/
|
|
305
|
+
async enableComments(settings = {}, options = {}) {
|
|
306
|
+
const url = this.#session.server.commentEndpoint;
|
|
307
|
+
if (!url)
|
|
308
|
+
throw new PupsError('unsupported', 'This PUPS server doesn\'t receive comments: its configuration has no comment_endpoint (RFC-6, Built-in receiver).');
|
|
309
|
+
return this.#setSubmissions({
|
|
310
|
+
about: RFC4_URL,
|
|
311
|
+
url,
|
|
312
|
+
...settings.tos ? { tos: settings.tos } : {},
|
|
313
|
+
policies: { comments: { title: 'none', minLength: 2, maxLength: 2000, ...settings.policy } },
|
|
314
|
+
republish: 'no',
|
|
315
|
+
}, options.signal);
|
|
316
|
+
}
|
|
317
|
+
/** Closes the feed for comments: removes `_submissions` from the feed file, whichever service it names. */
|
|
318
|
+
disableComments(options = {}) {
|
|
319
|
+
return this.#setSubmissions(undefined, options.signal);
|
|
320
|
+
}
|
|
321
|
+
#setSubmissions(submissions, signal) {
|
|
322
|
+
return this.#transaction(async () => {
|
|
323
|
+
const main = await this.#readControlled(this.path, signal);
|
|
324
|
+
const { _submissions: _old, ...doc } = main.doc;
|
|
325
|
+
return this.#writeMain(submissions ? { ...doc, _submissions: submissions } : doc, main.etag, signal);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
282
328
|
/**
|
|
283
329
|
* Uploads an image, audio or video file into the feed directory under a new, unique name, by default
|
|
284
330
|
* `images/<year>/…` for images and `media/<year>/…` for everything else. Reference it from a post by its `url`.
|
|
@@ -300,6 +346,8 @@ export class PupsFeed {
|
|
|
300
346
|
* media with `uploadMedia()` before posting.
|
|
301
347
|
* In a feed with archives, a post without `url` gets one from the site's post URL template, if `host-meta.json`
|
|
302
348
|
* has one and `postUrls` isn't false: the page that shows the post (RFC-7 "Post URLs").
|
|
349
|
+
* With the option `mentions`, the domains the post names and the author of the item it answers are notified
|
|
350
|
+
* (RFC-11) once the post is visible; see `PostResult.mentions`.
|
|
303
351
|
* @returns the post, with `url`: its archive's URL plus `#<id>`, which never changes; for a feed without
|
|
304
352
|
* archives, the feed file's URL plus `#<id>`, valid while the post is among the newest. The post's page, if it
|
|
305
353
|
* has one, is `item.url`.
|
|
@@ -348,7 +396,7 @@ export class PupsFeed {
|
|
|
348
396
|
doc.items = this.#newestItems(added.recent, doc.items, doc);
|
|
349
397
|
await this.#writeMain(doc, main.etag, signal);
|
|
350
398
|
});
|
|
351
|
-
return this.#result(stored, archiveUrl);
|
|
399
|
+
return this.#withMentions(options.mentions, this.#result(stored, archiveUrl), archiveUrl, stored, undefined, item => !!item);
|
|
352
400
|
}
|
|
353
401
|
/**
|
|
354
402
|
* Gives every item of the feed without an index one (RFC-7 "Indexing an existing feed"), and sets the counter.
|
|
@@ -402,13 +450,16 @@ export class PupsFeed {
|
|
|
402
450
|
* a function that gets a copy of the item and returns the new item, or `undefined` to leave it unchanged. The
|
|
403
451
|
* function may run more than once.
|
|
404
452
|
*
|
|
405
|
-
* Apps should edit posts only when the owner asks them to, whichever app created them.
|
|
453
|
+
* Apps should edit posts only when the owner asks them to, whichever app created them. With the option
|
|
454
|
+
* `mentions`, everyone the old or the new version mentions is notified. A post of a feed with
|
|
406
455
|
* archives that has no `url`, and had none before, gets one from the post URL template, as in `addPost()`.
|
|
407
456
|
* @throws {PupsError} `not_found`
|
|
408
457
|
*/
|
|
409
458
|
async editPost(id, changes, options = {}) {
|
|
410
459
|
const signal = options.signal;
|
|
411
|
-
|
|
460
|
+
let edit;
|
|
461
|
+
const result = await this.#transaction(async () => {
|
|
462
|
+
edit = undefined;
|
|
412
463
|
const { main, file, index } = await this.#findWritable(id, signal);
|
|
413
464
|
const old = file.doc.items[index];
|
|
414
465
|
const fileUrl = this.#session.publicUrl(file.path);
|
|
@@ -428,8 +479,11 @@ export class PupsFeed {
|
|
|
428
479
|
const mainIndex = main.doc.items.findIndex(i => i.id == id);
|
|
429
480
|
if (mainIndex >= 0)
|
|
430
481
|
await this.#writeMain({ ...main.doc, items: replaceAt(main.doc.items, mainIndex, item) }, main.etag, signal);
|
|
482
|
+
edit = { old, item, fileUrl };
|
|
431
483
|
return this.#result(item, fileUrl);
|
|
432
484
|
});
|
|
485
|
+
const done = edit;
|
|
486
|
+
return done ? this.#withMentions(options.mentions, result, done.fileUrl, done.item, done.old, found => found?.date_modified == done.item.date_modified) : result;
|
|
433
487
|
}
|
|
434
488
|
/**
|
|
435
489
|
* Deletes a post from its archive and from the feed file, which is then filled up again with the newest items
|
|
@@ -440,8 +494,10 @@ export class PupsFeed {
|
|
|
440
494
|
*/
|
|
441
495
|
async deletePost(id, options = {}) {
|
|
442
496
|
const signal = options.signal;
|
|
497
|
+
let fileUrl = '';
|
|
443
498
|
const item = await this.#transaction(async () => {
|
|
444
499
|
const { main, file, index } = await this.#findWritable(id, signal);
|
|
500
|
+
fileUrl = this.#session.publicUrl(file.path);
|
|
445
501
|
const item = file.doc.items[index];
|
|
446
502
|
if (file != main) {
|
|
447
503
|
await this.#writeArchive(file, file.doc.items.filter(i => i.id != id), signal);
|
|
@@ -471,7 +527,75 @@ export class PupsFeed {
|
|
|
471
527
|
deletedMedia.push(url);
|
|
472
528
|
}
|
|
473
529
|
}
|
|
474
|
-
|
|
530
|
+
const mentions = this.#sendMentions(options.mentions, fileUrl, undefined, item, found => !found);
|
|
531
|
+
return { item, deletedMedia, ...mentions ? { mentions } : {} };
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Sends the RFC-11 mentions of a post now, e.g. to try again those that failed (see `Mentions.notifyAll()`). With
|
|
535
|
+
* `previous`, the version before an edit, also to the accounts that one mentioned.
|
|
536
|
+
* @throws {PupsError} `not_found`
|
|
537
|
+
*/
|
|
538
|
+
async sendMentions(id, options = {}) {
|
|
539
|
+
const post = await this.getPost(id, options);
|
|
540
|
+
if (!post)
|
|
541
|
+
throw new PupsError('not_found', `The feed has no post with the id "${id}".`);
|
|
542
|
+
return this.#mentionSender.notifyAll({ source: post.url, item: post.item, previous: options.previous, me: this.#session.me }, options);
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Submits a post that answers an item of an RFC-4 feed, e.g. a comment, to that feed's `_submissions.url`
|
|
546
|
+
* (RFC-4 "Submitting"): `source` is the post's archive URL plus `#<id>`, `target` its `_source.inReplyTo`. Call it
|
|
547
|
+
* after `addPost()` or `editPost()`, also to submit an edit or a delete again. Show the target's terms of service
|
|
548
|
+
* and what its `republish` means before the first submission.
|
|
549
|
+
* @throws {PupsError} `not_found`; `invalid_request` if the post answers nothing; `unsupported` if the target
|
|
550
|
+
* feed takes no submissions.
|
|
551
|
+
*/
|
|
552
|
+
async submit(id, options = {}) {
|
|
553
|
+
const post = await this.getPost(id, options);
|
|
554
|
+
if (!post)
|
|
555
|
+
throw new PupsError('not_found', `The feed has no post with the id "${id}".`);
|
|
556
|
+
const source = isObject(post.item._source) ? post.item._source : {};
|
|
557
|
+
if (typeof source.inReplyTo != 'string')
|
|
558
|
+
throw new PupsError('invalid_request', `The post "${id}" has no _source.inReplyTo, so it answers nothing (RFC-4).`);
|
|
559
|
+
return this.#session.mentions.submit(post.url, source.inReplyTo, options);
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* The RFC-11 mentions a post would send (see `Mentions.plan()`), e.g. to ask the author before posting:
|
|
563
|
+
*
|
|
564
|
+
* ```ts
|
|
565
|
+
* const planned = await feed.planMentions(input)
|
|
566
|
+
* const confirmed = planned.length && await askToNotify(planned) ? planned : false // the app's dialog
|
|
567
|
+
* await feed.addPost(input, { mentions: confirmed })
|
|
568
|
+
* ```
|
|
569
|
+
*
|
|
570
|
+
* For an edit, pass the post as it will be and the current version as `previous`; for a delete, only `previous`.
|
|
571
|
+
*/
|
|
572
|
+
planMentions(post, options = {}) {
|
|
573
|
+
return this.#mentionSender.plan({ item: post, previous: options.previous, me: this.#session.me }, options);
|
|
574
|
+
}
|
|
575
|
+
get #mentionSender() {
|
|
576
|
+
return this.#mentions ?? this.#session.mentions;
|
|
577
|
+
}
|
|
578
|
+
/** The result with the RFC-11 mentions of the post, if the write sends them (see `#sendMentions()`). */
|
|
579
|
+
#withMentions(choice, result, fileUrl, item, previous, ready) {
|
|
580
|
+
const mentions = this.#sendMentions(choice, fileUrl, item, previous, ready);
|
|
581
|
+
return mentions ? { ...result, mentions } : result;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Sends the RFC-11 mentions of a post in the background, once its file at `fileUrl` is in the state `ready` wants:
|
|
585
|
+
* all, none, or the planned ones, as `choice` (default: the feed's option) says. Undefined if nothing is sent.
|
|
586
|
+
*/
|
|
587
|
+
#sendMentions(choice, fileUrl, item, previous, ready) {
|
|
588
|
+
choice ??= !!this.#mentions;
|
|
589
|
+
const relevant = (i) => !!i && (itemHandles(i).length > 0 || (isObject(i._source) && typeof i._source.inReplyTo == 'string'));
|
|
590
|
+
if (Array.isArray(choice) ? !choice.length : !choice || !(relevant(item) || relevant(previous)))
|
|
591
|
+
return;
|
|
592
|
+
const mentions = this.#mentionSender;
|
|
593
|
+
const id = (item ?? previous).id;
|
|
594
|
+
const source = `${fileUrl}#${encodeURIComponent(id)}`;
|
|
595
|
+
return (async () => {
|
|
596
|
+
await mentions.waitForItem(fileUrl, id, ready);
|
|
597
|
+
return Array.isArray(choice) ? mentions.sendPlanned(source, choice) : mentions.notifyAll({ source, item, previous, me: this.#session.me });
|
|
598
|
+
})().catch(() => []);
|
|
475
599
|
}
|
|
476
600
|
// Reading
|
|
477
601
|
/**
|
|
@@ -622,9 +746,12 @@ export class PupsFeed {
|
|
|
622
746
|
const match = /^feed\.(\d{6})\.json$/.exec(path.slice(this.directory.length));
|
|
623
747
|
return match ? Number(match[1]) : undefined;
|
|
624
748
|
}
|
|
625
|
-
/**
|
|
749
|
+
/**
|
|
750
|
+
* A new archive with the feed fields of the feed file (RFC-7 "Archives"), except `_submissions`: whether a feed
|
|
751
|
+
* accepts comments is said by its feed file alone.
|
|
752
|
+
*/
|
|
626
753
|
#newArchive(n, main, items, nextUrl, nextIndex) {
|
|
627
|
-
const { items: _items, next_url: _next, user_comment: _comment, hubs: _hubs, author: _author, _pups, ...fields } = main;
|
|
754
|
+
const { items: _items, next_url: _next, user_comment: _comment, hubs: _hubs, author: _author, _pups, _submissions: _s, ...fields } = main;
|
|
628
755
|
const { archive_url: _archive, next_index: _counter, ...marker } = _pups ?? {};
|
|
629
756
|
const podcast = fields._podcast;
|
|
630
757
|
if (isObject(podcast) && 'liveItems' in podcast) {
|