mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 13:17:39 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -3,23 +3,33 @@ import { normalizeChatType } from "./chat-type.js";
|
||||
|
||||
function extractConversationId(from?: string): string | undefined {
|
||||
const trimmed = from?.trim();
|
||||
if (!trimmed) return undefined;
|
||||
if (!trimmed) {
|
||||
return undefined;
|
||||
}
|
||||
const parts = trimmed.split(":").filter(Boolean);
|
||||
return parts.length > 0 ? parts[parts.length - 1] : trimmed;
|
||||
}
|
||||
|
||||
function shouldAppendId(id: string): boolean {
|
||||
if (/^[0-9]+$/.test(id)) return true;
|
||||
if (id.includes("@g.us")) return true;
|
||||
if (/^[0-9]+$/.test(id)) {
|
||||
return true;
|
||||
}
|
||||
if (id.includes("@g.us")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function resolveConversationLabel(ctx: MsgContext): string | undefined {
|
||||
const explicit = ctx.ConversationLabel?.trim();
|
||||
if (explicit) return explicit;
|
||||
if (explicit) {
|
||||
return explicit;
|
||||
}
|
||||
|
||||
const threadLabel = ctx.ThreadLabel?.trim();
|
||||
if (threadLabel) return threadLabel;
|
||||
if (threadLabel) {
|
||||
return threadLabel;
|
||||
}
|
||||
|
||||
const chatType = normalizeChatType(ctx.ChatType);
|
||||
if (chatType === "direct") {
|
||||
@@ -32,14 +42,28 @@ export function resolveConversationLabel(ctx: MsgContext): string | undefined {
|
||||
ctx.GroupSpace?.trim() ||
|
||||
ctx.From?.trim() ||
|
||||
"";
|
||||
if (!base) return undefined;
|
||||
if (!base) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const id = extractConversationId(ctx.From);
|
||||
if (!id) return base;
|
||||
if (!shouldAppendId(id)) return base;
|
||||
if (base === id) return base;
|
||||
if (base.includes(id)) return base;
|
||||
if (base.toLowerCase().includes(" id:")) return base;
|
||||
if (base.startsWith("#") || base.startsWith("@")) return base;
|
||||
if (!id) {
|
||||
return base;
|
||||
}
|
||||
if (!shouldAppendId(id)) {
|
||||
return base;
|
||||
}
|
||||
if (base === id) {
|
||||
return base;
|
||||
}
|
||||
if (base.includes(id)) {
|
||||
return base;
|
||||
}
|
||||
if (base.toLowerCase().includes(" id:")) {
|
||||
return base;
|
||||
}
|
||||
if (base.startsWith("#") || base.startsWith("@")) {
|
||||
return base;
|
||||
}
|
||||
return `${base} id:${id}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user