@kispi/chat 0.7.4 → 0.7.5
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 +89 -15
- package/README.md +108 -25
- package/dist/index.cjs +823 -22
- package/dist/index.d.cts +420 -17
- package/dist/index.d.ts +420 -17
- package/dist/index.js +818 -21
- package/dist/server/index.cjs +8 -1
- package/dist/server/index.d.cts +16 -1
- package/dist/server/index.d.ts +16 -1
- package/dist/server/index.js +8 -1
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -48,9 +48,12 @@ is in the browser, the whole app is open.
|
|
|
48
48
|
| `reconnect()` | **Re-authenticates**: calls `token()` again and replaces the socket. Room handles, subscriptions and `messages` are kept (**when the user changes, `messages` is dropped and refilled**), and the state goes `open → reconnecting → open` (never `closed`). Use it after a nickname or avatar change, and **when logging in or out switches the user** (below) |
|
|
49
49
|
| `room(roomId)` | Room handle. Same id, same object |
|
|
50
50
|
| `roomByKey(key)` | Handle for a room opened by key. The server tells you the id when you subscribe. **Does not create the room** — for a key that doesn't exist, `subscribe()` rejects with `not_found`. Rooms are created by the backend with `rooms.ensure()` |
|
|
51
|
-
| `
|
|
51
|
+
| `roomList()` | **The live list of my rooms** (`RoomList`, below) — a channel sidebar. One per client |
|
|
52
|
+
| `rooms.list({cursor?, limit?})` | One page of the rooms I'm in: `{rooms: MyRoom[], cursor}`. `MyRoom` is `{room, lastSeq, readSeq, unread, unreadMentions, unreadCapped?, lastMessage?}`, latest activity first |
|
|
52
53
|
| `rooms.discover({type?, cursor?, limit?})` | Browse public rooms |
|
|
53
|
-
| `rooms.
|
|
54
|
+
| `rooms.update(roomId, {name?, meta?})` | Rename a room or change its meta. Owners and admins only (otherwise `forbidden`); every subscriber gets `room.updated` |
|
|
55
|
+
| `rooms.delete(roomId)` | Soft-deletes the room. **Owner only** (`forbidden` otherwise). Subscribers get `room.deleted`; it leaves `roomList()` |
|
|
56
|
+
| `rooms.members(roomId).list/add/remove` | Membership. `list` is `{members: MemberRow[], cursor}` — `{userId?, name?, role, joinedAt?, withdrawn?}` (a withdrawn row has no `userId`) |
|
|
54
57
|
| `unread()` | `{total, mentions, roomsCapped?, rooms}` — the **same field names** as `chat.hello?.unread` |
|
|
55
58
|
| `updateMe(meta)` | My `meta`. **`name` and `avatar` come from the token claims** |
|
|
56
59
|
|
|
@@ -59,6 +62,7 @@ is in the browser, the whole app is open.
|
|
|
59
62
|
| `state` | The four values above |
|
|
60
63
|
| `error` | The client stopped at `closed` on its own, and why (a `ChatError`): an authentication refusal, or a `ChatError` from `token()`. Not emitted for `close()` |
|
|
61
64
|
| `notification` | A new message arrived in a room I'm a member of, but I'm not viewing that room |
|
|
65
|
+
| `resumed` | `{reconnected}` — back after a reconnect (`true`), or a tab/app return, network return or back/forward-cache restore (`pageshow`) found the socket alive and resubscribed every room (`false`). Rooms and `roomList()` catch themselves up; use it to refetch **what the SDK does not hold** (an activity feed, search results) |
|
|
62
66
|
| `user.presence` | Presence changes of my other connections |
|
|
63
67
|
| `frame` | Every received frame. For debugging |
|
|
64
68
|
|
|
@@ -74,6 +78,7 @@ off()
|
|
|
74
78
|
| Property | |
|
|
75
79
|
|---|---|
|
|
76
80
|
| `messages` | Ascending by seq. **The SDK handles ordering and gap filling.** A new array on every change. **Thread replies are included** (rows with a `threadId`) — to draw the main timeline only, keep the rows without one |
|
|
81
|
+
| `typing.changed` | `{threadId?, userIds}` — `typists()` changed for that place (the main timeline, or the thread rooted at `threadId`) |
|
|
77
82
|
| `id` / `key` | Room identifiers. If opened by key, `id` is absent until you subscribe |
|
|
78
83
|
| `lastSeq` | The room's last seq as reported by the server |
|
|
79
84
|
| `presence` | `{count, users?, capped?}` — who is in this room now. **The SDK folds** the subscribe ack and the increments of `presence` events into it. `users` is there **only for rooms of 100 or fewer**; larger, or unknown, it is absent — use `presenceList()` then |
|
|
@@ -86,12 +91,16 @@ off()
|
|
|
86
91
|
| `send({text, attachments?, entities?, replyTo?, threadId?, meta?}, {clientMessageId?})` | Publish. Acked with `{messageId, seq}`. If a subscription is in progress, it waits for it. **While reconnecting it waits for the connection, then sends** (below) |
|
|
87
92
|
| `loadOlder({limit?})` | Reads the page before the oldest message (default 100) and **prepends it to `messages`.** Returns `{messages, hasMore}`. Use it when scrolling up. If the list is empty (before subscribing), it reads nothing |
|
|
88
93
|
| `history({before?, after?, limit?, view?})` | Reads the past directly. **Independent of `messages`.** `view` is `'main'`, `'all'`, or `{thread: id}` |
|
|
89
|
-
| `
|
|
94
|
+
| `thread(rootId, {root?})` | **Thread handle** (`Thread`, below). One per root id, cached until `close()` |
|
|
95
|
+
| `edit(messageId, {text?, entities?, attachments?})` | Edits your own message. **Replaces the body** — pass back the `attachments`/`entities` to keep. Sender only, within the app's edit window (`forbidden` otherwise). The returned row is applied to `messages` and open threads at once |
|
|
96
|
+
| `delete(messageId)` | Deletes a message: your own, or anyone's for owners and admins. Idempotent. The row becomes a tombstone at once |
|
|
97
|
+
| `reload()` | Re-reads the latest page and **replaces** the list (pages loaded with `loadOlder()` are dropped). A reconnect already refreshes held rows by itself (below), so this is for manual refresh buttons |
|
|
90
98
|
| `react(messageId, emoji)` / `unreact(...)` | Reactions. Idempotent. Updates that row's `myReactions` **before the frame goes out**, and rolls it back if the server refuses. The count is not moved optimistically; **it is set to the server's value when the `reaction.*` event arrives** (below) |
|
|
91
99
|
| `reactionsOf(messageId, {emoji?, cursor?, limit?})` | Who reacted. **Each row is a (user, emoji) pair**, so one person can appear on several rows. `limit` defaults to 50, max 100; the last page's `cursor` is an empty string |
|
|
92
100
|
| `markRead(seq, {threadId?})` | Read cursor |
|
|
93
101
|
| `reads({userId?, cursor?, limit?})` | Read cursors, paged. `{reads: [{userId?, seq, threadId?, withdrawn?}], cursor}`. **`userId` narrows to one person** -- `reads({userId: chat.user.id})` recovers your own per-thread cursors. Stop when `cursor` is `''` |
|
|
94
102
|
| `typing({threadId?})` | Typing indicator. Does not throw. **Call it on every input event** — the SDK sends at most once per second per room. Pass `threadId` while writing a thread reply |
|
|
103
|
+
| `typists({threadId?})` | **Who is typing now**, user ids, earliest signal first. **Without you.** Someone drops out five seconds after their last signal or when their message arrives. `typing.changed` fires on every change |
|
|
95
104
|
| `join()` / `leave()` | Membership |
|
|
96
105
|
| `presenceList()` | Who is in this room right now |
|
|
97
106
|
|
|
@@ -101,8 +110,8 @@ Event names are **exactly the wire names**, and the payloads are in the type dec
|
|
|
101
110
|
|---|---|
|
|
102
111
|
| `message.created` / `message.updated` | `Message`. On `created`, `thread` is absent, `reactions` is empty, and **the SDK fills `myReactions` with `[]`** (the wire carries none) |
|
|
103
112
|
| `message.deleted` | `{id, seq}`. `seq` is the one the message got **when it was published** |
|
|
104
|
-
| `reaction.added` / `reaction.removed` | `{messageId, emoji, count, userId?}`. The SDK has already updated that row's `reactions` count
|
|
105
|
-
| `thread.updated` | `{rootId, count, lastSeq?, lastAt?}`. The SDK has already updated **the root row's `thread`** (`count`, `lastSeq`, `lastAt`) in `messages
|
|
113
|
+
| `reaction.added` / `reaction.removed` | `{messageId, emoji, count, userId?}`. The SDK has already updated that row's `reactions` count (and `myReactions` if it was yours) in `messages` and in open thread handles. Only rows read with `history()` are the consumer's |
|
|
114
|
+
| `thread.updated` | `{rootId, count, lastSeq?, lastAt?}`. The SDK has already updated **the root row's `thread`** (`count`, `lastSeq`, `lastAt`) in `messages` and in thread handles' `root` |
|
|
106
115
|
| `presence` | `{count, joined?, left?, users?, capped?}`. `joined`/`left` are incremental, `users` replaces |
|
|
107
116
|
| `typing` | `{userId, threadId?}` -- `threadId` is the thread **root** id, absent for the main timeline |
|
|
108
117
|
| `read` | `{userId, seq, threadId?}` |
|
|
@@ -116,7 +125,7 @@ The SDK emits three more that have no wire counterpart.
|
|
|
116
125
|
| Event | When |
|
|
117
126
|
|---|---|
|
|
118
127
|
| `messages` | Every time the list changes. **A new array each time; an emitted array is never touched again** |
|
|
119
|
-
| `error` | Reading history or filling a gap failed. **The room resubscribes itself.** The retry button for a person is `subscribe()
|
|
128
|
+
| `error` | Reading history or filling a gap failed. **The room resubscribes itself.** The retry button for a person is `subscribe()`. The refresh after a reconnect (below) failing also emits this, but then the room does **not** resubscribe (it stays subscribed; the next reconnect tries again) |
|
|
120
129
|
| `reset` | The list was discarded and refilled — the cursor was older than the retention period, or **the client reconnected as a different user** (below). **You must discard what you rendered** |
|
|
121
130
|
|
|
122
131
|
### Things to know
|
|
@@ -150,14 +159,12 @@ room.on('messages', m => (messages.value = m))
|
|
|
150
159
|
default). A new emoji past it is refused with `invalid` and the SDK rolls `myReactions` back.
|
|
151
160
|
Pressing an emoji already on the message is never capped. To disable a picker, check that
|
|
152
161
|
`reactions.length` has reached the cap and the emoji is not among them.
|
|
153
|
-
- **
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
`
|
|
159
|
-
reactions look frozen. Read again on `reset`.
|
|
160
|
-
- **`typing` is also delivered to the sender.** If you render "X is typing", skip your own `userId`.
|
|
162
|
+
- **Draw a thread panel with `room.thread(rootId)`** (`Thread`, below). Old replies may not be in the
|
|
163
|
+
room's `messages` (it holds the recent part of the whole stream), so the handle reads them through the
|
|
164
|
+
thread view and applies new replies, reactions, edits and deletes to them too.
|
|
165
|
+
- **Draw "X is typing" from `typists()`.** The SDK drops you, and drops someone after five quiet
|
|
166
|
+
seconds or when their message arrives. The raw `typing` event still comes, and
|
|
167
|
+
**`typing` is also delivered to the sender.** If you render "X is typing", skip your own `userId`.
|
|
161
168
|
- **`typing` carries no name.** Look the name up in `room.presence.users` — whoever is
|
|
162
169
|
watching the room is there. Collecting names from message senders misses anyone who has not
|
|
163
170
|
spoken yet. If `users` is absent (a room over 100), fetch it once with `presenceList()`, and fall
|
|
@@ -180,6 +187,7 @@ room.on('messages', m => (messages.value = m))
|
|
|
180
187
|
```
|
|
181
188
|
- **The connection comes back on its own.** It reconnects with exponential backoff, so don't
|
|
182
189
|
write your own retry loop.
|
|
190
|
+
- **A reconnect also brings the rows you already hold up to date.** The catch-up (`since`) only fills *new* messages; a reaction, a thread count (`thread.updated`), an edit or a delete on a message you already had rides on no event while you were away. So after a real reconnect (including a tab or app returning from the background, same user) and once the catch-up is done, the SDK **reads the newest 100 messages once (one GET per room) and merges them into the rows it holds.** The list is not replaced (no `reset`, pages loaded with `loadOlder()` stay); each row that actually changed becomes a new object with a `message.updated`, a row that is now deleted becomes a tombstone with `message.deleted` (`messages` fires once). A row that a live event, or a reaction this client pressed, touched while the read was in flight is left alone because that value is newer. **Rows older than the newest 100 are not re-read** — use `reload()` for those. Thread replies live in the same timeline, so they are refreshed along with their roots. If the read fails only `error` is emitted and the room stays subscribed. You do not need to call `reload()` yourself.
|
|
183
191
|
- **What you send while reconnecting waits, then goes out.** `send`, `react`, `unreact` and
|
|
184
192
|
`markRead` skip the backoff when the state is `connecting`/`reconnecting`, wait for the
|
|
185
193
|
connection, and send. If the socket drops before the ack, **the same frame is sent once more**
|
|
@@ -203,6 +211,68 @@ room.on('messages', m => (messages.value = m))
|
|
|
203
211
|
**Call `reconnect()` whenever the login state changes** — the REST path that refreshes a token
|
|
204
212
|
on a 401 does not check whether the user changed.
|
|
205
213
|
|
|
214
|
+
### `Thread` — `room.thread(rootId, {root?})`
|
|
215
|
+
|
|
216
|
+
One thread panel. Replies are part of the room's stream, so their seqs are not contiguous and old ones
|
|
217
|
+
are not in the room's `messages`; the handle holds the replies it read through the thread view
|
|
218
|
+
(`view=thread:<rootId>`) and **applies the room's events to them.** It is live while the room is subscribed.
|
|
219
|
+
|
|
220
|
+
| Property | |
|
|
221
|
+
|---|---|
|
|
222
|
+
| `messages` | Replies, ascending by seq. A new array on every change. A deleted reply keeps its place as a tombstone (`deletedAt`) — filter it to hide it |
|
|
223
|
+
| `root` | The root: the room's own row, else the copy passed as `{root}` (an old message opened from search or a link), else `undefined` |
|
|
224
|
+
| `hasOlder` | Whether `loadOlder()` would find more replies |
|
|
225
|
+
| `loaded` | `load()` finished once |
|
|
226
|
+
|
|
227
|
+
| Method | |
|
|
228
|
+
|---|---|
|
|
229
|
+
| `load({limit?})` | Reads the newest page of replies (100 by default and at most) and **replaces** what is held (replies that arrived live meanwhile stay). Call it when the panel opens |
|
|
230
|
+
| `loadOlder({limit?})` | Prepends the page above the oldest reply. `{messages, hasMore}` |
|
|
231
|
+
| `markRead(seq?)` | The thread's read cursor (default: the newest reply held). Sends nothing when this handle already marked that far, so it can run on every `messages` event |
|
|
232
|
+
| `close()` | Stops following. `room.thread(rootId)` afterwards is a new handle |
|
|
233
|
+
|
|
234
|
+
Events: `messages` (replies changed), `root` (`root` changed — reactions, edit, delete, reply count),
|
|
235
|
+
`error` (the re-read after a reconnect failed; the handle stays).
|
|
236
|
+
|
|
237
|
+
- **React with `room.react()`** — the room's list and every open thread press the same row optimistically together and roll back together.
|
|
238
|
+
- **Reply with `room.send({text, threadId: rootId})`.** The reply lands on this handle.
|
|
239
|
+
- **After a reconnect (same user)** the newest 100 replies are re-read and merged: replies posted while away come in, held ones get their reactions, edits and deletes. **A different user** drops them and reads again. A root copy outside the room's list moves by events only (there is no single-message route to re-read it).
|
|
240
|
+
|
|
241
|
+
### `RoomList` — `chat.roomList()`
|
|
242
|
+
|
|
243
|
+
The rooms you are in, with unread counts — a channel sidebar. Call `load()` once (up to 1000 rooms); the SDK keeps it current.
|
|
244
|
+
|
|
245
|
+
| | |
|
|
246
|
+
|---|---|
|
|
247
|
+
| `rooms` | `RoomSummary[]` — `{id, room, lastSeq, readSeq, unread, mentions, unreadCapped?, lastMessage?}`. A new array on every change. Server order (latest activity); **sorting and grouping are the screen's** |
|
|
248
|
+
| `get(roomId)` | One room |
|
|
249
|
+
| `load()` | Reads again and replaces. A call during one runs once more after it |
|
|
250
|
+
| `loaded` | `load()` finished once |
|
|
251
|
+
| events `rooms` / `error` | The list changed / a read failed |
|
|
252
|
+
|
|
253
|
+
What the SDK keeps current:
|
|
254
|
+
|
|
255
|
+
- **`notification`** (a message in a room you have not subscribed): the server's `unread`/`unreadMentions` and `lastSeq`; +1 if the counts are missing. An unknown room (you were just added) reloads the list.
|
|
256
|
+
- **Subscribed rooms**: a new message moves `lastSeq`. Your own `room.markRead(seq)` on the main timeline moves `readSeq` and zeroes `unread`/`mentions` once it reaches `lastSeq`. **A subscribed room's `unread` is never raised** — when a room on screen counts as read is the screen's call.
|
|
257
|
+
- `room.updated` replaces the room object; `room.deleted` and your own `member.left` remove it (both arrive for subscribed rooms only). `rooms.update()`/`rooms.delete()` correct it from their answer.
|
|
258
|
+
- **`resumed` reloads it** — counts that moved while away ride on no event. A different user empties and reloads it.
|
|
259
|
+
|
|
260
|
+
### Mention helpers — `buildMentions` · `mentionSpans`
|
|
261
|
+
|
|
262
|
+
An engine mention is `{type: 'mention', userId, offset, length}` in `body.entities`; `offset`/`length` are JS (UTF-16)
|
|
263
|
+
indexes into `body.text` covering the whole `@name`. The engine resolves `userId` for `unreadMentions` and push and **does not check the offsets.**
|
|
264
|
+
|
|
265
|
+
- `buildMentions(text, people, {skipCode?})` — finds `@name` for each of `people` (`{id, name}[]`) in **the final text being sent**.
|
|
266
|
+
Not mail (`a@b.com`); the longer name first (`@Anna` is not `Ann`); not when a letter follows the name;
|
|
267
|
+
skips markdown code (fenced blocks, inline spans) unless `skipCode: false`. Two people with one name are handed out in `people` order. At most 100.
|
|
268
|
+
- `mentionSpans(text, entities)` — the received entities that agree with the text, as `{start, end, userId}[]`:
|
|
269
|
+
a mention with a `userId`, inside the text on one line, starting at `@`, not overlapping an earlier one.
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
const text = input.trim()
|
|
273
|
+
await room.send({ text, entities: buildMentions(text, picked) })
|
|
274
|
+
```
|
|
275
|
+
|
|
206
276
|
### `text` is untrusted plain text
|
|
207
277
|
|
|
208
278
|
Message `text`, and user-supplied display names/nicknames (`name`), are **plain text
|
|
@@ -332,11 +402,15 @@ spaces don't overlap.
|
|
|
332
402
|
| Group | Methods |
|
|
333
403
|
|---|---|
|
|
334
404
|
| `rooms` | `list({type?, cursor?, limit?})`, `ensure({key?, type, name?, meta?, members?})`, `ensureDM([a, b])`, `get`, `update`, `delete`, `custom(roomId, payload)`, `presence(roomId, {full?})`, `members.list/add/remove` |
|
|
335
|
-
| `messages` | `send(roomId, {sender, text?, kind?, attachments?, appMeta?, replyTo?, threadId?, clientMessageId?})`, `list`, `delete` |
|
|
405
|
+
| `messages` | `send(roomId, {sender, text?, kind?, attachments?, appMeta?, replyTo?, threadId?, clientMessageId?})`, `list(roomId, {before?, after?, limit?, view?, q?})`, `delete` |
|
|
336
406
|
| `users` | `list({cursor?, limit?})`, `update(userId, {name?, avatar?, meta?})`, `withdraw(userId, {purgeMessages?})`, `purgeMessages(userId)`, `ban(userId, {until, reason?})`, `unban(userId)`, `revokeTokens(userId)`, `disconnect(userId, {connectionId?, reason?})` |
|
|
337
407
|
| `events` | `list({after?, limit?})` — catches up on missed webhook events |
|
|
338
408
|
| `webhooks` | `verify(headers, rawBody, {now?, tolerance?})` — `tolerance` is in milliseconds |
|
|
339
409
|
|
|
410
|
+
`messages.list` takes `view` — `'main'`, `'all'` (default) or `{thread: rootId}` — and **`q`, a body search in the room**
|
|
411
|
+
(substring, case-insensitive, deleted messages excluded). `q` is secret-key only — a user token gets 403 (an unindexed scan).
|
|
412
|
+
A search page's seqs are not contiguous; never use them as a sync cursor.
|
|
413
|
+
|
|
340
414
|
`rooms.list` returns the app's rooms, newest first. With no `type` it is the public listing
|
|
341
415
|
(`public` and `channel`); pass e.g. `type: ['private', 'dm']` for private rooms and DMs. `limit`
|
|
342
416
|
defaults to 50 (max 100), an empty `cursor` is the last page, and **the cursor does not carry
|
package/README.md
CHANGED
|
@@ -48,9 +48,12 @@ npm install @kispi/chat
|
|
|
48
48
|
| `reconnect()` | **다시 인증한다**: `token()`을 다시 불러 소켓을 바꾼다. 방 핸들과 구독, `messages`는 그대로이고(**사람이 바뀌면 `messages`는 버리고 다시 채운다**) 상태는 `open → reconnecting → open`이다(`closed`를 거치지 않는다). 닉네임·아바타를 바꾼 뒤, 그리고 **로그인·로그아웃으로 사람이 바뀔 때** 쓴다(아래) |
|
|
49
49
|
| `room(roomId)` | 방 핸들. 같은 id면 같은 객체 |
|
|
50
50
|
| `roomByKey(key)` | 키로 여는 방 핸들. 구독할 때 서버가 id를 알려 준다. **방을 만들지 않는다** — 없는 키면 `subscribe()`가 `not_found`로 거절한다. 방은 백엔드가 `rooms.ensure()`로 만든다 |
|
|
51
|
-
| `
|
|
51
|
+
| `roomList()` | **살아 있는 내 방 목록**(`RoomList`, 아래) — 채널 사이드바. 클라이언트마다 하나 |
|
|
52
|
+
| `rooms.list({cursor?, limit?})` | 내가 멤버인 방 한 페이지: `{rooms: MyRoom[], cursor}`. `MyRoom`은 `{room, lastSeq, readSeq, unread, unreadMentions, unreadCapped?, lastMessage?}`, 마지막 활동 순 |
|
|
52
53
|
| `rooms.discover({type?, cursor?, limit?})` | 공개 방 탐색 |
|
|
53
|
-
| `rooms.
|
|
54
|
+
| `rooms.update(roomId, {name?, meta?})` | 방 이름·meta 바꾸기. 방장·관리자만(아니면 `forbidden`), 구독자 모두에게 `room.updated`가 간다. 응답(`RoomInfo`)으로 `roomList()`도 고친다 |
|
|
55
|
+
| `rooms.delete(roomId)` | 방 지우기(소프트 삭제). **방장만**(아니면 `forbidden`). 구독자에게 `room.deleted`, `roomList()`에서 빠진다 |
|
|
56
|
+
| `rooms.members(roomId).list/add/remove` | 멤버 관리. `list`는 `{members: MemberRow[], cursor}` — `{userId?, name?, role, joinedAt?, withdrawn?}`(탈퇴한 행은 `userId` 없이 `withdrawn: true`) |
|
|
54
57
|
| `unread()` | `{total, mentions, roomsCapped?, rooms}`. `chat.hello?.unread`와 **같은 이름**이다 |
|
|
55
58
|
| `updateMe(meta)` | 내 `meta`. **`name`과 `avatar`는 토큰 claim에서 온다** |
|
|
56
59
|
|
|
@@ -59,6 +62,7 @@ npm install @kispi/chat
|
|
|
59
62
|
| `state` | 위 네 값 |
|
|
60
63
|
| `error` | 클라이언트가 스스로 `closed`로 멈췄고 그 이유(`ChatError`). 인증 거절이나 `token()`의 `ChatError`. `close()`로 닫을 때는 없다 |
|
|
61
64
|
| `notification` | 멤버인 방에 새 메시지가 왔는데 그 방을 보고 있지 않을 때 |
|
|
65
|
+
| `resumed` | `{reconnected}` — 다시 붙었거나(`true`), 탭·앱 복귀·온라인 복귀·bfcache 복원(`pageshow`)에서 소켓이 살아 있어 방들을 다시 구독했다(`false`). 방과 `roomList()`는 스스로 맞추니, **SDK가 들고 있지 않은 것**(활동 피드·검색 결과처럼 앱이 REST로 받은 목록)을 다시 받을 때 쓴다 |
|
|
62
66
|
| `user.presence` | 내 다른 접속의 presence 변화 |
|
|
63
67
|
| `frame` | 받은 프레임 전부. 디버깅용 |
|
|
64
68
|
|
|
@@ -85,13 +89,17 @@ off()
|
|
|
85
89
|
| `unsubscribe()` | 이 방 보기를 그만둔다. 재접속해도 다시 구독하지 않는다 |
|
|
86
90
|
| `send({text, attachments?, entities?, replyTo?, threadId?, meta?}, {clientMessageId?})` | 발행. ack로 `{messageId, seq}`. 구독이 진행 중이면 그것을 기다린다. **재접속 중이면 붙을 때까지 기다렸다가 보낸다**(아래) |
|
|
87
91
|
| `loadOlder({limit?})` | 가장 오래된 메시지 앞 페이지(기본 100)를 읽어 **`messages` 앞에 붙인다.** `{messages, hasMore}`. 스크롤을 올릴 때 쓴다. 목록이 비어 있으면(구독 전) 아무것도 읽지 않는다 |
|
|
88
|
-
| `history({before?, after?, limit?, view?})` | 과거를 직접 읽는다. **`messages`와 따로 논다.** `view`는 `'main'`, `'all'`, `{thread: id}` |
|
|
89
|
-
| `
|
|
92
|
+
| `history({before?, after?, limit?, view?})` | 과거를 직접 읽는다. **`messages`와 따로 논다.** `view`는 `'main'`, `'all'`, `{thread: id}`. 스레드 패널은 `thread()`를 쓴다 |
|
|
93
|
+
| `thread(rootId, {root?})` | **스레드 핸들**(`Thread`, 아래). 루트 id마다 하나, `close()`까지 캐시된다 |
|
|
94
|
+
| `edit(messageId, {text?, entities?, attachments?})` | 내 글 고치기. **본문을 통째로 바꾼다** — 남길 `attachments`·`entities`도 다시 넘긴다. 본인만·앱의 수정 가능 시간 안(아니면 `forbidden`). 응답 행(`Message`)을 `messages`와 열린 스레드에 바로 반영한다 |
|
|
95
|
+
| `delete(messageId)` | 글 지우기. 본인 글, 방장·관리자는 남의 글도. 멱등. 그 행을 바로 tombstone으로 |
|
|
96
|
+
| `reload()` | 최근 페이지를 다시 읽어 **교체한다**(`loadOlder()`로 불러 둔 윗부분은 버린다). 재접속 뒤의 갱신은 SDK가 알아서 하니(아래) 새로고침 버튼 같은 수동 용도다 |
|
|
90
97
|
| `react(messageId, emoji)` / `unreact(...)` | 리액션. 멱등. **프레임보다 먼저** 그 행의 `myReactions`를 고치고, 서버가 거절하면 되돌린다. 개수는 낙관적으로 올리지 않고 **`reaction.*` 이벤트가 올 때 서버 값으로 고친다**(아래) |
|
|
91
98
|
| `reactionsOf(messageId, {emoji?, cursor?, limit?})` | 누가 눌렀는지. **한 행은 (유저, 이모지) 쌍**이라 한 사람이 여러 줄일 수 있다. `limit` 기본 50 최대 100, 마지막 페이지의 `cursor`는 빈 문자열 |
|
|
92
99
|
| `markRead(seq, {threadId?})` | 읽음 커서 |
|
|
93
100
|
| `reads({userId?, cursor?, limit?})` | 읽음 커서 목록. `{reads: [{userId?, seq, threadId?, withdrawn?}], cursor}`. **`userId`로 한 사람만** — 자기 스레드별 커서를 되찾을 때 `reads({userId: chat.user.id})`. `cursor`가 `''`이면 끝 |
|
|
94
101
|
| `typing({threadId?})` | 입력 중. 던지지 않는다. **입력 이벤트마다 불러도 된다** — SDK가 방마다 1초에 한 번만 보낸다. 스레드 답글을 쓰는 중이면 `threadId` |
|
|
102
|
+
| `typists({threadId?})` | **지금 입력 중인 사람**의 user id(먼저 신호 온 순). **나는 빠진다.** 마지막 신호 뒤 5초가 지나거나 그 사람의 글이 오면 빠진다. 바뀔 때마다 `typing.changed` |
|
|
95
103
|
| `join()` / `leave()` | 멤버십 |
|
|
96
104
|
| `presenceList()` | 지금 이 방에 있는 사람 |
|
|
97
105
|
|
|
@@ -101,8 +109,8 @@ off()
|
|
|
101
109
|
|---|---|
|
|
102
110
|
| `message.created` / `message.updated` | `Message`. `created`에는 `thread`가 없고 `reactions`가 비어 있으며, `myReactions`는 **SDK가 `[]`로 채운다**(와이어에는 없다) |
|
|
103
111
|
| `message.deleted` | `{id, seq}`. `seq`는 그 메시지가 **발행될 때** 받은 값이다 |
|
|
104
|
-
| `reaction.added` / `reaction.removed` | `{messageId, emoji, count, userId?}`. SDK가 `messages
|
|
105
|
-
| `thread.updated` | `{rootId, count, lastSeq?, lastAt?}`. SDK가
|
|
112
|
+
| `reaction.added` / `reaction.removed` | `{messageId, emoji, count, userId?}`. SDK가 `messages`와 열린 스레드 핸들 안의 그 행의 `reactions` 개수를(내 것이면 `myReactions`도) 이미 고쳐 두었다. `history()`로 따로 읽은 행만 소비자 몫이다 |
|
|
113
|
+
| `thread.updated` | `{rootId, count, lastSeq?, lastAt?}`. SDK가 **루트 행 `thread`**(`count`·`lastSeq`·`lastAt`)를 `messages`와 스레드 핸들의 `root`에서 이미 고쳐 두었다 |
|
|
106
114
|
| `presence` | `{count, joined?, left?, users?, capped?}`. `joined`/`left`는 증분, `users`는 교체다 |
|
|
107
115
|
| `typing` | `{userId, threadId?}` — `threadId`는 스레드 **루트** id, 본 타임라인이면 없다 |
|
|
108
116
|
| `read` | `{userId, seq, threadId?}` |
|
|
@@ -116,7 +124,8 @@ off()
|
|
|
116
124
|
| 이벤트 | 언제 |
|
|
117
125
|
|---|---|
|
|
118
126
|
| `messages` | 목록이 바뀔 때마다. **매번 새 배열이고, 내보낸 배열은 다시 건드리지 않는다** |
|
|
119
|
-
| `
|
|
127
|
+
| `typing.changed` | `{threadId?, userIds}` — 그 자리(본 타임라인, 또는 루트가 `threadId`인 스레드)의 `typists()`가 바뀌었다 |
|
|
128
|
+
| `error` | 히스토리를 읽거나 구멍을 메우는 데 실패했다. **방이 스스로 다시 구독한다.** 사람이 누를 재시도 버튼은 `subscribe()`. 재접속 뒤 갱신(아래)이 실패해도 이 이벤트지만 그때는 **다시 구독하지 않는다**(방은 구독된 채이고 다음 재접속이 다시 한다) |
|
|
120
129
|
| `reset` | 목록을 버리고 다시 채웠다 — 커서가 보존 기간보다 오래됐거나, **다른 사람으로 다시 붙었다**(아래). **렌더한 것을 버려야 한다** |
|
|
121
130
|
|
|
122
131
|
### 알아 둘 것
|
|
@@ -146,30 +155,28 @@ room.on('messages', m => (messages.value = m))
|
|
|
146
155
|
- **이모지 종류에는 메시지당 상한이 있다**(`hello.limits.maxDistinctEmojiPerMessage`, 기본 20). 넘는 새
|
|
147
156
|
이모지는 `invalid`로 거절되고 SDK가 `myReactions`를 되돌린다. 이미 달린 이모지를 누르는 것은 상한과
|
|
148
157
|
무관하다. 피커를 막으려면 `reactions.length`가 상한에 닿았고 그 이모지가 없을 때 비활성화한다.
|
|
149
|
-
- **스레드 패널은
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
- **`typing`은 보낸 사람에게도 온다.** "X가 입력 중"을 그린다면 자기 `userId`를 건너뛴다.
|
|
158
|
+
- **스레드 패널은 `room.thread(rootId)`로 그린다**(아래 `Thread`). 지난 답글은 방 `messages`에 없을 수
|
|
159
|
+
있어서(방 전체 스트림의 최근 구간만 든다) 핸들이 스레드 뷰로 따로 읽고, 새 답글·리액션·수정·삭제를
|
|
160
|
+
그 행들에도 반영한다.
|
|
161
|
+
- **"X가 입력 중"은 `typists()`로 그린다.** 나를 빼고, 5초 지나거나 그 사람의 글이 오면 빼는 일을
|
|
162
|
+
SDK가 한다. 날것의 `typing` 이벤트는 그대로 오고 **보낸 사람에게도 온다.**
|
|
155
163
|
- **`typing`은 이름을 싣지 않는다.** 이름은 `room.presence.users`에서 찾는다 — 방을 보고 있는
|
|
156
|
-
사람이 거기 있다.
|
|
157
|
-
|
|
158
|
-
- **`typing`은 한 사람당 방마다 많아야 3초에 한 번 온다.** "입력 멈춤" 이벤트는 없으니 표시는
|
|
159
|
-
마지막 이벤트 뒤 **5초 이상** 유지한다 — 계속 입력하는 사람의 방송 간격도 4초를 넘을 수 있어서,
|
|
160
|
-
그보다 짧으면 이벤트 사이에서 깜빡인다.
|
|
161
|
-
- **방마다 한 번에 알리는 사람 수에 상한이 있다**(지금 3명). 방송 한 번이 인원수만큼 나가기
|
|
162
|
-
때문이고, 화면도 "A, B, C가 입력 중" 정도까지만 그린다. 붐비는 방에서는 입력 중인데 알려지지
|
|
164
|
+
사람이 거기 있다. `users`가 없으면(100명 넘는 방) `presenceList()`로 한 번 받아 오고, 그래도 없으면 대체 이름을 쓴다.
|
|
165
|
+
- **방마다 한 번에 알리는 사람 수에 상한이 있다**(지금 3명). 붐비는 방에서는 입력 중인데 알려지지
|
|
163
166
|
않는 사람이 있다 — 그 숫자에 기대는 코드는 짜지 않는다(엔진이 바꿀 수 있다).
|
|
164
167
|
|
|
165
168
|
```ts
|
|
166
|
-
room.on('typing', ({
|
|
167
|
-
if (
|
|
168
|
-
const
|
|
169
|
-
showTyping(
|
|
169
|
+
room.on('typing.changed', ({ threadId, userIds }) => {
|
|
170
|
+
if (threadId !== undefined) return // 본 타임라인만
|
|
171
|
+
const names = userIds.map(id => room.presence?.users?.find(u => u.id === id)?.name ?? '누군가')
|
|
172
|
+
showTyping(names) // 빈 배열이면 지운다
|
|
170
173
|
})
|
|
171
174
|
```
|
|
172
175
|
- **연결은 알아서 돌아온다.** 끊기면 지수 백오프로 다시 붙으니 재시도 루프를 짜지 않는다.
|
|
176
|
+
- **재접속하면 이미 들고 있는 행도 최신으로 맞춘다.** 따라잡기(`since`)는 새 메시지만 채우고, 끊긴 사이 이미 있던 메시지에 붙은 리액션·스레드 수(`thread.updated`)·수정·삭제는 어느 이벤트로도 오지 않는다. 그래서 진짜 재접속(탭·앱 복귀의 재구독 포함, 같은 사람일 때) 뒤 따라잡기가 끝나면 SDK가 **가장 최근 100건을 한 번 읽어(방마다 GET 1번) 들고 있는 행에 합친다.** 목록을 바꾸지 않고(`reset` 없음, `loadOlder()`로 불러 둔 윗부분 그대로) 바뀐 행만 새 객체로 `message.updated`, 지워진 행은 tombstone으로 `message.deleted`를 낸다(`messages`는 한 번). 읽는 사이 도착한 라이브 이벤트나 이 클라이언트가 누른 리액션이 더 새 값이라 그 행은 건드리지 않는다. **최근 100건보다 오래된 행은 다시 읽지 않는다** — 필요하면 `reload()`. 스레드 답글은 같은 타임라인이라 루트와 함께 맞춰진다. 이 읽기가 실패하면 `error`만 나가고 방은 구독된 채다. 소비자가 따로 `reload()`를 부를 필요가 없다.
|
|
177
|
+
- **떠났던 방을 다시 구독할 때도 같다.** 핸들은 캐시되므로 `unsubscribe()` 뒤 `subscribe()`한 방은 들고 있던
|
|
178
|
+
행을 그대로 받는다. 그래서 다시 구독하면 재접속 때처럼 따라잡은 뒤 최근 100건을 읽어 합친다 — 떠나 있던
|
|
179
|
+
사이의 리액션·스레드 수가 새로 고침 없이 보인다. 열린 스레드 핸들도 최근 답글 100개를 다시 읽어 합친다.
|
|
173
180
|
- **재접속 중에 보낸 것은 기다렸다가 나간다.** `send`·`react`·`unreact`·`markRead`는 상태가
|
|
174
181
|
`connecting`/`reconnecting`이면 백오프를 건너뛰고 붙기를 기다려 보낸다. ack 전에 소켓이
|
|
175
182
|
끊기면 **같은 프레임을 한 번 더** 보낸다 — 서버가 `clientMessageId`로 중복을 거르고 리액션·읽음은
|
|
@@ -190,6 +197,79 @@ room.on('messages', m => (messages.value = m))
|
|
|
190
197
|
**로그인 상태가 바뀌면 반드시 `reconnect()`를 부른다** — REST가 401에서 토큰을 갱신하는 길은
|
|
191
198
|
사람이 바뀌었는지 보지 않는다.
|
|
192
199
|
|
|
200
|
+
### `Thread` — `room.thread(rootId, {root?})`
|
|
201
|
+
|
|
202
|
+
스레드 패널 하나. 답글은 방 스트림의 일부라 seq가 이어지지 않고 오래된 답글은 방 `messages`에 없으므로,
|
|
203
|
+
핸들이 스레드 뷰(`view=thread:<rootId>`)로 읽은 답글을 따로 들고 **방이 받는 이벤트를 그 행들에도
|
|
204
|
+
적용한다.** 방을 구독해야 살아 있다(이벤트는 방 구독으로 온다).
|
|
205
|
+
|
|
206
|
+
| 프로퍼티 | |
|
|
207
|
+
|---|---|
|
|
208
|
+
| `messages` | 답글, seq 오름차순. 바뀔 때마다 새 배열. 지운 답글은 tombstone으로 자리를 지킨다(`deletedAt`) — 숨기려면 거른다 |
|
|
209
|
+
| `root` | 루트 메시지: 방 `messages`의 행, 없으면 `{root}`로 넘긴 사본(검색·링크로 연 오래된 글). 둘 다 없으면 `undefined` |
|
|
210
|
+
| `hasOlder` | `loadOlder()`로 더 읽을 답글이 있는지 |
|
|
211
|
+
| `loaded` | `load()`가 한 번 끝났다 |
|
|
212
|
+
|
|
213
|
+
| 메서드 | |
|
|
214
|
+
|---|---|
|
|
215
|
+
| `load({limit?})` | 최근 답글 한 페이지(기본·최대 100)를 읽어 **교체한다**(그사이 라이브로 온 답글은 남는다). 패널을 열 때 |
|
|
216
|
+
| `loadOlder({limit?})` | 가장 오래된 답글 앞 페이지를 읽어 앞에 붙인다. `{messages, hasMore}` |
|
|
217
|
+
| `markRead(seq?)` | 이 스레드의 읽음 커서(기본: 가진 마지막 답글). 이 핸들이 이미 그만큼 읽었으면 프레임을 보내지 않으니 `messages` 이벤트마다 불러도 된다 |
|
|
218
|
+
| `close()` | 그만 따라간다. 그 뒤 `room.thread(rootId)`는 새 핸들 |
|
|
219
|
+
|
|
220
|
+
| 이벤트 | |
|
|
221
|
+
|---|---|
|
|
222
|
+
| `messages` | 답글이 바뀌었다(새 배열) |
|
|
223
|
+
| `root` | `root`가 바뀌었다(리액션·수정·삭제·답글 수) |
|
|
224
|
+
| `error` | 재접속 뒤 다시 읽기가 실패했다. 핸들은 그대로다 |
|
|
225
|
+
|
|
226
|
+
- **리액션은 `room.react()`로 누른다** — 방 목록과 열린 스레드가 같은 행을 함께 낙관적으로 누르고, 거절되면 같이 되돌린다.
|
|
227
|
+
- **답글 보내기는 `room.send({text, threadId: rootId})`.** 답글이 오면 이 핸들에 붙는다.
|
|
228
|
+
- **재접속(같은 사람)** 뒤에는 최근 답글 100개를 다시 읽어 합친다 — 끊긴 사이 달린 답글이 들어오고, 들고 있던 답글의 리액션·수정·삭제가 맞춰진다. **다른 사람으로 다시 붙으면** 버리고 다시 읽는다. 목록 밖 루트 사본은 다시 읽을 길(메시지 한 건 조회 라우트)이 없어 이벤트로만 움직인다.
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
const thread = room.thread(root.id, { root })
|
|
232
|
+
thread.on('messages', m => (replies = m))
|
|
233
|
+
await thread.load()
|
|
234
|
+
// 닫을 때
|
|
235
|
+
thread.close()
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### `RoomList` — `chat.roomList()`
|
|
239
|
+
|
|
240
|
+
내가 들어 있는 방과 안 읽은 수 — 채널 사이드바. `load()`를 한 번 부르면(최대 1000개) 그 뒤는 SDK가 맞춘다.
|
|
241
|
+
|
|
242
|
+
| | |
|
|
243
|
+
|---|---|
|
|
244
|
+
| `rooms` | `RoomSummary[]` — `{id, room, lastSeq, readSeq, unread, mentions, unreadCapped?, lastMessage?}`. 바뀔 때마다 새 배열. 순서는 서버 것(마지막 활동 순)이고 **정렬·묶기는 화면 몫이다** |
|
|
245
|
+
| `get(roomId)` | 한 방 |
|
|
246
|
+
| `load()` | 다시 읽어 교체한다. 진행 중에 부르면 끝난 뒤 한 번 더 |
|
|
247
|
+
| `loaded` | `load()`가 한 번 끝났다 |
|
|
248
|
+
| 이벤트 `rooms` / `error` | 목록이 바뀌었다 / 읽기가 실패했다 |
|
|
249
|
+
|
|
250
|
+
SDK가 맞추는 것:
|
|
251
|
+
|
|
252
|
+
- **`notification`**(구독하지 않은 방의 새 글): 서버가 센 `unread`·`unreadMentions`와 `lastSeq`. 셈이 빠진 알림이면 +1. 목록에 없는 방(방금 초대됨)이면 다시 읽는다.
|
|
253
|
+
- **구독한 방**: 새 글이 `lastSeq`를 올린다. 이 클라이언트의 `room.markRead(seq)`(본 타임라인)가 `readSeq`를 올리고, `lastSeq`에 닿으면 `unread`·`mentions`를 0으로. **구독한 방의 `unread`를 올리지는 않는다** — 보고 있는 방을 언제 읽었다고 칠지는 화면이 정한다.
|
|
254
|
+
- `room.updated`는 방 객체를, `room.deleted`와 내 `member.left`는 목록에서 뺀다(둘 다 구독한 방에서만 온다). `rooms.update()`·`rooms.delete()`는 응답으로 고친다.
|
|
255
|
+
- **`resumed`면 다시 읽는다** — 끊긴 사이 바뀐 수는 어떤 이벤트로도 오지 않는다. 다른 사람으로 다시 붙으면 비우고 다시 읽는다.
|
|
256
|
+
|
|
257
|
+
### 멘션 도우미 — `buildMentions` · `mentionSpans`
|
|
258
|
+
|
|
259
|
+
엔진의 멘션은 `body.entities`의 `{type: 'mention', userId, offset, length}`다. `offset`·`length`는 `body.text`의
|
|
260
|
+
JS(UTF-16) 인덱스이고 `@이름` 전체를 덮는다. 엔진은 `userId`만 풀어 `unreadMentions`·푸시에 쓰고 **자리는 검증하지 않는다.**
|
|
261
|
+
|
|
262
|
+
- `buildMentions(text, people, {skipCode?})` — **보낼 최종 글**에서 `people`(`{id, name}[]`)의 `@이름`을 찾아 entities를 만든다.
|
|
263
|
+
메일(`a@b.com`)은 아니고, 더 긴 이름이 먼저(`@Anna`는 `Ann`이 아니다), 이름 뒤가 글자면 아니다(`@형님`은 `형`이 아니다),
|
|
264
|
+
마크다운 코드(``` 블록·`인라인`) 안은 건너뛴다(`skipCode: false`면 안 건너뜀). 같은 이름이 둘이면 `people` 순서대로 하나씩. 100개까지.
|
|
265
|
+
- `mentionSpans(text, entities)` — 받은 entities 중 글과 맞는 것만 `{start, end, userId}[]`로(남이 보낸 값이라 믿지 않는다).
|
|
266
|
+
멘션이고 `userId`가 있고, 글 안 한 줄에 있고 `@`로 시작하며 앞의 것과 겹치지 않는 것만.
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
const text = input.trim()
|
|
270
|
+
await room.send({ text, entities: buildMentions(text, picked) })
|
|
271
|
+
```
|
|
272
|
+
|
|
193
273
|
### `text`는 신뢰할 수 없는 평문이다
|
|
194
274
|
|
|
195
275
|
메시지 `text`와 유저가 넣는 표시 이름·닉네임(`name`)은 **엔진이 HTML 이스케이프하거나
|
|
@@ -312,7 +392,7 @@ app.post('/api/chat-token', (req, res) => {
|
|
|
312
392
|
| 그룹 | 메서드 |
|
|
313
393
|
|---|---|
|
|
314
394
|
| `rooms` | `list({type?, cursor?, limit?})`, `ensure({key?, type, name?, meta?, members?})`, `ensureDM([a, b])`, `get`, `update`, `delete`, `custom(roomId, payload)`, `presence(roomId, {full?})`, `members.list/add/remove` |
|
|
315
|
-
| `messages` | `send(roomId, {sender, text?, kind?, attachments?, appMeta?, replyTo?, threadId?, clientMessageId?})`, `list`, `delete` |
|
|
395
|
+
| `messages` | `send(roomId, {sender, text?, kind?, attachments?, appMeta?, replyTo?, threadId?, clientMessageId?})`, `list(roomId, {before?, after?, limit?, view?, q?})`, `delete` |
|
|
316
396
|
| `users` | `list({cursor?, limit?})`, `update(userId, {name?, avatar?, meta?})`, `withdraw(userId, {purgeMessages?})`, `purgeMessages(userId)`, `ban(userId, {until, reason?})`, `unban(userId)`, `revokeTokens(userId)`, `disconnect(userId, {connectionId?, reason?})` |
|
|
317
397
|
| `events` | `list({after?, limit?})` — 놓친 웹훅 이벤트를 따라잡는다 |
|
|
318
398
|
| `webhooks` | `verify(headers, rawBody, {now?, tolerance?})` — `tolerance`는 밀리초 |
|
|
@@ -323,6 +403,9 @@ app.post('/api/chat-token', (req, res) => {
|
|
|
323
403
|
`type: ['private', 'dm']`처럼 주면 비공개 방과 DM도 나온다. `limit` 기본 50 최대 100, 빈 `cursor`가
|
|
324
404
|
마지막 페이지이고, **커서는 `type`을 싣지 않으므로** 필터를 바꾸면 처음부터 받는다.
|
|
325
405
|
|
|
406
|
+
`messages.list`의 `view`는 `'main'`·`'all'`(기본)·`{thread: rootId}`, **`q`는 방 안 본문 검색**이다(부분 일치, 대소문자 무시, 지운 글 제외).
|
|
407
|
+
`q`는 서버 키만 된다 — 유저 토큰이면 403이다(인덱스 없이 방을 훑는 비용이라). 검색 결과의 seq는 이어지지 않으니 동기화 커서로 쓰지 않는다.
|
|
408
|
+
|
|
326
409
|
`rooms.presence(roomId)`는 `{count}`이고, `{full: true}`면 `users`(최대 1000명, 잘리면
|
|
327
410
|
`capped: true`)가 붙는다. 빈 방은 404가 아니라 `{count: 0}`이다.
|
|
328
411
|
|