@kispi/chat 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +23 -2
- package/README.md +18 -2
- package/dist/index.cjs +13 -4
- package/dist/index.d.cts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +13 -4
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -96,10 +96,10 @@ Event names are **exactly the wire names**, and the payloads are in the type dec
|
|
|
96
96
|
|
|
97
97
|
| Event | Payload |
|
|
98
98
|
|---|---|
|
|
99
|
-
| `message.created` / `message.updated` | `Message`. On `created`, `thread` is absent
|
|
99
|
+
| `message.created` / `message.updated` | `Message`. On `created`, `thread` is absent, `reactions` is empty, and **the SDK fills `myReactions` with `[]`** (the wire carries none) |
|
|
100
100
|
| `message.deleted` | `{id, seq}`. `seq` is the one the message got **when it was published** |
|
|
101
101
|
| `reaction.added` / `reaction.removed` | `{messageId, emoji, count, userId?}`. The SDK has already updated that row's `reactions` count in `messages` (and `myReactions` if it was yours). **Rows outside the list**, such as ones read with `history()`, are the consumer's to update |
|
|
102
|
-
| `thread.updated` | `{rootId, count, lastSeq?, lastAt?}` |
|
|
102
|
+
| `thread.updated` | `{rootId, count, lastSeq?, lastAt?}`. The SDK has already updated **the root row's `thread`** (`count`, `lastSeq`, `lastAt`) in `messages`. A root outside the list is the consumer's to update |
|
|
103
103
|
| `presence` | `{count, joined?, left?, users?, capped?}`. `joined`/`left` are incremental, `users` replaces |
|
|
104
104
|
| `typing` | `{userId, threadId?}` -- `threadId` is the thread **root** id, absent for the main timeline |
|
|
105
105
|
| `read` | `{userId, seq, threadId?}` |
|
|
@@ -139,6 +139,21 @@ room.on('messages', m => (messages.value = m))
|
|
|
139
139
|
that nobody fills.
|
|
140
140
|
- **Attach the past to the same list with `loadOlder()`.** `history()` is a direct read that
|
|
141
141
|
doesn't touch the list, so merging and deduplicating fall to you.
|
|
142
|
+
- **Draw reaction chips from `reactions` and `myReactions` together.** `react()` moves
|
|
143
|
+
`myReactions` first and waits for `reaction.added` for the count, so an emoji you are the first
|
|
144
|
+
to add sits briefly in `myReactions` only. Draw that chip as **the highlighted emoji alone** (no
|
|
145
|
+
count) rather than inventing a `1` — someone else may have pressed it in between.
|
|
146
|
+
- **Each message has a cap on distinct emoji** (`hello.limits.maxDistinctEmojiPerMessage`, 20 by
|
|
147
|
+
default). A new emoji past it is refused with `invalid` and the SDK rolls `myReactions` back.
|
|
148
|
+
Pressing an emoji already on the message is never capped. To disable a picker, check that
|
|
149
|
+
`reactions.length` has reached the cap and the emoji is not among them.
|
|
150
|
+
- **A thread panel merges two sources.** `messages` holds replies only for the range the SDK has
|
|
151
|
+
read (it is the whole room's stream, so an old thread's replies are not in it). Read past replies
|
|
152
|
+
with `history({view: {thread: rootId}})`, pick new ones from `messages` by
|
|
153
|
+
`threadId === rootId`, and **merge by id.** Rows read with `history()` are outside the list, so
|
|
154
|
+
**you apply** `reaction.added`/`removed` (the count, and `myReactions` when `userId` is yours),
|
|
155
|
+
`message.updated` and `message.deleted` to them yourself — miss it and only the older replies'
|
|
156
|
+
reactions look frozen. Read again on `reset`.
|
|
142
157
|
- **`typing` is also delivered to the sender.** If you render "X is typing", skip your own `userId`.
|
|
143
158
|
- **`typing` carries no name.** Look the name up in `room.presence.users` — whoever is
|
|
144
159
|
watching the room is there. Collecting names from message senders misses anyone who has not
|
|
@@ -226,6 +241,12 @@ From an origin that isn't on the list it isn't just REST that fails — **the co
|
|
|
226
241
|
is a 401.** An authentication refusal is a failure the SDK doesn't retry, so the client stops
|
|
227
242
|
at `closed`, and the reason arrives on `chat.on('error')`.
|
|
228
243
|
|
|
244
|
+
**On Node (bots, tests) there is no origin to add.** The server accepts a request with **no**
|
|
245
|
+
`Origin` header without an origin check — Node's global `WebSocket` and `fetch` don't send one,
|
|
246
|
+
so they connect as is. If you set the header yourself, its value must be on the allowed list.
|
|
247
|
+
The origin list only stops another site from using your `pk_` in a visitor's browser (a `pk_` is
|
|
248
|
+
public). A user token is required everywhere.
|
|
249
|
+
|
|
229
250
|
### Errors
|
|
230
251
|
|
|
231
252
|
Failures are `ChatError`.
|
package/README.md
CHANGED
|
@@ -96,10 +96,10 @@ off()
|
|
|
96
96
|
|
|
97
97
|
| 이벤트 | 페이로드 |
|
|
98
98
|
|---|---|
|
|
99
|
-
| `message.created` / `message.updated` | `Message`. `created`에는 `thread`가 없고 `reactions`가 비어
|
|
99
|
+
| `message.created` / `message.updated` | `Message`. `created`에는 `thread`가 없고 `reactions`가 비어 있으며, `myReactions`는 **SDK가 `[]`로 채운다**(와이어에는 없다) |
|
|
100
100
|
| `message.deleted` | `{id, seq}`. `seq`는 그 메시지가 **발행될 때** 받은 값이다 |
|
|
101
101
|
| `reaction.added` / `reaction.removed` | `{messageId, emoji, count, userId?}`. SDK가 `messages` 안의 그 행의 `reactions` 개수를(내 것이면 `myReactions`도) 이미 고쳐 두었다. `history()`로 따로 읽은 행처럼 **목록 밖의 행은 소비자가 고친다** |
|
|
102
|
-
| `thread.updated` | `{rootId, count, lastSeq?, lastAt?}` |
|
|
102
|
+
| `thread.updated` | `{rootId, count, lastSeq?, lastAt?}`. SDK가 `messages` 안의 **루트 행 `thread`**(`count`·`lastSeq`·`lastAt`)를 이미 고쳐 두었다. 목록 밖의 루트는 소비자가 고친다 |
|
|
103
103
|
| `presence` | `{count, joined?, left?, users?, capped?}`. `joined`/`left`는 증분, `users`는 교체다 |
|
|
104
104
|
| `typing` | `{userId, threadId?}` — `threadId`는 스레드 **루트** id, 본 타임라인이면 없다 |
|
|
105
105
|
| `read` | `{userId, seq, threadId?}` |
|
|
@@ -137,6 +137,17 @@ room.on('messages', m => (messages.value = m))
|
|
|
137
137
|
- **`reset`을 무시하면 안 된다.** 옛 목록에 이어 붙이면 아무도 메우지 않는 구멍이 남는다.
|
|
138
138
|
- **과거는 `loadOlder()`로 같은 목록에 붙인다.** `history()`는 목록을 건드리지 않는 직접
|
|
139
139
|
읽기이므로 합치고 중복을 거르는 일이 소비자 몫이 된다.
|
|
140
|
+
- **리액션 칩은 `reactions`와 `myReactions`를 합쳐 그린다.** `react()`는 `myReactions`를 먼저 옮기고
|
|
141
|
+
개수는 `reaction.added`를 기다리므로, 처음 다는 이모지는 잠깐 `myReactions`에만 있다. 그 칩은
|
|
142
|
+
**강조한 이모지만**(개수 없이) 그리고, `1`을 지어내지 않는다 — 그 사이 남이 눌렀으면 틀린 숫자다.
|
|
143
|
+
- **이모지 종류에는 메시지당 상한이 있다**(`hello.limits.maxDistinctEmojiPerMessage`, 기본 20). 넘는 새
|
|
144
|
+
이모지는 `invalid`로 거절되고 SDK가 `myReactions`를 되돌린다. 이미 달린 이모지를 누르는 것은 상한과
|
|
145
|
+
무관하다. 피커를 막으려면 `reactions.length`가 상한에 닿았고 그 이모지가 없을 때 비활성화한다.
|
|
146
|
+
- **스레드 패널은 두 곳을 합친다.** `messages`에는 SDK가 읽은 구간의 답글만 있다(방 전체 스트림이라
|
|
147
|
+
오래된 스레드의 답글은 없다). 지난 답글은 `history({view: {thread: rootId}})`로 읽고, 새 답글은
|
|
148
|
+
`messages`에서 `threadId === rootId`로 골라 **id로 합친다.** `history()`로 읽은 행은 목록 밖이라
|
|
149
|
+
`reaction.added`/`removed`(개수, 내 `userId`면 `myReactions`)와 `message.updated`·`message.deleted`를
|
|
150
|
+
**소비자가 직접 반영한다** — 빠뜨리면 지난 답글만 리액션이 멈춰 보인다. `reset`이면 다시 읽는다.
|
|
140
151
|
- **`typing`은 보낸 사람에게도 온다.** "X가 입력 중"을 그린다면 자기 `userId`를 건너뛴다.
|
|
141
152
|
- **`typing`은 이름을 싣지 않는다.** 이름은 `room.presence.users`에서 찾는다 — 방을 보고 있는
|
|
142
153
|
사람이 거기 있다. 메시지 발신자에서 이름을 모으면 아직 말하지 않은 사람을 모른다.
|
|
@@ -213,6 +224,11 @@ for (const part of splitByUrl(text)) {
|
|
|
213
224
|
목록에 없는 오리진에서는 REST만이 아니라 **접속부터 401이다.** 인증 거절은 SDK가 다시
|
|
214
225
|
시도하지 않으므로 클라이언트가 `closed`에서 멈추고, 이유는 `chat.on('error')`로 온다.
|
|
215
226
|
|
|
227
|
+
**Node(봇·테스트)에서는 오리진을 넣지 않는다.** 서버는 `Origin` 헤더가 **없는** 요청을 오리진
|
|
228
|
+
검사 없이 받는다 — Node의 전역 `WebSocket`·`fetch`는 그 헤더를 보내지 않으므로 그대로 붙는다.
|
|
229
|
+
헤더를 직접 붙이면 그 값은 허용 오리진에 있어야 한다. 오리진 목록은 남의 사이트가 방문자의 브라우저에서
|
|
230
|
+
당신의 `pk_`를 쓰는 것만 막는다(`pk_`는 공개값이다). 유저 토큰은 어디서나 필요하다.
|
|
231
|
+
|
|
216
232
|
### 에러
|
|
217
233
|
|
|
218
234
|
실패는 `ChatError`다.
|
package/dist/index.cjs
CHANGED
|
@@ -460,13 +460,21 @@ var Timeline = class {
|
|
|
460
460
|
this.items[at] = next;
|
|
461
461
|
this.changed();
|
|
462
462
|
}
|
|
463
|
-
/**
|
|
464
|
-
|
|
463
|
+
/**
|
|
464
|
+
* Applies a `thread.updated` to the root message's aggregate.
|
|
465
|
+
*
|
|
466
|
+
* `lastAt`도 옮긴다. 히스토리 행의 `thread`는 `{count, lastSeq, lastAt}`이라,
|
|
467
|
+
* 빼고 바꾸면 "마지막 답글 3분 전"을 그리던 화면이 답글이 달리는 순간 그 값을 잃는다.
|
|
468
|
+
*/
|
|
469
|
+
thread(rootId, count, lastSeq, lastAt) {
|
|
465
470
|
const at = this.items.findIndex((m) => m.id === rootId);
|
|
466
471
|
if (at === -1) return;
|
|
467
472
|
const current = this.items[at];
|
|
473
|
+
const thread = { count };
|
|
474
|
+
if (lastSeq !== void 0) thread.lastSeq = lastSeq;
|
|
475
|
+
if (lastAt !== void 0) thread.lastAt = lastAt;
|
|
468
476
|
this.own();
|
|
469
|
-
this.items[at] = { ...current, thread
|
|
477
|
+
this.items[at] = { ...current, thread };
|
|
470
478
|
this.changed();
|
|
471
479
|
}
|
|
472
480
|
/** Applies a `message.deleted`, remembering it if the row is not here. */
|
|
@@ -1101,6 +1109,7 @@ var Room = class extends Emitter {
|
|
|
1101
1109
|
switch (type) {
|
|
1102
1110
|
case "message.created":
|
|
1103
1111
|
if (data.seq > this.lastSeq) this.lastSeq = data.seq;
|
|
1112
|
+
if (data.myReactions === void 0) data = { ...data, myReactions: [] };
|
|
1104
1113
|
this.timeline.add(data).catch((err) => {
|
|
1105
1114
|
this.subscribed = false;
|
|
1106
1115
|
this.failed(err);
|
|
@@ -1125,7 +1134,7 @@ var Room = class extends Emitter {
|
|
|
1125
1134
|
}
|
|
1126
1135
|
case "thread.updated": {
|
|
1127
1136
|
const t = data;
|
|
1128
|
-
this.timeline.thread(t.rootId, t.count, t.lastSeq);
|
|
1137
|
+
this.timeline.thread(t.rootId, t.count, t.lastSeq, t.lastAt);
|
|
1129
1138
|
break;
|
|
1130
1139
|
}
|
|
1131
1140
|
case "presence":
|
package/dist/index.d.cts
CHANGED
|
@@ -190,18 +190,25 @@ type Message = {
|
|
|
190
190
|
* Filled by history reads and kept in step by the SDK afterwards: a
|
|
191
191
|
* `reaction.*` event whose `userId` is `chat.user.id` updates it, and
|
|
192
192
|
* this client's own `react()`/`unreact()` update it **before the frame
|
|
193
|
-
* goes out**, rolling back if the server refuses.
|
|
194
|
-
*
|
|
195
|
-
*
|
|
193
|
+
* goes out**, rolling back if the server refuses. A live
|
|
194
|
+
* `message.created` carries none on the wire (a room frame is the same
|
|
195
|
+
* bytes for every viewer), so the SDK fills it with `[]`: a message
|
|
196
|
+
* that was just published has no reactions, and an absent field reads
|
|
197
|
+
* as "no viewer", which is what it means on a REST row.
|
|
196
198
|
*
|
|
197
199
|
* The SDK owns this field, so a consumer does not need -- and should
|
|
198
200
|
* not add -- an optimistic layer of its own on top of it. The count in
|
|
199
201
|
* `reactions` is the opposite: always the server's, never moved locally.
|
|
200
202
|
*/
|
|
201
203
|
myReactions?: string[];
|
|
204
|
+
/**
|
|
205
|
+
* The root's reply summary. The SDK keeps it current from
|
|
206
|
+
* `thread.updated` (count, `lastSeq`, `lastAt`) on rows in `messages`.
|
|
207
|
+
*/
|
|
202
208
|
thread?: {
|
|
203
209
|
count: number;
|
|
204
210
|
lastSeq?: number;
|
|
211
|
+
lastAt?: number;
|
|
205
212
|
};
|
|
206
213
|
};
|
|
207
214
|
type ReactionUser = {
|
package/dist/index.d.ts
CHANGED
|
@@ -190,18 +190,25 @@ type Message = {
|
|
|
190
190
|
* Filled by history reads and kept in step by the SDK afterwards: a
|
|
191
191
|
* `reaction.*` event whose `userId` is `chat.user.id` updates it, and
|
|
192
192
|
* this client's own `react()`/`unreact()` update it **before the frame
|
|
193
|
-
* goes out**, rolling back if the server refuses.
|
|
194
|
-
*
|
|
195
|
-
*
|
|
193
|
+
* goes out**, rolling back if the server refuses. A live
|
|
194
|
+
* `message.created` carries none on the wire (a room frame is the same
|
|
195
|
+
* bytes for every viewer), so the SDK fills it with `[]`: a message
|
|
196
|
+
* that was just published has no reactions, and an absent field reads
|
|
197
|
+
* as "no viewer", which is what it means on a REST row.
|
|
196
198
|
*
|
|
197
199
|
* The SDK owns this field, so a consumer does not need -- and should
|
|
198
200
|
* not add -- an optimistic layer of its own on top of it. The count in
|
|
199
201
|
* `reactions` is the opposite: always the server's, never moved locally.
|
|
200
202
|
*/
|
|
201
203
|
myReactions?: string[];
|
|
204
|
+
/**
|
|
205
|
+
* The root's reply summary. The SDK keeps it current from
|
|
206
|
+
* `thread.updated` (count, `lastSeq`, `lastAt`) on rows in `messages`.
|
|
207
|
+
*/
|
|
202
208
|
thread?: {
|
|
203
209
|
count: number;
|
|
204
210
|
lastSeq?: number;
|
|
211
|
+
lastAt?: number;
|
|
205
212
|
};
|
|
206
213
|
};
|
|
207
214
|
type ReactionUser = {
|
package/dist/index.js
CHANGED
|
@@ -390,13 +390,21 @@ var Timeline = class {
|
|
|
390
390
|
this.items[at] = next;
|
|
391
391
|
this.changed();
|
|
392
392
|
}
|
|
393
|
-
/**
|
|
394
|
-
|
|
393
|
+
/**
|
|
394
|
+
* Applies a `thread.updated` to the root message's aggregate.
|
|
395
|
+
*
|
|
396
|
+
* `lastAt`도 옮긴다. 히스토리 행의 `thread`는 `{count, lastSeq, lastAt}`이라,
|
|
397
|
+
* 빼고 바꾸면 "마지막 답글 3분 전"을 그리던 화면이 답글이 달리는 순간 그 값을 잃는다.
|
|
398
|
+
*/
|
|
399
|
+
thread(rootId, count, lastSeq, lastAt) {
|
|
395
400
|
const at = this.items.findIndex((m) => m.id === rootId);
|
|
396
401
|
if (at === -1) return;
|
|
397
402
|
const current = this.items[at];
|
|
403
|
+
const thread = { count };
|
|
404
|
+
if (lastSeq !== void 0) thread.lastSeq = lastSeq;
|
|
405
|
+
if (lastAt !== void 0) thread.lastAt = lastAt;
|
|
398
406
|
this.own();
|
|
399
|
-
this.items[at] = { ...current, thread
|
|
407
|
+
this.items[at] = { ...current, thread };
|
|
400
408
|
this.changed();
|
|
401
409
|
}
|
|
402
410
|
/** Applies a `message.deleted`, remembering it if the row is not here. */
|
|
@@ -1031,6 +1039,7 @@ var Room = class extends Emitter {
|
|
|
1031
1039
|
switch (type) {
|
|
1032
1040
|
case "message.created":
|
|
1033
1041
|
if (data.seq > this.lastSeq) this.lastSeq = data.seq;
|
|
1042
|
+
if (data.myReactions === void 0) data = { ...data, myReactions: [] };
|
|
1034
1043
|
this.timeline.add(data).catch((err) => {
|
|
1035
1044
|
this.subscribed = false;
|
|
1036
1045
|
this.failed(err);
|
|
@@ -1055,7 +1064,7 @@ var Room = class extends Emitter {
|
|
|
1055
1064
|
}
|
|
1056
1065
|
case "thread.updated": {
|
|
1057
1066
|
const t = data;
|
|
1058
|
-
this.timeline.thread(t.rootId, t.count, t.lastSeq);
|
|
1067
|
+
this.timeline.thread(t.rootId, t.count, t.lastSeq, t.lastAt);
|
|
1059
1068
|
break;
|
|
1060
1069
|
}
|
|
1061
1070
|
case "presence":
|