feat(dm): 私信支持按用户名搜索开聊,并加入首轮发送条数限制
一、私信用户搜索 此前只能先进入对方个人主页、再点「私信」才能发起会话。现在私信窗口 顶部新增搜索框,输入用户名即可搜索并直接开聊。 - 新增 GET /api/users/search:按用户名模糊匹配,前缀匹配优先、其次按 名字长度排序(更接近精确结果)。只返回用户名、头像、角色、签名, 不暴露邮箱等隐私字段(已实测确认响应中不含 email)。 - 关键词转义 % 与 _,与帖子搜索同样处理,避免通配符被当作模式。 - 关键词长度上限 50 字,limit 上限 20。 - 搜索结果中排除自己;输入防抖 300ms,回车立即搜索,Esc 与清除按钮 回到会话列表。 - 搜索框同样带上防密码管理器误填的属性,并在关闭窗口时清空关键词, 避免下次打开残留上次的搜索状态。 二、首轮发送条数限制 对方尚未回复时,发起方最多先发 3 条消息;对方一旦回复过,限制永久 解除。仅对「对方从未回复」的会话生效,已正常交流过的会话不受影响。 - 判定放在事务中并对会话行加 FOR UPDATE 锁:限制依赖「我方已发几条、 对方是否回过」两个计数,不加锁时并发发送可绕过。 - 达到上限返回 429,附带 limit_reached 与 limit 字段,前端据此给出 针对性提示而非笼统的「发送失败」。 - 发送成功时在响应中返回 remaining(对方已回复时为 null)。 - 聊天窗口底部新增提示条,显示「对方回复前还可发送 N 条消息」, 对方回复后自动隐藏。数字与文字分置于不同元素,使固定文案能被 i18n 词典匹配(整句含动态数字时匹配不上)。 实测: - 用户搜索:「dmtester」命中 2 个、「tester2」命中 1 个、无匹配返回 0, 响应中 email 字段出现 0 次 - 连续发送 4 条:前 3 条成功且 remaining 依次为 2/1/0, 第 4 条返回 429 与明确提示 - 对方回复后再发送:成功且 remaining 为 null,限制已解除 - 前端:搜索框正常显示,点击结果直接进入聊天窗口 - 全新会话提示条显示「对方回复前还可发送 3 条消息」, 发送 1 条后更新为 2 条 完整测试套件 25/25 通过。
This commit is contained in:
1 parent
c26e834982
commit
5995efc7a0
6 files changed
+407
-7
No files matched your search
@@ -3589,6 +3589,123 @@ select:disabled {
|
||||
color: var(--glass-text);
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
✉️ 私信:用户搜索
|
||||
============================================================ */
|
||||
|
||||
.dm-search-wrap {
|
||||
padding: 12px 20px 0;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.dm-search {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.dm-search input {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
/* 右侧留出清除按钮的位置 */
|
||||
padding-right: 34px !important;
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.dm-search-clear {
|
||||
position: absolute;
|
||||
right: 6px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: transparent;
|
||||
color: var(--glass-text-light);
|
||||
cursor: pointer;
|
||||
transition: background var(--dur-fast, 0.16s) ease, color var(--dur-fast, 0.16s) ease;
|
||||
}
|
||||
|
||||
.dm-search-clear:hover {
|
||||
background: rgba(127, 127, 147, 0.18);
|
||||
color: var(--glass-text);
|
||||
}
|
||||
|
||||
/* 搜索结果条目 */
|
||||
.dm-user-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 20px;
|
||||
cursor: pointer;
|
||||
transition: background var(--dur-fast, 0.16s) ease;
|
||||
border-bottom: 1px solid var(--glass-border);
|
||||
}
|
||||
|
||||
.dm-user-row:hover {
|
||||
background: rgba(127, 127, 147, 0.08);
|
||||
}
|
||||
|
||||
.dm-user-row img {
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
border: 1px solid var(--glass-border);
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.dm-user-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.dm-user-name {
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
color: var(--glass-text);
|
||||
/* 过长的用户名截断而不是撑破布局 */
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.dm-user-hint {
|
||||
font-size: 12px;
|
||||
color: var(--glass-text-light);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.dm-user-row .dm-user-action {
|
||||
flex: none;
|
||||
font-size: 12px;
|
||||
color: var(--primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* 搜索状态提示 */
|
||||
.dm-search-status {
|
||||
text-align: center;
|
||||
color: var(--glass-text-light);
|
||||
font-size: 13px;
|
||||
padding: 28px 20px;
|
||||
}
|
||||
|
||||
/* 会话中的限制提示条 */
|
||||
.dm-limit-note {
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
color: var(--glass-text-light);
|
||||
padding: 8px 16px;
|
||||
background: rgba(245, 158, 11, 0.1);
|
||||
border-top: 1px solid rgba(245, 158, 11, 0.25);
|
||||
}
|
||||
|
||||
/* ===== 列表容器高度稳定 =====
|
||||
骨架屏按「理想内容」绘制,实际帖子往往更短,数据到达时容器高度会
|
||||
骤降,导致其下方的内容(分页控件、页脚)整体上跳——这就是首屏
|
||||
|
||||
Reference in new issue
Block a user