Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/scripts/d1-migration-manifest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,27 @@ export const D1_MIGRATIONS = [
"index:idx_messages_reply_attention",
],
},
{
id: "2026-09-11-r2-cleanup-guards",
file: "worker/migrations/2026-09-11-r2-cleanup-guards.sql",
artifacts: [
"index:idx_gc_uploaded_created",
"index:idx_gc_message_attachment",
"index:idx_gc_user_avatar",
"index:idx_gc_channel_avatar",
"trigger:prevent_pending_message_attachment_insert",
"trigger:prevent_pending_message_attachment_update",
"trigger:prevent_pending_user_avatar_insert",
"trigger:prevent_pending_user_avatar_update",
"trigger:prevent_pending_channel_avatar_insert",
"trigger:prevent_pending_channel_avatar_update",
],
},
{
id: "2026-09-11-user-blocks",
file: "worker/migrations/2026-09-11-user-blocks.sql",
artifacts: ["table:user_blocks", "index:idx_user_blocks_blocked"],
},
];

// b3f6855 曾发布、0c13e8f 已撤回的迁移:仅识别历史 ledger,不要求新安装创建废弃表,也不删除旧数据。
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

EdgeChat 从 `2.1.2` 起正式采用语义化版本。更早的版本号依据已经完成的主要里程碑补记,用于说明项目演进,不对应历史 Git 标签。

## 2.2.1 - 2026-09-11

- 修复刷新后私信顶栏丢失拉黑状态、需要重复点击才能解除拉黑的问题。

## 2.2.0 - 2026-09-11

- 新增私信用户拉黑与解除拉黑,服务端统一阻断双方发送,并向被拉黑者返回明确拒绝提示。

## 2.1.2 - 2026-09-08

- 统一 Web、安装维护页、demo 与 Capacitor 客户端的项目版本来源。
Expand Down
1 change: 1 addition & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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
- Block or unblock contacts from the direct-message header; direct messages pause in both directions while blocked
- 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
Expand Down
1 change: 1 addition & 0 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ EdgeChat は Cloudflare 上にデプロイするチーム向けチャットシ
- 公開グループ、プライベートグループ、ダイレクトメッセージの会話に対応
- [Telegram グループ双方向メッセージブリッジ](#注目機能telegram-双方向メッセージブリッジ):1 つの Bot で両側のメンバーをつなぐ
- リアルタイムメッセージ、履歴のページング、Telegram 風ボイスメッセージ、ファイルメッセージ
- ダイレクトメッセージのヘッダーから相手をブロック/解除でき、ブロック中は双方の送信を停止
- Web では Telegram 風の返信、引用元へのジャンプ、返信を含む「メンション」優先通知に対応
- Web / Android の録音、波形シーク、倍速再生、Telegram voice/audio の双方向同期
- ファイルアップロードとアバター管理
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ EdgeChat 是一个部署在 Cloudflare 上的团队聊天系统:账号体系
- 支持公开群组、私有群组与私信会话
- [Telegram 群组双向消息桥接](#特色功能telegram-消息双向桥接),一个 Bot 打通两侧成员
- 实时消息、历史消息分页、Telegram 风格语音消息与文件消息
- 可在私信顶部拉黑或解除拉黑联系人,拉黑期间双方均无法继续发送私信
- 网页支持 Telegram 风格消息回复、引用跳转,以及将回复纳入「有人@我」优先提醒
- 网页和 Android 均支持录音、波形进度、倍速播放;Telegram voice/audio 可双向同步
- 文件上传与头像管理
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ export default {
listDms() {
return request('/dm');
},
blockUser(userId) {
return request(`/users/${Number(userId)}/block`, { method: 'PUT' });
},
unblockUser(userId) {
return request(`/users/${Number(userId)}/block`, { method: 'DELETE' });
},
uploadFile(file) {
const form = new FormData();
form.append('file', file);
Expand Down Expand Up @@ -329,4 +335,3 @@ export default {
});
}
};

1 change: 1 addition & 0 deletions frontend/src/composables/useActiveRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function useActiveRoom({ activeRoom }) {
kind: "dm",
name: dm.name,
otherUser: dm.otherUser,
isBlockedByMe: Boolean(dm.isBlockedByMe),
};
}

