Merge pull request 'fix something idon't no' (#1) from zelda.fix-some-i-dont-no into main
Reviewed-on: #1
This commit is contained in:
commit
45bbf1f65f
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1,23 +1,26 @@
|
||||||
import js from '@eslint/js'
|
import js from "@eslint/js";
|
||||||
import globals from 'globals'
|
import globals from "globals";
|
||||||
import reactHooks from 'eslint-plugin-react-hooks'
|
import reactHooks from "eslint-plugin-react-hooks";
|
||||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
import reactRefresh from "eslint-plugin-react-refresh";
|
||||||
import tseslint from 'typescript-eslint'
|
import tseslint from "typescript-eslint";
|
||||||
import { globalIgnores } from 'eslint/config'
|
import { globalIgnores } from "eslint/config";
|
||||||
|
|
||||||
export default tseslint.config([
|
export default tseslint.config([
|
||||||
globalIgnores(['dist']),
|
globalIgnores(["dist"]),
|
||||||
{
|
{
|
||||||
files: ['**/*.{ts,tsx}'],
|
files: ["**/*.{ts,tsx}"],
|
||||||
extends: [
|
extends: [
|
||||||
js.configs.recommended,
|
js.configs.recommended,
|
||||||
tseslint.configs.recommended,
|
tseslint.configs.recommended,
|
||||||
reactHooks.configs['recommended-latest'],
|
reactHooks.configs["recommended-latest"],
|
||||||
reactRefresh.configs.vite,
|
reactRefresh.configs.vite,
|
||||||
],
|
],
|
||||||
languageOptions: {
|
languageOptions: {
|
||||||
ecmaVersion: 2020,
|
ecmaVersion: 2020,
|
||||||
globals: globals.browser,
|
globals: globals.browser,
|
||||||
},
|
},
|
||||||
|
rules: {
|
||||||
|
"@typescript-eslint/no-unused-vars": ["off"],
|
||||||
},
|
},
|
||||||
])
|
},
|
||||||
|
]);
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ function initSocket() {
|
||||||
|
|
||||||
// Socket.IO events
|
// Socket.IO events
|
||||||
socket.on("connect", () => {
|
socket.on("connect", () => {
|
||||||
console.log("✅ Socket.IO connected");
|
console.log("✅ Socket.IO connectedd");
|
||||||
broadcastToPorts({
|
broadcastToPorts({
|
||||||
type: "socket",
|
type: "socket",
|
||||||
event: "connect",
|
event: "connect",
|
||||||
|
|
@ -60,6 +60,7 @@ function initSocket() {
|
||||||
|
|
||||||
eventsToListen.forEach((event) => {
|
eventsToListen.forEach((event) => {
|
||||||
socket?.on(event, (data: any) => {
|
socket?.on(event, (data: any) => {
|
||||||
|
console.log({ event });
|
||||||
broadcastToPorts({
|
broadcastToPorts({
|
||||||
type: "socket",
|
type: "socket",
|
||||||
event,
|
event,
|
||||||
|
|
@ -143,7 +144,7 @@ chrome.alarms.onAlarm.addListener((alarm) => {
|
||||||
if (alarm.name === "reloadEvery4Hours") {
|
if (alarm.name === "reloadEvery4Hours") {
|
||||||
console.log(
|
console.log(
|
||||||
"🔄 Reloading all tabs (every 4 hours)",
|
"🔄 Reloading all tabs (every 4 hours)",
|
||||||
new Date().toLocaleString()
|
new Date().toLocaleString(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Reload tất cả các tab đang mở
|
// Reload tất cả các tab đang mở
|
||||||
|
|
|
||||||
|
|
@ -44,11 +44,3 @@ contentService.startSyncConversations();
|
||||||
|
|
||||||
// AUTO SYNC MESAGE PREFIX (INTERNAL)
|
// AUTO SYNC MESAGE PREFIX (INTERNAL)
|
||||||
contentService.autoSyncConversationPrefixMessages();
|
contentService.autoSyncConversationPrefixMessages();
|
||||||
|
|
||||||
// setTimeout(async () => {
|
|
||||||
// const a = new TeamsChatService();
|
|
||||||
|
|
||||||
// const conversations = await a.handleGetConversations();
|
|
||||||
|
|
||||||
// console.log({ conversations });
|
|
||||||
// }, 10000);
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ export class ContentService {
|
||||||
document,
|
document,
|
||||||
null,
|
null,
|
||||||
XPathResult.FIRST_ORDERED_NODE_TYPE,
|
XPathResult.FIRST_ORDERED_NODE_TYPE,
|
||||||
null
|
null,
|
||||||
).singleNodeValue;
|
).singleNodeValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,7 +74,7 @@ export class ContentService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _waitForMessagesToAppear(
|
private async _waitForMessagesToAppear(
|
||||||
timeoutMs = 10000
|
timeoutMs = 10000,
|
||||||
): Promise<HTMLElement[]> {
|
): Promise<HTMLElement[]> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const chatPaneList = document.getElementById("chat-pane-list");
|
const chatPaneList = document.getElementById("chat-pane-list");
|
||||||
|
|
@ -114,46 +114,46 @@ export class ContentService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _waitForNewMessages(
|
// private async _waitForNewMessages(
|
||||||
existingItems: HTMLElement[],
|
// existingItems: HTMLElement[],
|
||||||
timeoutMs = 10000
|
// timeoutMs = 10000
|
||||||
): Promise<HTMLElement[]> {
|
// ): Promise<HTMLElement[]> {
|
||||||
return new Promise((resolve, reject) => {
|
// return new Promise((resolve, reject) => {
|
||||||
const chatPaneList = document.getElementById("chat-pane-list");
|
// const chatPaneList = document.getElementById("chat-pane-list");
|
||||||
|
|
||||||
if (!chatPaneList) {
|
// if (!chatPaneList) {
|
||||||
return reject(new Error("#chat-pane-list not found"));
|
// return reject(new Error("#chat-pane-list not found"));
|
||||||
}
|
// }
|
||||||
|
|
||||||
const getChildren = () =>
|
// const getChildren = () =>
|
||||||
Array.from(chatPaneList.children) as HTMLElement[];
|
// Array.from(chatPaneList.children) as HTMLElement[];
|
||||||
|
|
||||||
const existingSet = new Set(existingItems);
|
// const existingSet = new Set(existingItems);
|
||||||
|
|
||||||
let timeoutHandle: any = null;
|
// let timeoutHandle: any = null;
|
||||||
|
|
||||||
const observer = new MutationObserver(() => {
|
// const observer = new MutationObserver(() => {
|
||||||
const currentChildren = getChildren();
|
// const currentChildren = getChildren();
|
||||||
const newItems = currentChildren.filter((el) => !existingSet.has(el));
|
// const newItems = currentChildren.filter((el) => !existingSet.has(el));
|
||||||
|
|
||||||
if (newItems.length > 0) {
|
// if (newItems.length > 0) {
|
||||||
observer.disconnect();
|
// observer.disconnect();
|
||||||
if (timeoutHandle) clearTimeout(timeoutHandle);
|
// if (timeoutHandle) clearTimeout(timeoutHandle);
|
||||||
resolve(newItems);
|
// resolve(newItems);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
observer.observe(chatPaneList, {
|
// observer.observe(chatPaneList, {
|
||||||
childList: true,
|
// childList: true,
|
||||||
subtree: true,
|
// subtree: true,
|
||||||
});
|
// });
|
||||||
|
|
||||||
timeoutHandle = setTimeout(() => {
|
// timeoutHandle = setTimeout(() => {
|
||||||
observer.disconnect();
|
// observer.disconnect();
|
||||||
reject(new Error("Timeout waiting for new messages"));
|
// reject(new Error("Timeout waiting for new messages"));
|
||||||
}, timeoutMs);
|
// }, timeoutMs);
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
private async _waitToloadMessages(stableTime = 300): Promise<any> {
|
private async _waitToloadMessages(stableTime = 300): Promise<any> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
|
@ -189,24 +189,24 @@ export class ContentService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getTypeGeo() {
|
// private _getTypeGeo() {
|
||||||
const el = document.querySelector(".ck-placeholder");
|
// const el = document.querySelector(".ck-placeholder");
|
||||||
|
|
||||||
if (el) {
|
// if (el) {
|
||||||
const rect = el.getBoundingClientRect();
|
// const rect = el.getBoundingClientRect();
|
||||||
|
|
||||||
return {
|
// return {
|
||||||
top: rect.top,
|
// top: rect.top,
|
||||||
left: rect.left,
|
// left: rect.left,
|
||||||
right: rect.right,
|
// right: rect.right,
|
||||||
bottom: rect.bottom,
|
// bottom: rect.bottom,
|
||||||
width: rect.width,
|
// width: rect.width,
|
||||||
height: rect.height,
|
// height: rect.height,
|
||||||
};
|
// };
|
||||||
}
|
// }
|
||||||
|
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
private async _rightClickMessage(date_time: number) {
|
private async _rightClickMessage(date_time: number) {
|
||||||
const selector = this.service.elTags.container_chat;
|
const selector = this.service.elTags.container_chat;
|
||||||
|
|
@ -234,7 +234,7 @@ export class ContentService {
|
||||||
|
|
||||||
scrollContainer.scrollTop = Math.max(
|
scrollContainer.scrollTop = Math.max(
|
||||||
0,
|
0,
|
||||||
scrollContainer.scrollTop - scrollStep
|
scrollContainer.scrollTop - scrollStep,
|
||||||
);
|
);
|
||||||
await delay(200); // Đợi scroll và DOM render lại
|
await delay(200); // Đợi scroll và DOM render lại
|
||||||
|
|
||||||
|
|
@ -385,6 +385,8 @@ export class ContentService {
|
||||||
|
|
||||||
initialMessages = await this._waitForMessagesToAppear(); // Đợi có item đầu tiên
|
initialMessages = await this._waitForMessagesToAppear(); // Đợi có item đầu tiên
|
||||||
await this._waitToloadMessages();
|
await this._waitToloadMessages();
|
||||||
|
|
||||||
|
console.log({ initialMessages });
|
||||||
}
|
}
|
||||||
|
|
||||||
await this._clickIfExists(this.service.elTags.close_reply_btn);
|
await this._clickIfExists(this.service.elTags.close_reply_btn);
|
||||||
|
|
@ -392,7 +394,7 @@ export class ContentService {
|
||||||
await this._rightClickMessage(time);
|
await this._rightClickMessage(time);
|
||||||
|
|
||||||
const replyBtn: any = document.querySelector(
|
const replyBtn: any = document.querySelector(
|
||||||
this.service.elTags.reply_btn
|
this.service.elTags.reply_btn,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (replyBtn) {
|
if (replyBtn) {
|
||||||
|
|
@ -410,7 +412,7 @@ export class ContentService {
|
||||||
fixedHeightChatInput(retry = 20, interval = 2000) {
|
fixedHeightChatInput(retry = 20, interval = 2000) {
|
||||||
const tryFind = () => {
|
const tryFind = () => {
|
||||||
const el = document.querySelector(
|
const el = document.querySelector(
|
||||||
this.service.elTags.chat_input
|
this.service.elTags.chat_input,
|
||||||
) as HTMLElement;
|
) as HTMLElement;
|
||||||
|
|
||||||
if (el) {
|
if (el) {
|
||||||
|
|
@ -419,7 +421,7 @@ export class ContentService {
|
||||||
} else if (retry > 0) {
|
} else if (retry > 0) {
|
||||||
setTimeout(
|
setTimeout(
|
||||||
() => this.fixedHeightChatInput(retry - 1, interval),
|
() => this.fixedHeightChatInput(retry - 1, interval),
|
||||||
interval
|
interval,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
console.warn("✘ Element not found with provided XPath after retries");
|
console.warn("✘ Element not found with provided XPath after retries");
|
||||||
|
|
@ -448,7 +450,7 @@ export class ContentService {
|
||||||
// Lấy attribute aria-labelledby
|
// Lấy attribute aria-labelledby
|
||||||
const ariaValue = document
|
const ariaValue = document
|
||||||
.querySelector(
|
.querySelector(
|
||||||
'[aria-labelledby^="cn-normal-notification-main-content-"]'
|
'[aria-labelledby^="cn-normal-notification-main-content-"]',
|
||||||
)
|
)
|
||||||
?.getAttribute("aria-labelledby");
|
?.getAttribute("aria-labelledby");
|
||||||
|
|
||||||
|
|
@ -478,7 +480,7 @@ export class ContentService {
|
||||||
|
|
||||||
if (!roomId) {
|
if (!roomId) {
|
||||||
console.warn(
|
console.warn(
|
||||||
"[Monitor] Could not extract room_id from aria-labelledby"
|
"[Monitor] Could not extract room_id from aria-labelledby",
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -563,7 +565,7 @@ export class ContentService {
|
||||||
() => {
|
() => {
|
||||||
this.getConversations();
|
this.getConversations();
|
||||||
},
|
},
|
||||||
120000
|
120000,
|
||||||
);
|
);
|
||||||
console.log("✅ startSyncConversations running");
|
console.log("✅ startSyncConversations running");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -572,13 +574,73 @@ export class ContentService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interval chạy, chỉ add task vào queue
|
// Interval chạy, chỉ add task vào queue
|
||||||
autoSyncConversationPrefixMessages() {
|
// autoSyncConversationPrefixMessages() {
|
||||||
(window as any)._chatIntervals = (window as any)?._chatIntervals || {};
|
// (window as any)._chatIntervals = (window as any)?._chatIntervals || {};
|
||||||
|
|
||||||
|
// if (!(window as any)._chatIntervals.syncPrefixMessages) {
|
||||||
|
// (window as any)._chatIntervals.syncPrefixMessages = (
|
||||||
|
// window as any
|
||||||
|
// ).setInterval(() => {
|
||||||
|
// (window as any)["is_sync_conversation_prefix"] = true;
|
||||||
|
|
||||||
|
// queue.add(async () => {
|
||||||
|
// try {
|
||||||
|
// const { data } =
|
||||||
|
// (await conversationApi.getConversationByPrefix()) as {
|
||||||
|
// data: ChatItem[];
|
||||||
|
// };
|
||||||
|
// if (!data) return;
|
||||||
|
// for (const chat of data) {
|
||||||
|
// this._clickToConversation(chat.id as string);
|
||||||
|
// await delay(5000);
|
||||||
|
// const currentRoom = this.service.getCurrentRoomInfo();
|
||||||
|
// if (!currentRoom || currentRoom.room_id !== chat.id) return;
|
||||||
|
// const filesMessages = this.filesMessages();
|
||||||
|
// if (filesMessages.length) {
|
||||||
|
// await this.clickToRefreshToken(filesMessages);
|
||||||
|
// }
|
||||||
|
// const messages = this.service.extractAllMessages();
|
||||||
|
// await messageApi.createAndSendToZulip(messages);
|
||||||
|
// await delay(5000);
|
||||||
|
// }
|
||||||
|
// } catch (err) {
|
||||||
|
// console.error(
|
||||||
|
// "❌ autoSyncConversationPrefixMessages error:",
|
||||||
|
// (err as any)?.message,
|
||||||
|
// );
|
||||||
|
// messageApi.sendLog({
|
||||||
|
// type: "error",
|
||||||
|
// message: `auto_to_sync_conersations: ${(err as any)?.message}`,
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }, 60000);
|
||||||
|
|
||||||
|
// console.log("✅ autoSyncConversationPrefixMessages running with PQueue");
|
||||||
|
// } else {
|
||||||
|
// console.log("ℹ️ autoSyncConversationPrefixMessages already running");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
autoSyncConversationPrefixMessages() {
|
||||||
|
(window as any)._chatIntervals = (window as any)._chatIntervals || {};
|
||||||
|
|
||||||
|
if ((window as any)._chatIntervals.syncPrefixMessages) {
|
||||||
|
console.log("autoSyncConversationPrefixMessages already running");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let isRunning = false;
|
||||||
|
|
||||||
|
(window as any)._chatIntervals.syncPrefixMessages = window.setInterval(
|
||||||
|
() => {
|
||||||
|
if (isRunning) {
|
||||||
|
console.log("syncPrefixMessages skipped (still running)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isRunning = true;
|
||||||
|
|
||||||
if (!(window as any)._chatIntervals.syncPrefixMessages) {
|
|
||||||
(window as any)._chatIntervals.syncPrefixMessages = (
|
|
||||||
window as any
|
|
||||||
).setInterval(() => {
|
|
||||||
queue.add(async () => {
|
queue.add(async () => {
|
||||||
try {
|
try {
|
||||||
const { data } =
|
const { data } =
|
||||||
|
|
@ -586,7 +648,7 @@ export class ContentService {
|
||||||
data: ChatItem[];
|
data: ChatItem[];
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!data) return;
|
if (!data?.length) return;
|
||||||
|
|
||||||
for (const chat of data) {
|
for (const chat of data) {
|
||||||
this._clickToConversation(chat.id as string);
|
this._clickToConversation(chat.id as string);
|
||||||
|
|
@ -594,37 +656,39 @@ export class ContentService {
|
||||||
await delay(5000);
|
await delay(5000);
|
||||||
|
|
||||||
const currentRoom = this.service.getCurrentRoomInfo();
|
const currentRoom = this.service.getCurrentRoomInfo();
|
||||||
|
if (!currentRoom || currentRoom.room_id !== chat.id) {
|
||||||
if (!currentRoom || currentRoom.room_id !== chat.id) return;
|
console.warn("room mismatch, skip:", chat.id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const filesMessages = this.filesMessages();
|
const filesMessages = this.filesMessages();
|
||||||
|
|
||||||
if (filesMessages.length) {
|
if (filesMessages.length) {
|
||||||
await this.clickToRefreshToken(filesMessages);
|
await this.clickToRefreshToken(filesMessages);
|
||||||
}
|
}
|
||||||
|
|
||||||
const messages = this.service.extractAllMessages();
|
const messages = this.service.extractAllMessages();
|
||||||
|
|
||||||
await messageApi.createAndSendToZulip(messages);
|
await messageApi.createAndSendToZulip(messages);
|
||||||
|
|
||||||
await delay(5000);
|
await delay(5000);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(
|
console.error(
|
||||||
"❌ autoSyncConversationPrefixMessages error:",
|
"autoSyncConversationPrefixMessages error:",
|
||||||
(err as any)?.message
|
(err as any)?.message,
|
||||||
);
|
);
|
||||||
|
|
||||||
messageApi.sendLog({
|
messageApi.sendLog({
|
||||||
type: "error",
|
type: "error",
|
||||||
message: `auto_to_sync_conersations: ${(err as any)?.message}`,
|
message: `auto_to_sync_conersations: ${(err as any)?.message}`,
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
isRunning = false; // 🔑 cực kỳ quan trọng
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 40000);
|
},
|
||||||
|
60000,
|
||||||
|
);
|
||||||
|
|
||||||
console.log("✅ autoSyncConversationPrefixMessages running with PQueue");
|
console.log("autoSyncConversationPrefixMessages running safely");
|
||||||
} else {
|
|
||||||
console.log("ℹ️ autoSyncConversationPrefixMessages already running");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,13 @@ import * as fs from 'fs';
|
||||||
import { SocketIoAdapter } from './socket-adapter';
|
import { SocketIoAdapter } from './socket-adapter';
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const httpsOptions = {
|
// const httpsOptions = {
|
||||||
key: fs.readFileSync('ssl/localhost+1-key.pem'),
|
// key: fs.readFileSync('ssl/localhost+1-key.pem'),
|
||||||
cert: fs.readFileSync('ssl/localhost+1.pem'),
|
// cert: fs.readFileSync('ssl/localhost+1.pem'),
|
||||||
};
|
// };
|
||||||
|
|
||||||
const app = await NestFactory.create(AppModule, { httpsOptions });
|
const app = await NestFactory.create(AppModule);
|
||||||
|
// const app = await NestFactory.create(AppModule, { httpsOptions });
|
||||||
|
|
||||||
const prefix_version = process.env.PREFIX_VERSION;
|
const prefix_version = process.env.PREFIX_VERSION;
|
||||||
|
|
||||||
|
|
@ -54,12 +55,14 @@ async function bootstrap() {
|
||||||
|
|
||||||
useContainer(app.select(AppModule), { fallbackOnErrors: true });
|
useContainer(app.select(AppModule), { fallbackOnErrors: true });
|
||||||
|
|
||||||
|
app.useWebSocketAdapter(new SocketIoAdapter(app));
|
||||||
|
|
||||||
await app.listen(Number(process.env.APP_API_PORT));
|
await app.listen(Number(process.env.APP_API_PORT));
|
||||||
|
|
||||||
// ===== App cho WebSocket (WS hoặc WSS) =====
|
// // ===== App cho WebSocket (WS hoặc WSS) =====
|
||||||
const wsApp = await NestFactory.create(AppModule);
|
// const wsApp = await NestFactory.create(AppModule);
|
||||||
wsApp.useWebSocketAdapter(new SocketIoAdapter(wsApp));
|
// wsApp.useWebSocketAdapter(new SocketIoAdapter(wsApp));
|
||||||
await wsApp.listen(Number(process.env.APP_SOCKET_PORT));
|
// await wsApp.listen(Number(process.env.APP_SOCKET_PORT));
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ export class MessagesGateway implements OnGatewayConnection {
|
||||||
|
|
||||||
for (const event of eventsToForward) {
|
for (const event of eventsToForward) {
|
||||||
this.event.on(event, (data) => {
|
this.event.on(event, (data) => {
|
||||||
|
console.log({ event, data });
|
||||||
this.server.emit(event, data);
|
this.server.emit(event, data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue