@paramms/chat-widget 1.0.6 → 1.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/dist/chatlist.d.ts +62 -0
- package/dist/chatlist.js +124 -0
- package/dist/chatlist.js.map +1 -0
- package/dist/index.d.ts +1 -6
- package/dist/index.js +607 -863
- package/dist/index.js.map +1 -1
- package/dist/react.d.ts +49 -8
- package/dist/react.js +121 -92
- package/dist/react.js.map +1 -1
- package/dist/renderer.d.ts +1 -46
- package/dist/uid.d.ts +3 -0
- package/package.json +9 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var ke = Object.defineProperty;
|
|
2
|
+
var Se = (s, e, t) => e in s ? ke(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var r = (s, e, t) => Se(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { p as Ie, r as Ce } from "./uid-BeWsLRS3.js";
|
|
5
|
+
import { h as _t } from "./uid-BeWsLRS3.js";
|
|
6
|
+
const Lt = (s) => s;
|
|
7
|
+
function Ee(s) {
|
|
6
8
|
const e = s.length;
|
|
7
9
|
let t = 0, i = 0;
|
|
8
10
|
for (; i < e; ) {
|
|
@@ -24,107 +26,107 @@ function Ae(s) {
|
|
|
24
26
|
}
|
|
25
27
|
return t;
|
|
26
28
|
}
|
|
27
|
-
function
|
|
29
|
+
function Ue(s, e, t) {
|
|
28
30
|
const i = s.length;
|
|
29
31
|
let n = t, o = 0;
|
|
30
32
|
for (; o < i; ) {
|
|
31
|
-
let
|
|
32
|
-
if (
|
|
33
|
-
if (!(
|
|
34
|
-
e[n++] =
|
|
33
|
+
let c = s.charCodeAt(o++);
|
|
34
|
+
if (c & 4294967168)
|
|
35
|
+
if (!(c & 4294965248))
|
|
36
|
+
e[n++] = c >> 6 & 31 | 192;
|
|
35
37
|
else {
|
|
36
|
-
if (
|
|
38
|
+
if (c >= 55296 && c <= 56319 && o < i) {
|
|
37
39
|
const l = s.charCodeAt(o);
|
|
38
|
-
(l & 64512) === 56320 && (++o,
|
|
40
|
+
(l & 64512) === 56320 && (++o, c = ((c & 1023) << 10) + (l & 1023) + 65536);
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
c & 4294901760 ? (e[n++] = c >> 18 & 7 | 240, e[n++] = c >> 12 & 63 | 128, e[n++] = c >> 6 & 63 | 128) : (e[n++] = c >> 12 & 15 | 224, e[n++] = c >> 6 & 63 | 128);
|
|
41
43
|
}
|
|
42
44
|
else {
|
|
43
|
-
e[n++] =
|
|
45
|
+
e[n++] = c;
|
|
44
46
|
continue;
|
|
45
47
|
}
|
|
46
|
-
e[n++] =
|
|
48
|
+
e[n++] = c & 63 | 128;
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
|
-
const
|
|
50
|
-
function
|
|
51
|
-
|
|
51
|
+
const Te = new TextEncoder(), Pe = 50;
|
|
52
|
+
function Be(s, e, t) {
|
|
53
|
+
Te.encodeInto(s, e.subarray(t));
|
|
52
54
|
}
|
|
53
|
-
function
|
|
54
|
-
s.length >
|
|
55
|
+
function Ke(s, e, t) {
|
|
56
|
+
s.length > Pe ? Be(s, e, t) : Ue(s, e, t);
|
|
55
57
|
}
|
|
56
|
-
const
|
|
57
|
-
function
|
|
58
|
+
const Ae = 4096;
|
|
59
|
+
function he(s, e, t) {
|
|
58
60
|
let i = e;
|
|
59
61
|
const n = i + t, o = [];
|
|
60
|
-
let
|
|
62
|
+
let c = "";
|
|
61
63
|
for (; i < n; ) {
|
|
62
64
|
const l = s[i++];
|
|
63
65
|
if (!(l & 128))
|
|
64
66
|
o.push(l);
|
|
65
67
|
else if ((l & 224) === 192) {
|
|
66
|
-
const
|
|
67
|
-
o.push((l & 31) << 6 |
|
|
68
|
+
const x = s[i++] & 63;
|
|
69
|
+
o.push((l & 31) << 6 | x);
|
|
68
70
|
} else if ((l & 240) === 224) {
|
|
69
|
-
const
|
|
70
|
-
o.push((l & 31) << 12 |
|
|
71
|
+
const x = s[i++] & 63, f = s[i++] & 63;
|
|
72
|
+
o.push((l & 31) << 12 | x << 6 | f);
|
|
71
73
|
} else if ((l & 248) === 240) {
|
|
72
|
-
const
|
|
73
|
-
let
|
|
74
|
-
|
|
74
|
+
const x = s[i++] & 63, f = s[i++] & 63, m = s[i++] & 63;
|
|
75
|
+
let w = (l & 7) << 18 | x << 12 | f << 6 | m;
|
|
76
|
+
w > 65535 && (w -= 65536, o.push(w >>> 10 & 1023 | 55296), w = 56320 | w & 1023), o.push(w);
|
|
75
77
|
} else
|
|
76
78
|
o.push(l);
|
|
77
|
-
o.length >=
|
|
79
|
+
o.length >= Ae && (c += String.fromCharCode(...o), o.length = 0);
|
|
78
80
|
}
|
|
79
|
-
return o.length > 0 && (
|
|
81
|
+
return o.length > 0 && (c += String.fromCharCode(...o)), c;
|
|
80
82
|
}
|
|
81
|
-
const
|
|
82
|
-
function
|
|
83
|
+
const ze = new TextDecoder(), Le = 200;
|
|
84
|
+
function Me(s, e, t) {
|
|
83
85
|
const i = s.subarray(e, e + t);
|
|
84
|
-
return
|
|
86
|
+
return ze.decode(i);
|
|
85
87
|
}
|
|
86
|
-
function
|
|
87
|
-
return t >
|
|
88
|
+
function De(s, e, t) {
|
|
89
|
+
return t > Le ? Me(s, e, t) : he(s, e, t);
|
|
88
90
|
}
|
|
89
|
-
class
|
|
91
|
+
class N {
|
|
90
92
|
constructor(e, t) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
r(this, "type");
|
|
94
|
+
r(this, "data");
|
|
93
95
|
this.type = e, this.data = t;
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
|
-
class
|
|
98
|
+
class U extends Error {
|
|
97
99
|
constructor(e) {
|
|
98
100
|
super(e);
|
|
99
|
-
const t = Object.create(
|
|
101
|
+
const t = Object.create(U.prototype);
|
|
100
102
|
Object.setPrototypeOf(this, t), Object.defineProperty(this, "name", {
|
|
101
103
|
configurable: !0,
|
|
102
104
|
enumerable: !1,
|
|
103
|
-
value:
|
|
105
|
+
value: U.name
|
|
104
106
|
});
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
|
-
const
|
|
108
|
-
function
|
|
109
|
+
const F = 4294967295;
|
|
110
|
+
function $e(s, e, t) {
|
|
109
111
|
const i = t / 4294967296, n = t;
|
|
110
112
|
s.setUint32(e, i), s.setUint32(e + 4, n);
|
|
111
113
|
}
|
|
112
|
-
function
|
|
114
|
+
function pe(s, e, t) {
|
|
113
115
|
const i = Math.floor(t / 4294967296), n = t;
|
|
114
116
|
s.setUint32(e, i), s.setUint32(e + 4, n);
|
|
115
117
|
}
|
|
116
|
-
function
|
|
118
|
+
function ue(s, e) {
|
|
117
119
|
const t = s.getInt32(e), i = s.getUint32(e + 4);
|
|
118
120
|
return t * 4294967296 + i;
|
|
119
121
|
}
|
|
120
|
-
function
|
|
122
|
+
function _e(s, e) {
|
|
121
123
|
const t = s.getUint32(e), i = s.getUint32(e + 4);
|
|
122
124
|
return t * 4294967296 + i;
|
|
123
125
|
}
|
|
124
|
-
const
|
|
125
|
-
function
|
|
126
|
-
if (s >= 0 && e >= 0 && s <=
|
|
127
|
-
if (e === 0 && s <=
|
|
126
|
+
const He = -1, Re = 4294967296 - 1, Fe = 17179869184 - 1;
|
|
127
|
+
function qe({ sec: s, nsec: e }) {
|
|
128
|
+
if (s >= 0 && e >= 0 && s <= Fe)
|
|
129
|
+
if (e === 0 && s <= Re) {
|
|
128
130
|
const t = new Uint8Array(4);
|
|
129
131
|
return new DataView(t.buffer).setUint32(0, s), t;
|
|
130
132
|
} else {
|
|
@@ -133,24 +135,24 @@ function We({ sec: s, nsec: e }) {
|
|
|
133
135
|
}
|
|
134
136
|
else {
|
|
135
137
|
const t = new Uint8Array(12), i = new DataView(t.buffer);
|
|
136
|
-
return i.setUint32(0, e),
|
|
138
|
+
return i.setUint32(0, e), pe(i, 4, s), t;
|
|
137
139
|
}
|
|
138
140
|
}
|
|
139
|
-
function
|
|
141
|
+
function je(s) {
|
|
140
142
|
const e = s.getTime(), t = Math.floor(e / 1e3), i = (e - t * 1e3) * 1e6, n = Math.floor(i / 1e9);
|
|
141
143
|
return {
|
|
142
144
|
sec: t + n,
|
|
143
145
|
nsec: i - n * 1e9
|
|
144
146
|
};
|
|
145
147
|
}
|
|
146
|
-
function
|
|
148
|
+
function Oe(s) {
|
|
147
149
|
if (s instanceof Date) {
|
|
148
|
-
const e =
|
|
149
|
-
return
|
|
150
|
+
const e = je(s);
|
|
151
|
+
return qe(e);
|
|
150
152
|
} else
|
|
151
153
|
return null;
|
|
152
154
|
}
|
|
153
|
-
function
|
|
155
|
+
function Ne(s) {
|
|
154
156
|
const e = new DataView(s.buffer, s.byteOffset, s.byteLength);
|
|
155
157
|
switch (s.byteLength) {
|
|
156
158
|
case 4:
|
|
@@ -160,34 +162,34 @@ function Ye(s) {
|
|
|
160
162
|
return { sec: n, nsec: o };
|
|
161
163
|
}
|
|
162
164
|
case 12: {
|
|
163
|
-
const t =
|
|
165
|
+
const t = ue(e, 4), i = e.getUint32(0);
|
|
164
166
|
return { sec: t, nsec: i };
|
|
165
167
|
}
|
|
166
168
|
default:
|
|
167
|
-
throw new
|
|
169
|
+
throw new U(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${s.length}`);
|
|
168
170
|
}
|
|
169
171
|
}
|
|
170
|
-
function
|
|
171
|
-
const e =
|
|
172
|
+
function Ve(s) {
|
|
173
|
+
const e = Ne(s);
|
|
172
174
|
return new Date(e.sec * 1e3 + e.nsec / 1e6);
|
|
173
175
|
}
|
|
174
|
-
const
|
|
175
|
-
type:
|
|
176
|
-
encode:
|
|
177
|
-
decode:
|
|
178
|
-
},
|
|
176
|
+
const We = {
|
|
177
|
+
type: He,
|
|
178
|
+
encode: Oe,
|
|
179
|
+
decode: Ve
|
|
180
|
+
}, X = class X {
|
|
179
181
|
constructor() {
|
|
180
182
|
// ensures ExtensionCodecType<X> matches ExtensionCodec<X>
|
|
181
183
|
// this will make type errors a lot more clear
|
|
182
184
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
183
|
-
|
|
185
|
+
r(this, "__brand");
|
|
184
186
|
// built-in extensions
|
|
185
|
-
|
|
186
|
-
|
|
187
|
+
r(this, "builtInEncoders", []);
|
|
188
|
+
r(this, "builtInDecoders", []);
|
|
187
189
|
// custom extensions
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
this.register(
|
|
190
|
+
r(this, "encoders", []);
|
|
191
|
+
r(this, "decoders", []);
|
|
192
|
+
this.register(We);
|
|
191
193
|
}
|
|
192
194
|
register({ type: e, encode: t, decode: i }) {
|
|
193
195
|
if (e >= 0)
|
|
@@ -203,8 +205,8 @@ const Ge = {
|
|
|
203
205
|
if (n != null) {
|
|
204
206
|
const o = n(e, t);
|
|
205
207
|
if (o != null) {
|
|
206
|
-
const
|
|
207
|
-
return new
|
|
208
|
+
const c = -1 - i;
|
|
209
|
+
return new N(c, o);
|
|
208
210
|
}
|
|
209
211
|
}
|
|
210
212
|
}
|
|
@@ -213,46 +215,46 @@ const Ge = {
|
|
|
213
215
|
if (n != null) {
|
|
214
216
|
const o = n(e, t);
|
|
215
217
|
if (o != null) {
|
|
216
|
-
const
|
|
217
|
-
return new
|
|
218
|
+
const c = i;
|
|
219
|
+
return new N(c, o);
|
|
218
220
|
}
|
|
219
221
|
}
|
|
220
222
|
}
|
|
221
|
-
return e instanceof
|
|
223
|
+
return e instanceof N ? e : null;
|
|
222
224
|
}
|
|
223
225
|
decode(e, t, i) {
|
|
224
226
|
const n = t < 0 ? this.builtInDecoders[-1 - t] : this.decoders[t];
|
|
225
|
-
return n ? n(e, t, i) : new
|
|
227
|
+
return n ? n(e, t, i) : new N(t, e);
|
|
226
228
|
}
|
|
227
229
|
};
|
|
228
|
-
|
|
229
|
-
let
|
|
230
|
-
function
|
|
230
|
+
r(X, "defaultCodec", new X());
|
|
231
|
+
let V = X;
|
|
232
|
+
function Xe(s) {
|
|
231
233
|
return s instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && s instanceof SharedArrayBuffer;
|
|
232
234
|
}
|
|
233
|
-
function
|
|
234
|
-
return s instanceof Uint8Array ? s : ArrayBuffer.isView(s) ? new Uint8Array(s.buffer, s.byteOffset, s.byteLength) :
|
|
235
|
+
function Z(s) {
|
|
236
|
+
return s instanceof Uint8Array ? s : ArrayBuffer.isView(s) ? new Uint8Array(s.buffer, s.byteOffset, s.byteLength) : Xe(s) ? new Uint8Array(s) : Uint8Array.from(s);
|
|
235
237
|
}
|
|
236
|
-
const
|
|
237
|
-
class
|
|
238
|
+
const Ye = 100, Je = 2048;
|
|
239
|
+
class te {
|
|
238
240
|
constructor(e) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ??
|
|
241
|
+
r(this, "extensionCodec");
|
|
242
|
+
r(this, "context");
|
|
243
|
+
r(this, "useBigInt64");
|
|
244
|
+
r(this, "maxDepth");
|
|
245
|
+
r(this, "initialBufferSize");
|
|
246
|
+
r(this, "sortKeys");
|
|
247
|
+
r(this, "forceFloat32");
|
|
248
|
+
r(this, "ignoreUndefined");
|
|
249
|
+
r(this, "forceIntegerToFloat");
|
|
250
|
+
r(this, "pos");
|
|
251
|
+
r(this, "view");
|
|
252
|
+
r(this, "bytes");
|
|
253
|
+
r(this, "entered", !1);
|
|
254
|
+
this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? V.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.maxDepth = (e == null ? void 0 : e.maxDepth) ?? Ye, this.initialBufferSize = (e == null ? void 0 : e.initialBufferSize) ?? Je, this.sortKeys = (e == null ? void 0 : e.sortKeys) ?? !1, this.forceFloat32 = (e == null ? void 0 : e.forceFloat32) ?? !1, this.ignoreUndefined = (e == null ? void 0 : e.ignoreUndefined) ?? !1, this.forceIntegerToFloat = (e == null ? void 0 : e.forceIntegerToFloat) ?? !1, this.pos = 0, this.view = new DataView(new ArrayBuffer(this.initialBufferSize)), this.bytes = new Uint8Array(this.view.buffer);
|
|
253
255
|
}
|
|
254
256
|
clone() {
|
|
255
|
-
return new
|
|
257
|
+
return new te({
|
|
256
258
|
extensionCodec: this.extensionCodec,
|
|
257
259
|
context: this.context,
|
|
258
260
|
useBigInt64: this.useBigInt64,
|
|
@@ -334,8 +336,8 @@ class oe {
|
|
|
334
336
|
throw new Error(`Too long string: ${e} bytes in UTF-8`);
|
|
335
337
|
}
|
|
336
338
|
encodeString(e) {
|
|
337
|
-
const i =
|
|
338
|
-
this.ensureBufferSizeToWrite(5 + i), this.writeStringHeader(i),
|
|
339
|
+
const i = Ee(e);
|
|
340
|
+
this.ensureBufferSizeToWrite(5 + i), this.writeStringHeader(i), Ke(e, this.bytes, this.pos), this.pos += i;
|
|
339
341
|
}
|
|
340
342
|
encodeObject(e, t) {
|
|
341
343
|
const i = this.extensionCodec.tryToEncode(e, this.context);
|
|
@@ -360,7 +362,7 @@ class oe {
|
|
|
360
362
|
this.writeU8(198), this.writeU32(t);
|
|
361
363
|
else
|
|
362
364
|
throw new Error(`Too large binary: ${t}`);
|
|
363
|
-
const i =
|
|
365
|
+
const i = Z(e);
|
|
364
366
|
this.writeU8a(i);
|
|
365
367
|
}
|
|
366
368
|
encodeArray(e, t) {
|
|
@@ -395,8 +397,8 @@ class oe {
|
|
|
395
397
|
else
|
|
396
398
|
throw new Error(`Too large map object: ${n}`);
|
|
397
399
|
for (const o of i) {
|
|
398
|
-
const
|
|
399
|
-
this.ignoreUndefined &&
|
|
400
|
+
const c = e[o];
|
|
401
|
+
this.ignoreUndefined && c === void 0 || (this.encodeString(o), this.doEncode(c, t + 1));
|
|
400
402
|
}
|
|
401
403
|
}
|
|
402
404
|
encodeExtension(e) {
|
|
@@ -457,10 +459,10 @@ class oe {
|
|
|
457
459
|
this.ensureBufferSizeToWrite(8), this.view.setFloat64(this.pos, e), this.pos += 8;
|
|
458
460
|
}
|
|
459
461
|
writeU64(e) {
|
|
460
|
-
this.ensureBufferSizeToWrite(8),
|
|
462
|
+
this.ensureBufferSizeToWrite(8), $e(this.view, this.pos, e), this.pos += 8;
|
|
461
463
|
}
|
|
462
464
|
writeI64(e) {
|
|
463
|
-
this.ensureBufferSizeToWrite(8),
|
|
465
|
+
this.ensureBufferSizeToWrite(8), pe(this.view, this.pos, e), this.pos += 8;
|
|
464
466
|
}
|
|
465
467
|
writeBigUint64(e) {
|
|
466
468
|
this.ensureBufferSizeToWrite(8), this.view.setBigUint64(this.pos, e), this.pos += 8;
|
|
@@ -469,20 +471,20 @@ class oe {
|
|
|
469
471
|
this.ensureBufferSizeToWrite(8), this.view.setBigInt64(this.pos, e), this.pos += 8;
|
|
470
472
|
}
|
|
471
473
|
}
|
|
472
|
-
function
|
|
473
|
-
return new
|
|
474
|
+
function Ge(s, e) {
|
|
475
|
+
return new te(e).encodeSharedRef(s);
|
|
474
476
|
}
|
|
475
|
-
function
|
|
477
|
+
function J(s) {
|
|
476
478
|
return `${s < 0 ? "-" : ""}0x${Math.abs(s).toString(16).padStart(2, "0")}`;
|
|
477
479
|
}
|
|
478
|
-
const
|
|
479
|
-
class
|
|
480
|
-
constructor(e =
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
480
|
+
const Ze = 16, Qe = 16;
|
|
481
|
+
class et {
|
|
482
|
+
constructor(e = Ze, t = Qe) {
|
|
483
|
+
r(this, "hit", 0);
|
|
484
|
+
r(this, "miss", 0);
|
|
485
|
+
r(this, "caches");
|
|
486
|
+
r(this, "maxKeyLength");
|
|
487
|
+
r(this, "maxLengthPerKey");
|
|
486
488
|
this.maxKeyLength = e, this.maxLengthPerKey = t, this.caches = [];
|
|
487
489
|
for (let i = 0; i < this.maxKeyLength; i++)
|
|
488
490
|
this.caches.push([]);
|
|
@@ -493,9 +495,9 @@ class st {
|
|
|
493
495
|
find(e, t, i) {
|
|
494
496
|
const n = this.caches[i - 1];
|
|
495
497
|
e: for (const o of n) {
|
|
496
|
-
const
|
|
498
|
+
const c = o.bytes;
|
|
497
499
|
for (let l = 0; l < i; l++)
|
|
498
|
-
if (
|
|
500
|
+
if (c[l] !== e[t + l])
|
|
499
501
|
continue e;
|
|
500
502
|
return o.str;
|
|
501
503
|
}
|
|
@@ -510,19 +512,19 @@ class st {
|
|
|
510
512
|
if (n != null)
|
|
511
513
|
return this.hit++, n;
|
|
512
514
|
this.miss++;
|
|
513
|
-
const o =
|
|
514
|
-
return this.store(
|
|
515
|
+
const o = he(e, t, i), c = Uint8Array.prototype.slice.call(e, t, t + i);
|
|
516
|
+
return this.store(c, o), o;
|
|
515
517
|
}
|
|
516
518
|
}
|
|
517
|
-
const
|
|
519
|
+
const Q = "array", j = "map_key", fe = "map_value", tt = (s) => {
|
|
518
520
|
if (typeof s == "string" || typeof s == "number")
|
|
519
521
|
return s;
|
|
520
|
-
throw new
|
|
522
|
+
throw new U("The type of key must be string or number but " + typeof s);
|
|
521
523
|
};
|
|
522
|
-
class
|
|
524
|
+
class it {
|
|
523
525
|
constructor() {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
+
r(this, "stack", []);
|
|
527
|
+
r(this, "stackHeadPosition", -1);
|
|
526
528
|
}
|
|
527
529
|
get length() {
|
|
528
530
|
return this.stackHeadPosition + 1;
|
|
@@ -532,11 +534,11 @@ class rt {
|
|
|
532
534
|
}
|
|
533
535
|
pushArrayState(e) {
|
|
534
536
|
const t = this.getUninitializedStateFromPool();
|
|
535
|
-
t.type =
|
|
537
|
+
t.type = Q, t.position = 0, t.size = e, t.array = new Array(e);
|
|
536
538
|
}
|
|
537
539
|
pushMapState(e) {
|
|
538
540
|
const t = this.getUninitializedStateFromPool();
|
|
539
|
-
t.type =
|
|
541
|
+
t.type = j, t.readCount = 0, t.size = e, t.map = {};
|
|
540
542
|
}
|
|
541
543
|
getUninitializedStateFromPool() {
|
|
542
544
|
if (this.stackHeadPosition++, this.stackHeadPosition === this.stack.length) {
|
|
@@ -556,11 +558,11 @@ class rt {
|
|
|
556
558
|
release(e) {
|
|
557
559
|
if (this.stack[this.stackHeadPosition] !== e)
|
|
558
560
|
throw new Error("Invalid stack state. Released state is not on top of the stack.");
|
|
559
|
-
if (e.type ===
|
|
561
|
+
if (e.type === Q) {
|
|
560
562
|
const i = e;
|
|
561
563
|
i.size = 0, i.array = void 0, i.position = 0, i.type = void 0;
|
|
562
564
|
}
|
|
563
|
-
if (e.type ===
|
|
565
|
+
if (e.type === j || e.type === fe) {
|
|
564
566
|
const i = e;
|
|
565
567
|
i.size = 0, i.map = void 0, i.readCount = 0, i.type = void 0;
|
|
566
568
|
}
|
|
@@ -570,38 +572,38 @@ class rt {
|
|
|
570
572
|
this.stack.length = 0, this.stackHeadPosition = -1;
|
|
571
573
|
}
|
|
572
574
|
}
|
|
573
|
-
const
|
|
575
|
+
const q = -1, ie = new DataView(new ArrayBuffer(0)), nt = new Uint8Array(ie.buffer);
|
|
574
576
|
try {
|
|
575
|
-
|
|
577
|
+
ie.getInt8(0);
|
|
576
578
|
} catch (s) {
|
|
577
579
|
if (!(s instanceof RangeError))
|
|
578
580
|
throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access");
|
|
579
581
|
}
|
|
580
|
-
const
|
|
581
|
-
class
|
|
582
|
+
const re = new RangeError("Insufficient data"), st = new et();
|
|
583
|
+
class ne {
|
|
582
584
|
constructor(e) {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ??
|
|
585
|
+
r(this, "extensionCodec");
|
|
586
|
+
r(this, "context");
|
|
587
|
+
r(this, "useBigInt64");
|
|
588
|
+
r(this, "rawStrings");
|
|
589
|
+
r(this, "maxStrLength");
|
|
590
|
+
r(this, "maxBinLength");
|
|
591
|
+
r(this, "maxArrayLength");
|
|
592
|
+
r(this, "maxMapLength");
|
|
593
|
+
r(this, "maxExtLength");
|
|
594
|
+
r(this, "keyDecoder");
|
|
595
|
+
r(this, "mapKeyConverter");
|
|
596
|
+
r(this, "totalPos", 0);
|
|
597
|
+
r(this, "pos", 0);
|
|
598
|
+
r(this, "view", ie);
|
|
599
|
+
r(this, "bytes", nt);
|
|
600
|
+
r(this, "headByte", q);
|
|
601
|
+
r(this, "stack", new it());
|
|
602
|
+
r(this, "entered", !1);
|
|
603
|
+
this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? V.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.rawStrings = (e == null ? void 0 : e.rawStrings) ?? !1, this.maxStrLength = (e == null ? void 0 : e.maxStrLength) ?? F, this.maxBinLength = (e == null ? void 0 : e.maxBinLength) ?? F, this.maxArrayLength = (e == null ? void 0 : e.maxArrayLength) ?? F, this.maxMapLength = (e == null ? void 0 : e.maxMapLength) ?? F, this.maxExtLength = (e == null ? void 0 : e.maxExtLength) ?? F, this.keyDecoder = (e == null ? void 0 : e.keyDecoder) !== void 0 ? e.keyDecoder : st, this.mapKeyConverter = (e == null ? void 0 : e.mapKeyConverter) ?? tt;
|
|
602
604
|
}
|
|
603
605
|
clone() {
|
|
604
|
-
return new
|
|
606
|
+
return new ne({
|
|
605
607
|
extensionCodec: this.extensionCodec,
|
|
606
608
|
context: this.context,
|
|
607
609
|
useBigInt64: this.useBigInt64,
|
|
@@ -615,17 +617,17 @@ class ae {
|
|
|
615
617
|
});
|
|
616
618
|
}
|
|
617
619
|
reinitializeState() {
|
|
618
|
-
this.totalPos = 0, this.headByte =
|
|
620
|
+
this.totalPos = 0, this.headByte = q, this.stack.reset();
|
|
619
621
|
}
|
|
620
622
|
setBuffer(e) {
|
|
621
|
-
const t =
|
|
623
|
+
const t = Z(e);
|
|
622
624
|
this.bytes = t, this.view = new DataView(t.buffer, t.byteOffset, t.byteLength), this.pos = 0;
|
|
623
625
|
}
|
|
624
626
|
appendBuffer(e) {
|
|
625
|
-
if (this.headByte ===
|
|
627
|
+
if (this.headByte === q && !this.hasRemaining(1))
|
|
626
628
|
this.setBuffer(e);
|
|
627
629
|
else {
|
|
628
|
-
const t = this.bytes.subarray(this.pos), i =
|
|
630
|
+
const t = this.bytes.subarray(this.pos), i = Z(e), n = new Uint8Array(t.length + i.length);
|
|
629
631
|
n.set(t), n.set(i, t.length), this.setBuffer(n);
|
|
630
632
|
}
|
|
631
633
|
}
|
|
@@ -677,9 +679,9 @@ class ae {
|
|
|
677
679
|
this.appendBuffer(l);
|
|
678
680
|
try {
|
|
679
681
|
i = this.doDecodeSync(), t = !0;
|
|
680
|
-
} catch (
|
|
681
|
-
if (!(
|
|
682
|
-
throw
|
|
682
|
+
} catch (x) {
|
|
683
|
+
if (!(x instanceof RangeError))
|
|
684
|
+
throw x;
|
|
683
685
|
}
|
|
684
686
|
this.totalPos += this.pos;
|
|
685
687
|
}
|
|
@@ -688,8 +690,8 @@ class ae {
|
|
|
688
690
|
throw this.createExtraByteError(this.totalPos);
|
|
689
691
|
return i;
|
|
690
692
|
}
|
|
691
|
-
const { headByte: n, pos: o, totalPos:
|
|
692
|
-
throw new RangeError(`Insufficient data in parsing ${
|
|
693
|
+
const { headByte: n, pos: o, totalPos: c } = this;
|
|
694
|
+
throw new RangeError(`Insufficient data in parsing ${J(n)} at ${c} (${o} in the current buffer)`);
|
|
693
695
|
} finally {
|
|
694
696
|
this.entered = !1;
|
|
695
697
|
}
|
|
@@ -715,9 +717,9 @@ class ae {
|
|
|
715
717
|
try {
|
|
716
718
|
for (; yield this.doDecodeSync(), --n !== 0; )
|
|
717
719
|
;
|
|
718
|
-
} catch (
|
|
719
|
-
if (!(
|
|
720
|
-
throw
|
|
720
|
+
} catch (c) {
|
|
721
|
+
if (!(c instanceof RangeError))
|
|
722
|
+
throw c;
|
|
721
723
|
}
|
|
722
724
|
this.totalPos += this.pos;
|
|
723
725
|
}
|
|
@@ -844,25 +846,25 @@ class ae {
|
|
|
844
846
|
const n = this.lookU32();
|
|
845
847
|
t = this.decodeExtension(n, 4);
|
|
846
848
|
} else
|
|
847
|
-
throw new
|
|
849
|
+
throw new U(`Unrecognized type byte: ${J(e)}`);
|
|
848
850
|
this.complete();
|
|
849
851
|
const i = this.stack;
|
|
850
852
|
for (; i.length > 0; ) {
|
|
851
853
|
const n = i.top();
|
|
852
|
-
if (n.type ===
|
|
854
|
+
if (n.type === Q)
|
|
853
855
|
if (n.array[n.position] = t, n.position++, n.position === n.size)
|
|
854
856
|
t = n.array, i.release(n);
|
|
855
857
|
else
|
|
856
858
|
continue e;
|
|
857
|
-
else if (n.type ===
|
|
859
|
+
else if (n.type === j) {
|
|
858
860
|
if (t === "__proto__")
|
|
859
|
-
throw new
|
|
860
|
-
n.key = this.mapKeyConverter(t), n.type =
|
|
861
|
+
throw new U("The key __proto__ is not allowed");
|
|
862
|
+
n.key = this.mapKeyConverter(t), n.type = fe;
|
|
861
863
|
continue e;
|
|
862
864
|
} else if (n.map[n.key] = t, n.readCount++, n.readCount === n.size)
|
|
863
865
|
t = n.map, i.release(n);
|
|
864
866
|
else {
|
|
865
|
-
n.key = null, n.type =
|
|
867
|
+
n.key = null, n.type = j;
|
|
866
868
|
continue e;
|
|
867
869
|
}
|
|
868
870
|
}
|
|
@@ -870,10 +872,10 @@ class ae {
|
|
|
870
872
|
}
|
|
871
873
|
}
|
|
872
874
|
readHeadByte() {
|
|
873
|
-
return this.headByte ===
|
|
875
|
+
return this.headByte === q && (this.headByte = this.readU8()), this.headByte;
|
|
874
876
|
}
|
|
875
877
|
complete() {
|
|
876
|
-
this.headByte =
|
|
878
|
+
this.headByte = q;
|
|
877
879
|
}
|
|
878
880
|
readArraySize() {
|
|
879
881
|
const e = this.readHeadByte();
|
|
@@ -885,18 +887,18 @@ class ae {
|
|
|
885
887
|
default: {
|
|
886
888
|
if (e < 160)
|
|
887
889
|
return e - 144;
|
|
888
|
-
throw new
|
|
890
|
+
throw new U(`Unrecognized array type byte: ${J(e)}`);
|
|
889
891
|
}
|
|
890
892
|
}
|
|
891
893
|
}
|
|
892
894
|
pushMapState(e) {
|
|
893
895
|
if (e > this.maxMapLength)
|
|
894
|
-
throw new
|
|
896
|
+
throw new U(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);
|
|
895
897
|
this.stack.pushMapState(e);
|
|
896
898
|
}
|
|
897
899
|
pushArrayState(e) {
|
|
898
900
|
if (e > this.maxArrayLength)
|
|
899
|
-
throw new
|
|
901
|
+
throw new U(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);
|
|
900
902
|
this.stack.pushArrayState(e);
|
|
901
903
|
}
|
|
902
904
|
decodeString(e, t) {
|
|
@@ -908,30 +910,30 @@ class ae {
|
|
|
908
910
|
decodeUtf8String(e, t) {
|
|
909
911
|
var o;
|
|
910
912
|
if (e > this.maxStrLength)
|
|
911
|
-
throw new
|
|
913
|
+
throw new U(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);
|
|
912
914
|
if (this.bytes.byteLength < this.pos + t + e)
|
|
913
|
-
throw
|
|
915
|
+
throw re;
|
|
914
916
|
const i = this.pos + t;
|
|
915
917
|
let n;
|
|
916
|
-
return this.stateIsMapKey() && ((o = this.keyDecoder) != null && o.canBeCached(e)) ? n = this.keyDecoder.decode(this.bytes, i, e) : n =
|
|
918
|
+
return this.stateIsMapKey() && ((o = this.keyDecoder) != null && o.canBeCached(e)) ? n = this.keyDecoder.decode(this.bytes, i, e) : n = De(this.bytes, i, e), this.pos += t + e, n;
|
|
917
919
|
}
|
|
918
920
|
stateIsMapKey() {
|
|
919
|
-
return this.stack.length > 0 ? this.stack.top().type ===
|
|
921
|
+
return this.stack.length > 0 ? this.stack.top().type === j : !1;
|
|
920
922
|
}
|
|
921
923
|
/**
|
|
922
924
|
* @throws {@link RangeError}
|
|
923
925
|
*/
|
|
924
926
|
decodeBinary(e, t) {
|
|
925
927
|
if (e > this.maxBinLength)
|
|
926
|
-
throw new
|
|
928
|
+
throw new U(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);
|
|
927
929
|
if (!this.hasRemaining(e + t))
|
|
928
|
-
throw
|
|
930
|
+
throw re;
|
|
929
931
|
const i = this.pos + t, n = this.bytes.subarray(i, i + e);
|
|
930
932
|
return this.pos += t + e, n;
|
|
931
933
|
}
|
|
932
934
|
decodeExtension(e, t) {
|
|
933
935
|
if (e > this.maxExtLength)
|
|
934
|
-
throw new
|
|
936
|
+
throw new U(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);
|
|
935
937
|
const i = this.view.getInt8(this.pos + t), n = this.decodeBinary(
|
|
936
938
|
e,
|
|
937
939
|
t + 1
|
|
@@ -973,11 +975,11 @@ class ae {
|
|
|
973
975
|
return this.pos += 4, e;
|
|
974
976
|
}
|
|
975
977
|
readU64() {
|
|
976
|
-
const e =
|
|
978
|
+
const e = _e(this.view, this.pos);
|
|
977
979
|
return this.pos += 8, e;
|
|
978
980
|
}
|
|
979
981
|
readI64() {
|
|
980
|
-
const e =
|
|
982
|
+
const e = ue(this.view, this.pos);
|
|
981
983
|
return this.pos += 8, e;
|
|
982
984
|
}
|
|
983
985
|
readU64AsBigInt() {
|
|
@@ -997,10 +999,10 @@ class ae {
|
|
|
997
999
|
return this.pos += 8, e;
|
|
998
1000
|
}
|
|
999
1001
|
}
|
|
1000
|
-
function
|
|
1001
|
-
return new
|
|
1002
|
+
function ot(s, e) {
|
|
1003
|
+
return new ne(e).decode(s);
|
|
1002
1004
|
}
|
|
1003
|
-
const
|
|
1005
|
+
const rt = /* @__PURE__ */ new Set([
|
|
1004
1006
|
"auth",
|
|
1005
1007
|
"open",
|
|
1006
1008
|
"send",
|
|
@@ -1017,50 +1019,50 @@ const lt = /* @__PURE__ */ new Set([
|
|
|
1017
1019
|
"annotate",
|
|
1018
1020
|
"annotate_clear"
|
|
1019
1021
|
]);
|
|
1020
|
-
function
|
|
1021
|
-
return
|
|
1022
|
+
function at(s) {
|
|
1023
|
+
return rt.has(s.type);
|
|
1022
1024
|
}
|
|
1023
|
-
function
|
|
1024
|
-
return
|
|
1025
|
+
function ct(s) {
|
|
1026
|
+
return Ge(s);
|
|
1025
1027
|
}
|
|
1026
|
-
function
|
|
1028
|
+
function dt(s) {
|
|
1027
1029
|
let e;
|
|
1028
1030
|
try {
|
|
1029
|
-
e =
|
|
1031
|
+
e = ot(s);
|
|
1030
1032
|
} catch {
|
|
1031
1033
|
return null;
|
|
1032
1034
|
}
|
|
1033
1035
|
return typeof e != "object" || e === null || typeof e.type != "string" ? null : e;
|
|
1034
1036
|
}
|
|
1035
|
-
class
|
|
1037
|
+
class lt {
|
|
1036
1038
|
constructor(e) {
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1039
|
+
r(this, "conversationId");
|
|
1040
|
+
r(this, "state", "");
|
|
1041
|
+
r(this, "version", 0);
|
|
1042
|
+
r(this, "hasMoreHistory", !1);
|
|
1043
|
+
r(this, "lastReadByOthers", 0);
|
|
1044
|
+
r(this, "assignedAgentId");
|
|
1045
|
+
r(this, "accent");
|
|
1046
|
+
r(this, "subject");
|
|
1047
|
+
r(this, "name");
|
|
1048
|
+
r(this, "e2e", !1);
|
|
1049
|
+
r(this, "offline", !1);
|
|
1050
|
+
r(this, "offlineMessage", "");
|
|
1051
|
+
r(this, "whiteLabel", !1);
|
|
1052
|
+
r(this, "typing", /* @__PURE__ */ new Set());
|
|
1053
|
+
r(this, "online", /* @__PURE__ */ new Set());
|
|
1052
1054
|
/** Co-browsing: shared whiteboard strokes for this conversation. */
|
|
1053
|
-
|
|
1055
|
+
r(this, "annotations", []);
|
|
1054
1056
|
/** Bumped on any annotation change so the renderer can cheaply detect updates. */
|
|
1055
|
-
|
|
1057
|
+
r(this, "annotationVersion", 0);
|
|
1056
1058
|
/** Live sentiment of the guest's latest message (agent-side only). */
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1059
|
+
r(this, "sentiment");
|
|
1060
|
+
r(this, "sentimentScore");
|
|
1061
|
+
r(this, "actions", []);
|
|
1062
|
+
r(this, "byId", /* @__PURE__ */ new Map());
|
|
1063
|
+
r(this, "keyByClient", /* @__PURE__ */ new Map());
|
|
1064
|
+
r(this, "_maxSeq", 0);
|
|
1065
|
+
r(this, "_sorted", null);
|
|
1064
1066
|
this.me = e;
|
|
1065
1067
|
}
|
|
1066
1068
|
messages() {
|
|
@@ -1130,7 +1132,7 @@ class de {
|
|
|
1130
1132
|
case "reaction": {
|
|
1131
1133
|
const i = this.byId.get(e.messageId);
|
|
1132
1134
|
if (!i) return;
|
|
1133
|
-
const n = { ...i.reactions ?? {} }, o = (n[e.emoji] ?? []).filter((
|
|
1135
|
+
const n = { ...i.reactions ?? {} }, o = (n[e.emoji] ?? []).filter((c) => c !== e.by);
|
|
1134
1136
|
e.removed || o.push(e.by), o.length ? n[e.emoji] = o : delete n[e.emoji], this.byId.set(e.messageId, { ...i, reactions: n }), this._sorted = null;
|
|
1135
1137
|
return;
|
|
1136
1138
|
}
|
|
@@ -1178,10 +1180,10 @@ class de {
|
|
|
1178
1180
|
}
|
|
1179
1181
|
markOwnStatus(e, t) {
|
|
1180
1182
|
for (const [i, n] of this.byId)
|
|
1181
|
-
n.senderId === this.me && n.seq > 0 && n.seq <= e &&
|
|
1183
|
+
n.senderId === this.me && n.seq > 0 && n.seq <= e && ae(t) > ae(n.status) && (this.byId.set(i, { ...n, status: t }), this._sorted = null);
|
|
1182
1184
|
}
|
|
1183
1185
|
}
|
|
1184
|
-
function
|
|
1186
|
+
function ae(s) {
|
|
1185
1187
|
switch (s) {
|
|
1186
1188
|
case "read":
|
|
1187
1189
|
return 3;
|
|
@@ -1193,27 +1195,27 @@ function le(s) {
|
|
|
1193
1195
|
return 0;
|
|
1194
1196
|
}
|
|
1195
1197
|
}
|
|
1196
|
-
class
|
|
1198
|
+
class ht {
|
|
1197
1199
|
constructor(e) {
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1200
|
+
r(this, "socket", null);
|
|
1201
|
+
r(this, "state", "idle");
|
|
1202
|
+
r(this, "authed", !1);
|
|
1203
|
+
r(this, "attempt", 0);
|
|
1204
|
+
r(this, "outbox", []);
|
|
1205
|
+
r(this, "stopped", !1);
|
|
1206
|
+
r(this, "timer", null);
|
|
1205
1207
|
this.opts = e;
|
|
1206
1208
|
}
|
|
1207
1209
|
connect() {
|
|
1208
1210
|
var i, n;
|
|
1209
1211
|
if (this.state === "connecting" || this.state === "open") return;
|
|
1210
1212
|
this.stopped = !1, this.state = "connecting", this.authed = !1, (n = (i = this.opts).onStatusChange) == null || n.call(i, this.attempt > 0 ? "reconnecting" : "connecting");
|
|
1211
|
-
const t = (this.opts.socketFactory ??
|
|
1213
|
+
const t = (this.opts.socketFactory ?? pt)(this.opts.url);
|
|
1212
1214
|
t.binaryType = "arraybuffer", this.socket = t, t.onopen = () => {
|
|
1213
1215
|
this.raw({ type: "auth", token: this.opts.token });
|
|
1214
1216
|
}, t.onmessage = (o) => {
|
|
1215
|
-
const
|
|
1216
|
-
!
|
|
1217
|
+
const c = dt(new Uint8Array(o.data));
|
|
1218
|
+
!c || at(c) || this.handle(c);
|
|
1217
1219
|
}, t.onclose = () => this.onClosed(), t.onerror = () => {
|
|
1218
1220
|
try {
|
|
1219
1221
|
t.close();
|
|
@@ -1252,7 +1254,7 @@ class he {
|
|
|
1252
1254
|
raw(e) {
|
|
1253
1255
|
var t;
|
|
1254
1256
|
try {
|
|
1255
|
-
(t = this.socket) == null || t.send(
|
|
1257
|
+
(t = this.socket) == null || t.send(ct(e));
|
|
1256
1258
|
} catch {
|
|
1257
1259
|
this.outbox.push(e);
|
|
1258
1260
|
}
|
|
@@ -1267,13 +1269,13 @@ class he {
|
|
|
1267
1269
|
this.attempt++, this.timer = setTimeout(() => this.connect(), i);
|
|
1268
1270
|
}
|
|
1269
1271
|
}
|
|
1270
|
-
function
|
|
1272
|
+
function pt(s) {
|
|
1271
1273
|
return new WebSocket(s);
|
|
1272
1274
|
}
|
|
1273
|
-
const
|
|
1274
|
-
class
|
|
1275
|
+
const ce = 200, ut = 7 * 864e5;
|
|
1276
|
+
class ft {
|
|
1275
1277
|
constructor(e) {
|
|
1276
|
-
|
|
1278
|
+
r(this, "key");
|
|
1277
1279
|
this.key = `ocw_outbox_${e}`;
|
|
1278
1280
|
}
|
|
1279
1281
|
/** All pending items, oldest first, with stale (>7d) entries dropped. */
|
|
@@ -1281,7 +1283,7 @@ class fe {
|
|
|
1281
1283
|
try {
|
|
1282
1284
|
const e = localStorage.getItem(this.key);
|
|
1283
1285
|
if (!e) return [];
|
|
1284
|
-
const t = JSON.parse(e), i = Date.now() -
|
|
1286
|
+
const t = JSON.parse(e), i = Date.now() - ut, n = t.filter((o) => o.ts >= i);
|
|
1285
1287
|
return n.length !== t.length && this.save(n), n;
|
|
1286
1288
|
} catch {
|
|
1287
1289
|
return [];
|
|
@@ -1290,7 +1292,7 @@ class fe {
|
|
|
1290
1292
|
add(e) {
|
|
1291
1293
|
try {
|
|
1292
1294
|
const t = this.load();
|
|
1293
|
-
t.push(e), this.save(t.length >
|
|
1295
|
+
t.push(e), this.save(t.length > ce ? t.slice(t.length - ce) : t);
|
|
1294
1296
|
} catch {
|
|
1295
1297
|
}
|
|
1296
1298
|
}
|
|
@@ -1309,31 +1311,31 @@ class fe {
|
|
|
1309
1311
|
}
|
|
1310
1312
|
}
|
|
1311
1313
|
}
|
|
1312
|
-
const
|
|
1313
|
-
function
|
|
1314
|
+
const S = () => globalThis.crypto.subtle;
|
|
1315
|
+
function W(s) {
|
|
1314
1316
|
const e = s instanceof Uint8Array ? s : new Uint8Array(s);
|
|
1315
1317
|
let t = "";
|
|
1316
1318
|
for (const i of e) t += String.fromCharCode(i);
|
|
1317
1319
|
return btoa(t);
|
|
1318
1320
|
}
|
|
1319
|
-
function
|
|
1321
|
+
function ee(s) {
|
|
1320
1322
|
const e = atob(s), t = new ArrayBuffer(e.length), i = new Uint8Array(t);
|
|
1321
1323
|
for (let n = 0; n < e.length; n++) i[n] = e.charCodeAt(n);
|
|
1322
1324
|
return i;
|
|
1323
1325
|
}
|
|
1324
|
-
async function
|
|
1325
|
-
const s = await
|
|
1326
|
+
async function O() {
|
|
1327
|
+
const s = await S().generateKey({ name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]);
|
|
1326
1328
|
return { publicKey: s.publicKey, privateKey: s.privateKey };
|
|
1327
1329
|
}
|
|
1328
|
-
async function
|
|
1329
|
-
return
|
|
1330
|
+
async function M(s) {
|
|
1331
|
+
return W(await S().exportKey("raw", s));
|
|
1330
1332
|
}
|
|
1331
|
-
async function
|
|
1332
|
-
return
|
|
1333
|
+
async function H(s) {
|
|
1334
|
+
return S().importKey("raw", ee(s), { name: "ECDH", namedCurve: "P-256" }, !1, []);
|
|
1333
1335
|
}
|
|
1334
|
-
async function
|
|
1335
|
-
const t = await
|
|
1336
|
-
return
|
|
1336
|
+
async function wt(s, e) {
|
|
1337
|
+
const t = await H(e);
|
|
1338
|
+
return S().deriveKey(
|
|
1337
1339
|
{ name: "ECDH", public: t },
|
|
1338
1340
|
s,
|
|
1339
1341
|
{ name: "AES-GCM", length: 256 },
|
|
@@ -1341,89 +1343,89 @@ async function xt(s, e) {
|
|
|
1341
1343
|
["encrypt", "decrypt"]
|
|
1342
1344
|
);
|
|
1343
1345
|
}
|
|
1344
|
-
async function
|
|
1345
|
-
const t = globalThis.crypto.getRandomValues(new Uint8Array(12)), i = new TextEncoder().encode(e), n = await
|
|
1346
|
-
return { ct:
|
|
1346
|
+
async function xt(s, e) {
|
|
1347
|
+
const t = globalThis.crypto.getRandomValues(new Uint8Array(12)), i = new TextEncoder().encode(e), n = await S().encrypt({ name: "AES-GCM", iv: t }, s, i);
|
|
1348
|
+
return { ct: W(n), iv: W(t) };
|
|
1347
1349
|
}
|
|
1348
1350
|
async function yt(s, e, t) {
|
|
1349
|
-
const i = await
|
|
1351
|
+
const i = await S().decrypt({ name: "AES-GCM", iv: ee(t) }, s, ee(e));
|
|
1350
1352
|
return new TextDecoder().decode(i);
|
|
1351
1353
|
}
|
|
1352
|
-
async function
|
|
1354
|
+
async function gt(s) {
|
|
1353
1355
|
var t, i;
|
|
1354
1356
|
try {
|
|
1355
1357
|
const n = (t = globalThis.localStorage) == null ? void 0 : t.getItem(s);
|
|
1356
1358
|
if (n) {
|
|
1357
|
-
const { pub: o, priv:
|
|
1358
|
-
return { publicKey: l, privateKey:
|
|
1359
|
+
const { pub: o, priv: c } = JSON.parse(n), l = await S().importKey("jwk", o, { name: "ECDH", namedCurve: "P-256" }, !0, []), x = await S().importKey("jwk", c, { name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]);
|
|
1360
|
+
return { publicKey: l, privateKey: x };
|
|
1359
1361
|
}
|
|
1360
1362
|
} catch {
|
|
1361
1363
|
}
|
|
1362
|
-
const e = await
|
|
1364
|
+
const e = await O();
|
|
1363
1365
|
try {
|
|
1364
|
-
const n = await
|
|
1366
|
+
const n = await S().exportKey("jwk", e.publicKey), o = await S().exportKey("jwk", e.privateKey);
|
|
1365
1367
|
(i = globalThis.localStorage) == null || i.setItem(s, JSON.stringify({ pub: n, priv: o }));
|
|
1366
1368
|
} catch {
|
|
1367
1369
|
}
|
|
1368
1370
|
return e;
|
|
1369
1371
|
}
|
|
1370
|
-
async function
|
|
1371
|
-
const t = await
|
|
1372
|
-
return
|
|
1372
|
+
async function bt(s, e) {
|
|
1373
|
+
const t = await S().exportKey("raw", e), i = await S().sign({ name: "ECDSA", hash: "SHA-256" }, s, t);
|
|
1374
|
+
return W(i);
|
|
1373
1375
|
}
|
|
1374
|
-
async function
|
|
1375
|
-
const s = await
|
|
1376
|
+
async function mt() {
|
|
1377
|
+
const s = await O(), e = await S().generateKey({ name: "ECDSA", namedCurve: "P-256" }, !0, ["sign", "verify"]);
|
|
1376
1378
|
return {
|
|
1377
1379
|
ecdhKP: s,
|
|
1378
1380
|
ecdsaKP: { publicKey: e.publicKey, privateKey: e.privateKey },
|
|
1379
|
-
publicKeyB64: await
|
|
1380
|
-
sigPublicKeyB64: await
|
|
1381
|
+
publicKeyB64: await M(s.publicKey),
|
|
1382
|
+
sigPublicKeyB64: await M(e.publicKey)
|
|
1381
1383
|
};
|
|
1382
1384
|
}
|
|
1383
|
-
async function
|
|
1385
|
+
async function de(s) {
|
|
1384
1386
|
var t, i;
|
|
1385
1387
|
try {
|
|
1386
1388
|
const n = (t = globalThis.localStorage) == null ? void 0 : t.getItem(`${s}-identity`);
|
|
1387
1389
|
if (n) {
|
|
1388
|
-
const o = JSON.parse(n),
|
|
1390
|
+
const o = JSON.parse(n), c = await S().importKey("jwk", o.ecdhPub, { name: "ECDH", namedCurve: "P-256" }, !0, []), l = await S().importKey("jwk", o.ecdhPriv, { name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]), x = await S().importKey("jwk", o.ecdsaPub, { name: "ECDSA", namedCurve: "P-256" }, !0, ["verify"]), f = await S().importKey("jwk", o.ecdsaPriv, { name: "ECDSA", namedCurve: "P-256" }, !0, ["sign"]);
|
|
1389
1391
|
return {
|
|
1390
|
-
ecdhKP: { publicKey:
|
|
1391
|
-
ecdsaKP: { publicKey:
|
|
1392
|
-
publicKeyB64: await
|
|
1393
|
-
sigPublicKeyB64: await
|
|
1392
|
+
ecdhKP: { publicKey: c, privateKey: l },
|
|
1393
|
+
ecdsaKP: { publicKey: x, privateKey: f },
|
|
1394
|
+
publicKeyB64: await M(c),
|
|
1395
|
+
sigPublicKeyB64: await M(x)
|
|
1394
1396
|
};
|
|
1395
1397
|
}
|
|
1396
1398
|
} catch {
|
|
1397
1399
|
}
|
|
1398
|
-
const e = await
|
|
1400
|
+
const e = await mt();
|
|
1399
1401
|
try {
|
|
1400
|
-
const n = await
|
|
1401
|
-
(i = globalThis.localStorage) == null || i.setItem(`${s}-identity`, JSON.stringify({ ecdhPub: n, ecdhPriv: o, ecdsaPub:
|
|
1402
|
+
const n = await S().exportKey("jwk", e.ecdhKP.publicKey), o = await S().exportKey("jwk", e.ecdhKP.privateKey), c = await S().exportKey("jwk", e.ecdsaKP.publicKey), l = await S().exportKey("jwk", e.ecdsaKP.privateKey);
|
|
1403
|
+
(i = globalThis.localStorage) == null || i.setItem(`${s}-identity`, JSON.stringify({ ecdhPub: n, ecdhPriv: o, ecdsaPub: c, ecdsaPriv: l }));
|
|
1402
1404
|
} catch {
|
|
1403
1405
|
}
|
|
1404
1406
|
return e;
|
|
1405
1407
|
}
|
|
1406
|
-
async function
|
|
1407
|
-
const t = await
|
|
1408
|
-
return { sharedKey: await
|
|
1408
|
+
async function vt(s, e) {
|
|
1409
|
+
const t = await O(), i = await M(t.publicKey), n = await H(e.identityKey), o = await H(e.signedPrekey), c = e.oneTimePrekey ? await H(e.oneTimePrekey) : null, l = await L(s.privateKey, o), x = await L(t.privateKey, n), f = await L(t.privateKey, o), m = c ? await L(t.privateKey, c) : null, w = we(l, x, f, ...m ? [m] : []);
|
|
1410
|
+
return { sharedKey: await xe(w), ephemeralPublicKey: i };
|
|
1409
1411
|
}
|
|
1410
|
-
async function
|
|
1411
|
-
const o = await
|
|
1412
|
-
return
|
|
1412
|
+
async function kt(s, e, t, i, n) {
|
|
1413
|
+
const o = await H(t), c = await H(i), l = await L(e.privateKey, o), x = await L(s.privateKey, c), f = await L(e.privateKey, c), m = n ? await L(n.privateKey, c) : null, w = we(l, x, f, ...m ? [m] : []);
|
|
1414
|
+
return xe(w);
|
|
1413
1415
|
}
|
|
1414
|
-
async function
|
|
1415
|
-
return
|
|
1416
|
+
async function L(s, e) {
|
|
1417
|
+
return S().deriveBits({ name: "ECDH", public: e }, s, 256);
|
|
1416
1418
|
}
|
|
1417
|
-
function
|
|
1419
|
+
function we(...s) {
|
|
1418
1420
|
const e = s.reduce((n, o) => n + o.byteLength, 0), t = new Uint8Array(e);
|
|
1419
1421
|
let i = 0;
|
|
1420
1422
|
for (const n of s)
|
|
1421
1423
|
t.set(new Uint8Array(n), i), i += n.byteLength;
|
|
1422
1424
|
return t.buffer;
|
|
1423
1425
|
}
|
|
1424
|
-
async function
|
|
1425
|
-
const e = await
|
|
1426
|
-
return
|
|
1426
|
+
async function xe(s) {
|
|
1427
|
+
const e = await S().importKey("raw", s, "HKDF", !1, ["deriveKey"]);
|
|
1428
|
+
return S().deriveKey(
|
|
1427
1429
|
{ name: "HKDF", hash: "SHA-256", salt: new Uint8Array(32), info: new TextEncoder().encode("ObjectChat X3DH v1") },
|
|
1428
1430
|
e,
|
|
1429
1431
|
{ name: "AES-GCM", length: 256 },
|
|
@@ -1431,21 +1433,21 @@ async function Se(s) {
|
|
|
1431
1433
|
["encrypt", "decrypt"]
|
|
1432
1434
|
);
|
|
1433
1435
|
}
|
|
1434
|
-
const
|
|
1436
|
+
const St = 20;
|
|
1435
1437
|
class It {
|
|
1436
1438
|
constructor(e) {
|
|
1437
1439
|
// Live ECDH mode state
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
+
r(this, "kp");
|
|
1441
|
+
r(this, "shared");
|
|
1440
1442
|
// X3DH async mode state
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1443
|
+
r(this, "identityKP");
|
|
1444
|
+
r(this, "signedPreKP");
|
|
1445
|
+
r(this, "signedPrekeyId");
|
|
1446
|
+
r(this, "otpKeys", []);
|
|
1445
1447
|
// one-time prekeys awaiting matching
|
|
1446
|
-
|
|
1448
|
+
r(this, "x3dhShared");
|
|
1447
1449
|
// Queued init messages arriving before we could derive (shouldn't happen, but safe)
|
|
1448
|
-
|
|
1450
|
+
r(this, "pendingX3DH");
|
|
1449
1451
|
this.storageKey = e;
|
|
1450
1452
|
}
|
|
1451
1453
|
get ready() {
|
|
@@ -1453,19 +1455,19 @@ class It {
|
|
|
1453
1455
|
}
|
|
1454
1456
|
/** Live ECDH mode: Generate/restore our keypair and return our public key to publish. */
|
|
1455
1457
|
async begin() {
|
|
1456
|
-
return this.kp = await
|
|
1458
|
+
return this.kp = await gt(this.storageKey), M(this.kp.publicKey);
|
|
1457
1459
|
}
|
|
1458
1460
|
/** Live ECDH mode: A peer published their key — derive the shared secret. */
|
|
1459
1461
|
async onPeerKey(e) {
|
|
1460
|
-
this.kp && (this.shared = await
|
|
1462
|
+
this.kp && (this.shared = await wt(this.kp.privateKey, e));
|
|
1461
1463
|
}
|
|
1462
1464
|
// ── X3DH async mode ────────────────────────────────────────────────────────
|
|
1463
1465
|
/** X3DH: Generate identity key, signed prekey, and OTP prekeys.
|
|
1464
1466
|
* Returns the upload frame payload the caller should send to the server. */
|
|
1465
1467
|
async initX3DH() {
|
|
1466
|
-
this.identityKP = await
|
|
1467
|
-
for (let n = 0; n <
|
|
1468
|
-
const e = await
|
|
1468
|
+
this.identityKP = await de(this.storageKey), this.signedPreKP = await O(), this.signedPrekeyId = `spk-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
1469
|
+
for (let n = 0; n < St; n++) this.otpKeys.push(await O());
|
|
1470
|
+
const e = await M(this.signedPreKP.publicKey), t = await bt(this.identityKP.ecdsaKP.privateKey, this.signedPreKP.publicKey), i = await Promise.all(this.otpKeys.map((n) => M(n.publicKey)));
|
|
1469
1471
|
return {
|
|
1470
1472
|
identityKey: this.identityKP.publicKeyB64,
|
|
1471
1473
|
signedPrekey: e,
|
|
@@ -1477,8 +1479,8 @@ class It {
|
|
|
1477
1479
|
/** X3DH sender: given a recipient's prekey bundle, derive the shared key and
|
|
1478
1480
|
* return the init message fields to embed in the first encrypted message. */
|
|
1479
1481
|
async x3dhSendTo(e) {
|
|
1480
|
-
this.identityKP || (this.identityKP = await
|
|
1481
|
-
const { sharedKey: t, ephemeralPublicKey: i } = await
|
|
1482
|
+
this.identityKP || (this.identityKP = await de(this.storageKey));
|
|
1483
|
+
const { sharedKey: t, ephemeralPublicKey: i } = await vt(this.identityKP.ecdhKP, e);
|
|
1482
1484
|
return this.x3dhShared = t, { ephemeralKey: i, spkId: e.signedPrekeyId, usedOTP: !!e.oneTimePrekey, senderIK: this.identityKP.publicKeyB64 };
|
|
1483
1485
|
}
|
|
1484
1486
|
/** X3DH recipient: given an init message's sender IK + EK + SPK ID, derive the shared key. */
|
|
@@ -1488,7 +1490,7 @@ class It {
|
|
|
1488
1490
|
return;
|
|
1489
1491
|
}
|
|
1490
1492
|
const n = this.otpKeys.shift();
|
|
1491
|
-
this.x3dhShared = await
|
|
1493
|
+
this.x3dhShared = await kt(this.identityKP.ecdhKP, this.signedPreKP, e, t, n);
|
|
1492
1494
|
}
|
|
1493
1495
|
/** Flush pending X3DH derivation after initX3DH() completes. */
|
|
1494
1496
|
async flushPendingX3DH() {
|
|
@@ -1501,7 +1503,7 @@ class It {
|
|
|
1501
1503
|
async sealText(e, t) {
|
|
1502
1504
|
const i = this.x3dhShared ?? this.shared;
|
|
1503
1505
|
if (!i) throw new Error("secure channel not ready");
|
|
1504
|
-
const { ct: n, iv: o } = await
|
|
1506
|
+
const { ct: n, iv: o } = await xt(i, e);
|
|
1505
1507
|
return {
|
|
1506
1508
|
kind: "text",
|
|
1507
1509
|
text: n,
|
|
@@ -1528,12 +1530,12 @@ class It {
|
|
|
1528
1530
|
for (const t of e.messages) t.content = await this.openContent(t.content);
|
|
1529
1531
|
}
|
|
1530
1532
|
}
|
|
1531
|
-
function
|
|
1533
|
+
function Ct(s) {
|
|
1532
1534
|
if (s.kind !== "text" || !s.enc) return null;
|
|
1533
1535
|
const e = s;
|
|
1534
1536
|
return !e.x3dhEK || !e.x3dhSPK || !e.x3dhIK ? null : { x3dhEK: e.x3dhEK, x3dhSPK: e.x3dhSPK, x3dhIK: e.x3dhIK };
|
|
1535
1537
|
}
|
|
1536
|
-
const
|
|
1538
|
+
const le = "objectchat-widget-styles", Et = ["👍", "❤️", "😂", "😮", "😢", "🙏"], Ut = `
|
|
1537
1539
|
.ocw { --ocw-accent:#f5713c; --ocw-bg:#f3efe9; --ocw-card:#fff; --ocw-line:#ececec; --ocw-ink:#1c1b1a; --ocw-mut:#9b9690;
|
|
1538
1540
|
position:relative;
|
|
1539
1541
|
display:flex; flex-direction:column; height:100%; min-height:320px; background:var(--ocw-bg);
|
|
@@ -1685,74 +1687,29 @@ const we = "objectchat-widget-styles", Ut = ["👍", "❤️", "😂", "😮", "
|
|
|
1685
1687
|
.ocw-cobrowse-clear:hover { border-color:#e74c3c; color:#e74c3c; }
|
|
1686
1688
|
.ocw-cobrowse-hint { position:absolute; bottom:8px; left:8px; z-index:41; font-size:11px; color:var(--ocw-mut); background:rgba(255,255,255,.9); border-radius:8px; padding:3px 8px; display:none; }
|
|
1687
1689
|
.ocw-cobrowse-hint.active { display:block; }
|
|
1688
|
-
|
|
1689
|
-
/* Screen A: conversation list — full widget, like WhatsApp's home screen */
|
|
1690
|
-
.ocw-screen { position:absolute; inset:0; display:flex; flex-direction:column; background:var(--ocw-bg); transition:transform .22s cubic-bezier(.4,0,.2,1); will-change:transform; }
|
|
1691
|
-
.ocw-screen-list { transform:translateX(0); z-index:10; }
|
|
1692
|
-
.ocw-screen-chat { transform:translateX(100%); z-index:20; background:var(--ocw-card); }
|
|
1693
|
-
.ocw-screen-list.hidden { transform:translateX(-30%); }
|
|
1694
|
-
.ocw-screen-chat.visible { transform:translateX(0); }
|
|
1695
|
-
/* List header */
|
|
1696
|
-
.ocw-cl-head { display:flex; align-items:center; padding:14px 16px 10px; background:var(--ocw-card); border-bottom:1px solid var(--ocw-line); gap:8px; }
|
|
1697
|
-
.ocw-cl-title { flex:1; font-size:17px; font-weight:700; color:var(--ocw-ink); }
|
|
1698
|
-
.ocw-cl-new { width:34px; height:34px; border-radius:50%; border:none; background:var(--ocw-accent); color:#fff; font-size:20px; cursor:pointer; display:flex; align-items:center; justify-content:center; flex:none; }
|
|
1699
|
-
/* Search bar */
|
|
1700
|
-
.ocw-cl-search-wrap { padding:8px 12px; background:var(--ocw-card); }
|
|
1701
|
-
.ocw-cl-search { width:100%; box-sizing:border-box; border:none; background:var(--ocw-bg); border-radius:20px; padding:8px 14px; font:inherit; font-size:14px; color:var(--ocw-ink); outline:none; }
|
|
1702
|
-
/* Section dividers: read / unread */
|
|
1703
|
-
.ocw-cl-section { padding:4px 16px 4px; font-size:11px; font-weight:700; color:var(--ocw-mut); letter-spacing:.5px; text-transform:uppercase; background:var(--ocw-bg); }
|
|
1704
|
-
/* Conversation row */
|
|
1705
|
-
.ocw-cl-row { display:flex; align-items:center; gap:12px; padding:10px 16px; background:var(--ocw-card); border:none; width:100%; text-align:left; cursor:pointer; border-bottom:1px solid var(--ocw-line); transition:background .1s; }
|
|
1706
|
-
.ocw-cl-row:hover, .ocw-cl-row:active { background:#faf8f6; }
|
|
1707
|
-
.ocw-cl-row.unread { background:var(--ocw-card); }
|
|
1708
|
-
/* Avatar circle with initial */
|
|
1709
|
-
.ocw-cl-av { width:46px; height:46px; border-radius:50%; background:var(--ocw-accent); color:#fff; font-size:18px; font-weight:700; display:flex; align-items:center; justify-content:center; flex:none; position:relative; }
|
|
1710
|
-
.ocw-cl-av img { width:100%; height:100%; border-radius:50%; object-fit:cover; }
|
|
1711
|
-
/* Status dot on avatar: green=open, grey=resolved */
|
|
1712
|
-
.ocw-cl-status { position:absolute; bottom:1px; right:1px; width:12px; height:12px; border-radius:50%; border:2px solid var(--ocw-card); background:#9b9690; }
|
|
1713
|
-
.ocw-cl-status.open { background:#22c55e; }
|
|
1714
|
-
.ocw-cl-status.waiting { background:#f59e0b; }
|
|
1715
|
-
/* Row content */
|
|
1716
|
-
.ocw-cl-body { flex:1; min-width:0; }
|
|
1717
|
-
.ocw-cl-name { font-size:15px; font-weight:600; color:var(--ocw-ink); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; margin-bottom:2px; }
|
|
1718
|
-
.ocw-cl-row.unread .ocw-cl-name { font-weight:700; }
|
|
1719
|
-
.ocw-cl-preview { font-size:13px; color:var(--ocw-mut); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
|
|
1720
|
-
.ocw-cl-row.unread .ocw-cl-preview { color:var(--ocw-ink); }
|
|
1721
|
-
/* Right side: time + unread badge */
|
|
1722
|
-
.ocw-cl-right { display:flex; flex-direction:column; align-items:flex-end; gap:4px; flex:none; }
|
|
1723
|
-
.ocw-cl-time { font-size:11px; color:var(--ocw-mut); }
|
|
1724
|
-
.ocw-cl-row.unread .ocw-cl-time { color:var(--ocw-accent); font-weight:600; }
|
|
1725
|
-
.ocw-cl-badge { background:var(--ocw-accent); color:#fff; border-radius:999px; font-size:11px; font-weight:700; min-width:20px; height:20px; padding:0 5px; display:flex; align-items:center; justify-content:center; }
|
|
1726
|
-
.ocw-cl-body-scroll { flex:1; overflow-y:auto; }
|
|
1727
|
-
/* Chat screen back button */
|
|
1728
|
-
.ocw-chat-back { background:none; border:none; cursor:pointer; font-size:22px; color:var(--ocw-ink); padding:2px 6px 2px 0; line-height:1; display:none; }
|
|
1729
|
-
.ocw-chat-back.show { display:block; }
|
|
1690
|
+
|
|
1730
1691
|
.ocw-translate-btn { position:absolute; bottom:2px; right:-26px; background:#fff; border:1px solid #e3ded7; border-radius:50%; width:22px; height:22px; font-size:11px; cursor:pointer; color:var(--ocw-mut); display:flex; align-items:center; justify-content:center; opacity:0; transition:opacity .15s; padding:0; }
|
|
1731
1692
|
.ocw-row.theirs .ocw-translate-btn { right:auto; left:-26px; }
|
|
1732
1693
|
.ocw-bubble-wrap:hover .ocw-translate-btn { opacity:1; }
|
|
1733
1694
|
.ocw-translated-tag { font-size:10px; color:var(--ocw-mut); margin-top:2px; }
|
|
1734
1695
|
`;
|
|
1735
|
-
function
|
|
1736
|
-
if (typeof document > "u" || document.getElementById(
|
|
1696
|
+
function Tt() {
|
|
1697
|
+
if (typeof document > "u" || document.getElementById(le)) return;
|
|
1737
1698
|
const s = document.createElement("style");
|
|
1738
|
-
s.id =
|
|
1699
|
+
s.id = le, s.textContent = Ut, document.head.appendChild(s);
|
|
1739
1700
|
}
|
|
1740
|
-
function
|
|
1701
|
+
function a(s, e, t) {
|
|
1741
1702
|
const i = document.createElement(s);
|
|
1742
1703
|
return e && (i.className = e), t !== void 0 && (i.textContent = t), i;
|
|
1743
1704
|
}
|
|
1744
|
-
function
|
|
1705
|
+
function Pt(s) {
|
|
1745
1706
|
try {
|
|
1746
1707
|
return new Date(s).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
|
1747
1708
|
} catch {
|
|
1748
1709
|
return "";
|
|
1749
1710
|
}
|
|
1750
1711
|
}
|
|
1751
|
-
function
|
|
1752
|
-
const e = Math.floor((Date.now() - s) / 1e3);
|
|
1753
|
-
return e < 60 ? "now" : e < 3600 ? `${Math.floor(e / 60)}m` : e < 86400 ? `${Math.floor(e / 3600)}h` : `${Math.floor(e / 86400)}d`;
|
|
1754
|
-
}
|
|
1755
|
-
function te(s) {
|
|
1712
|
+
function G(s) {
|
|
1756
1713
|
var e;
|
|
1757
1714
|
switch (s.kind) {
|
|
1758
1715
|
case "text":
|
|
@@ -1769,116 +1726,87 @@ function te(s) {
|
|
|
1769
1726
|
return `📅 ${s.title} — ${new Date(s.startIso).toLocaleString()}`;
|
|
1770
1727
|
}
|
|
1771
1728
|
}
|
|
1772
|
-
class
|
|
1729
|
+
class Bt {
|
|
1730
|
+
/** Last seq the guest has seen per conversationId — used to compute unread badges. */
|
|
1773
1731
|
constructor(e, t, i, n = {}) {
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1732
|
+
r(this, "scroll");
|
|
1733
|
+
r(this, "chips");
|
|
1734
|
+
r(this, "typing");
|
|
1735
|
+
r(this, "quick");
|
|
1736
|
+
r(this, "formHost");
|
|
1737
|
+
r(this, "csatPanel");
|
|
1738
|
+
r(this, "offlinePanel");
|
|
1739
|
+
r(this, "footer");
|
|
1740
|
+
r(this, "input");
|
|
1741
|
+
r(this, "subjectCard");
|
|
1742
|
+
r(this, "e2eBadge");
|
|
1743
|
+
r(this, "statusBadge");
|
|
1744
|
+
r(this, "headerName");
|
|
1745
|
+
r(this, "connStatus");
|
|
1746
|
+
r(this, "typingTimer", null);
|
|
1747
|
+
r(this, "csatSubmitted", !1);
|
|
1790
1748
|
// ── Co-browsing (shared whiteboard) ─────────────────────────────────────
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1749
|
+
r(this, "cobrowseBtn");
|
|
1750
|
+
r(this, "cobrowseCanvas");
|
|
1751
|
+
r(this, "cobrowseToolbar");
|
|
1752
|
+
r(this, "cobrowseHint");
|
|
1753
|
+
r(this, "cobrowseActive", !1);
|
|
1754
|
+
r(this, "cobrowseColor", "#f5713c");
|
|
1755
|
+
r(this, "lastAnnotationVersion", -1);
|
|
1756
|
+
r(this, "storeRef", null);
|
|
1757
|
+
r(this, "scrollCleanup", null);
|
|
1800
1758
|
// ── Live translation ──────────────────────────────────────────────────-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
a(
|
|
1807
|
-
a(this, "listSearch", null);
|
|
1808
|
-
a(this, "backBtn", null);
|
|
1809
|
-
a(this, "activeChatId", null);
|
|
1810
|
-
a(this, "inChatScreen", !1);
|
|
1811
|
-
a(this, "allEntries", []);
|
|
1812
|
-
/** Last seq the guest has seen per conversationId — used to compute unread badges. */
|
|
1813
|
-
a(this, "seenSeq", /* @__PURE__ */ new Map());
|
|
1814
|
-
a(this, "seenSeqKey", "");
|
|
1815
|
-
/** Fetch the list and re-render it. Called on mount and after switching chats. */
|
|
1816
|
-
a(this, "destroyed", !1);
|
|
1817
|
-
a(this, "subjectBuilt", !1);
|
|
1818
|
-
var b, v, U, A, K, P, D, _, q, X;
|
|
1819
|
-
this.root = e, this.me = t, this.h = i, this.cfg = n, Bt(), e.classList.add("ocw"), n.accent && e.style.setProperty("--ocw-accent", n.accent);
|
|
1820
|
-
const o = c("div", "ocw-head"), r = c("div", "ocw-avatar");
|
|
1759
|
+
r(this, "translationCache", /* @__PURE__ */ new Map());
|
|
1760
|
+
r(this, "showingTranslation", /* @__PURE__ */ new Set());
|
|
1761
|
+
r(this, "subjectBuilt", !1);
|
|
1762
|
+
var b, v, C, T, A, P, D, $, _;
|
|
1763
|
+
this.root = e, this.me = t, this.h = i, this.cfg = n, Tt(), e.classList.add("ocw"), n.accent && e.style.setProperty("--ocw-accent", n.accent);
|
|
1764
|
+
const o = a("div", "ocw-head"), c = a("div", "ocw-avatar");
|
|
1821
1765
|
if ((b = n.userInfo) != null && b.avatar) {
|
|
1822
1766
|
const k = document.createElement("img");
|
|
1823
|
-
k.src = n.userInfo.avatar, k.alt = n.userInfo.name ?? "You", k.style.cssText = "width:100%;height:100%;border-radius:50%;object-fit:cover",
|
|
1767
|
+
k.src = n.userInfo.avatar, k.alt = n.userInfo.name ?? "You", k.style.cssText = "width:100%;height:100%;border-radius:50%;object-fit:cover", c.append(k);
|
|
1824
1768
|
} else
|
|
1825
|
-
|
|
1826
|
-
o.append(
|
|
1827
|
-
const l =
|
|
1828
|
-
this.headerName =
|
|
1769
|
+
c.textContent = (v = n.userInfo) != null && v.name ? n.userInfo.name[0].toUpperCase() : "🧑";
|
|
1770
|
+
o.append(c);
|
|
1771
|
+
const l = a("div", "ocw-head-main");
|
|
1772
|
+
this.headerName = a("div", "ocw-head-name", ((C = n.subject) == null ? void 0 : C.ownerLabel) ?? ((T = n.subject) == null ? void 0 : T.title) ?? ""), l.append(this.headerName), (A = n.subject) != null && A.subtitle && l.append(a("div", "ocw-head-meta", n.subject.subtitle)), o.append(l), this.statusBadge = a("span", "ocw-badge", ((P = n.subject) == null ? void 0 : P.status) ?? ""), (D = n.subject) != null && D.status || (this.statusBadge.style.display = "none"), o.append(this.statusBadge), this.e2eBadge = a("span", "ocw-e2e", "🔒 E2E"), this.e2eBadge.style.display = "none", o.append(this.e2eBadge), this.connStatus = a("span", "ocw-conn-status"), this.connStatus.style.display = "none", o.append(this.connStatus), this.cobrowseBtn = a("button", "ocw-menu ocw-cobrowse-btn", "🖍"), this.cobrowseBtn.title = "Shared whiteboard — draw to point things out together", this.cobrowseBtn.addEventListener("click", () => {
|
|
1829
1773
|
this.cobrowseActive = !this.cobrowseActive, this.updateCobrowseUI();
|
|
1830
|
-
}), o.append(this.cobrowseBtn),
|
|
1831
|
-
const
|
|
1832
|
-
|
|
1774
|
+
}), o.append(this.cobrowseBtn), o.append(a("button", "ocw-menu", "⋯")), this.chips = a("div", "ocw-chiprow"), this.scroll = a("div", "ocw-scroll"), this.subjectCard = a("div", "ocw-subject"), this.typing = a("div", "ocw-typing");
|
|
1775
|
+
const x = a("div", "ocw-typing-bubble");
|
|
1776
|
+
x.append(a("div", "ocw-typing-dot"), a("div", "ocw-typing-dot"), a("div", "ocw-typing-dot")), this.typing.append(a("div", "ocw-dot", "🧑"), x), this.quick = a("div", "ocw-quick");
|
|
1833
1777
|
for (const k of n.quickReplies ?? []) {
|
|
1834
|
-
const E =
|
|
1778
|
+
const E = a("button", void 0, k);
|
|
1835
1779
|
E.addEventListener("click", () => this.h.onSend(k)), this.quick.append(E);
|
|
1836
1780
|
}
|
|
1837
|
-
this.formHost =
|
|
1838
|
-
const
|
|
1839
|
-
|
|
1781
|
+
this.formHost = a("div", "ocw-form-host"), this.csatPanel = a("div", "ocw-csat"), this.csatPanel.style.display = "none", this.offlinePanel = a("div", "ocw-offline"), this.offlinePanel.style.display = "none", this.input = a("textarea", void 0), this.input.rows = 1, this.input.placeholder = "Message…";
|
|
1782
|
+
const f = a("button", "ocw-sendbtn", (($ = n.i18n) == null ? void 0 : $.send) ?? "➤");
|
|
1783
|
+
f.addEventListener("click", () => this.flushSend()), this.input.addEventListener("keydown", (k) => {
|
|
1840
1784
|
k.isComposing || k.keyCode === 229 || (k.key === "Enter" && !k.shiftKey ? (k.preventDefault(), this.flushSend()) : this.signalTyping());
|
|
1841
1785
|
});
|
|
1842
|
-
const m =
|
|
1786
|
+
const m = a("button", "ocw-attach", "📎");
|
|
1843
1787
|
m.title = "Attach image or file";
|
|
1844
|
-
const
|
|
1845
|
-
|
|
1788
|
+
const w = document.createElement("input");
|
|
1789
|
+
w.type = "file", w.accept = "image/*,.pdf,.txt,.doc,.docx", w.style.display = "none", m.addEventListener("click", () => w.click()), w.addEventListener("change", () => {
|
|
1846
1790
|
var k;
|
|
1847
|
-
(k =
|
|
1791
|
+
(k = w.files) != null && k[0] && this.h.onAttach && this.h.onAttach(w.files[0]), w.value = "";
|
|
1848
1792
|
});
|
|
1849
|
-
const h =
|
|
1850
|
-
h.append(m,
|
|
1851
|
-
const p =
|
|
1852
|
-
|
|
1853
|
-
const k = c("div", "ocw-screen ocw-screen-list"), E = c("div", "ocw-cl-head");
|
|
1854
|
-
E.append(c("span", "ocw-cl-title", "Messages"));
|
|
1855
|
-
const S = c("button", "ocw-cl-new", "+");
|
|
1856
|
-
S.title = "New conversation", S.addEventListener("click", () => {
|
|
1857
|
-
var d, f;
|
|
1858
|
-
(f = (d = this.h).onSwitchChat) == null || f.call(d, { id: "__new__", state: "open", updatedAt: Date.now() });
|
|
1859
|
-
}), E.append(S);
|
|
1860
|
-
const Y = c("div", "ocw-cl-search-wrap"), z = c("input", "ocw-cl-search");
|
|
1861
|
-
z.placeholder = "🔍 Search", z.type = "search", z.addEventListener("input", () => this.renderListRows(this.allEntries, z.value.trim().toLowerCase())), Y.append(z);
|
|
1862
|
-
const H = c("div", "ocw-cl-body-scroll");
|
|
1863
|
-
H.append(c("div", "ocw-cl-section", "Loading…")), k.append(E, Y, H), e.append(k), this.listScreen = k, this.listBody = H, this.listSearch = z;
|
|
1864
|
-
const R = c("div", "ocw-screen ocw-screen-chat");
|
|
1865
|
-
R.append(o, this.chips, this.scroll, this.typing, this.quick, this.formHost, this.csatPanel, this.offlinePanel, h, this.footer), e.append(R), this.chatScreen = R, n.startOnChat ? (this.inChatScreen = !0, this.listScreen.classList.add("hidden"), this.chatScreen.classList.add("visible"), (X = this.backBtn) == null || X.classList.add("show")) : this.inChatScreen = !1, this.refreshList();
|
|
1866
|
-
} else
|
|
1867
|
-
e.append(o, this.chips, this.scroll, this.typing, this.quick, this.formHost, this.csatPanel, this.offlinePanel, h, this.footer);
|
|
1868
|
-
this.cobrowseCanvas = c("canvas", "ocw-cobrowse-canvas"), this.cobrowseToolbar = c("div", "ocw-cobrowse-toolbar");
|
|
1793
|
+
const h = a("div", "ocw-input");
|
|
1794
|
+
h.append(m, w, this.input, f);
|
|
1795
|
+
const p = a("div", "ocw-footer");
|
|
1796
|
+
p.innerHTML = ((_ = n.i18n) == null ? void 0 : _.poweredBy) !== void 0 ? n.i18n.poweredBy : 'Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>', this.footer = p, e.append(o, this.chips, this.scroll, this.typing, this.quick, this.formHost, this.csatPanel, this.offlinePanel, h, this.footer), this.cobrowseCanvas = a("canvas", "ocw-cobrowse-canvas"), this.cobrowseToolbar = a("div", "ocw-cobrowse-toolbar");
|
|
1869
1797
|
for (const k of ["#f5713c", "#1c1b1a", "#2563eb", "#16a34a", "#dc2626"]) {
|
|
1870
|
-
const E =
|
|
1798
|
+
const E = a("button", "ocw-cobrowse-swatch");
|
|
1871
1799
|
E.style.background = k, E.type = "button", k === this.cobrowseColor && E.classList.add("sel"), E.addEventListener("click", () => {
|
|
1872
1800
|
this.cobrowseColor = k;
|
|
1873
|
-
for (const
|
|
1801
|
+
for (const Y of this.cobrowseToolbar.querySelectorAll(".ocw-cobrowse-swatch")) Y.classList.remove("sel");
|
|
1874
1802
|
E.classList.add("sel");
|
|
1875
1803
|
}), this.cobrowseToolbar.append(E);
|
|
1876
1804
|
}
|
|
1877
|
-
const g =
|
|
1805
|
+
const g = a("button", "ocw-cobrowse-clear", "Clear");
|
|
1878
1806
|
g.addEventListener("click", () => {
|
|
1879
1807
|
var k, E;
|
|
1880
1808
|
return (E = (k = this.h).onAnnotateClear) == null ? void 0 : E.call(k);
|
|
1881
|
-
}), this.cobrowseToolbar.append(g), this.cobrowseHint =
|
|
1809
|
+
}), this.cobrowseToolbar.append(g), this.cobrowseHint = a("div", "ocw-cobrowse-hint", "🖍 Draw to point things out — visible to both sides"), e.append(this.cobrowseCanvas, this.cobrowseToolbar, this.cobrowseHint), this.bindCobrowsePointerEvents();
|
|
1882
1810
|
}
|
|
1883
1811
|
/** Returns the scroll container so history.ts can attach scroll listeners. */
|
|
1884
1812
|
getScrollEl() {
|
|
@@ -1889,98 +1817,16 @@ class Kt {
|
|
|
1889
1817
|
var t;
|
|
1890
1818
|
(t = this.scrollCleanup) == null || t.call(this), this.scrollCleanup = e;
|
|
1891
1819
|
}
|
|
1892
|
-
/**
|
|
1893
|
-
initSeenSeq(e) {
|
|
1894
|
-
this.seenSeqKey = e;
|
|
1895
|
-
try {
|
|
1896
|
-
const t = localStorage.getItem(`ocw_seen_${e}`);
|
|
1897
|
-
if (t) {
|
|
1898
|
-
const i = JSON.parse(t);
|
|
1899
|
-
for (const [n, o] of Object.entries(i)) this.seenSeq.set(n, o);
|
|
1900
|
-
}
|
|
1901
|
-
} catch {
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
setSeenSeq(e, t) {
|
|
1905
|
-
if (this.seenSeq.set(e, Math.max(this.seenSeq.get(e) ?? 0, t)), this.seenSeqKey)
|
|
1906
|
-
try {
|
|
1907
|
-
const i = {};
|
|
1908
|
-
for (const [n, o] of this.seenSeq) i[n] = o;
|
|
1909
|
-
localStorage.setItem(`ocw_seen_${this.seenSeqKey}`, JSON.stringify(i));
|
|
1910
|
-
} catch {
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
/** Call when the widget is unmounted. Disconnects scroll listeners and
|
|
1914
|
-
* prevents in-flight fetches from writing to dead DOM. */
|
|
1820
|
+
/** Call when the widget is unmounted. Disconnects scroll listeners. */
|
|
1915
1821
|
destroy() {
|
|
1916
1822
|
var e;
|
|
1917
|
-
|
|
1918
|
-
}
|
|
1919
|
-
refreshList() {
|
|
1920
|
-
var e, t;
|
|
1921
|
-
!this.listBody || this.destroyed || (t = (e = this.h).onListChats) == null || t.call(e).then((i) => {
|
|
1922
|
-
var n;
|
|
1923
|
-
this.destroyed || (this.allEntries = i, this.renderListRows(i, ((n = this.listSearch) == null ? void 0 : n.value.trim().toLowerCase()) ?? ""));
|
|
1924
|
-
}).catch(() => {
|
|
1925
|
-
var i;
|
|
1926
|
-
this.destroyed || (i = this.listBody) == null || i.replaceChildren(c("div", "ocw-cl-section", "Could not load conversations."));
|
|
1927
|
-
});
|
|
1823
|
+
(e = this.scrollCleanup) == null || e.call(this), this.scrollCleanup = null;
|
|
1928
1824
|
}
|
|
1929
1825
|
/** Render list rows, optionally filtered by search query. */
|
|
1930
|
-
renderListRows(e, t) {
|
|
1931
|
-
if (!this.listBody) return;
|
|
1932
|
-
const i = t ? e.filter((r) => (r.subjectTitle ?? "General enquiry").toLowerCase().includes(t) || r.state.includes(t)) : e;
|
|
1933
|
-
if (!i.length) {
|
|
1934
|
-
this.listBody.replaceChildren(c("div", "ocw-cl-section", t ? "No results." : "No conversations yet."));
|
|
1935
|
-
return;
|
|
1936
|
-
}
|
|
1937
|
-
const n = i.filter((r) => this.isUnread(r)).sort((r, l) => l.updatedAt - r.updatedAt), o = i.filter((r) => !this.isUnread(r)).sort((r, l) => l.updatedAt - r.updatedAt);
|
|
1938
|
-
if (this.listBody.replaceChildren(), n.length) {
|
|
1939
|
-
this.listBody.append(c("div", "ocw-cl-section", `Unread (${n.length})`));
|
|
1940
|
-
for (const r of n) this.listBody.append(this.buildRow(r));
|
|
1941
|
-
}
|
|
1942
|
-
if (o.length) {
|
|
1943
|
-
this.listBody.append(c("div", "ocw-cl-section", n.length ? "Read" : "All conversations"));
|
|
1944
|
-
for (const r of o) this.listBody.append(this.buildRow(r));
|
|
1945
|
-
}
|
|
1946
|
-
}
|
|
1947
|
-
isUnread(e) {
|
|
1948
|
-
return e.id === this.activeChatId ? !1 : (e.lastSeq ?? 0) > (this.seenSeq.get(e.id) ?? 0);
|
|
1949
|
-
}
|
|
1950
1826
|
/** Build a single WhatsApp-style conversation row. */
|
|
1951
|
-
buildRow(e) {
|
|
1952
|
-
var g;
|
|
1953
|
-
const t = this.seenSeq.get(e.id) ?? 0, i = e.lastSeq ?? 0, n = this.isUnread(e) ? Math.max(1, i - t) : 0, o = e.subjectTitle ?? "General enquiry", r = ((g = o[0]) == null ? void 0 : g.toUpperCase()) ?? "?", l = c("button", `ocw-cl-row${n > 0 ? " unread" : ""}`), w = c("div", "ocw-cl-av", r), u = c("div", "ocw-cl-status");
|
|
1954
|
-
e.state === "open" ? u.classList.add("open") : e.state === "awaiting_staff" && u.classList.add("waiting"), w.append(u), l.append(w);
|
|
1955
|
-
const m = c("div", "ocw-cl-body");
|
|
1956
|
-
m.append(c("div", "ocw-cl-name", o));
|
|
1957
|
-
const x = {
|
|
1958
|
-
open: "Conversation open",
|
|
1959
|
-
awaiting_staff: "Waiting for reply…",
|
|
1960
|
-
resolved: "Conversation resolved ✓",
|
|
1961
|
-
closed: "Conversation closed"
|
|
1962
|
-
}, h = e.lastMessage ?? x[e.state] ?? e.state;
|
|
1963
|
-
m.append(c("div", "ocw-cl-preview", h)), l.append(m);
|
|
1964
|
-
const p = c("div", "ocw-cl-right");
|
|
1965
|
-
return p.append(c("div", "ocw-cl-time", Pt(e.updatedAt))), n > 0 && p.append(c("div", "ocw-cl-badge", String(n > 99 ? "99+" : n))), l.append(p), l.addEventListener("click", () => {
|
|
1966
|
-
var b, v;
|
|
1967
|
-
i > 0 && this.seenSeq.set(e.id, i), this.activeChatId = e.id, this.showChatScreen(), (v = (b = this.h).onSwitchChat) == null || v.call(b, e);
|
|
1968
|
-
}), l;
|
|
1969
|
-
}
|
|
1970
1827
|
/** Returns true when the chat screen is visible (not the list). */
|
|
1971
|
-
isInChatScreen() {
|
|
1972
|
-
return this.inChatScreen;
|
|
1973
|
-
}
|
|
1974
1828
|
/** Navigate to the chat screen (slide list left, slide chat in from right). */
|
|
1975
|
-
showChatScreen() {
|
|
1976
|
-
var e, t, i;
|
|
1977
|
-
this.inChatScreen || (this.inChatScreen = !0, (e = this.listScreen) == null || e.classList.add("hidden"), (t = this.chatScreen) == null || t.classList.add("visible"), (i = this.backBtn) == null || i.classList.add("show"));
|
|
1978
|
-
}
|
|
1979
1829
|
/** Navigate back to the list screen. */
|
|
1980
|
-
showListScreen() {
|
|
1981
|
-
var e, t, i;
|
|
1982
|
-
this.inChatScreen && (this.inChatScreen = !1, (e = this.listScreen) == null || e.classList.remove("hidden"), (t = this.chatScreen) == null || t.classList.remove("visible"), (i = this.backBtn) == null || i.classList.remove("show"), this.refreshList());
|
|
1983
|
-
}
|
|
1984
1830
|
flushSend() {
|
|
1985
1831
|
const e = this.input.value.trim();
|
|
1986
1832
|
e && (this.input.value = "", this.h.onTyping(!1), this.h.onSend(e));
|
|
@@ -1989,9 +1835,9 @@ class Kt {
|
|
|
1989
1835
|
this.h.onTyping(!0), this.typingTimer && clearTimeout(this.typingTimer), this.typingTimer = setTimeout(() => this.h.onTyping(!1), 2e3);
|
|
1990
1836
|
}
|
|
1991
1837
|
render(e) {
|
|
1992
|
-
var
|
|
1838
|
+
var f, m, w;
|
|
1993
1839
|
if (this.storeRef = e, this.cobrowseBtn.classList.toggle("show", !!e.subject), !e.subject && this.cobrowseActive && (this.cobrowseActive = !1, this.updateCobrowseUI()), this.cobrowseActive && e.annotationVersion !== this.lastAnnotationVersion && (this.lastAnnotationVersion = e.annotationVersion, this.resizeCobrowseCanvas(), this.redrawCobrowse()), e.accent && this.root.style.setProperty("--ocw-accent", e.accent), this.e2eBadge.style.display = e.e2e ? "inline-flex" : "none", this.buildSubjectCard(e), e.subject) {
|
|
1994
|
-
const h = (
|
|
1840
|
+
const h = (f = this.cfg.subject) == null ? void 0 : f.ownerLabel;
|
|
1995
1841
|
h && (this.headerName.textContent = h);
|
|
1996
1842
|
}
|
|
1997
1843
|
this.chips.replaceChildren();
|
|
@@ -2000,19 +1846,19 @@ class Kt {
|
|
|
2000
1846
|
for (const h of t) this.chips.append(this.chipEl(h));
|
|
2001
1847
|
const i = this.scroll.scrollHeight, n = this.scroll.scrollTop;
|
|
2002
1848
|
if (this.scroll.replaceChildren(), this.subjectCard.childNodes.length && this.scroll.append(this.subjectCard), e.hasMoreHistory) {
|
|
2003
|
-
const h =
|
|
1849
|
+
const h = a("div", "ocw-load-more");
|
|
2004
1850
|
h.textContent = "↑ Loading earlier messages…", h.style.pointerEvents = "none", this.scroll.append(h);
|
|
2005
1851
|
}
|
|
2006
1852
|
let o = 0;
|
|
2007
1853
|
for (const h of e.messages())
|
|
2008
1854
|
this.scroll.append(this.messageEl(h, e)), h.senderId !== this.me && h.seq > o && (o = h.seq);
|
|
2009
1855
|
n > 20 ? this.scroll.scrollTop = this.scroll.scrollHeight - i + n : this.scroll.scrollTop = this.scroll.scrollHeight, o > 0 && this.h.onReadUpTo(o);
|
|
2010
|
-
const
|
|
2011
|
-
this.typing.classList.toggle("active",
|
|
1856
|
+
const c = [...e.typing];
|
|
1857
|
+
this.typing.classList.toggle("active", c.length > 0);
|
|
2012
1858
|
const l = this.typing.querySelector(".ocw-typing-bubble");
|
|
2013
|
-
l && l.setAttribute("aria-label",
|
|
2014
|
-
const
|
|
2015
|
-
this.h.onCsat && !this.csatSubmitted &&
|
|
1859
|
+
l && l.setAttribute("aria-label", c.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block", e.offline ? (this.offlinePanel.style.display === "none" && this.buildOfflinePanel(e.offlineMessage), this.offlinePanel.style.display = "block", (m = this.root.querySelector(".ocw-input")) == null || m.style.setProperty("display", "none")) : (this.offlinePanel.style.display = "none", (w = this.root.querySelector(".ocw-input")) == null || w.style.removeProperty("display"));
|
|
1860
|
+
const x = ["resolved", "closed", "sold", "issued", "checked_out"];
|
|
1861
|
+
this.h.onCsat && !this.csatSubmitted && x.includes(e.state) && e.messages().length > 0 && (this.csatPanel.style.display === "none" && this.buildCsatPanel(), this.csatPanel.style.display = "block");
|
|
2016
1862
|
}
|
|
2017
1863
|
setConnStatus(e) {
|
|
2018
1864
|
if (e === "open") {
|
|
@@ -2023,29 +1869,29 @@ class Kt {
|
|
|
2023
1869
|
}
|
|
2024
1870
|
buildOfflinePanel(e) {
|
|
2025
1871
|
var l;
|
|
2026
|
-
this.offlinePanel.replaceChildren(), this.offlinePanel.append(
|
|
2027
|
-
const t =
|
|
1872
|
+
this.offlinePanel.replaceChildren(), this.offlinePanel.append(a("div", "ocw-offline-icon", "🌙")), this.offlinePanel.append(a("div", "ocw-offline-title", ((l = this.cfg.i18n) == null ? void 0 : l.offline) ?? "We're offline right now")), this.offlinePanel.append(a("div", "ocw-offline-msg", e || "Leave your details and we'll get back to you soon."));
|
|
1873
|
+
const t = a("div", "ocw-offline-form"), i = a("input", "ocw-offline-input");
|
|
2028
1874
|
i.placeholder = "Your name", i.type = "text";
|
|
2029
|
-
const n =
|
|
1875
|
+
const n = a("input", "ocw-offline-input");
|
|
2030
1876
|
n.placeholder = "Your email", n.type = "email";
|
|
2031
|
-
const o =
|
|
1877
|
+
const o = a("textarea", "ocw-offline-input");
|
|
2032
1878
|
o.placeholder = "Your message", o.rows = 3;
|
|
2033
|
-
const
|
|
2034
|
-
|
|
1879
|
+
const c = a("button", "ocw-offline-submit", "Send message");
|
|
1880
|
+
c.addEventListener("click", () => {
|
|
2035
1881
|
!n.value.trim() || !o.value.trim() || (this.h.onSend(`[Offline form]
|
|
2036
1882
|
Name: ${i.value || "Anonymous"}
|
|
2037
1883
|
Email: ${n.value}
|
|
2038
|
-
Message: ${o.value}`), this.offlinePanel.replaceChildren(
|
|
2039
|
-
}), t.append(i, n, o,
|
|
1884
|
+
Message: ${o.value}`), this.offlinePanel.replaceChildren(a("div", "ocw-offline-thanks", "✓ Message sent! We'll reply to your email.")));
|
|
1885
|
+
}), t.append(i, n, o, c), this.offlinePanel.append(t);
|
|
2040
1886
|
}
|
|
2041
1887
|
buildCsatPanel() {
|
|
2042
|
-
this.csatPanel.replaceChildren(), this.csatPanel.append(
|
|
2043
|
-
const e =
|
|
1888
|
+
this.csatPanel.replaceChildren(), this.csatPanel.append(a("div", "ocw-csat-title", "How did we do?"));
|
|
1889
|
+
const e = a("div", "ocw-csat-stars"), t = [];
|
|
2044
1890
|
for (let i = 1; i <= 5; i++) {
|
|
2045
|
-
const n =
|
|
2046
|
-
n.dataset.score = String(i), n.addEventListener("mouseenter", () => t.forEach((o,
|
|
2047
|
-
var o,
|
|
2048
|
-
this.csatSubmitted = !0, this.csatPanel.replaceChildren(
|
|
1891
|
+
const n = a("button", "ocw-csat-star", "★");
|
|
1892
|
+
n.dataset.score = String(i), n.addEventListener("mouseenter", () => t.forEach((o, c) => o.classList.toggle("lit", c < i))), n.addEventListener("mouseleave", () => t.forEach((o) => o.classList.remove("lit"))), n.addEventListener("click", () => {
|
|
1893
|
+
var o, c;
|
|
1894
|
+
this.csatSubmitted = !0, this.csatPanel.replaceChildren(a("div", "ocw-csat-done", `Thanks for your ${i}★ rating!`)), (c = (o = this.h).onCsat) == null || c.call(o, i);
|
|
2049
1895
|
}), t.push(n), e.append(n);
|
|
2050
1896
|
}
|
|
2051
1897
|
this.csatPanel.append(e);
|
|
@@ -2079,21 +1925,21 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(c("div", "ocw-offline-t
|
|
|
2079
1925
|
}
|
|
2080
1926
|
bindCobrowsePointerEvents() {
|
|
2081
1927
|
let e = !1, t = [];
|
|
2082
|
-
const i = (
|
|
2083
|
-
const l = this.cobrowseCanvas.getBoundingClientRect(),
|
|
2084
|
-
return { x: Math.min(1, Math.max(0,
|
|
1928
|
+
const i = (c) => {
|
|
1929
|
+
const l = this.cobrowseCanvas.getBoundingClientRect(), x = l.width > 0 ? (c.clientX - l.left) / l.width : 0, f = l.height > 0 ? (c.clientY - l.top) / l.height : 0;
|
|
1930
|
+
return { x: Math.min(1, Math.max(0, x)), y: Math.min(1, Math.max(0, f)) };
|
|
2085
1931
|
}, n = 6e-3;
|
|
2086
|
-
this.cobrowseCanvas.addEventListener("pointerdown", (
|
|
2087
|
-
this.cobrowseActive && (e = !0, t = [i(
|
|
2088
|
-
}), this.cobrowseCanvas.addEventListener("pointermove", (
|
|
2089
|
-
e && (t.push(i(
|
|
1932
|
+
this.cobrowseCanvas.addEventListener("pointerdown", (c) => {
|
|
1933
|
+
this.cobrowseActive && (e = !0, t = [i(c)], this.cobrowseCanvas.setPointerCapture(c.pointerId));
|
|
1934
|
+
}), this.cobrowseCanvas.addEventListener("pointermove", (c) => {
|
|
1935
|
+
e && (t.push(i(c)), this.redrawCobrowse(), this.drawStroke({ points: t, color: this.cobrowseColor, width: n }));
|
|
2090
1936
|
});
|
|
2091
|
-
const o = (
|
|
2092
|
-
var l,
|
|
1937
|
+
const o = (c) => {
|
|
1938
|
+
var l, x;
|
|
2093
1939
|
if (e) {
|
|
2094
|
-
e = !1, t.length > 1 && ((
|
|
1940
|
+
e = !1, t.length > 1 && ((x = (l = this.h).onAnnotate) == null || x.call(l, { id: `an_${Date.now()}_${Math.random().toString(36).slice(2)}`, points: t, color: this.cobrowseColor, width: n })), t = [];
|
|
2095
1941
|
try {
|
|
2096
|
-
this.cobrowseCanvas.releasePointerCapture(
|
|
1942
|
+
this.cobrowseCanvas.releasePointerCapture(c.pointerId);
|
|
2097
1943
|
} catch {
|
|
2098
1944
|
}
|
|
2099
1945
|
}
|
|
@@ -2104,16 +1950,16 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(c("div", "ocw-offline-t
|
|
|
2104
1950
|
if (this.subjectBuilt) return;
|
|
2105
1951
|
const t = e.subject, i = this.cfg.subject, n = (t == null ? void 0 : t.title) ?? (i == null ? void 0 : i.title);
|
|
2106
1952
|
if (!n) return;
|
|
2107
|
-
this.subjectBuilt = !0, this.subjectCard.replaceChildren(), this.subjectCard.append(
|
|
2108
|
-
const o =
|
|
2109
|
-
if (t) for (const [l,
|
|
2110
|
-
else for (const l of (i == null ? void 0 : i.tags) ?? []) o.append(
|
|
1953
|
+
this.subjectBuilt = !0, this.subjectCard.replaceChildren(), this.subjectCard.append(a("div", "ocw-subject-title", n)), i != null && i.subtitle && this.subjectCard.append(a("div", "ocw-subject-sub", i.subtitle));
|
|
1954
|
+
const o = a("div", "ocw-tags");
|
|
1955
|
+
if (t) for (const [l, x] of Object.entries(t.fields)) o.append(a("span", "ocw-tag", `${l}: ${x}`));
|
|
1956
|
+
else for (const l of (i == null ? void 0 : i.tags) ?? []) o.append(a("span", "ocw-tag", l));
|
|
2111
1957
|
o.childNodes.length && this.subjectCard.append(o);
|
|
2112
|
-
const
|
|
2113
|
-
|
|
1958
|
+
const c = (t == null ? void 0 : t.state) ?? (i == null ? void 0 : i.status);
|
|
1959
|
+
c && (this.statusBadge.textContent = c, this.statusBadge.style.display = "inline-flex");
|
|
2114
1960
|
}
|
|
2115
1961
|
chipEl(e) {
|
|
2116
|
-
const t =
|
|
1962
|
+
const t = a("button", "ocw-chip", e.icon ? `${e.icon} ${e.label}` : e.label);
|
|
2117
1963
|
return t.dataset.actionId = e.id, t.addEventListener("click", async () => {
|
|
2118
1964
|
var i;
|
|
2119
1965
|
e.confirm && !await this.confirm(e.label) || ((i = e.input) != null && i.length ? this.openForm(e) : this.h.onInvoke(e.id));
|
|
@@ -2122,99 +1968,99 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(c("div", "ocw-offline-t
|
|
|
2122
1968
|
/** In-widget confirmation modal (replaces window.confirm). */
|
|
2123
1969
|
confirm(e) {
|
|
2124
1970
|
return new Promise((t) => {
|
|
2125
|
-
const i =
|
|
2126
|
-
n.append(
|
|
2127
|
-
const o =
|
|
2128
|
-
i.remove(), t(
|
|
1971
|
+
const i = a("div", "ocw-modal"), n = a("div", "ocw-modal-card");
|
|
1972
|
+
n.append(a("div", "ocw-modal-title", e)), n.append(a("div", "ocw-modal-body", `Confirm “${e}”?`));
|
|
1973
|
+
const o = a("div", "ocw-modal-actions"), c = a("button", "ocw-modal-cancel", "Cancel"), l = a("button", "ocw-modal-ok", "Confirm"), x = (f) => {
|
|
1974
|
+
i.remove(), t(f);
|
|
2129
1975
|
};
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
}), o.append(
|
|
1976
|
+
c.addEventListener("click", () => x(!1)), l.addEventListener("click", () => x(!0)), i.addEventListener("click", (f) => {
|
|
1977
|
+
f.target === i && x(!1);
|
|
1978
|
+
}), o.append(c, l), n.append(o), i.append(n), this.root.append(i), l.focus();
|
|
2133
1979
|
});
|
|
2134
1980
|
}
|
|
2135
1981
|
/** Inline form for a form-effect action: typed inputs (date picker, number,
|
|
2136
1982
|
* text) rendered above the composer — no browser prompts. */
|
|
2137
1983
|
openForm(e) {
|
|
2138
|
-
var l,
|
|
1984
|
+
var l, x;
|
|
2139
1985
|
this.formHost.replaceChildren();
|
|
2140
|
-
const t =
|
|
2141
|
-
t.append(
|
|
1986
|
+
const t = a("div", "ocw-form");
|
|
1987
|
+
t.append(a("div", "ocw-form-title", e.icon ? `${e.icon} ${e.label}` : e.label));
|
|
2142
1988
|
const i = /* @__PURE__ */ new Map();
|
|
2143
|
-
for (const
|
|
2144
|
-
const m =
|
|
2145
|
-
if (m.append(
|
|
2146
|
-
const
|
|
2147
|
-
|
|
2148
|
-
for (const h of
|
|
2149
|
-
const p =
|
|
2150
|
-
p.value = h, p.textContent = h,
|
|
1989
|
+
for (const f of e.input ?? []) {
|
|
1990
|
+
const m = a("label", "ocw-form-row");
|
|
1991
|
+
if (m.append(a("span", "ocw-form-lbl", f.label)), f.type === "select" && ((l = f.options) != null && l.length)) {
|
|
1992
|
+
const w = a("select", "ocw-form-input");
|
|
1993
|
+
f.required || w.append(a("option", void 0, "— select —"));
|
|
1994
|
+
for (const h of f.options) {
|
|
1995
|
+
const p = a("option");
|
|
1996
|
+
p.value = h, p.textContent = h, w.append(p);
|
|
2151
1997
|
}
|
|
2152
|
-
|
|
1998
|
+
f.required && (w.required = !0), m.append(w), i.set(f.name, w);
|
|
2153
1999
|
} else {
|
|
2154
|
-
const
|
|
2155
|
-
|
|
2000
|
+
const w = a("input", "ocw-form-input");
|
|
2001
|
+
w.type = f.type === "number" ? "number" : f.type === "date" ? "datetime-local" : "text", f.required && (w.required = !0), m.append(w), i.set(f.name, w);
|
|
2156
2002
|
}
|
|
2157
2003
|
t.append(m);
|
|
2158
2004
|
}
|
|
2159
|
-
const n =
|
|
2160
|
-
o.addEventListener("click", () => this.formHost.replaceChildren()),
|
|
2161
|
-
const
|
|
2162
|
-
for (const [m,
|
|
2163
|
-
if (
|
|
2164
|
-
|
|
2005
|
+
const n = a("div", "ocw-form-actions"), o = a("button", "ocw-form-cancel", "Cancel"), c = a("button", "ocw-form-submit", "Send");
|
|
2006
|
+
o.addEventListener("click", () => this.formHost.replaceChildren()), c.addEventListener("click", () => {
|
|
2007
|
+
const f = {};
|
|
2008
|
+
for (const [m, w] of i) {
|
|
2009
|
+
if (w.required && !w.value) {
|
|
2010
|
+
w.style.borderColor = "#e5484d";
|
|
2165
2011
|
return;
|
|
2166
2012
|
}
|
|
2167
|
-
|
|
2013
|
+
f[m] = w.type === "number" ? Number(w.value) : w.value;
|
|
2168
2014
|
}
|
|
2169
|
-
this.formHost.replaceChildren(), this.h.onInvoke(e.id,
|
|
2170
|
-
}), n.append(o,
|
|
2015
|
+
this.formHost.replaceChildren(), this.h.onInvoke(e.id, f);
|
|
2016
|
+
}), n.append(o, c), t.append(n), this.formHost.append(t), (x = i.values().next().value) == null || x.focus();
|
|
2171
2017
|
}
|
|
2172
2018
|
messageEl(e, t) {
|
|
2173
|
-
var
|
|
2019
|
+
var w;
|
|
2174
2020
|
if (e.senderRole === "system") {
|
|
2175
|
-
const h =
|
|
2176
|
-
return h.textContent = e.deletedAt ? "message deleted" :
|
|
2021
|
+
const h = a("div", "ocw-sys");
|
|
2022
|
+
return h.textContent = e.deletedAt ? "message deleted" : G(e.content), h;
|
|
2177
2023
|
}
|
|
2178
|
-
const i = e.senderId === this.me, n = !!e.internal, o =
|
|
2179
|
-
!i && !n && o.append(
|
|
2180
|
-
const
|
|
2024
|
+
const i = e.senderId === this.me, n = !!e.internal, o = a("div", `ocw-row ${n ? "ocw-note mine" : i ? "mine" : "theirs"} ${e.senderRole === "bot" ? "ocw-bot" : ""}`);
|
|
2025
|
+
!i && !n && o.append(a("div", "ocw-dot", e.senderRole === "bot" ? "🤖" : "🧑"));
|
|
2026
|
+
const c = a("div"), l = a("div", "ocw-bubble-wrap");
|
|
2181
2027
|
if (e.replyToId) {
|
|
2182
|
-
const h =
|
|
2183
|
-
h.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic",
|
|
2028
|
+
const h = a("div", "ocw-reply-to", "↩ replying to a message");
|
|
2029
|
+
h.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic", c.append(h);
|
|
2184
2030
|
}
|
|
2185
|
-
const
|
|
2186
|
-
let
|
|
2187
|
-
if (e.deletedAt)
|
|
2031
|
+
const x = a("div", "ocw-bubble");
|
|
2032
|
+
let f = null;
|
|
2033
|
+
if (e.deletedAt) x.append(a("span", "ocw-deleted", "message deleted"));
|
|
2188
2034
|
else if (e.content.kind === "attachment") {
|
|
2189
2035
|
const h = e.content;
|
|
2190
|
-
if ((
|
|
2036
|
+
if ((w = h.mime) != null && w.startsWith("image/")) {
|
|
2191
2037
|
const p = document.createElement("img");
|
|
2192
|
-
p.src = h.url, p.alt = h.name ?? "image", p.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", p.addEventListener("click", () => window.open(h.url, "_blank")),
|
|
2038
|
+
p.src = h.url, p.alt = h.name ?? "image", p.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", p.addEventListener("click", () => window.open(h.url, "_blank")), x.append(p);
|
|
2193
2039
|
} else {
|
|
2194
2040
|
const p = document.createElement("a");
|
|
2195
|
-
p.href = h.url, p.target = "_blank", p.rel = "noopener", p.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", p.append(
|
|
2041
|
+
p.href = h.url, p.target = "_blank", p.rel = "noopener", p.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", p.append(a("span", void 0, "📄"), a("span", void 0, h.name ?? "file")), x.append(p);
|
|
2196
2042
|
}
|
|
2197
2043
|
} else if (e.content.kind === "appointment") {
|
|
2198
|
-
const h = e.content, p =
|
|
2199
|
-
p.append(
|
|
2200
|
-
const g =
|
|
2044
|
+
const h = e.content, p = a("div", "ocw-appt");
|
|
2045
|
+
p.append(a("div", "ocw-appt-title", `📅 ${h.title}`)), p.append(a("div", "ocw-appt-time", new Date(h.startIso).toLocaleString() + " – " + new Date(h.endIso).toLocaleTimeString())), h.location && p.append(a("div", "ocw-appt-loc", `📍 ${h.location}`)), h.description && p.append(a("div", "ocw-appt-desc", h.description));
|
|
2046
|
+
const g = a("div", "ocw-appt-links"), b = document.createElement("a");
|
|
2201
2047
|
b.href = h.googleUrl, b.target = "_blank", b.rel = "noopener", b.className = "ocw-appt-btn", b.textContent = "📅 Add to Google Calendar";
|
|
2202
2048
|
const v = document.createElement("a");
|
|
2203
|
-
v.href = h.icalUrl, v.download = `${h.title}.ics`, v.className = "ocw-appt-btn ocw-appt-btn-sec", v.textContent = "🍎 Apple / iCal", g.append(b, v), p.append(g),
|
|
2049
|
+
v.href = h.icalUrl, v.download = `${h.title}.ics`, v.className = "ocw-appt-btn ocw-appt-btn-sec", v.textContent = "🍎 Apple / iCal", g.append(b, v), p.append(g), x.append(p);
|
|
2204
2050
|
} else
|
|
2205
|
-
|
|
2206
|
-
if (l.append(
|
|
2051
|
+
f = document.createTextNode(G(e.content)), x.append(f), e.editedAt && x.append(a("span", "ocw-edited", "(edited)"));
|
|
2052
|
+
if (l.append(x), !i && !n && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && f) {
|
|
2207
2053
|
const h = e.content.text;
|
|
2208
2054
|
if (h.trim()) {
|
|
2209
|
-
const p =
|
|
2055
|
+
const p = a("button", "ocw-translate-btn", "🌐");
|
|
2210
2056
|
p.type = "button", p.title = "Translate", p.addEventListener("click", (g) => {
|
|
2211
2057
|
if (g.stopPropagation(), this.showingTranslation.has(e.id)) {
|
|
2212
|
-
this.showingTranslation.delete(e.id),
|
|
2058
|
+
this.showingTranslation.delete(e.id), f.textContent = h, p.textContent = "🌐", p.title = "Translate";
|
|
2213
2059
|
return;
|
|
2214
2060
|
}
|
|
2215
2061
|
const b = this.translationCache.get(e.id);
|
|
2216
2062
|
if (b !== void 0) {
|
|
2217
|
-
this.showingTranslation.add(e.id),
|
|
2063
|
+
this.showingTranslation.add(e.id), f.textContent = b, p.textContent = "↩", p.title = "Show original";
|
|
2218
2064
|
return;
|
|
2219
2065
|
}
|
|
2220
2066
|
p.textContent = "⏳", this.h.onTranslate(h).then((v) => {
|
|
@@ -2224,64 +2070,64 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(c("div", "ocw-offline-t
|
|
|
2224
2070
|
}, 1500);
|
|
2225
2071
|
return;
|
|
2226
2072
|
}
|
|
2227
|
-
this.translationCache.set(e.id, v), this.showingTranslation.add(e.id),
|
|
2073
|
+
this.translationCache.set(e.id, v), this.showingTranslation.add(e.id), f.textContent = v, p.textContent = "↩", p.title = "Show original";
|
|
2228
2074
|
});
|
|
2229
2075
|
}), l.append(p);
|
|
2230
2076
|
}
|
|
2231
2077
|
}
|
|
2232
2078
|
if (i && !e.deletedAt && e.seq > 0 && (this.h.onEdit ?? this.h.onDelete)) {
|
|
2233
|
-
const h =
|
|
2079
|
+
const h = a("div", "ocw-msg-menu");
|
|
2234
2080
|
if (this.h.onEdit) {
|
|
2235
|
-
const p =
|
|
2081
|
+
const p = a("button", void 0, "✏️");
|
|
2236
2082
|
p.title = "Edit", p.addEventListener("click", (g) => {
|
|
2237
2083
|
g.stopPropagation();
|
|
2238
|
-
const b =
|
|
2084
|
+
const b = G(e.content), v = prompt("Edit message:", b);
|
|
2239
2085
|
v !== null && v.trim() && v !== b && this.h.onEdit(e.id, v.trim());
|
|
2240
2086
|
}), h.append(p);
|
|
2241
2087
|
}
|
|
2242
2088
|
if (this.h.onDelete) {
|
|
2243
|
-
const p =
|
|
2089
|
+
const p = a("button", "del", "🗑");
|
|
2244
2090
|
p.title = "Delete", p.addEventListener("click", (g) => {
|
|
2245
2091
|
g.stopPropagation(), this.h.onDelete(e.id);
|
|
2246
2092
|
}), h.append(p);
|
|
2247
2093
|
}
|
|
2248
2094
|
l.append(h);
|
|
2249
2095
|
}
|
|
2250
|
-
if (
|
|
2251
|
-
const h =
|
|
2096
|
+
if (c.append(l), this.h.onReact && !e.deletedAt && e.seq > 0) {
|
|
2097
|
+
const h = a("div", "ocw-react-wrap"), p = a("div", "ocw-react");
|
|
2252
2098
|
if (e.reactions && Object.keys(e.reactions).length)
|
|
2253
|
-
for (const [v,
|
|
2254
|
-
const
|
|
2255
|
-
|
|
2256
|
-
var
|
|
2257
|
-
return (P = (
|
|
2258
|
-
}), p.append(
|
|
2099
|
+
for (const [v, C] of Object.entries(e.reactions)) {
|
|
2100
|
+
const T = a("button", `ocw-react-pill${C.includes(this.me) ? " mine" : ""}`, `${v} ${C.length}`);
|
|
2101
|
+
T.addEventListener("click", () => {
|
|
2102
|
+
var A, P;
|
|
2103
|
+
return (P = (A = this.h).onReact) == null ? void 0 : P.call(A, e.id, v, C.includes(this.me));
|
|
2104
|
+
}), p.append(T);
|
|
2259
2105
|
}
|
|
2260
|
-
const g =
|
|
2261
|
-
for (const v of
|
|
2262
|
-
const
|
|
2263
|
-
|
|
2264
|
-
var P, D, _
|
|
2265
|
-
|
|
2266
|
-
const
|
|
2267
|
-
(
|
|
2268
|
-
}), b.append(
|
|
2106
|
+
const g = a("button", "ocw-react-btn", "+"), b = a("div", "ocw-react-picker");
|
|
2107
|
+
for (const v of Et) {
|
|
2108
|
+
const C = a("button", void 0, v);
|
|
2109
|
+
C.addEventListener("click", (T) => {
|
|
2110
|
+
var P, D, $, _;
|
|
2111
|
+
T.stopPropagation();
|
|
2112
|
+
const A = (D = (P = e.reactions) == null ? void 0 : P[v]) == null ? void 0 : D.includes(this.me);
|
|
2113
|
+
(_ = ($ = this.h).onReact) == null || _.call($, e.id, v, !!A), b.style.display = "none";
|
|
2114
|
+
}), b.append(C);
|
|
2269
2115
|
}
|
|
2270
2116
|
b.style.display = "none", g.addEventListener("click", (v) => {
|
|
2271
2117
|
v.stopPropagation(), b.style.display = b.style.display === "none" ? "flex" : "none";
|
|
2272
2118
|
}), document.addEventListener("click", () => {
|
|
2273
2119
|
b.style.display = "none";
|
|
2274
|
-
}, { once: !0 }), p.append(g), h.append(p, b),
|
|
2275
|
-
} else e.reactions && Object.keys(e.reactions).length &&
|
|
2276
|
-
const m =
|
|
2120
|
+
}, { once: !0 }), p.append(g), h.append(p, b), c.append(h);
|
|
2121
|
+
} else e.reactions && Object.keys(e.reactions).length && c.append(a("div", "ocw-react", Object.entries(e.reactions).map(([h, p]) => `${h}${p.length}`).join(" ")));
|
|
2122
|
+
const m = a("div", "ocw-time ocw-meta", Pt(e.ts));
|
|
2277
2123
|
if (i && e.status) {
|
|
2278
|
-
const h =
|
|
2124
|
+
const h = a("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, Kt(e.status));
|
|
2279
2125
|
m.append(h);
|
|
2280
2126
|
}
|
|
2281
|
-
return i && e.seq > 0 && t.lastReadByOthers >= e.seq && m.append(
|
|
2127
|
+
return i && e.seq > 0 && t.lastReadByOthers >= e.seq && m.append(a("span", "ocw-seen", " · Seen")), c.append(m), o.append(c), o;
|
|
2282
2128
|
}
|
|
2283
2129
|
}
|
|
2284
|
-
function
|
|
2130
|
+
function Kt(s) {
|
|
2285
2131
|
switch (s) {
|
|
2286
2132
|
case "read":
|
|
2287
2133
|
return "✓✓";
|
|
@@ -2293,78 +2139,20 @@ function Lt(s) {
|
|
|
2293
2139
|
return "🕓";
|
|
2294
2140
|
}
|
|
2295
2141
|
}
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
return [
|
|
2303
|
-
`${s}/conversations/${e}/messages?${n}`,
|
|
2304
|
-
`${s}/conversations/${e}/history?${n}`
|
|
2305
|
-
];
|
|
2306
|
-
}
|
|
2307
|
-
async function xe(s, e, t, i, n = zt) {
|
|
2308
|
-
for (const o of Mt(s, e, i, n))
|
|
2309
|
-
try {
|
|
2310
|
-
const r = await fetch(o, { headers: { authorization: `Bearer ${t}` } });
|
|
2311
|
-
if (!r.ok) continue;
|
|
2312
|
-
const l = await r.json();
|
|
2313
|
-
return { messages: l.messages ?? [], hasMore: l.hasMore ?? !1 };
|
|
2314
|
-
} catch {
|
|
2315
|
-
}
|
|
2316
|
-
return null;
|
|
2317
|
-
}
|
|
2318
|
-
async function ge(s, e, t, i, n) {
|
|
2319
|
-
const o = Ce(s), r = await xe(o, t, e, Number.MAX_SAFE_INTEGER);
|
|
2320
|
-
if (!r || (r.messages.length ? (i.apply({ type: "sync", conversationId: t, messages: r.messages }), i.apply({ type: "history", conversationId: t, messages: [], hasMore: r.hasMore }), n.render(i)) : i.apply({ type: "history", conversationId: t, messages: [], hasMore: !1 }), !r.hasMore)) return;
|
|
2321
|
-
let l = !1;
|
|
2322
|
-
const w = async () => {
|
|
2323
|
-
if (l || !i.hasMoreHistory) return;
|
|
2324
|
-
l = !0;
|
|
2325
|
-
const h = i.messages()[0];
|
|
2326
|
-
if (!h) {
|
|
2327
|
-
l = !1;
|
|
2328
|
-
return;
|
|
2329
|
-
}
|
|
2330
|
-
const p = await xe(o, t, e, h.seq);
|
|
2331
|
-
p && (i.apply({ type: "history", conversationId: t, messages: p.messages, hasMore: p.hasMore }), n.render(i)), l = !1;
|
|
2332
|
-
}, u = n.getScrollEl();
|
|
2333
|
-
if (!u) return;
|
|
2334
|
-
let m = !1;
|
|
2335
|
-
setTimeout(() => {
|
|
2336
|
-
m = !0;
|
|
2337
|
-
}, 300);
|
|
2338
|
-
const x = () => {
|
|
2339
|
-
m && u.scrollTop < 80 && i.hasMoreHistory && !l && w();
|
|
2340
|
-
};
|
|
2341
|
-
u.addEventListener("scroll", x, { passive: !0 }), n.setScrollCleanup(() => u.removeEventListener("scroll", x));
|
|
2342
|
-
}
|
|
2343
|
-
function $t() {
|
|
2344
|
-
const s = "oc_uid";
|
|
2345
|
-
try {
|
|
2346
|
-
const e = localStorage.getItem(s);
|
|
2347
|
-
if (e) return e;
|
|
2348
|
-
const t = `g_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;
|
|
2349
|
-
return localStorage.setItem(s, t), t;
|
|
2350
|
-
} catch {
|
|
2351
|
-
return `g_${Math.random().toString(36).slice(2)}`;
|
|
2352
|
-
}
|
|
2353
|
-
}
|
|
2354
|
-
function qt(s) {
|
|
2355
|
-
var H, R;
|
|
2356
|
-
const e = s.token ?? $t();
|
|
2357
|
-
let t = new de(e);
|
|
2358
|
-
const i = s.subjectId ? `${e}::${s.subjectId}` : e, n = new fe(i);
|
|
2359
|
-
let o, r = !1, l = null;
|
|
2142
|
+
function Mt(s) {
|
|
2143
|
+
var se, oe;
|
|
2144
|
+
const e = s.token ?? Ie();
|
|
2145
|
+
let t = new lt(e);
|
|
2146
|
+
const i = s.subjectId ? `${e}::${s.subjectId}` : e, n = new ft(i);
|
|
2147
|
+
let o, c = !1, l = null;
|
|
2360
2148
|
!s.launcher && !s.el.style.height && s.el.clientHeight === 0 && (s.el.style.width = s.el.style.width || "100%", s.el.style.height = "600px");
|
|
2361
2149
|
for (const d of n.load()) t.addOptimistic(d.clientMsgId, d.content);
|
|
2362
|
-
let
|
|
2150
|
+
let x = null, f = null, m = 0, w = !s.launcher;
|
|
2363
2151
|
if (s.launcher) {
|
|
2364
|
-
const
|
|
2365
|
-
|
|
2366
|
-
const y = document.createElement("div"),
|
|
2367
|
-
y.style.cssText =
|
|
2152
|
+
const u = (s.position ?? "bottom-right").includes("right");
|
|
2153
|
+
x = document.createElement("div"), x.style.cssText = `position:fixed;${u ? "right:20px" : "left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${u ? "flex-end" : "flex-start"};gap:12px`;
|
|
2154
|
+
const y = document.createElement("div"), B = typeof window < "u" && window.innerWidth < 480;
|
|
2155
|
+
y.style.cssText = B ? [
|
|
2368
2156
|
"position:fixed",
|
|
2369
2157
|
"inset:0",
|
|
2370
2158
|
"width:100%",
|
|
@@ -2387,97 +2175,97 @@ function qt(s) {
|
|
|
2387
2175
|
"display:none",
|
|
2388
2176
|
"flex-direction:column",
|
|
2389
2177
|
"background:#fff",
|
|
2390
|
-
"transform-origin:bottom " + (
|
|
2178
|
+
"transform-origin:bottom " + (u ? "right" : "left"),
|
|
2391
2179
|
"transition:opacity .18s,transform .18s",
|
|
2392
2180
|
"opacity:0",
|
|
2393
2181
|
"transform:scale(.95)"
|
|
2394
2182
|
].join(";"), s.el.style.cssText = "width:100%;height:100%;overflow:hidden", y.append(s.el);
|
|
2395
|
-
const
|
|
2396
|
-
|
|
2183
|
+
const I = document.createElement("button");
|
|
2184
|
+
I.style.cssText = [
|
|
2397
2185
|
"width:56px;height:56px;border-radius:50%",
|
|
2398
2186
|
`background:${s.accent ?? "#4F63F5"}`,
|
|
2399
2187
|
"color:#fff;border:none;font-size:24px;cursor:pointer",
|
|
2400
2188
|
"box-shadow:0 4px 16px rgba(0,0,0,.25)",
|
|
2401
2189
|
"position:relative;flex:none",
|
|
2402
2190
|
"transition:transform .15s"
|
|
2403
|
-
].join(";"),
|
|
2404
|
-
|
|
2405
|
-
},
|
|
2406
|
-
|
|
2407
|
-
},
|
|
2408
|
-
const
|
|
2409
|
-
|
|
2191
|
+
].join(";"), I.textContent = "💬", I.onmouseenter = () => {
|
|
2192
|
+
I.style.transform = "scale(1.08)";
|
|
2193
|
+
}, I.onmouseleave = () => {
|
|
2194
|
+
I.style.transform = "scale(1)";
|
|
2195
|
+
}, f = document.createElement("span"), f.style.cssText = "position:absolute;top:-4px;right:-4px;background:#ef4444;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center", I.append(f), x.append(y, I), document.body.append(x);
|
|
2196
|
+
const z = (R) => {
|
|
2197
|
+
R ? (y.style.display = "flex", requestAnimationFrame(() => {
|
|
2410
2198
|
y.style.opacity = "1", y.style.transform = "scale(1)";
|
|
2411
2199
|
})) : (y.style.opacity = "0", y.style.transform = "scale(.95)", setTimeout(() => {
|
|
2412
|
-
|
|
2200
|
+
w || (y.style.display = "none");
|
|
2413
2201
|
}, 180));
|
|
2414
2202
|
};
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
}), document.addEventListener("keydown", (
|
|
2418
|
-
|
|
2203
|
+
I.addEventListener("click", () => {
|
|
2204
|
+
w = !w, z(w), I.textContent = w ? "✕" : "💬", I.append(f), w && (m = 0, f && (f.style.display = "none"));
|
|
2205
|
+
}), document.addEventListener("keydown", (R) => {
|
|
2206
|
+
R.key === "Escape" && w && (w = !1, z(!1), I.textContent = "💬", I.append(f));
|
|
2419
2207
|
});
|
|
2420
2208
|
}
|
|
2421
2209
|
const h = () => {
|
|
2422
|
-
|
|
2210
|
+
w || (m++, f && (f.textContent = String(m), f.style.display = "flex"));
|
|
2423
2211
|
}, p = () => {
|
|
2424
2212
|
try {
|
|
2425
|
-
const d = new AudioContext(),
|
|
2426
|
-
|
|
2213
|
+
const d = new AudioContext(), u = d.createOscillator(), y = d.createGain();
|
|
2214
|
+
u.connect(y), y.connect(d.destination), u.frequency.setValueAtTime(880, d.currentTime), u.frequency.exponentialRampToValueAtTime(440, d.currentTime + 0.15), y.gain.setValueAtTime(0.3, d.currentTime), y.gain.exponentialRampToValueAtTime(1e-3, d.currentTime + 0.3), u.start(), u.stop(d.currentTime + 0.3);
|
|
2427
2215
|
} catch {
|
|
2428
2216
|
}
|
|
2429
2217
|
};
|
|
2430
2218
|
let g;
|
|
2431
2219
|
const b = new It(`ocw-e2e-${s.profileId}`);
|
|
2432
2220
|
let v = !1;
|
|
2433
|
-
const
|
|
2434
|
-
let
|
|
2435
|
-
const P = (d,
|
|
2436
|
-
b.sealText(
|
|
2221
|
+
const C = [], T = [];
|
|
2222
|
+
let A = !1;
|
|
2223
|
+
const P = (d, u) => {
|
|
2224
|
+
b.sealText(u).then((y) => {
|
|
2437
2225
|
o && g.send({ type: "send", conversationId: o, clientMsgId: d, content: y });
|
|
2438
2226
|
});
|
|
2439
|
-
}, D = (d,
|
|
2440
|
-
b.sealText(
|
|
2441
|
-
o && g.send({ type: "send", conversationId: o, clientMsgId: d, content:
|
|
2227
|
+
}, D = (d, u, y) => {
|
|
2228
|
+
b.sealText(u, y).then((B) => {
|
|
2229
|
+
o && g.send({ type: "send", conversationId: o, clientMsgId: d, content: B });
|
|
2442
2230
|
});
|
|
2443
|
-
},
|
|
2444
|
-
for (;
|
|
2445
|
-
const d =
|
|
2231
|
+
}, $ = () => {
|
|
2232
|
+
for (; C.length; ) {
|
|
2233
|
+
const d = C.shift();
|
|
2446
2234
|
P(d.clientMsgId, d.text);
|
|
2447
2235
|
}
|
|
2448
|
-
for (;
|
|
2449
|
-
const d =
|
|
2236
|
+
for (; T.length; ) {
|
|
2237
|
+
const d = T.shift();
|
|
2450
2238
|
P(d.clientMsgId, d.text);
|
|
2451
2239
|
}
|
|
2452
|
-
},
|
|
2240
|
+
}, _ = (d) => {
|
|
2453
2241
|
g.send({ type: "fetchPrekey", targetUserId: d });
|
|
2454
|
-
},
|
|
2455
|
-
|
|
2456
|
-
const
|
|
2242
|
+
}, k = s.i18n ?? {}, E = ["ar", "he", "fa", "ur"], Y = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
|
|
2243
|
+
E.includes(Y) && !s.el.dir && (s.el.dir = "rtl", s.el.style.fontFamily = s.el.style.fontFamily || "Tahoma,Arial,system-ui,sans-serif");
|
|
2244
|
+
const K = new Bt(s.el, e, {
|
|
2457
2245
|
onSend(d) {
|
|
2458
2246
|
if (!o) return;
|
|
2459
|
-
const
|
|
2460
|
-
t.addOptimistic(
|
|
2247
|
+
const u = `cm_${Math.random().toString(36).slice(2)}`;
|
|
2248
|
+
t.addOptimistic(u, { kind: "text", text: d }), K.render(t), t.e2e ? b.ready ? P(u, d) : A ? T.push({ clientMsgId: u, text: d }) : (C.push({ clientMsgId: u, text: d }), t.assignedAgentId && _(t.assignedAgentId)) : (n.add({ clientMsgId: u, content: { kind: "text", text: d }, ts: Date.now() }), g.send({ type: "send", conversationId: o, clientMsgId: u, content: { kind: "text", text: d } }));
|
|
2461
2249
|
},
|
|
2462
2250
|
async onAttach(d) {
|
|
2463
2251
|
if (!o) return;
|
|
2464
|
-
const
|
|
2465
|
-
t.addOptimistic(
|
|
2252
|
+
const B = `${s.url.replace(/^ws/, "http").replace(/\/ws$/, "")}/upload?name=${encodeURIComponent(d.name)}`, I = `cm_${Math.random().toString(36).slice(2)}`;
|
|
2253
|
+
t.addOptimistic(I, { kind: "text", text: `📎 Uploading ${d.name}…` }), K.render(t);
|
|
2466
2254
|
try {
|
|
2467
|
-
const
|
|
2255
|
+
const z = await fetch(B, {
|
|
2468
2256
|
method: "POST",
|
|
2469
2257
|
headers: { "content-type": d.type, ...s.token ? { authorization: `Bearer ${s.token}` } : {} },
|
|
2470
2258
|
body: d
|
|
2471
2259
|
});
|
|
2472
|
-
if (!
|
|
2473
|
-
const { url:
|
|
2474
|
-
g.send({ type: "send", conversationId: o, clientMsgId:
|
|
2475
|
-
} catch (
|
|
2476
|
-
t.addOptimistic(
|
|
2260
|
+
if (!z.ok) throw new Error(`Upload failed: ${z.status}`);
|
|
2261
|
+
const { url: R, name: be, mime: me, size: ve } = await z.json();
|
|
2262
|
+
g.send({ type: "send", conversationId: o, clientMsgId: I, content: { kind: "attachment", url: R, name: be, mime: me, size: ve } });
|
|
2263
|
+
} catch (z) {
|
|
2264
|
+
t.addOptimistic(I, { kind: "text", text: `⚠️ Upload failed: ${z.message}` }), K.render(t);
|
|
2477
2265
|
}
|
|
2478
2266
|
},
|
|
2479
|
-
onInvoke(d,
|
|
2480
|
-
o && g.send({ type: "invoke", conversationId: o, actionId: d, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...
|
|
2267
|
+
onInvoke(d, u) {
|
|
2268
|
+
o && g.send({ type: "invoke", conversationId: o, actionId: d, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...u ? { inputs: u } : {} });
|
|
2481
2269
|
},
|
|
2482
2270
|
onTyping(d) {
|
|
2483
2271
|
o && g.send({ type: "typing", conversationId: o, isTyping: d });
|
|
@@ -2490,19 +2278,19 @@ function qt(s) {
|
|
|
2490
2278
|
const d = t.messages()[0];
|
|
2491
2279
|
d && g.send({ type: "history", conversationId: o, beforeSeq: d.seq, limit: 20 });
|
|
2492
2280
|
},
|
|
2493
|
-
onEdit(d,
|
|
2494
|
-
o && g.send({ type: "edit", conversationId: o, messageId: d, content: { kind: "text", text:
|
|
2281
|
+
onEdit(d, u) {
|
|
2282
|
+
o && g.send({ type: "edit", conversationId: o, messageId: d, content: { kind: "text", text: u } });
|
|
2495
2283
|
},
|
|
2496
2284
|
onDelete(d) {
|
|
2497
2285
|
o && g.send({ type: "delete", conversationId: o, messageId: d });
|
|
2498
2286
|
},
|
|
2499
|
-
onReact(d,
|
|
2500
|
-
o && g.send({ type: "react", conversationId: o, messageId: d, emoji:
|
|
2287
|
+
onReact(d, u, y) {
|
|
2288
|
+
o && g.send({ type: "react", conversationId: o, messageId: d, emoji: u, remove: y });
|
|
2501
2289
|
},
|
|
2502
2290
|
onCsat(d) {
|
|
2503
2291
|
if (!o) return;
|
|
2504
|
-
const
|
|
2505
|
-
fetch(`${
|
|
2292
|
+
const u = s.url.replace(/^ws/, "http").replace(/\/+$/, "").replace(/:\d+$/, (y) => y);
|
|
2293
|
+
fetch(`${u}/conversations/${o}/csat`, {
|
|
2506
2294
|
method: "POST",
|
|
2507
2295
|
headers: { "Content-Type": "application/json", Authorization: `Bearer ${e}` },
|
|
2508
2296
|
body: JSON.stringify({ score: d })
|
|
@@ -2517,70 +2305,28 @@ function qt(s) {
|
|
|
2517
2305
|
},
|
|
2518
2306
|
...s.translateLang ? {
|
|
2519
2307
|
async onTranslate(d) {
|
|
2520
|
-
const
|
|
2308
|
+
const u = s.url.replace(/^ws/, "http").replace(/\/+$/, "");
|
|
2521
2309
|
try {
|
|
2522
|
-
const y = await fetch(`${
|
|
2310
|
+
const y = await fetch(`${u}/translate`, {
|
|
2523
2311
|
method: "POST",
|
|
2524
2312
|
headers: { "content-type": "application/json", authorization: `Bearer ${e}` },
|
|
2525
2313
|
body: JSON.stringify({ text: d, targetLang: s.translateLang })
|
|
2526
2314
|
});
|
|
2527
2315
|
if (!y.ok) return null;
|
|
2528
|
-
const { translated:
|
|
2529
|
-
return
|
|
2316
|
+
const { translated: B } = await y.json();
|
|
2317
|
+
return B;
|
|
2530
2318
|
} catch {
|
|
2531
2319
|
return null;
|
|
2532
2320
|
}
|
|
2533
2321
|
}
|
|
2534
|
-
} : {},
|
|
2535
|
-
...s.showChatList ? {
|
|
2536
|
-
async onListChats() {
|
|
2537
|
-
const d = Ce(s.url);
|
|
2538
|
-
try {
|
|
2539
|
-
const f = await fetch(`${d}/conversations/mine?profileId=${encodeURIComponent(s.profileId)}`, {
|
|
2540
|
-
headers: { authorization: `Bearer ${e}` }
|
|
2541
|
-
});
|
|
2542
|
-
return f.ok ? (await f.json()).conversations ?? [] : [];
|
|
2543
|
-
} catch {
|
|
2544
|
-
return [];
|
|
2545
|
-
}
|
|
2546
|
-
},
|
|
2547
|
-
onSwitchChat(d) {
|
|
2548
|
-
if (!d.id || d.id === "__new__") return;
|
|
2549
|
-
g == null || g.close(), o = void 0, r = !1, t = new de(e);
|
|
2550
|
-
const f = d.subjectId ? `${e}::${d.subjectId}` : e, y = new fe(f);
|
|
2551
|
-
for (const C of y.load()) t.addOptimistic(C.clientMsgId, C.content);
|
|
2552
|
-
const T = {
|
|
2553
|
-
type: "open",
|
|
2554
|
-
profileId: s.profileId,
|
|
2555
|
-
...d.subjectId ? { subjectId: d.subjectId } : {},
|
|
2556
|
-
...typeof location < "u" ? { pageUrl: location.href } : {},
|
|
2557
|
-
...typeof document < "u" && document.title ? { pageTitle: document.title } : {}
|
|
2558
|
-
};
|
|
2559
|
-
g = new he({
|
|
2560
|
-
url: s.url,
|
|
2561
|
-
token: e,
|
|
2562
|
-
open: T,
|
|
2563
|
-
getCursor: () => t.highestSeq(),
|
|
2564
|
-
onStatusChange: (C) => S.setConnStatus(C),
|
|
2565
|
-
onFrame(C) {
|
|
2566
|
-
if (C.type === "opened") {
|
|
2567
|
-
const L = o === void 0;
|
|
2568
|
-
o = C.conversation.id, L && (ge(s.url, e, o, t, S), S.showChatScreen());
|
|
2569
|
-
}
|
|
2570
|
-
(async () => (t.apply(C), S.render(t), o && S.setSeenSeq(o, t.highestSeq())))();
|
|
2571
|
-
}
|
|
2572
|
-
}), g.connect(), S.render(t);
|
|
2573
|
-
}
|
|
2574
2322
|
} : {}
|
|
2575
2323
|
}, {
|
|
2576
2324
|
...s.subject ? { subject: s.subject } : {},
|
|
2577
2325
|
...s.quickReplies ? { quickReplies: s.quickReplies } : {},
|
|
2578
2326
|
...s.accent ? { accent: s.accent } : {},
|
|
2579
|
-
...(
|
|
2580
|
-
i18n:
|
|
2581
|
-
|
|
2582
|
-
...s.showChatList && s.subjectId ? { startOnChat: !0 } : {}
|
|
2583
|
-
}), Y = {
|
|
2327
|
+
...(se = s.user) != null && se.name || (oe = s.user) != null && oe.avatar ? { userInfo: { ...s.user.name ? { name: s.user.name } : {}, ...s.user.avatar ? { avatar: s.user.avatar } : {} } } : {},
|
|
2328
|
+
i18n: k
|
|
2329
|
+
}), ye = {
|
|
2584
2330
|
type: "open",
|
|
2585
2331
|
profileId: s.profileId,
|
|
2586
2332
|
...s.subjectId ? { subjectId: s.subjectId } : {},
|
|
@@ -2588,81 +2334,79 @@ function qt(s) {
|
|
|
2588
2334
|
// This is pure display metadata — it never affects identity or access.
|
|
2589
2335
|
...typeof location < "u" ? { pageUrl: location.href } : {},
|
|
2590
2336
|
...typeof document < "u" && document.title ? { pageTitle: document.title } : {}
|
|
2591
|
-
},
|
|
2592
|
-
const
|
|
2593
|
-
if (!
|
|
2337
|
+
}, ge = (d) => {
|
|
2338
|
+
const u = s.user;
|
|
2339
|
+
if (!u || !u.name && !u.email && !u.avatar && !u.meta) return;
|
|
2594
2340
|
const y = [];
|
|
2595
|
-
if (
|
|
2341
|
+
if (u.name && y.push(`Name: ${u.name}`), u.email && y.push(`Email: ${u.email}`), u.avatar && y.push(`Avatar: ${u.avatar}`), u.meta) for (const [B, I] of Object.entries(u.meta)) y.push(`${B}: ${I}`);
|
|
2596
2342
|
g.send({ type: "note", conversationId: d, clientMsgId: `ui_${Date.now()}`, text: `[User info]
|
|
2597
2343
|
${y.join(`
|
|
2598
2344
|
`)}` });
|
|
2599
2345
|
};
|
|
2600
|
-
return g = new
|
|
2346
|
+
return g = new ht({
|
|
2601
2347
|
url: s.url,
|
|
2602
2348
|
token: e,
|
|
2603
|
-
open:
|
|
2349
|
+
open: ye,
|
|
2604
2350
|
getCursor: () => t.highestSeq(),
|
|
2605
|
-
onStatusChange: (d) =>
|
|
2351
|
+
onStatusChange: (d) => K.setConnStatus(d),
|
|
2606
2352
|
onFrame(d) {
|
|
2607
2353
|
if (d.type === "opened") {
|
|
2608
|
-
const
|
|
2609
|
-
if (o = d.conversation.id, !
|
|
2610
|
-
|
|
2354
|
+
const u = o === void 0;
|
|
2355
|
+
if (o = d.conversation.id, !c) {
|
|
2356
|
+
c = !0;
|
|
2611
2357
|
for (const y of n.load())
|
|
2612
2358
|
g.send({ type: "send", conversationId: o, clientMsgId: y.clientMsgId, content: y.content });
|
|
2613
2359
|
}
|
|
2614
|
-
|
|
2360
|
+
u && (Ce(s.url, e, o, t, K), d.conversation.lastSeq === 0 && ge(o));
|
|
2615
2361
|
}
|
|
2616
2362
|
if (d.type === "ack" && n.remove(d.clientMsgId), d.type === "prekeyBundle") {
|
|
2617
|
-
d.bundle && (
|
|
2618
|
-
const y = [...
|
|
2619
|
-
for (const
|
|
2620
|
-
|
|
2363
|
+
d.bundle && (A = !0, b.x3dhSendTo(d.bundle).then((u) => {
|
|
2364
|
+
const y = [...C.splice(0), ...T.splice(0)];
|
|
2365
|
+
for (const B of y) D(B.clientMsgId, B.text, u);
|
|
2366
|
+
K.render(t);
|
|
2621
2367
|
}));
|
|
2622
2368
|
return;
|
|
2623
2369
|
}
|
|
2624
2370
|
if (d.type === "message" && t.e2e) {
|
|
2625
|
-
const
|
|
2626
|
-
if (
|
|
2627
|
-
b.x3dhReceiveFrom(
|
|
2628
|
-
await b.openFrame(d), t.apply(d),
|
|
2371
|
+
const u = Ct(d.message.content);
|
|
2372
|
+
if (u && !b.ready) {
|
|
2373
|
+
b.x3dhReceiveFrom(u.x3dhIK, u.x3dhEK, u.x3dhSPK).then(async () => {
|
|
2374
|
+
await b.openFrame(d), t.apply(d), K.render(t);
|
|
2629
2375
|
});
|
|
2630
2376
|
return;
|
|
2631
2377
|
}
|
|
2632
2378
|
}
|
|
2633
2379
|
if (d.type === "peerkey") {
|
|
2634
2380
|
b.onPeerKey(d.key).then(() => {
|
|
2635
|
-
|
|
2381
|
+
$(), K.render(t);
|
|
2636
2382
|
});
|
|
2637
2383
|
return;
|
|
2638
2384
|
}
|
|
2639
2385
|
(async () => {
|
|
2640
|
-
if (t.e2e && await b.openFrame(d), t.apply(d), d.type === "message" && d.message.senderId !== e && !d.message.internal && (
|
|
2386
|
+
if (t.e2e && await b.openFrame(d), t.apply(d), d.type === "message" && d.message.senderId !== e && !d.message.internal && (h(), p()), t.e2e && o && !v) {
|
|
2641
2387
|
v = !0;
|
|
2642
|
-
const
|
|
2643
|
-
g.send({ type: "uploadPrekeys", ...
|
|
2388
|
+
const u = await b.initX3DH();
|
|
2389
|
+
g.send({ type: "uploadPrekeys", ...u });
|
|
2644
2390
|
const y = await b.begin();
|
|
2645
2391
|
g.send({ type: "pubkey", conversationId: o, key: y });
|
|
2646
2392
|
}
|
|
2647
|
-
|
|
2393
|
+
K.render(t);
|
|
2648
2394
|
})();
|
|
2649
2395
|
}
|
|
2650
|
-
}),
|
|
2651
|
-
|
|
2652
|
-
} }, l
|
|
2653
|
-
g.close(), w == null || w.remove(), S.destroy();
|
|
2654
|
-
} }, l);
|
|
2396
|
+
}), g.connect(), K.render(t), l = { close: () => {
|
|
2397
|
+
g.close(), x == null || x.remove(), K.destroy();
|
|
2398
|
+
} }, l;
|
|
2655
2399
|
}
|
|
2656
2400
|
export {
|
|
2657
|
-
|
|
2658
|
-
|
|
2401
|
+
lt as ChatStore,
|
|
2402
|
+
ht as ConnectionManager,
|
|
2659
2403
|
It as E2ESession,
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2404
|
+
ft as PersistentOutbox,
|
|
2405
|
+
Bt as Renderer,
|
|
2406
|
+
Lt as asConversationId,
|
|
2407
|
+
Ct as extractX3DHInit,
|
|
2408
|
+
_t as httpBaseFromWsUrl,
|
|
2409
|
+
Mt as mount,
|
|
2410
|
+
Ce as restoreHistory
|
|
2667
2411
|
};
|
|
2668
2412
|
//# sourceMappingURL=index.js.map
|