From 8c936753da2fb2d75569ac27e10ce8be85b0eb4a Mon Sep 17 00:00:00 2001 From: gdz66601 Date: Sat, 5 Sep 2026 07:02:00 +0800 Subject: [PATCH 1/7] feat: add Telegram-style message replies --- .github/scripts/d1-migration-manifest.mjs | 13 +- README.en.md | 1 + README.ja.md | 1 + README.md | 1 + docs/api/edgechat-v1.openapi.yaml | 16 +- docs/api/websocket-v1.md | 6 +- .../src/components/chat/MessageComposer.vue | 57 +++++- .../components/chat/MessageContextMenu.vue | 13 +- .../components/chat/MessageReplyPreview.vue | 88 ++++++++++ .../src/components/demo/DemoNavigator.vue | 5 + .../composables/useBrowserNotifications.js | 26 +-- frontend/src/composables/useChatRoom.js | 58 +++--- frontend/src/composables/useChatSidebar.js | 2 +- .../src/composables/useMessageContextMenu.ts | 18 +- frontend/src/demo/fixtures.js | 21 ++- frontend/src/demo/realtime.js | 25 ++- frontend/src/demo/state.js | 35 +++- frontend/src/locales/en-US.js | 9 + frontend/src/locales/zh-CN.js | 9 + frontend/src/pages/ChatPage.vue | 56 +++++- test/api-v1-contract.test.js | 5 +- test/browser-notifications.test.js | 10 ++ test/chat-page-composables.test.js | 9 +- test/chat-room-transition.test.js | 47 +++++ test/data-projections.test.js | 10 +- test/demo-runtime.test.js | 5 +- test/message-bubble-layout.test.js | 12 ++ test/message-delivery.test.js | 48 ++++- test/message-replies.test.js | 165 ++++++++++++++++++ test/telegram-bridge.test.js | 33 +++- .../migrations/2026-09-04-message-replies.sql | 7 + worker/schema.sql | 10 +- worker/src/api/v1.js | 7 +- worker/src/data/channels.js | 26 +-- worker/src/data/dm-queries.js | 18 +- worker/src/data/messages.js | 119 +++++++++++-- worker/src/data/replies.js | 76 ++++++++ worker/src/data/unread.js | 46 +++-- worker/src/do/ChannelRoom.js | 9 +- worker/src/external-message-submission.js | 3 + worker/src/integrations/telegram/bridge.js | 75 ++++++-- worker/src/integrations/telegram/client.js | 19 +- worker/src/integrations/telegram/parser.js | 6 +- worker/src/message-submission.js | 45 +++-- worker/src/unread-projection.js | 46 +++-- 45 files changed, 1114 insertions(+), 202 deletions(-) create mode 100644 frontend/src/components/chat/MessageReplyPreview.vue create mode 100644 test/message-replies.test.js create mode 100644 worker/migrations/2026-09-04-message-replies.sql create mode 100644 worker/src/data/replies.js diff --git a/.github/scripts/d1-migration-manifest.mjs b/.github/scripts/d1-migration-manifest.mjs index 9d14f189..7fa7b095 100644 --- a/.github/scripts/d1-migration-manifest.mjs +++ b/.github/scripts/d1-migration-manifest.mjs @@ -129,13 +129,22 @@ export const D1_MIGRATIONS = [ file: "worker/migrations/2026-09-01-message-mentions.sql", artifacts: ["column:messages.mention_user_ids"], }, - { - id: "2026-09-02-voice-messages", + { + id: "2026-09-02-voice-messages", file: "worker/migrations/2026-09-02-voice-messages.sql", artifacts: [ "column:messages.attachment_kind", "column:messages.attachment_duration_ms", "column:messages.attachment_waveform", + ], + }, + { + id: "2026-09-04-message-replies", + file: "worker/migrations/2026-09-04-message-replies.sql", + artifacts: [ + "column:messages.reply_to_message_id", + "column:messages.reply_to_sender_id", + "index:idx_messages_reply_attention", ], }, ]; diff --git a/README.en.md b/README.en.md index ed0fa19e..e3581577 100644 --- a/README.en.md +++ b/README.en.md @@ -116,6 +116,7 @@ Admins can bind any group in EdgeChat to a Telegram group. Once bound, messages - Public groups, private groups, and direct message conversations - [Two-way Telegram group bridge](#featured-feature-telegram-two-way-message-bridge) — one Bot connects members on both sides - Real-time messaging, paginated history, Telegram-style voice messages, and file messages +- The web client supports Telegram-style replies, quoted-message navigation, and reply-aware direct-attention alerts - Web and Android recording, waveform seeking, playback speed controls, and two-way Telegram voice/audio sync - File uploads and avatar management - Scheduled hard deletion of expired messages diff --git a/README.ja.md b/README.ja.md index 458a79dd..7d01bfd5 100644 --- a/README.ja.md +++ b/README.ja.md @@ -116,6 +116,7 @@ EdgeChat は Cloudflare 上にデプロイするチーム向けチャットシ - 公開グループ、プライベートグループ、ダイレクトメッセージの会話に対応 - [Telegram グループ双方向メッセージブリッジ](#注目機能telegram-双方向メッセージブリッジ):1 つの Bot で両側のメンバーをつなぐ - リアルタイムメッセージ、履歴のページング、Telegram 風ボイスメッセージ、ファイルメッセージ +- Web では Telegram 風の返信、引用元へのジャンプ、返信を含む「メンション」優先通知に対応 - Web / Android の録音、波形シーク、倍速再生、Telegram voice/audio の双方向同期 - ファイルアップロードとアバター管理 - 期限切れメッセージの定期ハード削除に対応 diff --git a/README.md b/README.md index 593da634..d9332548 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,7 @@ EdgeChat 是一个部署在 Cloudflare 上的团队聊天系统:账号体系 - 支持公开群组、私有群组与私信会话 - [Telegram 群组双向消息桥接](#特色功能telegram-消息双向桥接),一个 Bot 打通两侧成员 - 实时消息、历史消息分页、Telegram 风格语音消息与文件消息 +- 网页支持 Telegram 风格消息回复、引用跳转,以及将回复纳入「有人@我」优先提醒 - 网页和 Android 均支持录音、波形进度、倍速播放;Telegram voice/audio 可双向同步 - 文件上传与头像管理 - 支持定时硬删除过期消息 diff --git a/docs/api/edgechat-v1.openapi.yaml b/docs/api/edgechat-v1.openapi.yaml index def9042a..46cb34e5 100644 --- a/docs/api/edgechat-v1.openapi.yaml +++ b/docs/api/edgechat-v1.openapi.yaml @@ -289,6 +289,7 @@ paths: mentionUserIds: type: array items: { type: integer } + replyMessageId: { type: [integer, "null"], minimum: 1 } responses: "200": { $ref: "#/components/responses/MessageSubmission" } "201": { $ref: "#/components/responses/MessageSubmission" } @@ -551,7 +552,9 @@ components: memberCount: { type: integer } lastMessageAt: { type: [string, "null"] } unreadCount: { type: integer } - mentionUnreadCount: { type: integer } + mentionUnreadCount: + type: integer + description: Legacy field name for Telegram-style direct attention unread messages, including mentions and replies. Member: type: object required: [id, username, displayName, avatarUrl, role] @@ -594,6 +597,15 @@ components: userId: { type: integer } username: { type: string } displayName: { type: string } + ReplyPreview: + type: object + required: [id, deleted] + properties: + id: { type: integer } + deleted: { type: boolean } + content: { type: string } + sender: { $ref: "#/components/schemas/Sender" } + attachment: { oneOf: [{ $ref: "#/components/schemas/Attachment" }, { type: "null" }] } Message: type: object required: [id, content, createdAt, source, sender, attachment] @@ -607,6 +619,8 @@ components: attachment: { oneOf: [{ $ref: "#/components/schemas/Attachment" }, { type: "null" }] } mentionUserIds: { type: array, items: { type: integer } } mentions: { type: array, items: { $ref: "#/components/schemas/Mention" } } + replyToMessageId: { type: integer } + replyTo: { $ref: "#/components/schemas/ReplyPreview" } Bootstrap: type: object required: [users, channels, dms] diff --git a/docs/api/websocket-v1.md b/docs/api/websocket-v1.md index c90ff2ee..de443541 100644 --- a/docs/api/websocket-v1.md +++ b/docs/api/websocket-v1.md @@ -15,17 +15,17 @@ The ticket is bound to one device session and one scope. It is consumed once, in Every server frame is JSON and contains `protocolVersion: 1` plus `type`. - `ready`: the connection is authorized; room sockets include `room`. -- `message`: includes the canonical `message`, including `mentionUserIds` and resolved `mentions`. Room clients merge by `message.id` and `message.clientMessageId`. +- `message`: includes the canonical `message`, including `mentionUserIds`, resolved `mentions`, and optional `replyToMessageId` / `replyTo` preview fields. A deleted or expired target is represented by `replyTo.deleted: true`. Room clients merge by `message.id` and `message.clientMessageId`. - `message_deleted`: includes `messageId`. - `message_pinned`: includes the canonical pinned `message` for the room. - `message_unpinned`: includes `messageId`; clients clear the pin only when it still matches that ID. -- `room_message`: inbox signal with `room`, `messageId`, `createdAt`, `unreadCount`, `mentionsMe`, `contentPreview` and `sender`; `mentionUnreadCount` is included for mentioned recipients and may be omitted otherwise so clients preserve their current value. The client then runs room sync. +- `room_message`: inbox signal with `room`, `messageId`, `createdAt`, `unreadCount`, `mentionsMe`, `replyToMe`, `contentPreview` and `sender`; `mentionUnreadCount` keeps its legacy name but counts both mentions and replies, and is included only for directly addressed recipients so clients preserve their current value otherwise. The client then runs room sync. - `error`: includes a client-safe `error` message and never contains a stack trace. Example: ```json -{"protocolVersion":1,"type":"room_message","room":{"id":7,"kind":"private","name":"team"},"messageId":52,"createdAt":"2026-09-01 12:00:00","unreadCount":3,"mentionUnreadCount":1,"mentionsMe":true,"contentPreview":"@alice please review","sender":{"kind":"local","id":4,"username":"bob","displayName":"Bob","avatarUrl":"","source":"edgechat"}} +{"protocolVersion":1,"type":"room_message","room":{"id":7,"kind":"private","name":"team"},"messageId":52,"createdAt":"2026-09-04 12:00:00","unreadCount":3,"mentionUnreadCount":1,"mentionsMe":false,"replyToMe":true,"contentPreview":"handled","sender":{"kind":"local","id":4,"username":"bob","displayName":"Bob","avatarUrl":"","source":"edgechat"}} ``` ## Lifecycle and recovery diff --git a/frontend/src/components/chat/MessageComposer.vue b/frontend/src/components/chat/MessageComposer.vue index 5e62e2e7..a0be4921 100644 --- a/frontend/src/components/chat/MessageComposer.vue +++ b/frontend/src/components/chat/MessageComposer.vue @@ -1,5 +1,5 @@