diff --git a/README.md b/README.md index a6a4e34..d434768 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ | 账号与设备 | Windows 和 Web 共用账号,支持用户名注册、登录、查看设备和远程撤销。 | | 联系人 | 按用户名查找、处理好友申请、管理备注与分组,以及拉黑。变更可在双端实时同步。 | | 加密文字聊天 | 在两个已核验设备之间发送 MLS 加密消息,支持离线接收。 | -| 加密群聊 | 创建群组、邀请联系人、管理成员和转让群主。群主可发布加密公告。群列表显示本机未读,并按账号同步置顶和免打扰。 | +| 加密群聊 | 创建群组、通过联系人或一次性链接及二维码邀请、管理成员和转让群主。群主可发布加密公告。群列表显示本机未读,并按账号同步置顶和免打扰。 | | 加密附件 | 两端可在私聊和群聊发送、下载最多 8 MiB 的文件,并在本机预览图片和视频。群聊支持多选、拖拽发送,以及文件、图片和视频分类。 | | 加密语音 | 两端可在私聊和群聊录制、取消或发送最长 60 秒的语音消息,接收方在本机解密播放。 | | 消息管理 | 私聊和群聊支持引用回复、编辑文字、撤回、本机搜索和收藏。消息可转发到已建立加密会话的群或已核验的联系人设备。私聊支持可选加密已读回执。 | diff --git a/docs/api.md b/docs/api.md index efc2e0a..caf72b8 100644 --- a/docs/api.md +++ b/docs/api.md @@ -30,6 +30,8 @@ | GET / POST | /api/v1/groups/{id} | 查看群组详情或执行邀请、接受、拒绝、改名、升降管理员、转让群主、移除、退出或解散 | | POST | /api/v1/groups/{id}/preferences | 更新当前账号的 `pinned` 和 `muted`,可只传其中一项 | | POST | /api/v1/groups/{id}/seen | 提交当前设备已同步的消息游标 `sequence`,成功返回 204 | +| POST / DELETE | /api/v1/groups/{id}/invite-link | 群主生成或撤销一次性链接。生成返回 `code` 和 `expiresAt`,撤销返回 204 | +| POST | /api/v1/group-invites/redeem | 登录后提交 `code`,成功返回 `groupId`,供用户打开邀请并接受或拒绝 | | GET | /api/v1/groups/{id}/devices | 获取群成员的有效设备与 MLS 公钥 | | POST | /api/v1/groups/{id}/devices/{device}/claim | 群主一次性领取群成员设备的 KeyPackage | | GET / POST | /api/v1/groups/{id}/epochs | 读取当前设备可访问的会话信息或由群主发布新世代 | @@ -54,6 +56,8 @@ MLS 凭据由标准 Base64 的 publicKey 和 signature 组成,使用 UTF-8 前 群主可使用 `transfer` 和有效成员的 `target` 转让群主。转让会将原群主设为普通成员,更新群版本,由新群主创建后续 MLS 会话。公告使用现有 MLS 密文投递接口,客户端验证公告来自该会话经核验的群主设备。 +邀请链接有效 24 小时,重新生成、撤销或群主转让会使当前链接失效。服务端保存邀请码的 SHA-256 摘要。单次领取和创建待接受邀请在同一事务内完成,领取后须接受邀请才可访问成员和加密会话。链接使用 URL 片段,客户端在确认领取时才把邀请码发给当前服务。 + 创建或更新群资料和成员后,受影响账号的在线客户端收到 `{"type":"group_list_changed"}`,再用授权 API 刷新。邀请相关提示发送给管理者和被邀请人。提示只包含类型字段,不传群号、群名或成员资料。 群组密文投递使用 `/groups/{id}/epochs` 和 `/groups/{id}/messages`。群主发布带 membershipVersion 的世代,选取每个有效成员的一台已登记 MLS 设备,提交其他设备的 Welcome。GET epochs 返回当前有效世代的设备名单和本设备获准接收的 Welcome,旧世代仅向在本次成员资格期间加入过该世代的设备返回。POST messages 接受当前世代的 MLS PrivateMessage,GET messages 通过 after 游标返回本设备有权读取的密文。 diff --git a/docs/progress.md b/docs/progress.md index d657ce5..92ce7b3 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -186,3 +186,9 @@ Windows 和 Edge 验证加密发布与清除公告、群主转让、原群主退 群附件发送区支持文件多选、拖拽、移除单项与清空待发列表。每批最多 8 个,单文件上限 8 MiB。客户端逐个加密和发送,展示批次进度。中断时未进入加密发件箱的文件留在当前页面,可再次提交,已进入发件箱的密文沿用现有重试机制。群会话变更会停止当前批次,剩余文件由用户在新会话中确认发送。 Windows Electron 与 Edge 验证多选发送、拖拽和移除待发文件。模拟第二个文件上传失败后只重试剩余文件,已送达的文件未重复出现。群聊、私聊与服务端投递回归共 7 项通过。 + +## 群邀请链接与二维码 + +群主可生成或撤销有效 24 小时的一次性邀请链接,客户端在本机绘制二维码。Web 可以直接打开链接,Windows 群组页可以粘贴链接或邀请码。服务端只存邀请码摘要,生成新链接或转让群主会撤销旧链接。领取成功会生成待接受邀请,成员确认后才加入现有群权限流程。 + +接口测试验证并发领取仅一次成功、链接轮换、撤销、群主转让后失效及领取后权限隔离。Windows 与 Edge 验证二维码绘制、桌面端粘贴领取、Web 登录后领取和接受或拒绝流程。 diff --git a/package-lock.json b/package-lock.json index 8e72c24..98201ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -515,6 +515,16 @@ "undici-types": ">=7.24.0 <7.24.7" } }, + "node_modules/@types/qrcode": { + "version": "1.5.6", + "resolved": "https://registry.npmmirror.com/@types/qrcode/-/qrcode-1.5.6.tgz", + "integrity": "sha512-te7NQcV2BOvdj2b1hCAHzAoMNuj65kNBMz0KBaxM6c3VGBOhU0dURQKOtH8CFNI/dsKkwlv32p26qYQTWoB5bw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@vitejs/plugin-vue": { "version": "6.0.11", "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-6.0.11.tgz", @@ -786,6 +796,30 @@ "dev": true, "license": "MIT" }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmmirror.com/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmmirror.com/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "license": "MIT", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, "node_modules/ast-kit": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/ast-kit/-/ast-kit-2.2.0.tgz", @@ -900,6 +934,15 @@ "url": "https://github.com/sponsors/antfu" } }, + "node_modules/camelcase": { + "version": "5.3.1", + "resolved": "https://registry.npmmirror.com/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/chokidar": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-5.0.0.tgz", @@ -915,6 +958,35 @@ "url": "https://paulmillr.com/funding/" } }, + "node_modules/cliui": { + "version": "6.0.0", + "resolved": "https://registry.npmmirror.com/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "license": "ISC", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmmirror.com/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "license": "MIT", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmmirror.com/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "license": "MIT" + }, "node_modules/confbox": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/confbox/-/confbox-0.3.2.tgz", @@ -945,6 +1017,15 @@ } } }, + "node_modules/decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmmirror.com/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/detect-libc": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", @@ -955,6 +1036,12 @@ "node": ">=8" } }, + "node_modules/dijkstrajs": { + "version": "1.0.3", + "resolved": "https://registry.npmmirror.com/dijkstrajs/-/dijkstrajs-1.0.3.tgz", + "integrity": "sha512-qiSlmBq9+BCdCA/L46dw8Uy93mloxsPSbwnm5yrKn2vMPiy8KyAskTF6zuV/j5BMsmOGZDPs7KjU+mjb670kfA==", + "license": "MIT" + }, "node_modules/electron": { "version": "45.3.1", "resolved": "https://registry.npmjs.org/electron/-/electron-45.3.1.tgz", @@ -974,6 +1061,12 @@ "node": ">= 22.12.0" } }, + "node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmmirror.com/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "license": "MIT" + }, "node_modules/entities": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/entities/-/entities-7.0.1.tgz", @@ -1028,6 +1121,19 @@ } } }, + "node_modules/find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmmirror.com/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "license": "MIT", + "dependencies": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -1042,6 +1148,15 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmmirror.com/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "license": "ISC", + "engines": { + "node": "6.* || 8.* || >= 10.*" + } + }, "node_modules/graceful-fs": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.12.tgz", @@ -1055,6 +1170,15 @@ "integrity": "sha512-Yc+BQe8SvoXH1643Qez1zqLRmbA5rCL+sSmk6TVos0LWVfNIB7PGncdlId77WzLGSIB5KaWgTaNTs2lNVEI6VQ==", "license": "MIT" }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmmirror.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/lightningcss": { "version": "1.33.0", "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", @@ -1334,6 +1458,18 @@ "url": "https://github.com/sponsors/antfu" } }, + "node_modules/locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmmirror.com/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "license": "MIT", + "dependencies": { + "p-locate": "^4.1.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/magic-string": { "version": "0.30.21", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", @@ -1424,6 +1560,42 @@ "integrity": "sha512-wzRsrJwNlFbqIRQt8aCeL2WE8USip/uuvGSOZV1D02CxX8ABTMbw8IywKjH7yWHETMXbWJI4OBpihg9rmz2Vyg==", "license": "MIT" }, + "node_modules/p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmmirror.com/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "license": "MIT", + "dependencies": { + "p-try": "^2.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmmirror.com/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "license": "MIT", + "dependencies": { + "p-limit": "^2.2.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmmirror.com/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/path-browserify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", @@ -1431,6 +1603,15 @@ "dev": true, "license": "MIT" }, + "node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmmirror.com/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/pathe": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", @@ -1526,6 +1707,15 @@ "node": ">=20" } }, + "node_modules/pngjs": { + "version": "5.0.0", + "resolved": "https://registry.npmmirror.com/pngjs/-/pngjs-5.0.0.tgz", + "integrity": "sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw==", + "license": "MIT", + "engines": { + "node": ">=10.13.0" + } + }, "node_modules/postcss": { "version": "8.5.32", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.32.tgz", @@ -1564,6 +1754,23 @@ "node": ">=0.4.0" } }, + "node_modules/qrcode": { + "version": "1.5.4", + "resolved": "https://registry.npmmirror.com/qrcode/-/qrcode-1.5.4.tgz", + "integrity": "sha512-1ca71Zgiu6ORjHqFBDpnSMTR2ReToX4l1Au1VFLyVeBTFavzQnv5JxMFr3ukHVKpSrSA2MCk0lNJSykjUfz7Zg==", + "license": "MIT", + "dependencies": { + "dijkstrajs": "^1.0.1", + "pngjs": "^5.0.0", + "yargs": "^15.3.1" + }, + "bin": { + "qrcode": "bin/qrcode" + }, + "engines": { + "node": ">=10.13.0" + } + }, "node_modules/quansync": { "version": "0.2.11", "resolved": "https://registry.npmjs.org/quansync/-/quansync-0.2.11.tgz", @@ -1593,6 +1800,21 @@ "url": "https://paulmillr.com/funding/" } }, + "node_modules/require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmmirror.com/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/require-main-filename": { + "version": "2.0.0", + "resolved": "https://registry.npmmirror.com/require-main-filename/-/require-main-filename-2.0.0.tgz", + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", + "license": "ISC" + }, "node_modules/rolldown": { "version": "1.2.19", "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.19.tgz", @@ -1647,6 +1869,12 @@ "node": ">=10" } }, + "node_modules/set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmmirror.com/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==", + "license": "ISC" + }, "node_modules/source-map-js": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.2.tgz", @@ -1656,6 +1884,32 @@ "node": ">=0.10.0" } }, + "node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "license": "MIT", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmmirror.com/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/sumchecker": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/sumchecker/-/sumchecker-3.0.1.tgz", @@ -2026,6 +2280,26 @@ "integrity": "sha512-66/V2i5hQanC51vBQKPH4aI8NMAcBW59FVBs+rC7eGHupMyfn34q7rZIE+ETlJ+XTevqfUhVVBgSUNSW2flEUQ==", "license": "MIT" }, + "node_modules/which-module": { + "version": "2.0.1", + "resolved": "https://registry.npmmirror.com/which-module/-/which-module-2.0.1.tgz", + "integrity": "sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==", + "license": "ISC" + }, + "node_modules/wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmmirror.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/ws": { "version": "8.23.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.23.0.tgz", @@ -2048,15 +2322,58 @@ } } }, + "node_modules/y18n": { + "version": "4.0.3", + "resolved": "https://registry.npmmirror.com/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", + "license": "ISC" + }, + "node_modules/yargs": { + "version": "15.4.1", + "resolved": "https://registry.npmmirror.com/yargs/-/yargs-15.4.1.tgz", + "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "license": "MIT", + "dependencies": { + "cliui": "^6.0.0", + "decamelize": "^1.2.0", + "find-up": "^4.1.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^4.2.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^18.1.2" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/yargs-parser": { + "version": "18.1.3", + "resolved": "https://registry.npmmirror.com/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", + "license": "ISC", + "dependencies": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + }, + "engines": { + "node": ">=6" + } + }, "web": { "name": "@xhchat/web", "dependencies": { "pinia": "4.1.0", + "qrcode": "1.5.4", "vue": "3.5.45", "vue-router": "5.5.0" }, "devDependencies": { "@types/node": "^24.0.0", + "@types/qrcode": "1.5.6", "@vitejs/plugin-vue": "6.0.11", "typescript": "~6.0.3", "vite": "8.3.8", diff --git a/server/internal/database/012_group_invite_link.sql b/server/internal/database/012_group_invite_link.sql new file mode 100644 index 0000000..c667e8c --- /dev/null +++ b/server/internal/database/012_group_invite_link.sql @@ -0,0 +1,5 @@ +CREATE TABLE group_invite_links ( + group_id uuid PRIMARY KEY REFERENCES chat_groups(id) ON DELETE CASCADE, + token_hash bytea NOT NULL UNIQUE CHECK (octet_length(token_hash) = 32), + expires_at timestamptz NOT NULL +); diff --git a/server/internal/database/database.go b/server/internal/database/database.go index fb72603..0e1999b 100644 --- a/server/internal/database/database.go +++ b/server/internal/database/database.go @@ -40,6 +40,9 @@ var groupPreferencesMigration string //go:embed 011_group_seen.sql var groupSeenMigration string +//go:embed 012_group_invite_link.sql +var groupInviteLinkMigration string + func Migrate(ctx context.Context, pool *pgxpool.Pool) error { tx, err := pool.Begin(ctx) if err != nil { @@ -55,7 +58,7 @@ func Migrate(ctx context.Context, pool *pgxpool.Pool) error { for index, migration := range []string{ identityMigration, contactsMigration, deliveryMigration, keyPackagesMigration, mlsCredentialsMigration, attachmentsMigration, groupsMigration, groupTransportMigration, groupAttachmentsMigration, groupPreferencesMigration, - groupSeenMigration, + groupSeenMigration, groupInviteLinkMigration, } { version := index + 1 var applied bool diff --git a/server/internal/groups/invite_link.go b/server/internal/groups/invite_link.go new file mode 100644 index 0000000..9976a1b --- /dev/null +++ b/server/internal/groups/invite_link.go @@ -0,0 +1,97 @@ +package groups + +import ( + "context" + "errors" + "time" + + "github.com/jackc/pgx/v5" +) + +func (s *Store) SetInviteLink(ctx context.Context, group, user, device string, digest []byte) (time.Time, error) { + var expiry time.Time + tx, err := s.db.Begin(ctx) + if err != nil { + return expiry, err + } + defer tx.Rollback(ctx) + _, owner, err := lockTransport(ctx, tx, group, user, device) + if err != nil { + return expiry, err + } + if !owner { + return expiry, ErrAction + } + if digest == nil { + _, err = tx.Exec(ctx, "DELETE FROM group_invite_links WHERE group_id=$1", group) + } else { + err = tx.QueryRow(ctx, ` + INSERT INTO group_invite_links(group_id,token_hash,expires_at) VALUES($1,$2,now()+interval '24 hours') + ON CONFLICT(group_id) DO UPDATE SET token_hash=EXCLUDED.token_hash, expires_at=EXCLUDED.expires_at + RETURNING expires_at + `, group, digest).Scan(&expiry) + } + if err != nil { + return expiry, err + } + return expiry, tx.Commit(ctx) +} + +func (s *Store) RedeemInviteLink(ctx context.Context, user, device string, digest []byte) (string, []string, error) { + tx, err := s.db.Begin(ctx) + if err != nil { + return "", nil, err + } + defer tx.Rollback(ctx) + var group, owner string + // All membership changes lock the group row before touching its invitation. + err = tx.QueryRow(ctx, ` + SELECT g.id,g.owner_id FROM chat_groups g JOIN group_invite_links l ON l.group_id=g.id + WHERE l.token_hash=$1 AND l.expires_at>now() FOR UPDATE OF g + `, digest).Scan(&group, &owner) + if errors.Is(err, pgx.ErrNoRows) { + return "", nil, ErrUnavailable + } + if err != nil { + return "", nil, err + } + // Recheck the token after acquiring the group lock so rotation and redemption serialize. + var valid bool + err = tx.QueryRow(ctx, ` + SELECT EXISTS(SELECT 1 FROM group_invite_links WHERE group_id=$1 AND token_hash=$2 AND expires_at>clock_timestamp()) + `, group, digest).Scan(&valid) + if err != nil { + return "", nil, err + } + if !valid { + return "", nil, ErrUnavailable + } + var currentDevice string + err = tx.QueryRow(ctx, "SELECT id FROM devices WHERE id=$1 AND user_id=$2 AND revoked_at IS NULL FOR UPDATE", device, user).Scan(¤tDevice) + if errors.Is(err, pgx.ErrNoRows) { + return "", nil, ErrUnavailable + } + if err != nil { + return "", nil, err + } + if err = checkMemberLimit(ctx, tx, group); err != nil { + return "", nil, err + } + tag, err := tx.Exec(ctx, ` + INSERT INTO group_members(group_id,user_id,state) VALUES($1,$2,'invited') ON CONFLICT DO NOTHING + `, group, user) + if err != nil { + return "", nil, err + } + if tag.RowsAffected() == 0 { + return "", nil, ErrAction + } + if _, err = tx.Exec(ctx, "DELETE FROM group_invite_links WHERE group_id=$1", group); err != nil { + return "", nil, err + } + users, err := groupChangeAudience(ctx, tx, group, owner, "managers") + if err != nil { + return "", nil, err + } + return group, append(users, user), tx.Commit(ctx) +} diff --git a/server/internal/groups/store.go b/server/internal/groups/store.go index ff048ee..6d9a007 100644 --- a/server/internal/groups/store.go +++ b/server/internal/groups/store.go @@ -289,6 +289,10 @@ func changeActive(ctx context.Context, tx pgx.Tx, user, id, owner, role string, return false, ErrAction } _, err = tx.Exec(ctx, "UPDATE group_members SET role='member' WHERE group_id=$1 AND user_id IN ($2,$3)", id, owner, change.Target) + if err != nil { + return false, err + } + _, err = tx.Exec(ctx, "DELETE FROM group_invite_links WHERE group_id=$1", id) // The new owner establishes a new authenticated MLS session for the same roster. return true, err case "remove", "promote", "demote": @@ -302,13 +306,9 @@ func changeActive(ctx context.Context, tx pgx.Tx, user, id, owner, role string, } func invite(ctx context.Context, tx pgx.Tx, user, id, target string) error { - var count int - if err := tx.QueryRow(ctx, "SELECT count(*) FROM group_members WHERE group_id=$1", id).Scan(&count); err != nil { + if err := checkMemberLimit(ctx, tx, id); err != nil { return err } - if count >= 32 { - return ErrLimit - } tag, err := tx.Exec(ctx, ` INSERT INTO group_members(group_id,user_id,state) SELECT $1,$3,'invited' FROM contact_relationships @@ -322,6 +322,17 @@ func invite(ctx context.Context, tx pgx.Tx, user, id, target string) error { return err } +func checkMemberLimit(ctx context.Context, tx pgx.Tx, id string) error { + var count int + if err := tx.QueryRow(ctx, "SELECT count(*) FROM group_members WHERE group_id=$1", id).Scan(&count); err != nil { + return err + } + if count >= 32 { + return ErrLimit + } + return nil +} + func changeMember(ctx context.Context, tx pgx.Tx, id, role string, change Change) (bool, error) { if change.Action == "remove" { var state string diff --git a/server/internal/httpapi/api.go b/server/internal/httpapi/api.go index 9aa2063..3930127 100644 --- a/server/internal/httpapi/api.go +++ b/server/internal/httpapi/api.go @@ -66,6 +66,9 @@ func New(accounts *account.Store, contactStore *contacts.Store, envelopeStore *d mux.HandleFunc("POST /api/v1/groups/{id}", a.authorized(a.changeGroup)) mux.HandleFunc("POST /api/v1/groups/{id}/preferences", a.authorized(a.setGroupPreferences)) mux.HandleFunc("POST /api/v1/groups/{id}/seen", a.authorized(a.markGroupSeen)) + mux.HandleFunc("POST /api/v1/groups/{id}/invite-link", a.authorized(a.issueGroupInviteLink)) + mux.HandleFunc("DELETE /api/v1/groups/{id}/invite-link", a.authorized(a.revokeGroupInviteLink)) + mux.HandleFunc("POST /api/v1/group-invites/redeem", a.authorized(a.redeemGroupInviteLink)) mux.HandleFunc("GET /api/v1/groups/{id}/epochs", a.authorized(a.groupEpochs)) mux.HandleFunc("POST /api/v1/groups/{id}/epochs", a.authorized(a.publishGroupEpoch)) mux.HandleFunc("GET /api/v1/groups/{id}/messages", a.authorized(a.groupInbox)) diff --git a/server/internal/httpapi/group_invite_link.go b/server/internal/httpapi/group_invite_link.go new file mode 100644 index 0000000..1b71074 --- /dev/null +++ b/server/internal/httpapi/group_invite_link.go @@ -0,0 +1,69 @@ +package httpapi + +import ( + "crypto/sha256" + "net/http" + "time" + + "xhchat/server/internal/account" + "xhchat/server/internal/groups" +) + +func (a *API) issueGroupInviteLink(w http.ResponseWriter, r *http.Request, _ string, actor account.Identity) { + group := r.PathValue("id") + if !uuidPattern.MatchString(group) { + groupError(w, groups.ErrUnavailable) + return + } + if !a.limit(w, r, "group-invite-issue:"+actor.User.ID, 20) { + return + } + secret := account.Secret() + digest := sha256.Sum256([]byte(secret)) + expiry, err := a.groups.SetInviteLink(r.Context(), group, actor.User.ID, actor.Device.ID, digest[:]) + if err != nil { + groupError(w, err) + return + } + respond(w, 201, struct { + Code string `json:"code"` + ExpiresAt time.Time `json:"expiresAt"` + }{secret, expiry}) +} + +func (a *API) revokeGroupInviteLink(w http.ResponseWriter, r *http.Request, _ string, actor account.Identity) { + group := r.PathValue("id") + if !uuidPattern.MatchString(group) { + groupError(w, groups.ErrUnavailable) + return + } + if !a.limit(w, r, "group-invite-issue:"+actor.User.ID, 20) { + return + } + if _, err := a.groups.SetInviteLink(r.Context(), group, actor.User.ID, actor.Device.ID, nil); err != nil { + groupError(w, err) + return + } + w.WriteHeader(204) +} + +func (a *API) redeemGroupInviteLink(w http.ResponseWriter, r *http.Request, _ string, actor account.Identity) { + var input struct { + Code string `json:"code"` + } + if !parse(w, r, &input) || !a.limit(w, r, "group-invite-redeem:"+actor.User.ID, 30) { + return + } + if decoded, err := account.Encoding.Strict().DecodeString(input.Code); err != nil || len(decoded) != 32 || len(input.Code) != 43 { + problem(w, 400, "invalid_group_invite", "群邀请链接格式无效") + return + } + digest := sha256.Sum256([]byte(input.Code)) + group, users, err := a.groups.RedeemInviteLink(r.Context(), actor.User.ID, actor.Device.ID, digest[:]) + if err != nil { + groupError(w, err) + return + } + a.hintGroupList(r.Context(), users) + respond(w, 200, map[string]string{"groupId": group}) +} diff --git a/tests/delivery.test.mjs b/tests/delivery.test.mjs index 222b521..e467b32 100644 --- a/tests/delivery.test.mjs +++ b/tests/delivery.test.mjs @@ -154,6 +154,39 @@ test('群组邀请、授权、成员移除、版本变更与实时提示', { tim assert.deepEqual(unrelated, []) }) +test('群邀请链接可轮换、撤销且只能领取一次', { timeout: 25_000 }, async () => { + const [owner, first, second] = await Promise.all([register(), register(), register()]) + const group = await json('/groups', 'POST', owner.token, { name: '群链接验收' }, 201) + const path = '/groups/' + group.id + const issue = () => json(path + '/invite-link', 'POST', owner.token, undefined, 201) + const redeem = (actor, code) => call('/group-invites/redeem', 'POST', actor.token, { code }) + assert.equal((await call(path + '/invite-link', 'POST', first.token)).status, 404) + const initial = await issue() + assert.match(initial.code, /^[A-Za-z0-9_-]{43}$/) + assert.ok(Date.parse(initial.expiresAt) - Date.now() > 23 * 60 * 60 * 1000) + const current = await issue() + assert.equal((await redeem(first, initial.code)).status, 404) + assert.equal((await redeem(owner, current.code)).status, 409) + const results = await Promise.all([redeem(first, current.code), redeem(second, current.code)]) + assert.deepEqual(results.map((result) => result.status).sort(), [200, 404]) + const winner = results[0].ok ? first : second + const other = results[0].ok ? second : first + assert.deepEqual(await results.find((result) => result.ok).json(), { groupId: group.id }) + const pending = await json(path, 'GET', winner.token) + assert.equal(pending.state, 'invited') + assert.deepEqual(pending.members, []) + assert.equal((await call(path + '/messages', 'GET', winner.token)).status, 404) + assert.equal((await call(path, 'POST', winner.token, { action: 'accept' })).status, 204) + assert.equal((await json(path, 'GET', winner.token)).membershipVersion, '2') + assert.equal((await call(path + '/invite-link', 'POST', winner.token)).status, 409) + const revoked = await issue() + assert.equal((await call(path + '/invite-link', 'DELETE', owner.token)).status, 204) + assert.equal((await redeem(other, revoked.code)).status, 404) + const previousOwner = await issue() + assert.equal((await call(path, 'POST', owner.token, { action: 'transfer', target: winner.user.id })).status, 204) + assert.equal((await redeem(other, previousOwner.code)).status, 404) +}) + test('群密文和实时提示只投递到名单设备,移除或撤销阻断旧世代', { timeout: 25_000 }, async (t) => { const enroll = async () => { const keys = generateKeyPairSync('ed25519') diff --git a/tests/group-chat.test.mjs b/tests/group-chat.test.mjs index a4e68b3..90bfd67 100644 --- a/tests/group-chat.test.mjs +++ b/tests/group-chat.test.mjs @@ -482,11 +482,35 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员 await owner.getByRole('button', { name: '创建群组' }).click() await owner.getByRole('heading', { name: targetGroup }).waitFor() assert.match(await owner.getByRole('complementary', { name: '群组列表' }).getByRole('link').first().textContent(), /已置顶/) - await owner.getByLabel('邀请联系人').selectOption({ label: names[1] }) - await owner.getByRole('button', { name: '发送邀请' }).click() - await windows.getByRole('link', { name: new RegExp(targetGroup) }).click() + await owner.getByText('群邀请链接和二维码', { exact: true }).click() + await owner.getByRole('button', { name: '生成邀请链接', exact: true }).click() + const qr = owner.getByRole('img', { name: '群邀请二维码' }) + const inviteURL = await owner.getByLabel('邀请链接', { exact: true }).inputValue() + assert.match(inviteURL, /#\/groups\?invite=[A-Za-z0-9_-]{43}$/) + await owner.waitForFunction(() => { + const image = document.querySelector('canvas[aria-label="群邀请二维码"]') + return image?.getContext('2d').getImageData(0, 0, 1, 1).data[3] === 255 + }) + assert.ok(await qr.evaluate((canvas) => canvas.width > 150)) + await windows.getByLabel('群邀请链接或邀请码').fill(inviteURL) + await windows.getByRole('button', { name: '领取群邀请' }).click() + await windows.getByRole('heading', { name: targetGroup }).waitFor() await windows.getByRole('button', { name: '接受邀请' }).click() await owner.getByRole('list', { name: '群成员' }).getByRole('listitem').getByText(names[1] + ' · 成员', { exact: true }).waitFor() + + await owner.getByRole('button', { name: '重新生成邀请链接', exact: true }).click() + await owner.waitForFunction((old) => document.querySelector('.invite-output input')?.value !== old, inviteURL) + const newURL = await owner.getByLabel('邀请链接', { exact: true }).inputValue() + const invitePage = await browser.newPage() + await invitePage.goto(newURL) + await invitePage.getByRole('heading', { name: '登录 XHChat' }).waitFor() + assert.ok(!new URL(invitePage.url()).hash.includes('invite=')) + await register(invitePage, 'inviteqa_' + id(), password) + await invitePage.getByRole('button', { name: '领取群邀请' }).click() + await invitePage.getByRole('heading', { name: targetGroup }).waitFor() + await invitePage.getByRole('button', { name: '拒绝邀请' }).click() + await invitePage.getByRole('heading', { name: targetGroup }).waitFor({ state: 'detached' }) + await invitePage.close() await windows.getByRole('link', { name: new RegExp(group) }).click() await chat(windows).getByRole('button', { name: '启用本机群聊' }).click() const forwardPanel = chat(windows).getByRole('form', { name: '转发群消息' }) @@ -586,7 +610,11 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员 await windows.getByRole('link', { name: new RegExp(targetGroup) }).click() const successor = owner.getByRole('list', { name: '群成员' }).getByRole('listitem').filter({ hasText: names[1] }) await successor.getByRole('button', { name: '转让群主', exact: true }).click() + await owner.getByText(new RegExp('确认将群主转让给 ' + names[1])).waitFor() + const transferred = owner.waitForResponse((response) => response.request().method() === 'POST' && + /\/groups\/[^/]+$/.test(response.url()) && response.request().postDataJSON().action === 'transfer') await owner.getByRole('button', { name: '确认操作', exact: true }).click() + assert.equal((await transferred).status(), 204) await windows.getByRole('list', { name: '群成员' }).getByText(names[1] + ' · 群主', { exact: true }).waitFor() await owner.getByRole('button', { name: '退出群组', exact: true }).waitFor() await owner.getByRole('button', { name: '退出群组', exact: true }).click() diff --git a/web/package.json b/web/package.json index 49da3db..922b56f 100644 --- a/web/package.json +++ b/web/package.json @@ -1 +1 @@ -{"name":"@xhchat/web","private":true,"type":"module","scripts":{"dev":"vite","build":"vue-tsc --noEmit && vite build","check":"vue-tsc --noEmit"},"dependencies":{"vue":"3.5.45","vue-router":"5.5.0","pinia":"4.1.0"},"devDependencies":{"vite":"8.3.8","@vitejs/plugin-vue":"6.0.11","typescript":"~6.0.3","vue-tsc":"3.3.14","@types/node":"^24.0.0"}} +{"name":"@xhchat/web","private":true,"type":"module","scripts":{"dev":"vite","build":"vue-tsc --noEmit && vite build","check":"vue-tsc --noEmit"},"dependencies":{"pinia":"4.1.0","qrcode":"1.5.4","vue":"3.5.45","vue-router":"5.5.0"},"devDependencies":{"@types/node":"^24.0.0","@types/qrcode":"1.5.6","@vitejs/plugin-vue":"6.0.11","typescript":"~6.0.3","vite":"8.3.8","vue-tsc":"3.3.14"}} \ No newline at end of file diff --git a/web/src/App.vue b/web/src/App.vue index 8fbc6bf..50a714f 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -2,11 +2,12 @@ import { watch } from 'vue' import { useRouter } from 'vue-router' import { useSession } from './session' +import { incomingGroupInvite } from './chat/group-invites' const session = useSession() const router = useRouter() watch(() => session.identity, (identity) => { - void router.replace(identity ? '/devices' : '/login') + void router.replace(identity ? incomingGroupInvite.value ? '/groups' : '/devices' : '/login') }) diff --git a/web/src/chat/GroupInviteLink.vue b/web/src/chat/GroupInviteLink.vue new file mode 100644 index 0000000..23bfa93 --- /dev/null +++ b/web/src/chat/GroupInviteLink.vue @@ -0,0 +1,77 @@ + + + + + diff --git a/web/src/chat/group-invites.ts b/web/src/chat/group-invites.ts new file mode 100644 index 0000000..e17ad7a --- /dev/null +++ b/web/src/chat/group-invites.ts @@ -0,0 +1,29 @@ +import { ref } from 'vue' + +const inviteCode = /^[A-Za-z0-9_-]{43}$/ +export const incomingGroupInvite = ref('') + +function serviceURL() { + return new URL(window.xhchat?.apiBase ?? location.origin) +} + +export function groupInviteURL(code: string) { + const url = serviceURL() + url.hash = '/groups?invite=' + code + return url.href +} + +export function parseGroupInvite(value: string) { + const input = value.trim() + if (inviteCode.test(input)) return input + try { + const url = new URL(input) + if (url.origin !== serviceURL().origin || url.username || url.password) return '' + const [route, query] = url.hash.slice(1).split('?') + const code = new URLSearchParams(query).get('invite') ?? '' + if (route === '/groups' && inviteCode.test(code)) return code + } catch { + return '' + } + return '' +} diff --git a/web/src/main.ts b/web/src/main.ts index 045da6a..92a9827 100644 --- a/web/src/main.ts +++ b/web/src/main.ts @@ -9,6 +9,7 @@ import ChatView from './views/ChatView.vue' import GroupView from './views/GroupView.vue' import Workspace from './views/Workspace.vue' import { useSession } from './session' +import { incomingGroupInvite, parseGroupInvite } from './chat/group-invites' import './style.css' const pinia = createPinia() @@ -29,6 +30,10 @@ const router = createRouter({ router.beforeEach((to) => { const signedIn = Boolean(useSession(pinia).identity) + if (to.path === '/groups' && typeof to.query.invite === 'string') { + incomingGroupInvite.value = parseGroupInvite(to.query.invite) + return { path: signedIn ? '/groups' : '/login', replace: true } + } if (!signedIn && to.path !== '/login') return '/login' if (signedIn && to.path === '/login') return '/devices' }) diff --git a/web/src/views/GroupView.vue b/web/src/views/GroupView.vue index ce82cca..9cd76e5 100644 --- a/web/src/views/GroupView.vue +++ b/web/src/views/GroupView.vue @@ -5,6 +5,8 @@ import { useSession } from '../session' import { APIError } from '../api' import type { Contact } from '../contacts' import GroupChat from '../chat/GroupChat.vue' +import GroupInviteLink from '../chat/GroupInviteLink.vue' +import { incomingGroupInvite, parseGroupInvite } from '../chat/group-invites' import type { GroupPreferences, GroupSummary, ListedGroup } from '../chat/group-chat' type Group = GroupSummary @@ -20,6 +22,7 @@ const term = ref('') const name = ref('') const nextName = ref('') const invite = ref('') +const inviteCode = ref('') const busy = ref(false) const error = ref('') const confirmation = ref<{ action: string; target?: string; label: string }>() @@ -84,10 +87,10 @@ function reload() { function queueRefresh() { refreshPending = true - if (busy.value || refreshTimer) return + if (busy.value || confirmation.value || refreshTimer) return refreshTimer = setTimeout(() => { refreshTimer = undefined - reload() + if (!confirmation.value) reload() }, 250) } @@ -120,6 +123,17 @@ function setPreference(key: keyof GroupPreferences) { }) } +function redeemInvite() { + const code = parseGroupInvite(inviteCode.value) + if (!code) { error.value = '请输入当前 XHChat 服务的邀请链接或邀请码'; return } + void run(async () => { + const { groupId } = await session.authorized<{ groupId: string }>('/group-invites/redeem', 'POST', { code }) + inviteCode.value = '' + await router.push('/groups/' + groupId) + await refresh() + }) +} + watch(id, () => { detail.value = undefined confirmation.value = undefined @@ -129,7 +143,13 @@ watch(id, () => { else reload() }) watch(() => session.groupListChanges, queueRefresh) +watch(confirmation, (value) => { if (!value && refreshPending) queueRefresh() }) watch(() => session.groupChange, queueRefresh) +watch(incomingGroupInvite, (code) => { + if (!code) return + inviteCode.value = code + incomingGroupInvite.value = '' +}, { immediate: true }) watch(() => session.connection, (connection) => { if (connection === '实时连接已建立') queueRefresh() }) onMounted(() => { reload() @@ -152,6 +172,10 @@ onBeforeUnmount(() => { + @@ -181,6 +205,7 @@ onBeforeUnmount(() => { +