no message
This commit is contained in:
parent
cc58301191
commit
efe1b2994e
@ -217,6 +217,7 @@ const timChatManager = globalTimChatManager;
|
||||
const PENDING_FOLLOWUP_SEND_STORAGE_KEY = "ykt_followup_pending_send";
|
||||
const pendingFollowUpSendConsumed = ref(false);
|
||||
const initialMessageListLoaded = ref(false);
|
||||
const isCallbacksInitialized = ref(false); // 标记回调是否已初始化
|
||||
|
||||
function normalizeGroupId(v) {
|
||||
const s = String(v || "").trim();
|
||||
@ -515,6 +516,9 @@ const checkLoginAndInitTIM = async () => {
|
||||
|
||||
// 初始化IM回调函数
|
||||
const initTIMCallbacks = async () => {
|
||||
// 标记回调已初始化
|
||||
isCallbacksInitialized.value = true;
|
||||
|
||||
timChatManager.setCallback("onSDKReady", () => {
|
||||
if (messageList.value.length === 0 && !isLoading.value) {
|
||||
loadMessageList();
|
||||
@ -901,13 +905,46 @@ onShow(() => {
|
||||
if (!isIMInitialized.value) {
|
||||
checkLoginAndInitTIM();
|
||||
} else if (timChatManager.tim && !timChatManager.isLoggedIn) {
|
||||
timChatManager.ensureIMConnection();
|
||||
// IM未登录,尝试重连
|
||||
timChatManager.ensureIMConnection().then(() => {
|
||||
// 重连成功后重新注册回调
|
||||
if (timChatManager.isLoggedIn && chatInfo.value.conversationID) {
|
||||
console.log("✓ 重连成功,重新注册消息监听回调");
|
||||
initTIMCallbacks();
|
||||
timChatManager.setConversationID(chatInfo.value.conversationID);
|
||||
}
|
||||
});
|
||||
} else if (
|
||||
timChatManager.tim &&
|
||||
timChatManager.isLoggedIn &&
|
||||
chatInfo.value.conversationID
|
||||
)
|
||||
) {
|
||||
// IM已登录,只需要重新设置会话ID,不重新注册回调(避免影响正在发送的消息)
|
||||
console.log("✓ 页面显示,重新设置当前会话ID");
|
||||
timChatManager.setConversationID(chatInfo.value.conversationID);
|
||||
|
||||
// 如果回调未初始化,才进行初始化
|
||||
if (!isCallbacksInitialized.value) {
|
||||
console.log("✓ 回调未初始化,进行初始化");
|
||||
initTIMCallbacks();
|
||||
}
|
||||
|
||||
// 标记会话为已读
|
||||
if (timChatManager.tim && timChatManager.isLoggedIn) {
|
||||
timChatManager.tim
|
||||
.setMessageRead({
|
||||
conversationID: chatInfo.value.conversationID,
|
||||
})
|
||||
.then(() => {
|
||||
console.log("✓ 页面显示时已标记会话为已读");
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("✗ 标记会话已读失败:", error);
|
||||
});
|
||||
}
|
||||
|
||||
startIMMonitoring(30000);
|
||||
}
|
||||
|
||||
// 监听回访任务发送事件
|
||||
uni.$on("send-followup-message", handleSendFollowUpMessage);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user