@blogmcp/sdk 0.9.3 → 0.10.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/dist/community/channels.d.ts +7 -6
- package/dist/community/channels.js +4 -4
- package/dist/community/client.d.ts +74 -4
- package/dist/community/client.js +143 -91
- package/dist/community/index.d.ts +11 -6
- package/dist/community/index.js +111 -80
- package/dist/community/links.d.ts +61 -1
- package/dist/community/links.js +94 -40
- package/dist/community/manifest/index.d.ts +54 -0
- package/dist/community/manifest/index.js +46 -0
- package/dist/community/mentions.d.ts +38 -0
- package/dist/community/mentions.js +25 -0
- package/dist/community/messages.cs.d.ts +73 -3
- package/dist/community/messages.cs.js +82 -3
- package/dist/community/messages.d.ts +11 -0
- package/dist/community/messages.en.d.ts +69 -1
- package/dist/community/messages.en.js +71 -1
- package/dist/community/messages.js +26 -16
- package/dist/community/outcome.d.ts +8 -3
- package/dist/community/outcome.js +72 -28
- package/dist/community/realtime/index.d.ts +118 -0
- package/dist/community/realtime/index.js +215 -0
- package/dist/community/routes.d.ts +12 -0
- package/dist/community/routes.js +41 -25
- package/dist/community/server/bff.js +25 -25
- package/dist/community/server/host-routes.js +12 -0
- package/dist/community/server/index.d.ts +1 -1
- package/dist/community/server/index.js +15 -14
- package/dist/community/server/route-decision.d.ts +8 -0
- package/dist/community/server/route-decision.js +28 -22
- package/dist/community/shapes.d.ts +214 -2
- package/dist/community/shapes.js +65 -25
- package/dist/community/store.d.ts +18 -1
- package/dist/community/store.js +316 -261
- package/dist/community/sw/index.d.ts +45 -0
- package/dist/community/sw/index.js +59 -0
- package/dist/community/ua.d.ts +12 -0
- package/dist/community/ua.js +9 -0
- package/dist/packages/mdx-render-vue/dist/node_modules/dompurify/dist/purify.es.js +1342 -484
- package/dist/packages/tripmap-core/dist/generated/maplibre-worker.bundle.js +1 -1
- package/package.json +21 -3
- package/src/community/channels.ts +8 -7
- package/src/community/client.ts +116 -5
- package/src/community/index.ts +59 -1
- package/src/community/links.ts +119 -2
- package/src/community/manifest/index.ts +107 -0
- package/src/community/mentions.ts +59 -0
- package/src/community/messages.cs.ts +88 -3
- package/src/community/messages.en.ts +77 -1
- package/src/community/messages.ts +19 -0
- package/src/community/outcome.ts +50 -1
- package/src/community/realtime/index.ts +522 -0
- package/src/community/routes.ts +16 -0
- package/src/community/server/bff.ts +2 -4
- package/src/community/server/host-routes.ts +12 -0
- package/src/community/server/index.ts +1 -0
- package/src/community/server/route-decision.ts +15 -0
- package/src/community/shapes.ts +256 -3
- package/src/community/store.ts +114 -0
- package/src/community/sw/index.ts +112 -0
- package/src/community/ua.ts +17 -0
package/dist/community/store.js
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import { isKnownNeed as
|
|
2
|
-
const
|
|
3
|
-
function
|
|
4
|
-
if (!
|
|
5
|
-
const
|
|
6
|
-
if (
|
|
7
|
-
for (const [
|
|
8
|
-
typeof r == "number" && Number.isSafeInteger(r) && r > 0 && (n
|
|
9
|
-
return Object.freeze({ counts: Object.freeze(
|
|
1
|
+
import { isKnownNeed as w, isKnownState as ge, isKnownRestrictionKind as me, isKnownAuthorKind as be } from "./shapes.js";
|
|
2
|
+
const C = (e) => typeof e == "object" && e !== null && !Array.isArray(e), f = (e) => typeof e == "string" ? e : null, P = (e) => typeof e == "number" && Number.isSafeInteger(e) && e > 0, D = Object.freeze({ counts: Object.freeze({}), mine: null });
|
|
3
|
+
function L(e) {
|
|
4
|
+
if (!C(e)) return D;
|
|
5
|
+
const s = {};
|
|
6
|
+
if (C(e.counts))
|
|
7
|
+
for (const [n, r] of Object.entries(e.counts))
|
|
8
|
+
typeof r == "number" && Number.isSafeInteger(r) && r > 0 && (s[n] = r);
|
|
9
|
+
return Object.freeze({ counts: Object.freeze(s), mine: f(e.mine) });
|
|
10
10
|
}
|
|
11
|
-
const
|
|
11
|
+
const $ = Object.freeze({
|
|
12
12
|
kind: "member",
|
|
13
13
|
memberId: null,
|
|
14
14
|
handle: null,
|
|
15
15
|
displayName: null,
|
|
16
16
|
avatarPreset: null,
|
|
17
17
|
deleted: !0
|
|
18
|
-
}),
|
|
19
|
-
function
|
|
20
|
-
if (!
|
|
21
|
-
if (e.kind === "system") return
|
|
18
|
+
}), ye = Object.freeze({ kind: "system" });
|
|
19
|
+
function J(e) {
|
|
20
|
+
if (!C(e) || !be(e.kind)) return null;
|
|
21
|
+
if (e.kind === "system") return ye;
|
|
22
22
|
if (e.kind === "staff")
|
|
23
|
-
return Object.freeze({ kind: "staff", staffId:
|
|
24
|
-
const
|
|
25
|
-
return
|
|
23
|
+
return Object.freeze({ kind: "staff", staffId: f(e.staffId) ?? "", displayName: f(e.displayName) ?? "", badge: f(e.badge) ?? "" });
|
|
24
|
+
const s = f(e.memberId), n = f(e.handle), r = f(e.displayName);
|
|
25
|
+
return s === null || n === null || r === null || e.deleted === !0 ? $ : Object.freeze({ kind: "member", memberId: s, handle: n, displayName: r, avatarPreset: f(e.avatarPreset) });
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function Q(e) {
|
|
28
28
|
if (Array.isArray(e))
|
|
29
|
-
return Object.freeze(e.filter((
|
|
29
|
+
return Object.freeze(e.filter((s) => typeof s == "string"));
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
if (!
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
const r =
|
|
36
|
-
if (r === null ||
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
39
|
-
for (const
|
|
40
|
-
const
|
|
41
|
-
|
|
31
|
+
function N(e, s) {
|
|
32
|
+
if (!C(e)) return null;
|
|
33
|
+
const n = J(e.author);
|
|
34
|
+
if (n === null || !ge(e.state)) return null;
|
|
35
|
+
const r = f(e.conversationId), c = f(e.id);
|
|
36
|
+
if (r === null || c === null || !P(e.seq)) return null;
|
|
37
|
+
const g = f(e.body), m = [];
|
|
38
|
+
if (s && Array.isArray(e.replies))
|
|
39
|
+
for (const y of e.replies) {
|
|
40
|
+
const M = N(y, !1);
|
|
41
|
+
M && m.push(M);
|
|
42
42
|
}
|
|
43
|
-
const
|
|
43
|
+
const z = Q(e.notes);
|
|
44
44
|
return Object.freeze({
|
|
45
45
|
conversationId: r,
|
|
46
46
|
seq: e.seq,
|
|
47
|
-
id:
|
|
47
|
+
id: c,
|
|
48
48
|
rev: typeof e.rev == "number" ? e.rev : 0,
|
|
49
|
-
replyToSeq:
|
|
50
|
-
author:
|
|
49
|
+
replyToSeq: s ? null : P(e.replyToSeq) ? e.replyToSeq : null,
|
|
50
|
+
author: n,
|
|
51
51
|
state: e.state,
|
|
52
|
-
body:
|
|
53
|
-
displayBody:
|
|
54
|
-
displayLanguageCode:
|
|
55
|
-
sourceLanguageCode:
|
|
52
|
+
body: g,
|
|
53
|
+
displayBody: f(e.displayBody) ?? g,
|
|
54
|
+
displayLanguageCode: f(e.displayLanguageCode),
|
|
55
|
+
sourceLanguageCode: f(e.sourceLanguageCode),
|
|
56
56
|
isTranslated: e.isTranslated === !0,
|
|
57
57
|
isEdited: e.isEdited === !0,
|
|
58
|
-
createdAt:
|
|
59
|
-
editedAt:
|
|
58
|
+
createdAt: f(e.createdAt) ?? "",
|
|
59
|
+
editedAt: f(e.editedAt),
|
|
60
60
|
collapsed: e.collapsed === !0,
|
|
61
|
-
reactions:
|
|
62
|
-
translationVersionId:
|
|
63
|
-
...
|
|
61
|
+
reactions: L(e.reactions),
|
|
62
|
+
translationVersionId: f(e.translationVersionId),
|
|
63
|
+
...z && z.length > 0 ? { notes: z } : {},
|
|
64
64
|
// Only as kb-api sends it: true, on a `held` message (the author's own, held back by the art. 9 policy).
|
|
65
65
|
...e.hiddenUntilConsent === !0 && e.state === "held" ? { hiddenUntilConsent: !0 } : {},
|
|
66
|
-
replies:
|
|
67
|
-
...
|
|
66
|
+
replies: x(m),
|
|
67
|
+
...s && e.repliesTruncated === !0 ? { repliesTruncated: !0 } : {}
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
|
-
function
|
|
71
|
-
const
|
|
72
|
-
if (Array.isArray(
|
|
73
|
-
for (const
|
|
74
|
-
!
|
|
70
|
+
function Ie(e) {
|
|
71
|
+
const s = C(e) ? e : {}, n = Array.isArray(s.needs) ? s.needs.filter(w) : [], r = [];
|
|
72
|
+
if (Array.isArray(s.restrictions))
|
|
73
|
+
for (const c of s.restrictions)
|
|
74
|
+
!C(c) || !me(c.kind) || typeof c.decisionId != "string" || r.push(Object.freeze({ kind: c.kind, scope: f(c.scope) ?? "", endsAt: f(c.endsAt), decisionId: c.decisionId }));
|
|
75
75
|
return Object.freeze({
|
|
76
|
-
memberId:
|
|
77
|
-
canPost:
|
|
78
|
-
needs: Object.freeze([...new Set(
|
|
76
|
+
memberId: f(s.memberId),
|
|
77
|
+
canPost: s.canPost === !0,
|
|
78
|
+
needs: Object.freeze([...new Set(n)]),
|
|
79
79
|
restrictions: Object.freeze(r)
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
-
const
|
|
82
|
+
const qe = Object.freeze({ memberId: null, canPost: !1, needs: Object.freeze([]), restrictions: Object.freeze([]) }), V = Object.freeze({
|
|
83
83
|
articleId: null,
|
|
84
84
|
conversationId: null,
|
|
85
85
|
count: 0,
|
|
@@ -87,125 +87,130 @@ const pe = Object.freeze({ memberId: null, canPost: !1, needs: Object.freeze([])
|
|
|
87
87
|
lastChangeAt: null,
|
|
88
88
|
messages: Object.freeze([]),
|
|
89
89
|
nextCursor: null,
|
|
90
|
-
articleReactions:
|
|
90
|
+
articleReactions: D,
|
|
91
91
|
reactionSet: Object.freeze([]),
|
|
92
92
|
preset: null,
|
|
93
|
-
viewer:
|
|
93
|
+
viewer: qe,
|
|
94
94
|
loaded: !1,
|
|
95
95
|
stale: !1
|
|
96
|
-
}),
|
|
97
|
-
function
|
|
98
|
-
const
|
|
99
|
-
return Object.freeze([...
|
|
96
|
+
}), Se = (e, s) => e === null ? s : s === null ? e : Date.parse(s) > Date.parse(e) ? s : e;
|
|
97
|
+
function x(e) {
|
|
98
|
+
const s = e.filter((r) => r.seq > 0).sort((r, c) => r.seq - c.seq), n = e.filter((r) => r.seq < 0).sort((r, c) => c.seq - r.seq);
|
|
99
|
+
return Object.freeze([...s, ...n]);
|
|
100
100
|
}
|
|
101
|
-
function
|
|
102
|
-
let
|
|
101
|
+
function T(e, s) {
|
|
102
|
+
let n = !1;
|
|
103
103
|
const r = [];
|
|
104
|
-
for (const
|
|
105
|
-
let
|
|
106
|
-
if (
|
|
107
|
-
const
|
|
108
|
-
|
|
104
|
+
for (const c of e) {
|
|
105
|
+
let g = s(c);
|
|
106
|
+
if (g !== null && g.replies.length > 0) {
|
|
107
|
+
const m = T(g.replies, s);
|
|
108
|
+
m !== g.replies && (g = Object.freeze({ ...g, replies: m }));
|
|
109
109
|
}
|
|
110
|
-
|
|
110
|
+
g !== c && (n = !0), g !== null && r.push(g);
|
|
111
111
|
}
|
|
112
|
-
return
|
|
112
|
+
return n ? Object.freeze(r) : e;
|
|
113
113
|
}
|
|
114
|
-
function h(e,
|
|
115
|
-
for (const
|
|
116
|
-
if (n
|
|
117
|
-
for (const r of
|
|
114
|
+
function h(e, s) {
|
|
115
|
+
for (const n of e) {
|
|
116
|
+
if (s(n)) return n;
|
|
117
|
+
for (const r of n.replies) if (s(r)) return r;
|
|
118
118
|
}
|
|
119
119
|
return null;
|
|
120
120
|
}
|
|
121
|
-
function
|
|
122
|
-
return
|
|
121
|
+
function K(e, s) {
|
|
122
|
+
return T(e, (n) => n.seq === s.seq ? n.replyToSeq === null && s.replyToSeq === null ? Object.freeze({ ...s, replies: n.replies }) : s : n);
|
|
123
123
|
}
|
|
124
|
-
function
|
|
125
|
-
if (h(e, (r) => r.seq ===
|
|
126
|
-
if (
|
|
127
|
-
const
|
|
128
|
-
return
|
|
124
|
+
function U(e, s) {
|
|
125
|
+
if (h(e, (r) => r.seq === s.seq)) return K(e, s);
|
|
126
|
+
if (s.replyToSeq === null) return x([...e, s]);
|
|
127
|
+
const n = e.find((r) => r.seq === s.replyToSeq);
|
|
128
|
+
return n ? Object.freeze(e.map((r) => r === n ? Object.freeze({ ...r, replies: x([...r.replies, s]) }) : r)) : e;
|
|
129
129
|
}
|
|
130
|
-
const
|
|
131
|
-
function
|
|
132
|
-
let e =
|
|
133
|
-
const
|
|
134
|
-
let
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
for (const t of
|
|
130
|
+
const Y = (e) => e.replyToSeq === null && e.replies.length > 0, G = (e, s) => e.toLowerCase() === s.toLowerCase(), W = (e) => e.author.kind === "member" && e.author.memberId !== null ? e.author.memberId.toLowerCase() : null, Oe = 256, Z = /* @__PURE__ */ new WeakMap();
|
|
131
|
+
function Ce() {
|
|
132
|
+
let e = V;
|
|
133
|
+
const s = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
|
|
134
|
+
let c = 0, g = -1;
|
|
135
|
+
const m = /* @__PURE__ */ new Set(), z = () => {
|
|
136
|
+
c += 1, m.clear();
|
|
137
|
+
for (const t of n.keys())
|
|
138
138
|
r.delete(t), r.add(t);
|
|
139
|
-
|
|
139
|
+
n.clear();
|
|
140
140
|
for (const t of r) {
|
|
141
|
-
if (r.size <=
|
|
141
|
+
if (r.size <= Oe) break;
|
|
142
142
|
r.delete(t);
|
|
143
143
|
}
|
|
144
|
-
},
|
|
144
|
+
}, y = (t) => {
|
|
145
145
|
if (t !== e) {
|
|
146
146
|
e = Object.freeze(t);
|
|
147
|
-
for (const o of [...
|
|
147
|
+
for (const o of [...s])
|
|
148
148
|
try {
|
|
149
149
|
o(e);
|
|
150
150
|
} catch {
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
};
|
|
154
|
-
function
|
|
155
|
-
if (!
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
for (const
|
|
160
|
-
const
|
|
161
|
-
|
|
154
|
+
function M(t, o = {}) {
|
|
155
|
+
if (!C(t)) return;
|
|
156
|
+
const u = f(t.articleId)?.toLowerCase() ?? null, l = e.articleId !== null && u !== null && u !== e.articleId, i = l ? V : e;
|
|
157
|
+
l && z();
|
|
158
|
+
const b = typeof o.cursor == "number" && Number.isFinite(o.cursor) ? o.cursor : null, I = b ?? 0, q = typeof t.nextCursor == "number" && Number.isFinite(t.nextCursor) ? t.nextCursor : null, k = q ?? Number.POSITIVE_INFINITY, j = /* @__PURE__ */ new Map();
|
|
159
|
+
for (const d of Array.isArray(t.messages) ? t.messages : []) {
|
|
160
|
+
const a = N(d, !0);
|
|
161
|
+
a && a.seq > I && a.seq <= k && j.set(a.seq, a);
|
|
162
162
|
}
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
163
|
+
for (const d of j.values())
|
|
164
|
+
for (const a of [d, ...d.replies]) {
|
|
165
|
+
const S = W(a);
|
|
166
|
+
S === null || a.body === null || (a.collapsed ? m.add(S) : m.delete(S));
|
|
167
|
+
}
|
|
168
|
+
const p = /* @__PURE__ */ new Map();
|
|
169
|
+
for (const d of i.messages) {
|
|
170
|
+
const a = [d, ...d.replies];
|
|
171
|
+
for (const S of a) S.pending && S.pending !== "post" && S.clientMsgId && p.set(S.seq, S);
|
|
167
172
|
}
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
if (!
|
|
171
|
-
const S =
|
|
172
|
-
return S && (S.before =
|
|
173
|
-
},
|
|
174
|
-
for (const
|
|
175
|
-
for (const
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
if (!
|
|
179
|
-
const
|
|
180
|
-
return S.some((
|
|
181
|
-
}),
|
|
182
|
-
|
|
183
|
-
articleId:
|
|
184
|
-
conversationId:
|
|
185
|
-
count: typeof t.count == "number" && t.count >= 0 ? t.count :
|
|
186
|
-
lastSeq: Math.max(typeof t.lastSeq == "number" ? t.lastSeq : 0,
|
|
187
|
-
lastChangeAt:
|
|
188
|
-
messages:
|
|
189
|
-
nextCursor:
|
|
190
|
-
articleReactions:
|
|
191
|
-
reactionSet: Object.freeze(Array.isArray(t.reactionSet) ? t.reactionSet.filter((
|
|
192
|
-
preset:
|
|
193
|
-
viewer:
|
|
173
|
+
const O = (d) => {
|
|
174
|
+
const a = p.get(d.seq);
|
|
175
|
+
if (!a) return d;
|
|
176
|
+
const S = a.clientMsgId ? n.get(a.clientMsgId) : void 0;
|
|
177
|
+
return S && (S.before = d), a.replyToSeq === null ? Object.freeze({ ...a, replies: d.replies }) : a;
|
|
178
|
+
}, v = i.messages.filter((d) => d.seq < 0 || d.seq <= I || d.seq > k), R = /* @__PURE__ */ new Map();
|
|
179
|
+
for (const d of i.messages)
|
|
180
|
+
for (const a of d.replies)
|
|
181
|
+
a.seq < 0 && a.replyToSeq !== null && R.set(a.replyToSeq, [...R.get(a.replyToSeq) ?? [], a]);
|
|
182
|
+
const A = [...v.filter((d) => !j.has(d.seq)), ...j.values()].map((d) => {
|
|
183
|
+
if (!j.has(d.seq)) return d;
|
|
184
|
+
const a = O(d), S = a.replies.map(O), H = R.get(d.seq) ?? [];
|
|
185
|
+
return S.some((fe, pe) => fe !== a.replies[pe]) || H.length > 0 ? Object.freeze({ ...a, replies: x([...S, ...H]) }) : a;
|
|
186
|
+
}), _ = i.loaded ? i.nextCursor : 0, de = _ === null ? null : I > _ ? _ : q === null ? null : Math.max(_, q);
|
|
187
|
+
y({
|
|
188
|
+
articleId: u ?? i.articleId,
|
|
189
|
+
conversationId: f(t.conversationId) ?? i.conversationId,
|
|
190
|
+
count: typeof t.count == "number" && t.count >= 0 ? t.count : i.count,
|
|
191
|
+
lastSeq: Math.max(typeof t.lastSeq == "number" ? t.lastSeq : 0, i.lastSeq),
|
|
192
|
+
lastChangeAt: Se(i.lastChangeAt, f(t.lastChangeAt)),
|
|
193
|
+
messages: x(A),
|
|
194
|
+
nextCursor: de,
|
|
195
|
+
articleReactions: L(t.articleReactions),
|
|
196
|
+
reactionSet: Object.freeze(Array.isArray(t.reactionSet) ? t.reactionSet.filter((d) => typeof d == "string") : []),
|
|
197
|
+
preset: f(t.preset),
|
|
198
|
+
viewer: Ie(t.viewer),
|
|
194
199
|
loaded: !0,
|
|
195
|
-
stale:
|
|
200
|
+
stale: b === null ? !1 : i.stale
|
|
196
201
|
});
|
|
197
202
|
}
|
|
198
|
-
function
|
|
199
|
-
if (
|
|
200
|
-
const o =
|
|
201
|
-
if (o !== null && !e.messages.some((
|
|
202
|
-
const
|
|
203
|
+
function E(t) {
|
|
204
|
+
if (n.has(t.clientMsgId)) return;
|
|
205
|
+
const o = P(t.replyToSeq) ? t.replyToSeq : null;
|
|
206
|
+
if (o !== null && !e.messages.some((b) => b.seq === o)) return;
|
|
207
|
+
const u = J(t.author) ?? $, l = Object.freeze({
|
|
203
208
|
conversationId: e.conversationId ?? "",
|
|
204
|
-
seq:
|
|
209
|
+
seq: g--,
|
|
205
210
|
id: `pending:${t.clientMsgId}`,
|
|
206
211
|
rev: 0,
|
|
207
212
|
replyToSeq: o,
|
|
208
|
-
author:
|
|
213
|
+
author: u,
|
|
209
214
|
state: "visible",
|
|
210
215
|
body: t.body,
|
|
211
216
|
displayBody: t.body,
|
|
@@ -216,22 +221,22 @@ function Oe() {
|
|
|
216
221
|
createdAt: t.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
217
222
|
editedAt: null,
|
|
218
223
|
collapsed: !1,
|
|
219
|
-
reactions:
|
|
224
|
+
reactions: D,
|
|
220
225
|
translationVersionId: null,
|
|
221
226
|
replies: Object.freeze([]),
|
|
222
227
|
pending: "post",
|
|
223
228
|
clientMsgId: t.clientMsgId
|
|
224
229
|
});
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
|
|
230
|
+
n.set(t.clientMsgId, { type: "post", before: null });
|
|
231
|
+
const i = o === null ? x([...e.messages, l]) : Object.freeze(e.messages.map((b) => b.seq === o ? Object.freeze({ ...b, replies: x([...b.replies, l]) }) : b));
|
|
232
|
+
y({ ...e, messages: i });
|
|
228
233
|
}
|
|
229
|
-
function
|
|
230
|
-
if (
|
|
231
|
-
const o = h(e.messages, (
|
|
234
|
+
function te(t) {
|
|
235
|
+
if (n.has(t.clientMsgId)) return;
|
|
236
|
+
const o = h(e.messages, (l) => l.seq === t.seq);
|
|
232
237
|
if (!o || o.pending) return;
|
|
233
|
-
|
|
234
|
-
const
|
|
238
|
+
n.set(t.clientMsgId, { type: t.type, before: o });
|
|
239
|
+
const u = t.type === "edit" ? Object.freeze({
|
|
235
240
|
...o,
|
|
236
241
|
body: t.body,
|
|
237
242
|
displayBody: t.body,
|
|
@@ -241,183 +246,233 @@ function Oe() {
|
|
|
241
246
|
pending: "edit",
|
|
242
247
|
clientMsgId: t.clientMsgId
|
|
243
248
|
}) : Object.freeze({ ...o, pending: "delete", clientMsgId: t.clientMsgId });
|
|
244
|
-
|
|
249
|
+
y({ ...e, messages: T(e.messages, (l) => l === o ? u : l) });
|
|
245
250
|
}
|
|
246
|
-
const
|
|
247
|
-
function
|
|
248
|
-
const o =
|
|
251
|
+
const F = (t) => e.conversationId === null || G(t.conversationId, e.conversationId);
|
|
252
|
+
function se(t) {
|
|
253
|
+
const o = n.get(t.clientMsgId);
|
|
249
254
|
if (!o && r.has(t.clientMsgId)) return;
|
|
250
|
-
|
|
251
|
-
const
|
|
255
|
+
n.delete(t.clientMsgId);
|
|
256
|
+
const u = N(t.message, t.message?.replyToSeq === null || t.message?.replyToSeq === void 0), l = u && F(u) ? u : null, i = T(
|
|
252
257
|
e.messages,
|
|
253
|
-
(
|
|
258
|
+
(p) => p.clientMsgId === t.clientMsgId && p.pending === "post" ? null : p.clientMsgId === t.clientMsgId ? X(p) : p
|
|
254
259
|
);
|
|
255
|
-
if (!
|
|
256
|
-
|
|
260
|
+
if (!l) {
|
|
261
|
+
i !== e.messages && y({ ...e, messages: i });
|
|
257
262
|
return;
|
|
258
263
|
}
|
|
259
|
-
const
|
|
260
|
-
let
|
|
264
|
+
const b = t.warnings ? Q(t.warnings) : void 0, I = b && b.length > 0 ? Object.freeze({ ...l, warnings: b }) : l, q = h(i, (p) => p.seq === I.seq);
|
|
265
|
+
let k, j = e.count;
|
|
261
266
|
if (I.state === "deleted" || o?.type === "delete") {
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
(
|
|
266
|
-
),
|
|
267
|
+
const p = q ?? null, O = p?.state === "visible" && p.body !== null;
|
|
268
|
+
k = T(
|
|
269
|
+
i,
|
|
270
|
+
(v) => v.seq !== I.seq ? v : Y(v) ? Object.freeze({ ...I, replies: v.replies }) : null
|
|
271
|
+
), O && (j = Math.max(0, j - 1));
|
|
267
272
|
} else
|
|
268
|
-
|
|
269
|
-
|
|
273
|
+
k = U(i, I), !q && I.state === "visible" && (j += 1);
|
|
274
|
+
y({
|
|
270
275
|
...e,
|
|
271
276
|
// The answer to this store's own change names the new conversation; a row it never saw may be another article's.
|
|
272
277
|
conversationId: e.conversationId ?? (o ? I.conversationId : null),
|
|
273
278
|
lastSeq: Math.max(e.lastSeq, I.seq),
|
|
274
|
-
count:
|
|
275
|
-
messages:
|
|
279
|
+
count: j,
|
|
280
|
+
messages: k
|
|
276
281
|
});
|
|
277
282
|
}
|
|
278
|
-
function
|
|
279
|
-
const o =
|
|
283
|
+
function ne(t) {
|
|
284
|
+
const o = n.get(t);
|
|
280
285
|
if (!o) return;
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
if (
|
|
286
|
+
n.delete(t);
|
|
287
|
+
const u = T(e.messages, (l) => {
|
|
288
|
+
if (l.clientMsgId !== t) return l;
|
|
284
289
|
if (o.type === "post") return null;
|
|
285
|
-
const
|
|
286
|
-
return
|
|
290
|
+
const i = o.before;
|
|
291
|
+
return i ? l.replyToSeq === null ? Object.freeze({ ...i, replies: l.replies }) : i : X(l);
|
|
287
292
|
});
|
|
288
|
-
|
|
293
|
+
u !== e.messages && y({ ...e, messages: u });
|
|
289
294
|
}
|
|
290
|
-
function
|
|
291
|
-
const o =
|
|
292
|
-
!o || !h(e.messages, (
|
|
295
|
+
function re(t) {
|
|
296
|
+
const o = N(t, t?.replyToSeq === null || t?.replyToSeq === void 0);
|
|
297
|
+
!o || !h(e.messages, (u) => u.seq === o.seq && !u.pending && G(u.conversationId, o.conversationId)) || y({ ...e, messages: K(e.messages, o) });
|
|
293
298
|
}
|
|
294
|
-
function
|
|
295
|
-
if (
|
|
299
|
+
function oe(t) {
|
|
300
|
+
if (C(t))
|
|
296
301
|
switch (t.type) {
|
|
297
302
|
case "post":
|
|
298
|
-
return
|
|
303
|
+
return E(t);
|
|
299
304
|
case "edit":
|
|
300
305
|
case "delete":
|
|
301
|
-
return
|
|
306
|
+
return te(t);
|
|
302
307
|
case "confirm":
|
|
303
|
-
return
|
|
308
|
+
return se(t);
|
|
304
309
|
case "rollback":
|
|
305
|
-
return
|
|
310
|
+
return ne(t.clientMsgId);
|
|
306
311
|
case "server":
|
|
307
|
-
return
|
|
312
|
+
return re(t.message);
|
|
308
313
|
}
|
|
309
314
|
}
|
|
310
|
-
function
|
|
311
|
-
if (!
|
|
315
|
+
function ie(t) {
|
|
316
|
+
if (!C(t) || !e.loaded || e.articleId === null || f(t.articleId)?.toLowerCase() !== e.articleId) return !1;
|
|
312
317
|
if (e.stale) return !0;
|
|
313
|
-
const o = typeof t.lastSeq == "number" && t.lastSeq > e.lastSeq,
|
|
314
|
-
return !o && !
|
|
318
|
+
const o = typeof t.lastSeq == "number" && t.lastSeq > e.lastSeq, u = typeof t.count == "number" && t.count !== e.count, l = f(t.lastChangeAt), i = l !== null && (e.lastChangeAt === null || Date.parse(l) > Date.parse(e.lastChangeAt));
|
|
319
|
+
return !o && !u && !i ? !1 : (y({ ...e, stale: !0 }), !0);
|
|
315
320
|
}
|
|
316
|
-
function
|
|
317
|
-
if (!
|
|
318
|
-
const
|
|
321
|
+
function le(t, o) {
|
|
322
|
+
if (!C(t)) return;
|
|
323
|
+
const u = L(o);
|
|
319
324
|
if ("articleId" in t) {
|
|
320
|
-
if (
|
|
321
|
-
|
|
325
|
+
if (f(t.articleId)?.toLowerCase() !== e.articleId) return;
|
|
326
|
+
y({ ...e, articleReactions: u });
|
|
322
327
|
return;
|
|
323
328
|
}
|
|
324
|
-
const { conversationId:
|
|
325
|
-
if (!
|
|
326
|
-
const
|
|
327
|
-
I !== e.messages &&
|
|
329
|
+
const { conversationId: l, seq: i } = t;
|
|
330
|
+
if (!P(i) || typeof l != "string") return;
|
|
331
|
+
const b = l.toLowerCase(), I = T(e.messages, (q) => q.seq === i && q.conversationId.toLowerCase() === b ? Object.freeze({ ...q, reactions: u }) : q);
|
|
332
|
+
I !== e.messages && y({ ...e, messages: I });
|
|
328
333
|
}
|
|
329
|
-
function
|
|
334
|
+
function ce(t, o) {
|
|
330
335
|
if (typeof t != "string" || t === "") return;
|
|
331
|
-
const
|
|
336
|
+
const u = t.toLowerCase();
|
|
337
|
+
o ? m.add(u) : m.delete(u);
|
|
338
|
+
const l = T(
|
|
332
339
|
e.messages,
|
|
333
|
-
(
|
|
340
|
+
(i) => i.author.kind === "member" && i.author.memberId !== null && i.author.memberId.toLowerCase() === u && i.body !== null && i.collapsed !== o ? Object.freeze({ ...i, collapsed: o }) : i
|
|
334
341
|
);
|
|
335
|
-
|
|
342
|
+
l !== e.messages && y({ ...e, messages: l });
|
|
343
|
+
}
|
|
344
|
+
function ue(t, o) {
|
|
345
|
+
const u = W(t), l = t.body !== null && u !== null && m.has(u), i = o ? o.reactions.mine : null, b = i === t.reactions.mine ? t.reactions : Object.freeze({ counts: t.reactions.counts, mine: i }), I = o?.repliesTruncated === !0 && t.replyToSeq === null, q = o?.warnings;
|
|
346
|
+
return l === t.collapsed && b === t.reactions && !I && !q ? t : Object.freeze({
|
|
347
|
+
...t,
|
|
348
|
+
collapsed: l,
|
|
349
|
+
reactions: b,
|
|
350
|
+
...I ? { repliesTruncated: !0 } : {},
|
|
351
|
+
...q ? { warnings: q } : {}
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
function ae(t) {
|
|
355
|
+
if (!C(t) || !e.loaded) return "dropped";
|
|
356
|
+
const o = typeof t.rev == "number" && Number.isSafeInteger(t.rev) && t.rev >= 0 ? t.rev : null;
|
|
357
|
+
if (t.kind === "resync") return "resync";
|
|
358
|
+
if (o === null) return "dropped";
|
|
359
|
+
if (t.kind === "reaction") {
|
|
360
|
+
if (t.seq === void 0) {
|
|
361
|
+
const A = L(t.reactions);
|
|
362
|
+
return y({ ...e, articleReactions: Object.freeze({ counts: A.counts, mine: e.articleReactions.mine }) }), "applied";
|
|
363
|
+
}
|
|
364
|
+
if (!P(t.seq)) return "dropped";
|
|
365
|
+
const p = t.seq, O = h(e.messages, (A) => A.seq === p);
|
|
366
|
+
if (!O || O.pending || o < O.rev) return "dropped";
|
|
367
|
+
if (o > O.rev) return "resync";
|
|
368
|
+
const v = L(t.reactions), R = Object.freeze({ counts: v.counts, mine: O.reactions.mine });
|
|
369
|
+
return y({ ...e, messages: T(e.messages, (A) => A === O ? Object.freeze({ ...A, reactions: R }) : A) }), "applied";
|
|
370
|
+
}
|
|
371
|
+
if (t.kind !== "message" && t.kind !== "edit" && t.kind !== "delete") return "dropped";
|
|
372
|
+
const u = t.message, l = N(u, u?.replyToSeq === null || u?.replyToSeq === void 0);
|
|
373
|
+
if (!l || !F(l)) return "dropped";
|
|
374
|
+
const i = h(e.messages, (p) => p.seq === l.seq);
|
|
375
|
+
if (i?.pending) return "dropped";
|
|
376
|
+
const b = i?.rev ?? 0;
|
|
377
|
+
if (t.kind === "delete") {
|
|
378
|
+
if (!i || o <= b) return "dropped";
|
|
379
|
+
const p = i.state === "visible" && i.body !== null, O = T(
|
|
380
|
+
e.messages,
|
|
381
|
+
(v) => v.seq !== l.seq ? v : Y(v) ? Object.freeze({ ...l, replies: v.replies }) : null
|
|
382
|
+
);
|
|
383
|
+
return y({ ...e, messages: O, count: p ? Math.max(0, e.count - 1) : e.count, lastSeq: Math.max(e.lastSeq, l.seq) }), "applied";
|
|
384
|
+
}
|
|
385
|
+
const I = l.author.kind === "member" && l.author.memberId !== null && l.author.memberId === e.viewer.memberId;
|
|
386
|
+
if (!i && I && [...n.values()].some((p) => p.type === "post") || o <= b) return "dropped";
|
|
387
|
+
if (o > b + 1 || !i && l.replyToSeq !== null && !e.messages.some((p) => p.seq === l.replyToSeq)) return "resync";
|
|
388
|
+
const q = ue(l, i), k = i ? K(e.messages, q) : U(e.messages, q), j = !i && l.state === "visible" ? e.count + 1 : e.count;
|
|
389
|
+
return y({ ...e, messages: k, count: j, lastSeq: Math.max(e.lastSeq, l.seq) }), "applied";
|
|
336
390
|
}
|
|
337
|
-
const
|
|
391
|
+
const B = {
|
|
338
392
|
getState: () => e,
|
|
339
393
|
subscribe(t) {
|
|
340
|
-
return
|
|
341
|
-
|
|
394
|
+
return s.add(t), () => {
|
|
395
|
+
s.delete(t);
|
|
342
396
|
};
|
|
343
397
|
},
|
|
344
|
-
applyPage:
|
|
345
|
-
applyMessage:
|
|
346
|
-
applyHead:
|
|
347
|
-
applyReaction:
|
|
348
|
-
collapse:
|
|
398
|
+
applyPage: M,
|
|
399
|
+
applyMessage: oe,
|
|
400
|
+
applyHead: ie,
|
|
401
|
+
applyReaction: le,
|
|
402
|
+
collapse: ce,
|
|
403
|
+
applyEvent: ae,
|
|
349
404
|
reset() {
|
|
350
|
-
|
|
405
|
+
z(), y(V);
|
|
351
406
|
}
|
|
352
407
|
};
|
|
353
|
-
return
|
|
408
|
+
return Z.set(B, () => c), B;
|
|
354
409
|
}
|
|
355
|
-
function
|
|
356
|
-
const { pending:
|
|
410
|
+
function X(e) {
|
|
411
|
+
const { pending: s, clientMsgId: n, ...r } = e;
|
|
357
412
|
return Object.freeze(r);
|
|
358
413
|
}
|
|
359
|
-
function
|
|
360
|
-
const
|
|
361
|
-
return Object.freeze({ signIn: r, onboarding:
|
|
414
|
+
function Te(e) {
|
|
415
|
+
const s = "viewer" in e ? e.viewer.needs : e.needs, n = new Set(s.filter(w)), r = n.has("sign_in"), c = n.has("onboarding"), g = c || n.has("reconsent_rules"), m = n.has("art9_consent");
|
|
416
|
+
return Object.freeze({ signIn: r, onboarding: c, rules: g, art9: m, any: r || c || g || m });
|
|
362
417
|
}
|
|
363
|
-
function
|
|
364
|
-
return h(e.messages, (
|
|
418
|
+
function Me(e, s) {
|
|
419
|
+
return h(e.messages, (n) => n.seq === s);
|
|
365
420
|
}
|
|
366
|
-
function
|
|
367
|
-
return
|
|
421
|
+
function Ae(e, s) {
|
|
422
|
+
return s.author.kind === "member" && s.author.memberId !== null && s.author.memberId === e.viewer.memberId;
|
|
368
423
|
}
|
|
369
|
-
function
|
|
370
|
-
if ("articleId" in
|
|
371
|
-
const
|
|
372
|
-
return h(e.messages, (
|
|
424
|
+
function ke(e, s) {
|
|
425
|
+
if ("articleId" in s) return e.articleReactions;
|
|
426
|
+
const n = s.conversationId.toLowerCase();
|
|
427
|
+
return h(e.messages, (c) => c.seq === s.seq && c.conversationId.toLowerCase() === n)?.reactions ?? D;
|
|
373
428
|
}
|
|
374
|
-
function
|
|
375
|
-
const
|
|
429
|
+
function he(e, s) {
|
|
430
|
+
const n = { ...e.counts }, r = e.mine;
|
|
376
431
|
if (r !== null) {
|
|
377
|
-
const
|
|
378
|
-
|
|
432
|
+
const c = (n[r] ?? 0) - 1;
|
|
433
|
+
c > 0 ? n[r] = c : delete n[r];
|
|
379
434
|
}
|
|
380
|
-
return
|
|
435
|
+
return s !== null && (n[s] = (n[s] ?? 0) + 1), Object.freeze({ counts: Object.freeze(n), mine: s });
|
|
381
436
|
}
|
|
382
|
-
const
|
|
383
|
-
function
|
|
384
|
-
const
|
|
385
|
-
let
|
|
437
|
+
const ve = 20;
|
|
438
|
+
function ee(e) {
|
|
439
|
+
const s = Z.get(e);
|
|
440
|
+
let n = s?.(), r = e.getState().articleId;
|
|
386
441
|
return {
|
|
387
|
-
moved: () =>
|
|
442
|
+
moved: () => s !== void 0 && s() !== n || e.getState().articleId !== r,
|
|
388
443
|
mark() {
|
|
389
|
-
|
|
444
|
+
n = s?.(), r = e.getState().articleId;
|
|
390
445
|
}
|
|
391
446
|
};
|
|
392
447
|
}
|
|
393
|
-
const
|
|
394
|
-
async function
|
|
395
|
-
const
|
|
396
|
-
let
|
|
397
|
-
for (let
|
|
398
|
-
const
|
|
399
|
-
if (!
|
|
400
|
-
if (
|
|
401
|
-
e.applyPage(
|
|
402
|
-
const
|
|
403
|
-
if (
|
|
404
|
-
|
|
448
|
+
const ze = (e) => typeof e == "number" && Number.isFinite(e) ? e : null;
|
|
449
|
+
async function xe(e, s, n, r) {
|
|
450
|
+
const c = e.getState(), g = c.loaded ? c.nextCursor : 0, m = ee(e);
|
|
451
|
+
let z = null;
|
|
452
|
+
for (let y = 0; y < ve; y++) {
|
|
453
|
+
const M = await s.discussions.list({ articleId: n.articleId, languageCode: n.languageCode ?? null, cursor: z }, r);
|
|
454
|
+
if (!M.ok) return M;
|
|
455
|
+
if (m.moved()) break;
|
|
456
|
+
e.applyPage(M.value, { cursor: z }), m.mark();
|
|
457
|
+
const E = ze(M.value.nextCursor);
|
|
458
|
+
if (E === null || g !== null && E >= g || z !== null && E <= z) break;
|
|
459
|
+
z = E;
|
|
405
460
|
}
|
|
406
461
|
return { ok: !0, value: e.getState() };
|
|
407
462
|
}
|
|
408
|
-
async function
|
|
409
|
-
const
|
|
410
|
-
if (
|
|
411
|
-
const
|
|
412
|
-
return
|
|
463
|
+
async function Ee(e, s, n, r) {
|
|
464
|
+
const c = e.getState().nextCursor;
|
|
465
|
+
if (c === null) return { ok: !0, value: e.getState() };
|
|
466
|
+
const g = ee(e), m = await s.discussions.list({ articleId: n.articleId, languageCode: n.languageCode ?? null, cursor: c }, r);
|
|
467
|
+
return m.ok ? (g.moved() || e.applyPage(m.value, { cursor: c }), { ok: !0, value: e.getState() }) : m;
|
|
413
468
|
}
|
|
414
469
|
export {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
470
|
+
Ce as createDiscussionStore,
|
|
471
|
+
Me as findMessage,
|
|
472
|
+
Ae as isOwnMessage,
|
|
473
|
+
Ee as loadMoreDiscussion,
|
|
474
|
+
he as reactionAfter,
|
|
475
|
+
ke as reactionsFor,
|
|
476
|
+
xe as refreshDiscussion,
|
|
477
|
+
Te as viewerNeeds
|
|
423
478
|
};
|