fix not found el #2

Merged
zelda merged 1 commits from zelda.fix-some-i-dont-no into main 2026-04-24 17:18:21 +10:00
3 changed files with 28 additions and 15 deletions

File diff suppressed because one or more lines are too long

View File

@ -59,16 +59,15 @@ export class ContentService {
}
private _clickToConversation(id: string) {
const el = document.getElementById(`chat-list-item_${id}`);
// New Teams DOM: find via title element → closest treeitem
const titleEl = document.getElementById(`title-chat-list-item_${id}`);
const el =
titleEl?.closest<HTMLElement>('[data-testid="list-item"]') ??
document.getElementById(`chat-list-item_${id}`);
if (el) {
el.scrollIntoView({
behavior: "smooth", // hoặc "auto"
block: "center", // cuộn sao cho phần tử nằm giữa view
});
// Đợi 1 chút cho scroll xong (nếu cần)
setTimeout(() => el.click(), 200); // delay 200ms là đủ mượt
el.scrollIntoView({ behavior: "smooth", block: "center" });
setTimeout(() => el.click(), 200);
}
return el?.click();
}

View File

@ -36,13 +36,27 @@ export class TeamsChatService {
}
public getCurrentRoomInfo(): { room_id?: string; room_name?: string } {
// const roomId = document
// .querySelector(this.elTags.root_id)
// ?.id?.split(":")[1];
let roomId: string | undefined;
const roomId = document
.querySelector(this.elTags.root_id)
?.id?.replace("chat-list-item_", "");
// New Teams DOM: selected treeitem has aria-selected="true" + data-fui-tree-item-value
const selectedItem = document.querySelector(
'[role="treeitem"][aria-selected="true"][data-item-type="chat"]',
);
if (selectedItem) {
const treeItemValue =
selectedItem.getAttribute("data-fui-tree-item-value") || "";
const lastSegment = treeItemValue.split("/").pop() || "";
roomId = lastSegment.includes("|")
? lastSegment.split("|")[1]
: undefined;
}
// Fallback: old DOM
if (!roomId) {
roomId = document
.querySelector(this.elTags.root_id)
?.id?.replace("chat-list-item_", "");
}
const roomName = (
document.querySelector(this.elTags.room_name) as HTMLElement