Expand Down
80 changes: 80 additions & 0 deletions frontend/src/composables/useUserBlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { computed, ref, type Ref } from "vue";
import api from "../api.js";
import { t } from "../i18n.js";

interface DirectMessage {
id: number;
kind: "dm";
isBlockedByMe?: boolean;
otherUser: { id: number; displayName?: string };
}

interface UserBlockApi {
blockUser(userId: number): Promise<{ blockedByMe: boolean }>;
unblockUser(userId: number): Promise<{ blockedByMe: boolean }>;
}

export function useUserBlock({
activeRoom,
dms,
error,
blockApi = api,
confirmBlock = (message: string) => globalThis.confirm(message),
}: {
activeRoom: Ref<DirectMessage | Record<string, unknown> | null>;
dms: Ref<DirectMessage[]>;
error: Ref<string>;
blockApi?: UserBlockApi;
confirmBlock?: (message: string) => boolean;
}) {
const saving = ref(false);
const isBlockedByMe = computed(
() => activeRoom.value?.kind === "dm" && Boolean(activeRoom.value.isBlockedByMe),
);

function peerUserId() {
return Number(
activeRoom.value?.kind === "dm"
? (activeRoom.value as DirectMessage).otherUser?.id
: 0,
);
}

function applyBlockState(userId: number, blockedByMe: boolean) {
if (activeRoom.value?.kind === "dm" && peerUserId() === userId) {
activeRoom.value.isBlockedByMe = blockedByMe;
}
const dm = dms.value.find((item) => Number(item.otherUser.id) === userId);
if (dm) dm.isBlockedByMe = blockedByMe;
}

async function toggleUserBlock() {
if (activeRoom.value?.kind !== "dm" || saving.value) return false;
const room = activeRoom.value as DirectMessage;
const userId = peerUserId();
const nextBlocked = !room.isBlockedByMe;
if (
nextBlocked &&
!confirmBlock(t("chat.blockUserConfirm", { name: room.otherUser.displayName || "" }))
) {
return false;
}

saving.value = true;
error.value = "";
try {
const result = nextBlocked
? await blockApi.blockUser(userId)
: await blockApi.unblockUser(userId);
applyBlockState(userId, result.blockedByMe);
return true;
} catch (currentError) {
error.value = currentError instanceof Error ? currentError.message : String(currentError);
return false;
} finally {
saving.value = false;
}
}

return { isBlockedByMe, saving, toggleUserBlock };
}
24 changes: 19 additions & 5 deletions frontend/src/demo/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
projectDemoDm,
projectDemoUser,
roomKey,
setDemoUserBlocked,
storeDemoFile
} from './state.js';

Expand Down Expand Up @@ -52,7 +53,7 @@ function sessionForUser(user) {
function bootstrapPayload() {
return {
channels: demoState.channels.map(projectDemoChannel),
dms: demoState.dms.map(projectDemoDm),
dms: demoState.dms.map((dm) => projectDemoDm(dm, demoState.session.userId)),
users: demoState.users
.map(projectDemoUser)
.filter((user) => Number(user.id) !== Number(demoState.session.userId) && !user.isDisabled)
Expand Down Expand Up @@ -262,6 +263,16 @@ export async function requestDemo(path, options = {}) {
if (method === 'GET' && pathname === '/users') {
return { users: bootstrapPayload().users };
}
let match = pathname.match(/^\/users\/(\d+)\/block$/);
if ((method === 'PUT' || method === 'DELETE') && match) {
const userId = Number(match[1]);
if (userId === Number(demoState.session.userId) || !findDemoUser(userId)) {
fail('请选择有效用户');
}
const blockedByMe = method === 'PUT';
setDemoUserBlocked(demoState.session.userId, userId, blockedByMe);
return { blockedByMe };
}
if (method === 'GET' && pathname === '/bootstrap') {
return bootstrapPayload();
}
Expand All @@ -274,7 +285,7 @@ export async function requestDemo(path, options = {}) {
return { channel: createGroup(body) };
}

let match = pathname.match(/^\/channels\/(\d+)\/join$/);
match = pathname.match(/^\/channels\/(\d+)\/join$/);
if (method === 'POST' && match) {
const channel = findDemoChannel(match[1]);
if (!channel || channel.kind !== 'public') fail('公开群组不存在', 404);
Expand Down Expand Up @@ -357,7 +368,10 @@ export async function requestDemo(path, options = {}) {
if (method === 'POST' && pathname === '/dm/open') {
const user = findDemoUser(body.userId);
if (!user) fail('用户不存在', 404);
let dm = demoState.dms.find((item) => Number(item.otherUser.id) === Number(user.id));
let dm = demoState.dms.find(
(item) => item.participantIds.includes(Number(demoState.session.userId))
&& item.participantIds.includes(Number(user.id))
);
if (!dm) {
dm = {
id: demoState.nextDmId++,
Expand All @@ -371,10 +385,10 @@ export async function requestDemo(path, options = {}) {
demoState.dms.push(dm);
demoState.messages[roomKey('dm', dm.id)] = [];
}
return { dm: projectDemoDm(dm) };
return { dm: projectDemoDm(dm, demoState.session.userId) };
}
if (method === 'GET' && pathname === '/dm') {
return { dms: demoState.dms.map(projectDemoDm) };
return { dms: demoState.dms.map((dm) => projectDemoDm(dm, demoState.session.userId)) };
}
if (method === 'POST' && pathname === '/upload') {
const file = body.get('file');
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/demo/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ export function createDemoFixtures() {
users,
channels,
dms,
messages,
messages,
userBlocks: new Set(),
pinnedMessages: {
'public:1': messages['public:1'][1]
},
Expand Down
25 changes: 21 additions & 4 deletions frontend/src/demo/realtime.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { cloneDemo, createDemoMessage, demoState, roomKey } from './state.js';
import {
cloneDemo,
createDemoMessage,
demoState,
getDemoDirectMessageBlockStatus,
roomKey
} from './state.js';

const roomSockets = new Map();
const inboxSockets = new Set();
Expand Down Expand Up @@ -73,9 +79,20 @@ function hasEnabledTelegramMapping(kind, roomId) {
}

function handleRoomFrame(socket, frame) {
const payload = JSON.parse(frame);
if (payload.type === 'send') {
const message = createDemoMessage({
const payload = JSON.parse(frame);
if (payload.type === 'send') {
if (socket.kind === 'dm') {
const status = getDemoDirectMessageBlockStatus(socket.roomId, demoState.session.userId);
if (status.blockedByPeer) {
emit(socket, { type: 'error', error: '发送被拒,你已经被拉黑' });
return;
}
if (status.blockedBySender) {
emit(socket, { type: 'error', error: '请先解除拉黑再发送' });
return;
}
}
const message = createDemoMessage({
kind: socket.kind,
roomId: socket.roomId,
content: payload.content,
Expand Down
48 changes: 38 additions & 10 deletions frontend/src/demo/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,44 @@ export function projectDemoChannel(channel) {
return cloneDemo(projection);
}

export function projectDemoDm(dm) {
if (!dm) return null;
return {
id: dm.id,
kind: 'dm',
otherUser: projectDemoUser(dm.otherUser),
lastMessageAt: dm.lastMessageAt,
unreadCount: dm.unreadCount,
mentionUnreadCount: Number(dm.mentionUnreadCount || 0)
};
export function projectDemoDm(dm, viewerUserId = demoState.session.userId) {
if (!dm) return null;
const peerUserId = dm.participantIds.find(
(userId) => Number(userId) !== Number(viewerUserId)
);
const otherUser = findDemoUser(peerUserId) || dm.otherUser;
return {
id: dm.id,
kind: 'dm',
otherUser: projectDemoUser(otherUser),
lastMessageAt: dm.lastMessageAt,
unreadCount: dm.unreadCount,
mentionUnreadCount: Number(dm.mentionUnreadCount || 0),
isBlockedByMe: isDemoUserBlocked(viewerUserId, otherUser.id)
};
}

function userBlockKey(blockerId, blockedId) {
return `${Number(blockerId)}:${Number(blockedId)}`;
}

export function isDemoUserBlocked(blockerId, blockedId) {
return demoState.userBlocks.has(userBlockKey(blockerId, blockedId));
}

export function setDemoUserBlocked(blockerId, blockedId, blocked) {
const key = userBlockKey(blockerId, blockedId);
if (blocked) demoState.userBlocks.add(key);
else demoState.userBlocks.delete(key);
}

export function getDemoDirectMessageBlockStatus(dmId, senderId) {
const dm = demoState.dms.find((item) => Number(item.id) === Number(dmId));
const peerId = dm?.participantIds.find((userId) => Number(userId) !== Number(senderId));
return {
blockedBySender: Boolean(peerId && isDemoUserBlocked(senderId, peerId)),
blockedByPeer: Boolean(peerId && isDemoUserBlocked(peerId, senderId))
};
}

export function getDemoMembers(channel) {
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ export default {
'chat.noConversationSelected': 'No conversation selected',
'chat.roomAccessRevokedNamed': 'You no longer have access to "{name}".',
'chat.roomAccessRevoked': 'You no longer have access to this conversation.',
'chat.deleteMessageConfirm': 'Delete this message? It will disappear for everyone in this conversation.',
'chat.deleteMessageConfirm': 'Delete this message? It will disappear for everyone in this conversation.',
'chat.blockUser': 'Block this user',
'chat.unblockUser': 'Unblock user',
'chat.block': 'Block',
'chat.unblock': 'Unblock',
'chat.blockUserConfirm': 'Block {name}? Neither of you will be able to send direct messages until you unblock them.',
'chat.addPeople': 'Add people',
'chat.loadingConversations': 'Loading...',
'chat.noConversations': 'No conversations',
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/locales/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ export default {
'chat.noConversationSelected': '未选择会话',
'chat.roomAccessRevokedNamed': '你已无法访问“{name}”。',
'chat.roomAccessRevoked': '你已无法访问这个会话。',
'chat.deleteMessageConfirm': '确认删除这条消息吗?删除后会话中的所有人都将看不到它。',
'chat.deleteMessageConfirm': '确认删除这条消息吗?删除后会话中的所有人都将看不到它。',
'chat.blockUser': '拉黑此用户',
'chat.unblockUser': '解除拉黑',
'chat.block': '拉黑',
'chat.unblock': '解除拉黑',
'chat.blockUserConfirm': '确定要拉黑{name}吗?拉黑后,双方将无法继续发送私信。',
'chat.addPeople': '添加人员',
'chat.loadingConversations': '加载中...',
'chat.noConversations': '暂无会话',
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/localized-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ const fixedErrorTranslations = new Map([
['消息不存在', 'Message not found'],
['无权删除该消息', 'You do not have permission to delete this message'],
['消息不存在或已被删除', 'Message not found or already deleted'],
['消息操作失败', 'Message operation failed'],
['消息操作失败', 'Message operation failed'],
['发送被拒,你已经被拉黑', 'Message rejected. This user has blocked you'],
['请先解除拉黑再发送', 'Unblock this user before sending a message'],
['头像不存在', 'Avatar not found'],
['Telegram Bridge 未配置', 'Telegram Bridge is not configured'],
['Telegram 头像暂时不可用', 'Telegram avatar is temporarily unavailable'],
Expand Down
Loading
Loading