@pkcprotocol/active-page-sort 0.0.5 → 0.0.7
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/AGENTS.md +5 -2
- package/README.md +14 -9
- package/dist/active-page-sort.d.ts +1 -1
- package/dist/active-page-sort.js +13 -3
- package/dist/active-page-sort.js.map +1 -1
- package/dist/no-bump.d.ts +13 -4
- package/dist/no-bump.js +26 -6
- package/dist/no-bump.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -25,11 +25,12 @@ Conventions specific to this package:
|
|
|
25
25
|
- `NO_BUMP_KEYWORDS_OPTION` (`noBumpKeywords`) is the wire contract. UIs read it off
|
|
26
26
|
`community.pageSorts.posts.active.publicOptions` to render a sage marker, and most of them never install
|
|
27
27
|
this package. A rename is a new contract, never an edit. The literal is pinned in `test/unit/no-bump.test.ts`.
|
|
28
|
+
`BUMP_LIMIT_OPTION` (`bumpLimit`) is the same kind of contract and is pinned next to it.
|
|
28
29
|
- The match is a whole line equal to the keyword, exact and case-sensitive. `src/no-bump.ts` imports
|
|
29
30
|
nothing and must keep matching what the README describes, because UIs copy or bundle it for the browser.
|
|
30
31
|
- `score` is sync and never returns `null`: a saged thread sinks, it is not filtered. It reads
|
|
31
32
|
`comment.timestamp`, the reserved `exclude*` options, and per reply `timestamp`, `content`, and the
|
|
32
|
-
CommentUpdate's `removed`, `approved`, `pendingApproval` and `edit.deleted`. There is no database access and
|
|
33
|
+
CommentUpdate's `cid`, `removed`, `approved`, `pendingApproval` and `edit.deleted`. There is no database access and
|
|
33
34
|
no network; a need for either is a later iteration of the pkc-js contract, not a reason to reach around it.
|
|
34
35
|
- `isCountedReply` / `bumpTimestamp` (in `src/no-bump.ts`) apply the `exclude*` options to each reply's own
|
|
35
36
|
CommentUpdate, the tombstone rule of pkc-js's "Which replies count" (`docs/protocol/comment-lifecycle.md`):
|
|
@@ -38,9 +39,11 @@ Conventions specific to this package:
|
|
|
38
39
|
(trimmed, case-insensitive `true`). With the `posts` defaults it must match the built-in `active`. A new
|
|
39
40
|
reserved exclusion in pkc-js means a release here. `excludeCommentsWithDifferentCommunityAddress` is left
|
|
40
41
|
out on purpose: pkc-js applies it, and `score` has no community address (pkc-js#401).
|
|
42
|
+
- The bump limit counts the replies `isCountedReply` keeps, saged or not, ordered by `(timestamp, cid)` with the
|
|
43
|
+
CID compared as a plain string, so the community and a client re-sort agree on a tie at the boundary.
|
|
41
44
|
- The scorer ignores `commentUpdate.lastReplyTimestamp` on purpose. That aggregate counts saged replies.
|
|
42
45
|
- `validatePageSortSettings` is sync and rejects only what can never work (empty list, line break, size
|
|
43
|
-
bounds). An unset option is valid and means plain bump order.
|
|
46
|
+
bounds, a `bumpLimit` that is not a positive integer). An unset option is valid and means plain bump order.
|
|
44
47
|
- Test fixtures are typed against pkc-js's own types through `test/unit/fixtures.ts`. Do not cast a
|
|
45
48
|
fixture through `unknown`; a field that does not exist on the wire must fail to compile.
|
|
46
49
|
- Never use the `any` type.
|
package/README.md
CHANGED
|
@@ -10,12 +10,13 @@ A board's catalog shows threads in bump order: the thread with the newest reply
|
|
|
10
10
|
- A **no-bump reply** is a reply whose content has a whole line equal to one of the configured keywords. The match is exact and case-sensitive: a content of `sage`, or a multi-line content with a line that is exactly `sage`, does not bump. `sage is overused` in prose, `Sage`, `#sage` and ` sage` all bump.
|
|
11
11
|
- Replies **under** a no-bump reply still count, at any depth. Someone answering a saged reply bumps the thread as usual.
|
|
12
12
|
- A reply the sort's exclusion options drop (by default: removed, deleted, disapproved or pending approval) does not bump the thread, but the present replies under it still do, at any depth: a removed or deleted reply is a **tombstone**, not a cut. This is pkc-js's [Which replies count](https://github.com/pkcprotocol/pkc-js/blob/master/docs/protocol/comment-lifecycle.md#which-replies-count) rule, the one the built-in `active` follows through `lastReplyTimestamp`. A board that turns a flag off (`excludeDeletedComments: "false"`) lets those replies bump again.
|
|
13
|
-
-
|
|
14
|
-
-
|
|
13
|
+
- With a **bump limit** set, only a thread's first `bumpLimit` counted replies can bump it. Past the limit the thread stays open and keeps taking replies, but none of them bump it, so it sinks, the imageboard bump limit. Every counted reply counts toward the limit, saged or not, at any depth. "First" is by reply timestamp, ties broken by the reply's CID.
|
|
14
|
+
- A saged thread, or one past its bump limit, **sinks, it is never hidden**. The sort ranks, it does not filter.
|
|
15
|
+
- With both options unset the sort is plain bump order, identical to pkc-js's built-in `active`.
|
|
15
16
|
|
|
16
17
|
The sort publishes under the wire key `active`, the same key as the built-in, so a UI that already reads `community.posts.pages.active` shows the saged order without any change. The community also publishes what the key means in `community.pageSorts.posts.active`, including the keyword list, so a UI can tell this sort from the built-in and render a sage marker on matching replies.
|
|
17
18
|
|
|
18
|
-
The word `sage` appears nowhere in this package. The board supplies its vocabulary through the `noBumpKeywords` option
|
|
19
|
+
The word `sage` appears nowhere in this package. The board supplies its vocabulary through the `noBumpKeywords` option, and its limit through `bumpLimit`.
|
|
19
20
|
|
|
20
21
|
## How the sorting works
|
|
21
22
|
|
|
@@ -23,7 +24,8 @@ pkc-js regenerates a community's post pages on every publish cycle. For each con
|
|
|
23
24
|
|
|
24
25
|
```
|
|
25
26
|
counted = replies no exclude* option that is on drops (each judged on its own)
|
|
26
|
-
|
|
27
|
+
within = counted sorted by (timestamp, cid), the first bumpLimit of them (all of them without a limit)
|
|
28
|
+
max(post.timestamp, ...within.filter(not no-bump).map(reply => reply.timestamp))
|
|
27
29
|
```
|
|
28
30
|
|
|
29
31
|
Each reply is judged on its own, so a skipped reply never hides the replies under it. The reply pages a UI walks keep removed and deleted replies as tombstones too, so a raw walk scores like the community (see [Re-sort a page locally](#4-re-sort-a-page-locally-optional)). That is the whole algorithm. pkc-js owns everything around it: pinned threads first (`pinnedFirst`), the optional age window (`maxAge`), chunking into pages, the moderation exclusions on the threads being ranked. The file contains no date arithmetic and never sees a pinned flag.
|
|
@@ -119,11 +121,12 @@ Page sort options are strings, like challenge options. Unlike challenge options
|
|
|
119
121
|
| Option | Required | Published in `publicOptions` | Default | Description |
|
|
120
122
|
|---|---|---|---|---|
|
|
121
123
|
| `noBumpKeywords` | no | yes, unless listed in `privateOptions` | unset (plain bump order) | Comma-separated keywords, e.g. `sage` or `sage,nobump`. A reply whose content has a whole line equal to one of these does not bump its thread. Exact and case-sensitive |
|
|
124
|
+
| `bumpLimit` | no | yes, unless listed in `privateOptions` | unset (no limit) | A positive integer, e.g. `"300"`. Only a thread's first this many counted replies, saged or not, can bump it; past the limit it sinks while staying open. Counted replies are the ones the `exclude*` options keep, the same set as the thread's `replyCount` |
|
|
122
125
|
| `maxAge` | no | always (reserved) | none | pkc-js reserved: a sliding window such as `"36h"`, `"7d"`, `"2w"`, `"1M"`, `"1y"`. Threads older than the window drop out of the pages (pinned threads bypass it) |
|
|
123
126
|
| `pinnedFirst` | no | always (reserved) | `"true"` | pkc-js reserved: pinned threads first and outside the window. `"false"` treats them as ordinary threads |
|
|
124
127
|
| `excludeRemovedComments`, `excludeDeletedComments`, `excludeCommentPendingApproval`, `excludeCommentWithApprovedFalse`, `excludeCommentsWithDifferentCommunityAddress` | no | always (reserved) | `"true"` for the `posts` scope | pkc-js reserved moderation filters on the threads the sort ranks. `score` also applies the first four to the replies: a reply one of them drops does not bump, the replies under it still do. `excludeCommentsWithDifferentCommunityAddress` is applied to replies by pkc-js before `score` runs (checking it needs the community's address, which `score` does not get, [pkc-js#401](https://github.com/pkcprotocol/pkc-js/issues/401)) |
|
|
125
128
|
|
|
126
|
-
Keep `noBumpKeywords` public unless you have a reason not to: a UI reads it to know the board supports sage, to put the keyword on the wire the way the sort reads it, and to mark saged replies. With the option private the order still applies but UIs cannot do any of that. The reserved options cannot be made private (`ERR_PAGE_SORT_RESERVED_OPTION_CANNOT_BE_PRIVATE`): a client re-sorting a page must know how its comment set was filtered. Their full semantics are in the pkc-js page sorts doc, "Reserved options". If pkc-js adds a reserved exclusion, this package needs a release that applies it to replies too.
|
|
129
|
+
Keep `noBumpKeywords` public unless you have a reason not to: a UI reads it to know the board supports sage, to put the keyword on the wire the way the sort reads it, and to mark saged replies. With the option private the order still applies but UIs cannot do any of that. The same goes for `bumpLimit`: a UI compares it to a thread's `replyCount` to show that the thread no longer bumps. The reserved options cannot be made private (`ERR_PAGE_SORT_RESERVED_OPTION_CANNOT_BE_PRIVATE`): a client re-sorting a page must know how its comment set was filtered. Their full semantics are in the pkc-js page sorts doc, "Reserved options". If pkc-js adds a reserved exclusion, this package needs a release that applies it to replies too.
|
|
127
130
|
|
|
128
131
|
### Validation
|
|
129
132
|
|
|
@@ -132,6 +135,7 @@ The entry is validated when the community is created, on every edit (rejecting t
|
|
|
132
135
|
- `noBumpKeywords` set but holding no keyword (`""`, `" , ,"`): that would silently be plain bump order. Unset it instead.
|
|
133
136
|
- More than 64 keywords, or a keyword over 128 characters.
|
|
134
137
|
- A keyword containing a line break, which can never equal a line.
|
|
138
|
+
- `bumpLimit` set to anything but a positive integer (`"0"`, `"-1"`, `"1.5"`, `"300 replies"`, `""`). Surrounding whitespace is trimmed. Unset it for no limit.
|
|
135
139
|
|
|
136
140
|
Failures surface as `ERR_PAGE_SORT_SETTINGS_VALIDATION_FAILED` inside pkc-js's aggregated `ERR_PAGE_SORT_SETTINGS_VALIDATION_FAILED_FOR_PAGE_SORTS`.
|
|
137
141
|
|
|
@@ -142,9 +146,10 @@ community.pageSorts = {
|
|
|
142
146
|
posts: {
|
|
143
147
|
active: {
|
|
144
148
|
name: "@pkcprotocol/active-page-sort", // absent for a path entry
|
|
145
|
-
description: "Bump order where a reply whose content has a line equal to a configured keyword does not bump its thread",
|
|
149
|
+
description: "Bump order where a reply whose content has a line equal to a configured keyword does not bump its thread, with an optional bump limit",
|
|
146
150
|
publicOptions: {
|
|
147
151
|
noBumpKeywords: "sage",
|
|
152
|
+
bumpLimit: "300",
|
|
148
153
|
pinnedFirst: "true",
|
|
149
154
|
excludeRemovedComments: "true",
|
|
150
155
|
excludeDeletedComments: "true",
|
|
@@ -190,7 +195,7 @@ import { isNoBumpReplyForOptions } from "@pkcprotocol/active-page-sort";
|
|
|
190
195
|
const saged = isNoBumpReplyForOptions(reply.content, community.pageSorts?.posts?.active?.publicOptions);
|
|
191
196
|
```
|
|
192
197
|
|
|
193
|
-
`isNoBumpContent(content, keywords)` and `splitKeywords(raw)` are the same test without the options lookup, and `bumpTimestamp({ postTimestamp, replies, keywords, options })` gives a thread's effective bump time from a reply tree walked from reply pages, tombstones included, with the published `publicOptions` as `options`. `isCountedReply(reply, options)` is the exclusion check on its own. `src/no-bump.ts` imports nothing and bundles for a browser.
|
|
198
|
+
`isNoBumpContent(content, keywords)` and `splitKeywords(raw)` are the same test without the options lookup, and `bumpTimestamp({ postTimestamp, replies, keywords, options, bumpLimit })` gives a thread's effective bump time from a reply tree walked from reply pages, tombstones included, with the published `publicOptions` as `options` and `parseBumpLimit(publicOptions.bumpLimit)` as `bumpLimit`. `isCountedReply(reply, options)` is the exclusion check on its own. `src/no-bump.ts` imports nothing and bundles for a browser.
|
|
194
199
|
|
|
195
200
|
### 4. Re-sort a page locally (optional)
|
|
196
201
|
|
|
@@ -216,8 +221,8 @@ Treat `community.pageSorts[].name` as data: look it up in your own registry, nev
|
|
|
216
221
|
|---|---|
|
|
217
222
|
| `default` / `activePageSort` | The `PageSortFileFactory` pkc-js calls |
|
|
218
223
|
| `SORT_NAME`, `DESCRIPTION`, `optionInputs`, `validatePageSortSettings` | The file's declared surface, for config UIs and tests |
|
|
219
|
-
| `NO_BUMP_KEYWORDS_OPTION` | `"noBumpKeywords"`, the option
|
|
220
|
-
| `splitKeywords`, `isNoBumpContent`, `bumpTimestamp`, `isNoBumpReplyForOptions` | The matching rules, import-free, for browsers |
|
|
224
|
+
| `NO_BUMP_KEYWORDS_OPTION`, `BUMP_LIMIT_OPTION` | `"noBumpKeywords"` and `"bumpLimit"`, the option keys. Renaming one is a new contract |
|
|
225
|
+
| `splitKeywords`, `isNoBumpContent`, `parseBumpLimit`, `bumpTimestamp`, `isNoBumpReplyForOptions` | The matching rules, import-free, for browsers |
|
|
221
226
|
| `isCountedReply`, `EXCLUSION_OPTIONS` | Whether a reply can bump at all: the published `exclude*` options checked against its own CommentUpdate, never its ancestors. Import-free |
|
|
222
227
|
| `PageSortFile`, `PageSortFileInput`, `PageSortFileFactory`, `PageSortFileFactoryInput`, `PageSortFileFactoryArgs`, `PageSortScoreArgs`, `PageSortReplyEntry`, `PageSortScope`, `CommunityPageSortSetting` | Re-exported pkc-js types (root exports since pkc-js 0.0.110) |
|
|
223
228
|
| `PageSortSettingsEntry` | Alias of `CommunityPageSortSetting`, the `settings.pages` entry the factory receives |
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PageSortFile, PageSortFileFactory, PageSortSettingsEntry } from "./types.js";
|
|
2
2
|
/** The wire key: this sort publishes under `community.posts.pages.active` / `pageCids.active`, like the built-in it replaces. */
|
|
3
3
|
export declare const SORT_NAME = "active";
|
|
4
|
-
export declare const DESCRIPTION = "Bump order where a reply whose content has a line equal to a configured keyword does not bump its thread";
|
|
4
|
+
export declare const DESCRIPTION = "Bump order where a reply whose content has a line equal to a configured keyword does not bump its thread, with an optional bump limit";
|
|
5
5
|
export declare const MAX_KEYWORDS = 64;
|
|
6
6
|
export declare const MAX_KEYWORD_LENGTH = 128;
|
|
7
7
|
export declare const optionInputs: NonNullable<PageSortFile["optionInputs"]>;
|
package/dist/active-page-sort.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { NO_BUMP_KEYWORDS_OPTION, bumpTimestamp, isNoBumpContent, splitKeywords } from "./no-bump.js";
|
|
1
|
+
import { BUMP_LIMIT_OPTION, NO_BUMP_KEYWORDS_OPTION, bumpTimestamp, isNoBumpContent, parseBumpLimit, splitKeywords } from "./no-bump.js";
|
|
2
2
|
/** The wire key: this sort publishes under `community.posts.pages.active` / `pageCids.active`, like the built-in it replaces. */
|
|
3
3
|
export const SORT_NAME = "active";
|
|
4
|
-
export const DESCRIPTION = "Bump order where a reply whose content has a line equal to a configured keyword does not bump its thread";
|
|
4
|
+
export const DESCRIPTION = "Bump order where a reply whose content has a line equal to a configured keyword does not bump its thread, with an optional bump limit";
|
|
5
5
|
export const MAX_KEYWORDS = 64;
|
|
6
6
|
export const MAX_KEYWORD_LENGTH = 128;
|
|
7
7
|
export const optionInputs = [
|
|
@@ -10,6 +10,12 @@ export const optionInputs = [
|
|
|
10
10
|
label: "No-bump keywords",
|
|
11
11
|
description: "Comma-separated. A reply whose content has a whole line equal to one of these does not bump its thread (exact, case-sensitive). Leave unset for plain bump order.",
|
|
12
12
|
placeholder: "sage"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
option: BUMP_LIMIT_OPTION,
|
|
16
|
+
label: "Bump limit",
|
|
17
|
+
description: "A positive integer. Only a thread's first this many replies, saged or not, can bump it; past the limit it sinks while staying open. Leave unset for no limit.",
|
|
18
|
+
placeholder: "300"
|
|
13
19
|
}
|
|
14
20
|
];
|
|
15
21
|
const keywordsOf = (pageSortSettings) => splitKeywords(pageSortSettings.options?.[NO_BUMP_KEYWORDS_OPTION]);
|
|
@@ -18,6 +24,9 @@ const keywordsOf = (pageSortSettings) => splitKeywords(pageSortSettings.options?
|
|
|
18
24
|
* cannot match anything, which would silently turn the board into plain bump order.
|
|
19
25
|
*/
|
|
20
26
|
export const validatePageSortSettings = ({ pageSortSettings }) => {
|
|
27
|
+
const rawLimit = pageSortSettings.options?.[BUMP_LIMIT_OPTION];
|
|
28
|
+
if (rawLimit !== undefined && parseBumpLimit(rawLimit) === undefined)
|
|
29
|
+
throw new Error(`${BUMP_LIMIT_OPTION} must be a positive integer, got "${rawLimit.slice(0, 32)}": unset it for no limit`);
|
|
21
30
|
const raw = pageSortSettings.options?.[NO_BUMP_KEYWORDS_OPTION];
|
|
22
31
|
if (raw === undefined)
|
|
23
32
|
return;
|
|
@@ -41,6 +50,7 @@ export const validatePageSortSettings = ({ pageSortSettings }) => {
|
|
|
41
50
|
*/
|
|
42
51
|
export const activePageSort = ({ pageSortSettings }) => {
|
|
43
52
|
const keywords = keywordsOf(pageSortSettings);
|
|
53
|
+
const bumpLimit = parseBumpLimit(pageSortSettings.options?.[BUMP_LIMIT_OPTION]);
|
|
44
54
|
return {
|
|
45
55
|
sortName: SORT_NAME,
|
|
46
56
|
description: DESCRIPTION,
|
|
@@ -51,7 +61,7 @@ export const activePageSort = ({ pageSortSettings }) => {
|
|
|
51
61
|
// MAX(timestamp) over the post and its counted, non-no-bump descendants. pkc-js hands `replies` as one flat
|
|
52
62
|
// list of every descendant, tombstones and pending replies included (pkc-js#407), and so does a client's walk
|
|
53
63
|
// of the reply pages; bumpTimestamp skips what the exclude* options drop and keeps the replies under them.
|
|
54
|
-
score: ({ comment, options, replies }) => bumpTimestamp({ postTimestamp: comment.timestamp, replies: replies ?? [], keywords, options }),
|
|
64
|
+
score: ({ comment, options, replies }) => bumpTimestamp({ postTimestamp: comment.timestamp, replies: replies ?? [], keywords, options, bumpLimit }),
|
|
55
65
|
validatePageSortSettings
|
|
56
66
|
};
|
|
57
67
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"active-page-sort.js","sourceRoot":"","sources":["../src/active-page-sort.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"active-page-sort.js","sourceRoot":"","sources":["../src/active-page-sort.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEzI,iIAAiI;AACjI,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAAC;AAElC,MAAM,CAAC,MAAM,WAAW,GACtB,uIAAuI,CAAC;AAE1I,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC;AAC/B,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAA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AAuB,CAAC,CAAC,CAAC,CAAC;AAE9E,eAAe,cAAc,CAAC"}
|
package/dist/no-bump.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import type { NoBumpReplyLike } from "./types.js";
|
|
2
2
|
/** The option key under `settings.pages.posts[i].options`. Published as `community.pageSorts.posts.active.publicOptions.noBumpKeywords`. */
|
|
3
3
|
export declare const NO_BUMP_KEYWORDS_OPTION = "noBumpKeywords";
|
|
4
|
+
/** The option key for the bump limit. Published as `community.pageSorts.posts.active.publicOptions.bumpLimit`. */
|
|
5
|
+
export declare const BUMP_LIMIT_OPTION = "bumpLimit";
|
|
4
6
|
/** Comma-separated list to keywords: trimmed, empty entries dropped, duplicates kept out. */
|
|
5
7
|
export declare const splitKeywords: (raw: string | undefined) => string[];
|
|
8
|
+
/**
|
|
9
|
+
* The bump limit an option value holds: a positive integer, surrounding whitespace trimmed. `undefined` for an
|
|
10
|
+
* unset option (no limit) and for anything else, which `validatePageSortSettings` rejects on the community.
|
|
11
|
+
*/
|
|
12
|
+
export declare const parseBumpLimit: (raw: string | undefined) => number | undefined;
|
|
6
13
|
/**
|
|
7
14
|
* Whether a reply is a no-bump reply: its content has a whole line equal to one of the keywords. Exact and
|
|
8
15
|
* case-sensitive, so `sage` in prose ("sage is overused") still bumps, while a content of `sage`, or a
|
|
@@ -32,13 +39,15 @@ export declare const isCountedReply: (reply: NoBumpReplyLike, options: Readonly<
|
|
|
32
39
|
/**
|
|
33
40
|
* A thread's bump time: the newest of the post's own timestamp and the timestamps of its counted replies (see
|
|
34
41
|
* `isCountedReply`) that are not no-bump replies. Each reply is judged on its own: a normal reply under a saged
|
|
35
|
-
* reply or a tombstone bumps.
|
|
36
|
-
*
|
|
37
|
-
* the
|
|
42
|
+
* reply or a tombstone bumps. With a `bumpLimit`, only the first `bumpLimit` counted replies by `(timestamp, cid)`
|
|
43
|
+
* can bump, saged ones included in the count. This is exactly what `score` returns, exposed so a UI can show
|
|
44
|
+
* "last bump" without the page sort machinery. Pass the replies as pkc-js or a reply-page walk gives them,
|
|
45
|
+
* tombstones included, the published `publicOptions` as `options`, and `parseBumpLimit` of its `bumpLimit`.
|
|
38
46
|
*/
|
|
39
|
-
export declare const bumpTimestamp: ({ postTimestamp, replies, keywords, options }: {
|
|
47
|
+
export declare const bumpTimestamp: ({ postTimestamp, replies, keywords, options, bumpLimit }: {
|
|
40
48
|
postTimestamp: number;
|
|
41
49
|
replies: readonly NoBumpReplyLike[];
|
|
42
50
|
keywords: readonly string[];
|
|
43
51
|
options?: Readonly<Record<string, string>>;
|
|
52
|
+
bumpLimit?: number | undefined;
|
|
44
53
|
}) => number;
|
package/dist/no-bump.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// README's description of the match: both are the contract a board's users rely on.
|
|
4
4
|
/** The option key under `settings.pages.posts[i].options`. Published as `community.pageSorts.posts.active.publicOptions.noBumpKeywords`. */
|
|
5
5
|
export const NO_BUMP_KEYWORDS_OPTION = "noBumpKeywords";
|
|
6
|
+
/** The option key for the bump limit. Published as `community.pageSorts.posts.active.publicOptions.bumpLimit`. */
|
|
7
|
+
export const BUMP_LIMIT_OPTION = "bumpLimit";
|
|
6
8
|
/** Comma-separated list to keywords: trimmed, empty entries dropped, duplicates kept out. */
|
|
7
9
|
export const splitKeywords = (raw) => {
|
|
8
10
|
const keywords = [];
|
|
@@ -13,6 +15,17 @@ export const splitKeywords = (raw) => {
|
|
|
13
15
|
}
|
|
14
16
|
return keywords;
|
|
15
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* The bump limit an option value holds: a positive integer, surrounding whitespace trimmed. `undefined` for an
|
|
20
|
+
* unset option (no limit) and for anything else, which `validatePageSortSettings` rejects on the community.
|
|
21
|
+
*/
|
|
22
|
+
export const parseBumpLimit = (raw) => {
|
|
23
|
+
const trimmed = raw?.trim();
|
|
24
|
+
if (!trimmed || !/^[1-9][0-9]*$/.test(trimmed))
|
|
25
|
+
return undefined;
|
|
26
|
+
const limit = Number(trimmed);
|
|
27
|
+
return Number.isSafeInteger(limit) ? limit : undefined;
|
|
28
|
+
};
|
|
16
29
|
/**
|
|
17
30
|
* Whether a reply is a no-bump reply: its content has a whole line equal to one of the keywords. Exact and
|
|
18
31
|
* case-sensitive, so `sage` in prose ("sage is overused") still bumps, while a content of `sage`, or a
|
|
@@ -50,19 +63,26 @@ export const isCountedReply = (reply, options) => !exclusionsOf(options).some((d
|
|
|
50
63
|
/**
|
|
51
64
|
* A thread's bump time: the newest of the post's own timestamp and the timestamps of its counted replies (see
|
|
52
65
|
* `isCountedReply`) that are not no-bump replies. Each reply is judged on its own: a normal reply under a saged
|
|
53
|
-
* reply or a tombstone bumps.
|
|
54
|
-
*
|
|
55
|
-
* the
|
|
66
|
+
* reply or a tombstone bumps. With a `bumpLimit`, only the first `bumpLimit` counted replies by `(timestamp, cid)`
|
|
67
|
+
* can bump, saged ones included in the count. This is exactly what `score` returns, exposed so a UI can show
|
|
68
|
+
* "last bump" without the page sort machinery. Pass the replies as pkc-js or a reply-page walk gives them,
|
|
69
|
+
* tombstones included, the published `publicOptions` as `options`, and `parseBumpLimit` of its `bumpLimit`.
|
|
56
70
|
*/
|
|
57
|
-
export const bumpTimestamp = ({ postTimestamp, replies, keywords, options = {} }) => {
|
|
71
|
+
export const bumpTimestamp = ({ postTimestamp, replies, keywords, options = {}, bumpLimit }) => {
|
|
58
72
|
const exclusions = exclusionsOf(options);
|
|
73
|
+
let counted = replies.filter((reply) => !exclusions.some((drops) => drops(reply.commentUpdate)));
|
|
74
|
+
if (bumpLimit !== undefined && counted.length > bumpLimit)
|
|
75
|
+
counted = [...counted].sort(byTimestampThenCid).slice(0, bumpLimit);
|
|
59
76
|
let bump = postTimestamp;
|
|
60
|
-
for (const reply of
|
|
61
|
-
if (
|
|
77
|
+
for (const reply of counted) {
|
|
78
|
+
if (isNoBumpContent(reply.comment.content, keywords))
|
|
62
79
|
continue;
|
|
63
80
|
if (reply.comment.timestamp > bump)
|
|
64
81
|
bump = reply.comment.timestamp;
|
|
65
82
|
}
|
|
66
83
|
return bump;
|
|
67
84
|
};
|
|
85
|
+
// The order "the first bumpLimit replies" is taken in. The CID breaks a tie in the same second, compared as a
|
|
86
|
+
// plain string so the community and every client agree.
|
|
87
|
+
const byTimestampThenCid = (a, b) => a.comment.timestamp - b.comment.timestamp || (a.commentUpdate.cid < b.commentUpdate.cid ? -1 : a.commentUpdate.cid > b.commentUpdate.cid ? 1 : 0);
|
|
68
88
|
//# sourceMappingURL=no-bump.js.map
|
package/dist/no-bump.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-bump.js","sourceRoot":"","sources":["../src/no-bump.ts"],"names":[],"mappings":"AAEA,wGAAwG;AACxG,qGAAqG;AACrG,oFAAoF;AAEpF,4IAA4I;AAC5I,MAAM,CAAC,MAAM,uBAAuB,GAAG,gBAAgB,CAAC;AAExD,6FAA6F;AAC7F,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAuB,EAAY,EAAE;IACjE,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC;YAAE,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAAgB,EAAE,QAA2B,EAAW,EAAE;IACxF,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACvE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,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AkB,GAAG,CAAC,CAAkB,EAAE,CAAkB,EAAU,EAAE,CAC5E,CAAC,CAAC,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC,OAAO,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pkcprotocol/active-page-sort",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Bump-order (active) page sort for pkc-js communities where replies carrying a configured keyword, such as sage, do not bump the thread",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|