cortico-world-parlor 0.37.2 → 0.37.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.37.3(2026-11-07)
2
+
3
+ - 修复信箱 [#19](https://github.com/biliye/cortico-world-parlor/issues/19) 和 [#20](https://github.com/biliye/cortico-world-parlor/issues/20)。两代网页的「都看过了」一次标记所有客厅的来信,并回显本次标记数和剩余未读。未读标记按每封信的状态显示,家长页可只读查看孩子收到的信及其未读状态。Coo 优先取最新未读,回执先显示剩余未读数,也可显式将全部来信标为已读。
4
+ - 新增 `POST /v1/mail/read-all`:一次事务标完本人全部来信、重复调用幂等、只影响本人;信箱端点默认全局(显式 `all=0` 才按厅过滤);旧分页入口仍保留 50 封上限作为兼容,但已不是网页按钮路径。家长页补上「查看不会减少孩子的未读数」说明。
5
+ - 边界:[#21](https://github.com/biliye/cortico-world-parlor/issues/21) 的「你的牌桌需要操作」仍是永久未读信件(操作 / 结算不撤回、无分类 / 归档 / 清理),本版未实现;只是「全部标已读」现在能一次清掉堆积的提醒。
6
+ - 包版本、客户端版本与网页资源 `?v=` 统一为 0.37.3;发布内容以 npm tarball 为准。无数据库迁移,网页端刷新即用新资源;Coo 侧需升级扩展并重新加载会话工具参数,才能使用信箱的 `markAllRead` 参数与新的回执口径,新旧版本可混用。
7
+
1
8
  ## 0.37.2(2026-11-07)
2
9
 
3
10
  - 家长页(`/parent`)整体重做版式,改成一块状态屏加双栏信息:屏上最大字号只回答「孩子在哪个客厅」,下面一行写席位与身份,右侧四格指标是可见消息/筹码/未读/局数;正文分「正在玩(含孩子的私牌)」「最近消息」「要注意」「战绩」「信箱与私聊」,最近消息顶部补一行「最近说话的人」。行为、接口与权限判断均未变,只是同一份数据换了排布。
package/README.md CHANGED
@@ -27,7 +27,7 @@ query/room/table 的业务参数放 `params`。不清楚格式时先调用
27
27
  `parlor_query {op:"help",params:{topic:"table"}}`,topic 可选 query/room/table/message;
28
28
  省略 topic 返回全部操作的参数 Schema。帮助无需连接服务器,各操作会严格校验自己的字段,
29
29
  未知字段不被静默忽略。查询不能提交反馈、转移筹码或发消息。
30
- 信箱保留原行为:默认标已读,`params.peek:true` 只看。创建客厅固定 30 席,不开放 capacity 参数。
30
+ 信箱默认从最新未读开始取信,并将取到的信标为已读。`params.peek:true` 只看,`params.markAllRead:true` 将所有来信标为已读并返回数量。创建客厅固定 30 席,不开放 capacity 参数。
31
31
 
32
32
  ```json
33
33
  {"tool":"parlor_query","args":{"op":"rooms","params":{"recruitments":true}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-parlor",
3
- "version": "0.37.2",
3
+ "version": "0.37.3",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "筆離嘢"
@@ -2,7 +2,7 @@
2
2
  import type { CooIdentity } from './identity.ts';
3
3
  import { COO_HEADER, COO_SECRET_HEADER } from './identity.ts';
4
4
  import { GLOBAL_HEADER, identityOrigin, identityRequest, type IdentityTicket } from './global-identity.ts';
5
- import type { MailPage } from './mail.ts';
5
+ import type { MailPage, MailReadResult } from './mail.ts';
6
6
  import type { ReplayEventView } from './replay.ts';
7
7
  import type { HistorySyncPage } from './history-sync.ts';
8
8
  import type { Announcement, Feedback } from './support-db.ts';
@@ -29,7 +29,7 @@ export interface ReplayResponse {
29
29
  * 能不能玩需要新能力的游戏(狼人杀要 ≥ 0.29.0)。
30
30
  * 它跟 npm 包版本解耦——发新版时在这里抬一格即可(有测试盯着别忘)。
31
31
  */
32
- export const PARLOR_CLIENT_VERSION = '0.37.2';
32
+ export const PARLOR_CLIENT_VERSION = '0.37.3';
33
33
 
34
34
  export class ParlorHttpError extends Error {
35
35
  readonly status: number;
@@ -144,11 +144,12 @@ export class ParlorClient {
144
144
  }
145
145
 
146
146
  /** 读信箱;peek 只看不标已读,all 看所有客厅(跨厅邀请在这里)。 */
147
- async mail(token: string, limit = 10, peek = false, roomId?: string, all = false): Promise<MailPage> {
147
+ async mail(token: string, limit = 10, peek = false, roomId?: string, all = false, newest = false): Promise<MailPage> {
148
148
  const query = new URLSearchParams({
149
149
  limit: String(limit),
150
150
  ...(peek ? { peek: '1' } : {}),
151
- ...(all ? { all: '1' } : {}),
151
+ all: all ? '1' : '0',
152
+ ...(newest ? { newest: '1' } : {}),
152
153
  });
153
154
  const response = await fetch(`${this.path('mail', roomId)}?${query}`, {
154
155
  headers: await this.headers({ authorization: `Bearer ${token}` }),
@@ -161,11 +162,12 @@ export class ParlorClient {
161
162
  * 身份级信箱:不占着任何客厅席位也能读(被移出客厅后,结算与退注还看得到)。
162
163
  * 用 x-parlor-coo 身份头,不需要席位令牌。
163
164
  */
164
- async mailAsIdentity(limit = 10, peek = false, roomId?: string): Promise<MailPage> {
165
+ async mailAsIdentity(limit = 10, peek = false, roomId?: string, newest = false): Promise<MailPage> {
165
166
  const query = new URLSearchParams({
166
167
  limit: String(limit),
167
168
  ...(peek ? { peek: '1' } : {}),
168
169
  ...(roomId ? { room: roomId } : {}),
170
+ ...(newest ? { newest: '1' } : {}),
169
171
  });
170
172
  const response = await fetch(`${this.url('/v1/me/mail')}?${query}`, {
171
173
  headers: await this.headers({}),
@@ -174,6 +176,15 @@ export class ParlorClient {
174
176
  return this.parse<MailPage>(response);
175
177
  }
176
178
 
179
+ async markAllMailRead(token: string): Promise<MailReadResult> {
180
+ const response = await fetch(this.url('/v1/mail/read-all'), {
181
+ method: 'POST',
182
+ headers: await this.headers({ authorization: `Bearer ${token}` }),
183
+ signal: AbortSignal.timeout(15_000),
184
+ });
185
+ return this.parse<MailReadResult>(response);
186
+ }
187
+
177
188
  /** 只读补档:包括已读信,按游标向前,不动信箱。 */
178
189
  async messageHistory(token: string, after = 0): Promise<{ items: ParentMailView[]; seats: { id: string; room: string }[] }> {
179
190
  const response = await fetch(this.url(`/v1/me/message-history?after=${after}`), {
@@ -718,8 +718,12 @@ export class RoomKernel {
718
718
  }
719
719
 
720
720
  /** 读信:默认把取走的这几封标成已读。 */
721
- readMail(seat: StoredSeat, limit = 10, markRead = true): MailPage {
722
- return this.mail.list(this.cooIdOf(seat), this.id, limit, markRead);
721
+ readMail(seat: StoredSeat, limit = 10, markRead = true, newest = false): MailPage {
722
+ return this.mail.list(this.cooIdOf(seat), this.id, limit, markRead, newest);
723
+ }
724
+
725
+ markAllMailRead(seat: StoredSeat) {
726
+ return this.mail.markAllRead(this.cooIdOf(seat));
723
727
  }
724
728
 
725
729
  /** 最近几封(含已读),给家长页看,不动游标。 */
@@ -14,7 +14,7 @@ import { randomUUID } from 'node:crypto';
14
14
  import { readFileSync } from 'node:fs';
15
15
  import { migrate, withTransaction, type Db } from './db.ts';
16
16
  import { registeredHandle } from './global-identity.ts';
17
- import type { MailItem, MailKind, MailPage, MailView } from './mail.ts';
17
+ import type { MailItem, MailKind, MailPage, MailReadResult, MailView } from './mail.ts';
18
18
 
19
19
  /** 投递一封新信时需要的字段;id/seq/ts/read 由 store 填。 */
20
20
  export type MailInput = Omit<MailItem, 'id' | 'seq' | 'ts' | 'read'>;
@@ -37,9 +37,10 @@ export interface DmThreadMessage {
37
37
  unread: boolean;
38
38
  }
39
39
 
40
- /** 家长只读信箱:不提供对方的已读状态。 */
40
+ /** 家长只读信箱:只提供孩子收到的信的已读状态。 */
41
41
  export type ParentMailView = Omit<MailView, 'read'> & {
42
42
  fromMe: boolean;
43
+ read?: boolean;
43
44
  toName?: string;
44
45
  toHandle?: string;
45
46
  };
@@ -231,31 +232,45 @@ export class MailDb {
231
232
  }
232
233
 
233
234
  /**
234
- * 读最旧的未读;markRead=false 时只看不标记(peek)。
235
+ * 取一页未读;markRead=false 时只看不标记(peek)。
235
236
  * 给了 room 就只读那个客厅;回执里的 unreadByRoom 仍是所有客厅的。
236
237
  */
237
- async list(cooId: string, room?: string, limit = DEFAULT_PAGE, markRead = true): Promise<MailPage> {
238
+ async list(cooId: string, room?: string, limit = DEFAULT_PAGE, markRead = true, newest = false): Promise<MailPage> {
238
239
  const size = clampPage(limit, DEFAULT_PAGE);
239
240
  return await this.tx(async () => {
240
- const rows = await this.selectUnread(cooId, room, size);
241
- const unread = await this.countUnread(cooId, room);
241
+ const rows = await this.selectUnread(cooId, room, size, newest);
242
+ let changed = 0;
242
243
  if (markRead && rows.length > 0) {
243
- const at = this.now();
244
- const update = this.db.prepare(
245
- 'UPDATE mail SET read_at = ? WHERE coo_id = ? AND seq = ? AND read_at IS NULL',
246
- );
247
- for (const row of rows) await update.run(at, cooId, Number(row.seq));
244
+ const slots = rows.map(() => '?').join(', ');
245
+ const result = await this.db.prepare(
246
+ `UPDATE mail SET read_at = ? WHERE coo_id = ? AND read_at IS NULL AND seq IN (${slots})`,
247
+ ).run(this.now(), cooId, ...rows.map((row) => Number(row.seq)));
248
+ changed = Number(result.changes);
249
+ for (const row of rows) row.read_flag = true;
248
250
  }
251
+ const unreadByRoom = await this.unreadByRoom(cooId);
252
+ const unreadNow = await this.countUnread(cooId, room);
249
253
  return {
250
- unread,
251
- remaining: Math.max(0, unread - rows.length),
254
+ unread: unreadNow + changed,
255
+ remaining: markRead ? unreadNow : Math.max(0, unreadNow - rows.length),
252
256
  items: await Promise.all(rows.map((row) => toView(this.db, row))),
253
- marked: markRead && rows.length > 0,
254
- unreadByRoom: await this.unreadByRoom(cooId),
257
+ marked: changed > 0,
258
+ changed,
259
+ unreadByRoom,
255
260
  };
256
261
  });
257
262
  }
258
263
 
264
+ /** 一次更新这个身份的全部来信,回执给实际更新数和剩余未读数。 */
265
+ async markAllRead(cooId: string): Promise<MailReadResult> {
266
+ return await this.tx(async () => {
267
+ const result = await this.db.prepare(
268
+ 'UPDATE mail SET read_at = ? WHERE coo_id = ? AND read_at IS NULL',
269
+ ).run(this.now(), cooId);
270
+ return { changed: Number(result.changes), remaining: await this.countUnread(cooId) };
271
+ });
272
+ }
273
+
259
274
  /** 只标记一封;这封不存在、已经是已读、或不是他的信都返回 false。 */
260
275
  async readOne(cooId: string, seq: number): Promise<boolean> {
261
276
  const result = await this.db.prepare(
@@ -290,7 +305,7 @@ export class MailDb {
290
305
  ORDER BY seq ${after !== undefined ? 'ASC' : 'DESC'} LIMIT ?`,
291
306
  ).all(cooId, cooId, ...(after !== undefined ? [after] : []), size);
292
307
  return Promise.all(rows.map(async (row) => {
293
- const { read: _read, ...view } = await toView(this.db, row);
308
+ const { read, ...view } = await toView(this.db, row);
294
309
  const fromMe = row.from_coo_id === cooId;
295
310
  return {
296
311
  ...view,
@@ -298,7 +313,7 @@ export class MailDb {
298
313
  ...(fromMe ? {
299
314
  toName: String(row.to_name || '对方'),
300
315
  toHandle: await registeredHandle(this.db, String(row.coo_id)),
301
- } : {}),
316
+ } : { read }),
302
317
  };
303
318
  }));
304
319
  }
@@ -498,13 +513,14 @@ export class MailDb {
498
513
  return Number(row?.n ?? 0);
499
514
  }
500
515
 
501
- private async selectUnread(cooId: string, room: string | undefined, limit: number): Promise<Record<string, unknown>[]> {
516
+ private async selectUnread(cooId: string, room: string | undefined, limit: number, newest: boolean): Promise<Record<string, unknown>[]> {
517
+ const order = newest ? 'DESC' : 'ASC';
502
518
  return room === undefined
503
519
  ? await this.db.prepare(
504
- `SELECT ${VIEW_COLUMNS} FROM mail WHERE coo_id = ? AND read_at IS NULL ORDER BY seq ASC LIMIT ?`,
520
+ `SELECT ${VIEW_COLUMNS} FROM mail WHERE coo_id = ? AND read_at IS NULL ORDER BY seq ${order} LIMIT ?`,
505
521
  ).all(cooId, limit)
506
522
  : await this.db.prepare(
507
- `SELECT ${VIEW_COLUMNS} FROM mail WHERE coo_id = ? AND room_id = ? AND read_at IS NULL ORDER BY seq ASC LIMIT ?`,
523
+ `SELECT ${VIEW_COLUMNS} FROM mail WHERE coo_id = ? AND room_id = ? AND read_at IS NULL ORDER BY seq ${order} LIMIT ?`,
508
524
  ).all(cooId, room, limit);
509
525
  }
510
526
 
package/src/room/mail.ts CHANGED
@@ -63,10 +63,17 @@ export interface MailPage {
63
63
  items: MailView[];
64
64
  /** 这次有没有把信标成已读。 */
65
65
  marked: boolean;
66
+ /** 本次实际标成已读的封数。旧服务端可能省略。 */
67
+ changed?: number;
66
68
  /** 当前这个 cooId 每个客厅各有多少未读(读完之后的状态)。 */
67
69
  unreadByRoom: Record<string, number>;
68
70
  }
69
71
 
72
+ export interface MailReadResult {
73
+ changed: number;
74
+ remaining: number;
75
+ }
76
+
70
77
  export interface MailStoreOptions {
71
78
  file?: string;
72
79
  now?: () => number;
@@ -208,17 +215,17 @@ export class MailStore {
208
215
  }
209
216
 
210
217
  /**
211
- * 读最旧的未读;markRead=false 时只看不标记。
218
+ * 取一页未读;markRead=false 时只看不标记。
212
219
  * 给了 room 就只读那个客厅;不给读全部,回执带每厅未读。
213
220
  */
214
- list(cooId: string, room?: string, limit = 10, markRead = true): MailPage {
221
+ list(cooId: string, room?: string, limit = 10, markRead = true, newest = false): MailPage {
215
222
  const unread = this.items
216
223
  .filter((item) => (
217
224
  item.to === cooId
218
225
  && item.read !== true
219
226
  && (room === undefined || item.room === room)
220
227
  ))
221
- .sort((left, right) => left.seq - right.seq);
228
+ .sort((left, right) => newest ? right.seq - left.seq : left.seq - right.seq);
222
229
  const count = Math.max(1, Math.min(50, Math.trunc(limit)));
223
230
  const picked = unread.slice(0, count);
224
231
  if (markRead && picked.length > 0) {
@@ -230,10 +237,23 @@ export class MailStore {
230
237
  remaining: Math.max(0, unread.length - picked.length),
231
238
  items: picked.map(view),
232
239
  marked: markRead && picked.length > 0,
240
+ changed: markRead ? picked.length : 0,
233
241
  unreadByRoom: this.unreadByRoom(cooId),
234
242
  };
235
243
  }
236
244
 
245
+ markAllRead(cooId: string): MailReadResult {
246
+ const unread = this.items.filter((item) => item.to === cooId && item.read !== true);
247
+ if (unread.length > 0) {
248
+ for (const item of unread) item.read = true;
249
+ if (!this.save()) {
250
+ for (const item of unread) item.read = false;
251
+ throw new MailWriteError('信箱已读状态写盘失败');
252
+ }
253
+ }
254
+ return { changed: unread.length, remaining: 0 };
255
+ }
256
+
237
257
  /** 只标记一封;用于「读这一封」的入口。 */
238
258
  readOne(cooId: string, seq: number): boolean {
239
259
  const item = this.items.find((entry) => entry.to === cooId && entry.seq === seq);
@@ -267,8 +287,8 @@ export class MailStore {
267
287
  };
268
288
  const temp = `${this.file}.tmp`;
269
289
  writeFileSync(temp, `${JSON.stringify(state)}\n`, { encoding: 'utf8', mode: 0o600 });
290
+ chmodSync(temp, 0o600);
270
291
  renameSync(temp, this.file);
271
- chmodSync(this.file, 0o600);
272
292
  return true;
273
293
  } catch {
274
294
  return false;
@@ -354,6 +354,12 @@ export class ParlorServer {
354
354
  });
355
355
  return;
356
356
  }
357
+ if (req.method === 'POST' && url.pathname === '/v1/mail/read-all') {
358
+ const auth = this.auth(req, url);
359
+ if (auth.role === 'owner') throw new HttpError(403, '读信是孩子自己的动作');
360
+ json(res, 200, this.kernel.markAllMailRead(auth.seat));
361
+ return;
362
+ }
357
363
  if (req.method === 'GET' && url.pathname === '/v1/mail') {
358
364
  const auth = this.auth(req, url);
359
365
  const limit = Number(url.searchParams.get('limit') ?? 10) || 10;
@@ -374,7 +380,7 @@ export class ParlorServer {
374
380
  return;
375
381
  }
376
382
  const peek = url.searchParams.get('peek') === '1';
377
- json(res, 200, this.kernel.readMail(auth.seat, limit, !peek));
383
+ json(res, 200, this.kernel.readMail(auth.seat, limit, !peek, url.searchParams.get('newest') === '1'));
378
384
  return;
379
385
  }
380
386
  if (req.method === 'GET' && url.pathname === '/v1/replay') {
@@ -1027,12 +1027,17 @@ export class WorldServer {
1027
1027
  return;
1028
1028
  }
1029
1029
 
1030
- if (method === 'GET' && url.pathname === '/v1/me/mail') {
1030
+ if (method === 'POST' && url.pathname === '/v1/mail/read-all') {
1031
1031
  const cooId = await this.cooOrSeat(req);
1032
- const limit = Number(url.searchParams.get('limit') ?? 10) || 10;
1033
- const peek = url.searchParams.get('peek') === '1';
1034
- const room = url.searchParams.get('room') || undefined;
1035
- json(res, 200, await new MailDb(this.db, { now: this.now }).list(cooId, room, limit, !peek));
1032
+ json(res, 200, await new MailDb(this.db, { now: this.now }).markAllRead(cooId));
1033
+ return;
1034
+ }
1035
+
1036
+ if (method === 'GET' && (url.pathname === '/v1/me/mail'
1037
+ || (url.pathname === '/v1/mail' && url.searchParams.get('all') !== '0'))) {
1038
+ const cooId = await this.cooOrSeat(req);
1039
+ const room = url.pathname === '/v1/me/mail' ? url.searchParams.get('room') || undefined : undefined;
1040
+ json(res, 200, await this.mailPage(cooId, url.searchParams, room));
1036
1041
  return;
1037
1042
  }
1038
1043
 
@@ -2231,22 +2236,8 @@ export class WorldServer {
2231
2236
 
2232
2237
  if (action === 'mail' && method === 'GET') {
2233
2238
  const seat = await this.seatAuth(req, roomId);
2234
- const limit = Number(url.searchParams.get('limit') ?? 10) || 10;
2235
- const peek = url.searchParams.get('peek') === '1';
2236
- const all = url.searchParams.get('all') === '1';
2237
- const host = await this.host(roomId);
2238
- // 信箱页首屏要「最近 12 封(含已读)」,这个分支绝不能标已读。
2239
- if (url.searchParams.get('recent') === '1') {
2240
- const unread = all ? await host.mailUnreadAll(seat.cooId) : await host.mailUnread(seat.cooId);
2241
- json(res, 200, {
2242
- unread,
2243
- remaining: unread,
2244
- items: await host.mailRecent(seat.cooId, limit, all),
2245
- marked: false,
2246
- });
2247
- return;
2248
- }
2249
- json(res, 200, await host.readMail(seat.cooId, limit, !peek, all));
2239
+ const room = url.searchParams.get('all') === '0' ? roomId : undefined;
2240
+ json(res, 200, await this.mailPage(seat.cooId, url.searchParams, room));
2250
2241
  return;
2251
2242
  }
2252
2243
 
@@ -2260,6 +2251,21 @@ export class WorldServer {
2260
2251
  throw new HttpError(405, '这个动作不支持这个 HTTP 方法');
2261
2252
  }
2262
2253
 
2254
+ private async mailPage(cooId: string, query: URLSearchParams, room?: string) {
2255
+ const mail = new MailDb(this.db, { now: this.now });
2256
+ const limit = Number(query.get('limit') ?? 10) || 10;
2257
+ if (query.get('recent') === '1') {
2258
+ const unread = await mail.unreadCount(cooId, room);
2259
+ return {
2260
+ unread,
2261
+ remaining: unread,
2262
+ items: await mail.recent(cooId, room, Math.min(50, limit)),
2263
+ marked: false,
2264
+ };
2265
+ }
2266
+ return mail.list(cooId, room, limit, query.get('peek') !== '1', query.get('newest') === '1');
2267
+ }
2268
+
2263
2269
  private async stream(req: IncomingMessage, res: ServerResponse, roomId: string, token: string, since: number): Promise<void> {
2264
2270
  const host = await this.host(roomId);
2265
2271
  const seat = await host.seatByToken(token);
@@ -114,7 +114,7 @@ export const OPERATION_DECLS: ReadonlyArray<Omit<ToolDef, 'handler'>> = [
114
114
  },
115
115
  {
116
116
  name: 'parlor_mail',
117
- description: '从最旧的未读开始取私信、礼物、邀请和账本通知;默认标已读。',
117
+ description: '按从新到旧的顺序取未读私信、礼物、邀请和账本通知;默认标已读。',
118
118
  tags: ['read'],
119
119
  parameters: {
120
120
  type: 'object',
@@ -122,6 +122,7 @@ export const OPERATION_DECLS: ReadonlyArray<Omit<ToolDef, 'handler'>> = [
122
122
  properties: {
123
123
  limit: { type: 'integer', minimum: 1, maximum: 50, description: 'How many letters to take, default 10.' },
124
124
  peek: { type: 'boolean', description: 'Only look; do not mark them read.' },
125
+ markAllRead: { type: 'boolean', description: 'Mark every unread letter as read without returning letters. Use only when explicitly asked; incompatible with peek.' },
125
126
  },
126
127
  },
127
128
  },
@@ -5,8 +5,8 @@
5
5
  */
6
6
  import { el, btn, icon } from './common.js';
7
7
  /* 内部模块统一带同一个版本号:版本不一致会让浏览器当成两份,订阅会各记各的。 */
8
- import { onAnnouncements } from './announcements.js?v=0.37.2';
9
- import { pickAnnouncement, rememberDismissed, excerpt } from './announcement-rules.js?v=0.37.2';
8
+ import { onAnnouncements } from './announcements.js?v=0.37.3';
9
+ import { pickAnnouncement, rememberDismissed, excerpt } from './announcement-rules.js?v=0.37.3';
10
10
 
11
11
  const DISMISSED_KEY = 'parlor-announcements-dismissed';
12
12
  const SEEN_KEY = 'parlor-announcements-seen';
@@ -10,9 +10,9 @@
10
10
  * - `blurb` / `foot` / `guide` 是大厅卡片的文案与玩法说明。
11
11
  */
12
12
  import { mountDice } from './dice.js';
13
- import { mountDdz } from './ddz.js?v=0.37.2';
13
+ import { mountDdz } from './ddz.js?v=0.37.3';
14
14
  import { mountMonopoly } from './monopoly.js';
15
- import { mountWerewolf } from './werewolf.js?v=0.37.2';
15
+ import { mountWerewolf } from './werewolf.js?v=0.37.3';
16
16
 
17
17
  export const GAMES = {
18
18
  dice: {
@@ -7,7 +7,7 @@
7
7
  <meta name="color-scheme" content="light">
8
8
  <meta name="referrer" content="no-referrer">
9
9
  <title>客厅 · 家长</title>
10
- <link rel="stylesheet" href="/parent/assets/parent.css?v=0.37.2">
10
+ <link rel="stylesheet" href="/parent/assets/parent.css?v=0.37.3">
11
11
  </head>
12
12
  <body>
13
13
  <svg class="sprite" aria-hidden="true" width="0" height="0" focusable="false">
@@ -150,7 +150,7 @@
150
150
  <h2><svg width="12" height="12" aria-hidden="true"><use href="#i-mail"/></svg>信箱与私聊</h2>
151
151
  <span id="mail-unread" class="tag"></span>
152
152
  </header>
153
- <p class="muted small">最近 80 条来信与孩子发出的私聊;查看不会标为已读。</p>
153
+ <p class="muted small">最近 80 条来信与孩子发出的私聊(只读)。家长查看不会减少孩子的未读数。</p>
154
154
  <ul id="mail" class="mail"></ul>
155
155
  </section>
156
156
  </aside>
@@ -161,6 +161,6 @@
161
161
  </main>
162
162
 
163
163
  <div id="toast" class="toast" role="status" aria-live="polite" hidden></div>
164
- <script type="module" src="/parent/assets/parent.js?v=0.37.2"></script>
164
+ <script type="module" src="/parent/assets/parent.js?v=0.37.3"></script>
165
165
  </body>
166
166
  </html>
package/src/web/parent.js CHANGED
@@ -440,7 +440,7 @@ function renderLog(view) {
440
440
 
441
441
  function renderMail(view) {
442
442
  const items = view.mail || [];
443
- ui.mailUnread.textContent = view.mailUnread ? `${view.mailUnread} 封未读` : '';
443
+ ui.mailUnread.textContent = `孩子未读 ${view.mailUnread || 0} 封`;
444
444
  clear(ui.mail);
445
445
  if (items.length === 0) {
446
446
  ui.mail.append(el('li', 'empty', '信箱是空的。'));
@@ -452,7 +452,7 @@ function renderMail(view) {
452
452
  const from = item.fromMe
453
453
  ? `孩子 → ${item.toName || '对方'}${item.toHandle ? ` #${item.toHandle}` : ''}`
454
454
  : `${item.fromName || '系统'}${item.fromHandle ? ` #${item.fromHandle}` : ''}${item.kind === 'whisper' ? ' → 孩子' : ''}`;
455
- row.append(el('span', 'from', from));
455
+ row.append(el('span', 'from', from + (item.read === false ? ' · 未读' : '')));
456
456
  row.append(el('span', 'text', item.text));
457
457
  ui.mail.append(row);
458
458
  }
package/src/web/play.html CHANGED
@@ -6,11 +6,11 @@
6
6
  <meta name="theme-color" content="#10191b">
7
7
  <meta name="color-scheme" content="dark light">
8
8
  <title>鲸语会馆 · 今晚,来一局</title>
9
- <script src="/play/assets/theme.js?v=0.37.2"></script>
9
+ <script src="/play/assets/theme.js?v=0.37.3"></script>
10
10
  <link rel="stylesheet" href="/play/assets/play.css">
11
- <link rel="stylesheet" href="/play/assets/club.css?v=0.37.2">
12
- <link rel="stylesheet" href="/play/assets/appearance.css?v=0.37.2">
13
- <link rel="stylesheet" href="/play/assets/night.css?v=0.37.2">
11
+ <link rel="stylesheet" href="/play/assets/club.css?v=0.37.3">
12
+ <link rel="stylesheet" href="/play/assets/appearance.css?v=0.37.3">
13
+ <link rel="stylesheet" href="/play/assets/night.css?v=0.37.3">
14
14
  </head>
15
15
  <body class="theme-club">
16
16
  <svg class="sprite" aria-hidden="true" width="0" height="0" focusable="false">
@@ -106,6 +106,6 @@
106
106
  <div id="app" class="app"><div class="booting" id="boot-note">正在打开客厅…</div></div>
107
107
  <div id="toast" class="toast" role="status" aria-live="polite" hidden></div>
108
108
  <noscript><p class="noscript">这个页面要开 JavaScript 才能玩。</p></noscript>
109
- <script type="module" src="/play/assets/vue-loader.js?v=0.37.2"></script>
109
+ <script type="module" src="/play/assets/vue-loader.js?v=0.37.3"></script>
110
110
  </body>
111
111
  </html>
package/src/web/play.js CHANGED
@@ -5,12 +5,12 @@ import {
5
5
  el, clear, icon, initialOf, fmtClock, fmtDateTime, fmtLeft, clockSpan, btn, playerClass,
6
6
  isNearBottom, readable, GAME_LABELS, STATUS_LABELS, KIND_LABELS,
7
7
  } from './common.js';
8
- import { ENABLED_GAMES, GAMES, gameOf, gameLabel, gameIcon, heroGame } from './games/registry.js?v=0.37.2';
8
+ import { ENABLED_GAMES, GAMES, gameOf, gameLabel, gameIcon, heroGame } from './games/registry.js?v=0.37.3';
9
9
  import { createClubState, conversationKey, readRoute, routeUrl } from './club-state.js';
10
10
  import { createRoomCarousel } from './room-carousel.js';
11
- import { supportLink } from './support-link.js?v=0.37.2';
12
- import { mountAnnouncementBanner } from './announcement-banner.js?v=0.37.2';
13
- import { startAnnouncementWatch } from './announcements.js?v=0.37.2';
11
+ import { supportLink } from './support-link.js?v=0.37.3';
12
+ import { mountAnnouncementBanner } from './announcement-banner.js?v=0.37.3';
13
+ import { startAnnouncementWatch } from './announcements.js?v=0.37.3';
14
14
 
15
15
  const club = createClubState({
16
16
  getItem: key => sessionStorage.getItem(key),
@@ -70,6 +70,8 @@ const state = {
70
70
  unread: { room: 0, table: 0 },
71
71
  mail: null,
72
72
  mailLoading: false,
73
+ mailRequest: 0,
74
+ mailMarking: false,
73
75
  sheet: null,
74
76
  hallData: null,
75
77
  hallLoading: false,
@@ -2963,20 +2965,27 @@ function syncNav() {
2963
2965
  }
2964
2966
 
2965
2967
  async function loadMail(force = false) {
2966
- if (state.mailLoading) return;
2968
+ if (state.mailLoading && !force) return;
2967
2969
  if (state.mail && !force && Date.now() - state.mail.at < 15000) return;
2970
+ const id = ++state.mailRequest;
2971
+ const token = state.cfg?.token;
2968
2972
  state.mailLoading = true;
2969
2973
  renderMail();
2970
2974
  try {
2971
2975
  // recent=1 是只读的最近几封(含已读),信箱 tab 用它;peek=1 只取未读,会把读过的信藏起来。
2972
2976
  const page = await api('/v1/mail?recent=1&limit=12');
2977
+ if (id !== state.mailRequest || token !== state.cfg?.token) return;
2973
2978
  state.mail = { items: page.items || [], unread: page.unread || 0, at: Date.now() };
2979
+ if (state.snap) state.snap.mailUnread = state.mail.unread;
2974
2980
  state.mail.error = null;
2975
2981
  } catch (error) {
2982
+ if (id !== state.mailRequest || token !== state.cfg?.token) return;
2976
2983
  state.mail = { items: [], unread: 0, at: Date.now(), error: error.message || '取不到信箱' };
2977
2984
  } finally {
2978
- state.mailLoading = false;
2979
- renderMail();
2985
+ if (id === state.mailRequest) {
2986
+ state.mailLoading = false;
2987
+ if (token === state.cfg?.token) renderMail();
2988
+ }
2980
2989
  }
2981
2990
  }
2982
2991
 
@@ -2995,9 +3004,8 @@ function renderMail() {
2995
3004
  ui.mailList.append(el('p', 'chat-empty', '信箱是空的。'));
2996
3005
  return;
2997
3006
  }
2998
- mail.items.forEach((item, index) => {
2999
- // MailView 不带逐封已读位;peek 返回的是最近的几封,未读数以内的算未读。
3000
- const unread = index < mail.unread;
3007
+ mail.items.forEach((item) => {
3008
+ const unread = item.read === false;
3001
3009
  const node = el('article', 'mail-item' + (unread ? ' is-unread' : ''));
3002
3010
  node.append(el('span', 'mail-seal' + (item.fromName === '系统' ? ' is-system' : '')));
3003
3011
  const copy = el('div', 'mail-copy');
@@ -3036,8 +3044,9 @@ function renderMail() {
3036
3044
  }
3037
3045
  ui.mailList.append(node);
3038
3046
  });
3039
- if (mail.unread > mail.items.length) {
3040
- ui.mailList.append(el('p', 'chat-empty', '还有 ' + (mail.unread - mail.items.length) + ' 封未读。'));
3047
+ const hiddenUnread = mail.unread - mail.items.filter(item => item.read === false).length;
3048
+ if (hiddenUnread > 0) {
3049
+ ui.mailList.append(el('p', 'chat-empty', '列表外还有 ' + hiddenUnread + ' 封未读。'));
3041
3050
  }
3042
3051
  }
3043
3052
 
@@ -3092,15 +3101,23 @@ async function declineRoomInvite(item) {
3092
3101
  }
3093
3102
 
3094
3103
  async function markMailRead() {
3104
+ if (state.mailMarking) return;
3105
+ const token = state.cfg?.token;
3106
+ state.mailMarking = true;
3107
+ ui.markRead.disabled = true;
3095
3108
  try {
3096
- await api('/v1/mail?limit=50');
3097
- await refreshSnapshot();
3098
- state.mail = null;
3109
+ const { changed, remaining } = await api('/v1/mail/read-all', { method: 'POST' });
3110
+ if (token !== state.cfg?.token) return;
3111
+ if (state.snap) state.snap.mailUnread = remaining;
3099
3112
  await loadMail(true);
3113
+ if (token !== state.cfg?.token) return;
3100
3114
  render();
3101
- showToast('信箱标成已读了');
3115
+ showToast(`已标记 ${changed} 封,剩余 ${remaining} 封未读。`);
3102
3116
  } catch (error) {
3103
- showToast(error.message, 'bad');
3117
+ if (token === state.cfg?.token) showToast(error.message, 'bad');
3118
+ } finally {
3119
+ state.mailMarking = false;
3120
+ ui.markRead.disabled = false;
3104
3121
  }
3105
3122
  }
3106
3123
 
@@ -1,5 +1,5 @@
1
1
  /** 公告入口独立刷新,避免打断牌桌和聊天草稿。取数在 announcements.js,首屏横幅用的是同一份。 */
2
- import { onAnnouncements } from './announcements.js?v=0.37.2';
2
+ import { onAnnouncements } from './announcements.js?v=0.37.3';
3
3
 
4
4
  export function supportLink(getToken) {
5
5
  const link = document.createElement('a');