Commit 6431eaf6 by Sixong.Zhu

update

parent 1f105b96
Showing with 57 additions and 11 deletions
......@@ -8,13 +8,30 @@ const chatInfo: ChatInfo = {};
export const getChatModel = () => chatInfo;
const loadingKeys = new Set<string>();
let waitingAction = [];
export interface ChatModelInfoData {
uniplatId: string | number;
chat_id: number;
uniplat_version: number;
data: any;
}
export async function getChatModelInfo(
modelName: string,
id: string | number,
detailname?: string,
forceReload = false
) {
const key = `${modelName}-${id}`
const key = `${modelName}-${id}`;
if (loadingKeys.has(key)) {
return new Promise<ChatModelInfoData>((resolve) =>
waitingAction.push({ key, resolve })
);
}
if (chatInfo[key] && !forceReload) {
const d = chatInfo[key];
if (d.row && d.row.UniplatChatId) {
......@@ -23,23 +40,52 @@ export async function getChatModelInfo(
chat_id: +d.row.UniplatImChatId.value,
uniplat_version: 0,
data: d,
});
} as ChatModelInfoData);
}
return Promise.resolve({ uniplatId: 0, chat_id: 0, uniplat_version: 0, data: d });
return Promise.resolve({
uniplatId: 0,
chat_id: 0,
uniplat_version: 0,
data: d,
});
}
loadingKeys.add(key);
const info = await Chat.getSdk()
.model(modelName)
.detail(id + "", detailname)
.query();
const data = info;
chatInfo[key] = data;
if (info.row && info.row.UniplatChatId) {
return {
uniplatId: info.row.UniplatChatId.value,
chat_id: Number(info.row.UniplatImChatId.value),
uniplat_version: 0,
data,
};
loadingKeys.delete(key);
const o = (
info.row && info.row.UniplatChatId
? {
uniplatId: info.row.UniplatChatId.value,
chat_id: +info.row.UniplatImChatId.value,
uniplat_version: 0,
data,
}
: {
uniplatId: 0,
chat_id: 0,
uniplat_version: 0,
data,
}
) as ChatModelInfoData;
let removing = [];
for (const item of waitingAction) {
if (item.key === key) {
item.resolve(o);
removing.push(item.key);
}
}
return { uniplatId: 0, chat_id: 0, uniplat_version: 0, data, };
for (const item of removing) {
waitingAction = waitingAction.filter((i) => i.key !== item);
}
return o;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment