@droppii-org/chat-sdk 0.1.36 → 0.1.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/biz-thread-detail/BizMessageList.d.ts.map +1 -1
- package/dist/components/biz-thread-detail/BizMessageList.js +7 -4
- package/dist/context/ChatContext.d.ts.map +1 -1
- package/dist/context/ChatContext.js +30 -4
- package/dist/hooks/global/useGlobalEvent.d.ts.map +1 -1
- package/dist/hooks/global/useGlobalEvent.js +3 -5
- package/dist/hooks/message/useMessageListScroll.d.ts.map +1 -1
- package/dist/hooks/message/useMessageListScroll.js +27 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +127 -126
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BizMessageList.d.ts","sourceRoot":"","sources":["../../../src/components/biz-thread-detail/BizMessageList.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BizMessageList.d.ts","sourceRoot":"","sources":["../../../src/components/biz-thread-detail/BizMessageList.tsx"],"names":[],"mappings":"AAiBA,QAAA,MAAM,cAAc,+CAgFnB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -9,20 +9,23 @@ import { useMessage } from "../../hooks/message/useMessage";
|
|
|
9
9
|
import { useMessageListScroll } from "../../hooks/message/useMessageListScroll";
|
|
10
10
|
import useBizConversationStore from "../../store/bizConversation";
|
|
11
11
|
import useConversationStore from "../../store/conversation";
|
|
12
|
-
import
|
|
12
|
+
import useAuthStore from "../../store/auth";
|
|
13
|
+
import { ConnectStatus, SyncStatus } from "../../types/chat";
|
|
13
14
|
import { isBizGroupChat } from "../../utils/bizConversation";
|
|
14
15
|
import emitter from "../../utils/events";
|
|
15
16
|
import BizMessageItem from "./item/BizMessageItem";
|
|
16
17
|
const BizMessageList = () => {
|
|
17
18
|
const { t } = useTranslation("biz-inbox");
|
|
18
|
-
const { user, connectStatus } = useChatContext();
|
|
19
|
+
const { user, connectStatus, syncStatus } = useChatContext();
|
|
20
|
+
const authUserID = useAuthStore((state) => state.userID);
|
|
19
21
|
const conversation = useBizConversationStore((state) => state.conversationData);
|
|
20
22
|
const selectedConversationId = useConversationStore((state) => state.selectedConversationId);
|
|
21
23
|
const conversationId = selectedConversationId || (conversation === null || conversation === void 0 ? void 0 : conversation.conversationId) || "";
|
|
22
24
|
const isGroupChat = conversation ? isBizGroupChat(conversation) : false;
|
|
23
|
-
const isSdkReady = connectStatus === ConnectStatus.Connected
|
|
25
|
+
const isSdkReady = connectStatus === ConnectStatus.Connected &&
|
|
26
|
+
syncStatus !== SyncStatus.Loading;
|
|
24
27
|
const messageController = useMessage(conversationId, undefined, isSdkReady && !!conversationId);
|
|
25
|
-
const { scrollRef, loadMoreOldMessage, handleInfiniteScroll, scrollToBottomIfAtBottom, } = useMessageListScroll(Object.assign({ conversationId, userId: user === null || user === void 0 ? void 0 : user.userID }, messageController));
|
|
28
|
+
const { scrollRef, loadMoreOldMessage, handleInfiniteScroll, scrollToBottomIfAtBottom, } = useMessageListScroll(Object.assign({ conversationId, userId: (user === null || user === void 0 ? void 0 : user.userID) || authUserID }, messageController));
|
|
26
29
|
const { loadState, moreOldLoading } = messageController;
|
|
27
30
|
const isMessageLoading = !conversationId || !isSdkReady || loadState.initLoading;
|
|
28
31
|
useEffect(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatContext.d.ts","sourceRoot":"","sources":["../../src/context/ChatContext.tsx"],"names":[],"mappings":"AAEA,OAAO,sBAAsB,CAAC;AAG9B,OAAO,EACL,eAAe,EACf,iBAAiB,EAGlB,MAAM,cAAc,CAAC;AAStB,eAAO,MAAM,WAAW,0CAOtB,CAAC;AAEH,eAAO,MAAM,cAAc,uBAAgC,CAAC;AAE5D,eAAO,MAAM,YAAY,GAAI,sBAAsB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"ChatContext.d.ts","sourceRoot":"","sources":["../../src/context/ChatContext.tsx"],"names":[],"mappings":"AAEA,OAAO,sBAAsB,CAAC;AAG9B,OAAO,EACL,eAAe,EACf,iBAAiB,EAGlB,MAAM,cAAc,CAAC;AAStB,eAAO,MAAM,WAAW,0CAOtB,CAAC;AAEH,eAAO,MAAM,cAAc,uBAAgC,CAAC;AAE5D,eAAO,MAAM,YAAY,GAAI,sBAAsB,iBAAiB,4CA+FnE,CAAC"}
|
|
@@ -23,15 +23,36 @@ export const ChatProvider = ({ children, config }) => {
|
|
|
23
23
|
const [syncStatus, setSyncStatus] = useState(SyncStatus.Success);
|
|
24
24
|
const [user, setUser] = useState(null);
|
|
25
25
|
const initAuthStore = useAuthStore((state) => state.initAuthStore);
|
|
26
|
+
const setFallbackUserFromAuth = () => {
|
|
27
|
+
const { userID } = useAuthStore.getState();
|
|
28
|
+
if (!userID)
|
|
29
|
+
return;
|
|
30
|
+
setUser((current) => (current === null || current === void 0 ? void 0 : current.userID) === userID
|
|
31
|
+
? current
|
|
32
|
+
: { userID, nickname: "", faceURL: "" });
|
|
33
|
+
};
|
|
26
34
|
const getSelfUserInfo = () => {
|
|
27
35
|
DChatSDK.getSelfUserInfo()
|
|
28
36
|
.then(({ data }) => {
|
|
29
|
-
|
|
37
|
+
if (data === null || data === void 0 ? void 0 : data.userID) {
|
|
38
|
+
setUser(data);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
setFallbackUserFromAuth();
|
|
30
42
|
})
|
|
31
|
-
.catch((
|
|
32
|
-
|
|
43
|
+
.catch((error) => {
|
|
44
|
+
var _a;
|
|
45
|
+
const sdkError = error;
|
|
46
|
+
const errCode = sdkError === null || sdkError === void 0 ? void 0 : sdkError.errCode;
|
|
47
|
+
const errMsg = (_a = sdkError === null || sdkError === void 0 ? void 0 : sdkError.errMsg) !== null && _a !== void 0 ? _a : sdkError === null || sdkError === void 0 ? void 0 : sdkError.message;
|
|
48
|
+
setFallbackUserFromAuth();
|
|
49
|
+
if (errCode === 100 || errCode === 10004 || errCode === 10005)
|
|
50
|
+
return;
|
|
51
|
+
if (errCode != null || errMsg) {
|
|
52
|
+
console.error("getSelfUserInfo", errCode, errMsg);
|
|
33
53
|
return;
|
|
34
|
-
|
|
54
|
+
}
|
|
55
|
+
console.error("getSelfUserInfo", error);
|
|
35
56
|
});
|
|
36
57
|
};
|
|
37
58
|
const updateConnectStatus = (status) => {
|
|
@@ -51,6 +72,11 @@ export const ChatProvider = ({ children, config }) => {
|
|
|
51
72
|
applicationType: config.applicationType,
|
|
52
73
|
isCrm: config.isCrm,
|
|
53
74
|
});
|
|
75
|
+
setUser({
|
|
76
|
+
userID: config.userID,
|
|
77
|
+
nickname: "",
|
|
78
|
+
faceURL: "",
|
|
79
|
+
});
|
|
54
80
|
}
|
|
55
81
|
}, [config]);
|
|
56
82
|
return (_jsx(ChatContext.Provider, { value: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGlobalEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/global/useGlobalEvent.ts"],"names":[],"mappings":"AAiCA,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"useGlobalEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/global/useGlobalEvent.ts"],"names":[],"mappings":"AAiCA,eAAO,MAAM,cAAc,YAqT1B,CAAC"}
|
|
@@ -100,7 +100,6 @@ export const useGlobalEvent = () => {
|
|
|
100
100
|
var _a;
|
|
101
101
|
if (data) {
|
|
102
102
|
useAuthStore.getState().setChatToken((_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.token);
|
|
103
|
-
getSelfUserInfo();
|
|
104
103
|
}
|
|
105
104
|
},
|
|
106
105
|
});
|
|
@@ -123,6 +122,7 @@ export const useGlobalEvent = () => {
|
|
|
123
122
|
catch (error) {
|
|
124
123
|
if (error.errCode === 10102) {
|
|
125
124
|
updateConnectStatus(ConnectStatus.Connected);
|
|
125
|
+
updateSyncStatus(SyncStatus.Success);
|
|
126
126
|
getSelfUserInfo();
|
|
127
127
|
initStore();
|
|
128
128
|
return;
|
|
@@ -143,7 +143,7 @@ export const useGlobalEvent = () => {
|
|
|
143
143
|
};
|
|
144
144
|
const connectSuccessHandler = () => {
|
|
145
145
|
updateConnectStatus(ConnectStatus.Connected);
|
|
146
|
-
|
|
146
|
+
updateSyncStatus(SyncStatus.Loading);
|
|
147
147
|
};
|
|
148
148
|
const connectFailedHandler = () => {
|
|
149
149
|
updateConnectStatus(ConnectStatus.Disconnected);
|
|
@@ -153,11 +153,9 @@ export const useGlobalEvent = () => {
|
|
|
153
153
|
};
|
|
154
154
|
const syncFinishHandler = () => {
|
|
155
155
|
updateSyncStatus(SyncStatus.Success);
|
|
156
|
-
|
|
157
|
-
// getGroupListByReq();
|
|
156
|
+
getSelfUserInfo();
|
|
158
157
|
getConversationListByReq(false);
|
|
159
158
|
void refreshCurrentGroupState();
|
|
160
|
-
// getUnReadCountByReq();
|
|
161
159
|
};
|
|
162
160
|
const syncFailedHandler = () => {
|
|
163
161
|
updateSyncStatus(SyncStatus.Failed);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMessageListScroll.d.ts","sourceRoot":"","sources":["../../../src/hooks/message/useMessageListScroll.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAKtD,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,WAAW,EAAE,CAAC;CAC5B;AAED,UAAU,0BAA0B;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,oBAAoB,CAAC;IAChC,eAAe,EAAE,SAAS,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAAC;IACxD,cAAc,EAAE,OAAO,CAAC;IACxB,cAAc,EAAE,OAAO,CAAC;IACxB,kBAAkB,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAClD,kBAAkB,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACnD;AAED,eAAO,MAAM,oBAAoB,GAAI,iIASlC,0BAA0B;;;;
|
|
1
|
+
{"version":3,"file":"useMessageListScroll.d.ts","sourceRoot":"","sources":["../../../src/hooks/message/useMessageListScroll.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAKtD,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,WAAW,EAAE,CAAC;CAC5B;AAED,UAAU,0BAA0B;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,oBAAoB,CAAC;IAChC,eAAe,EAAE,SAAS,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAAC;IACxD,cAAc,EAAE,OAAO,CAAC;IACxB,cAAc,EAAE,OAAO,CAAC;IACxB,kBAAkB,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAClD,kBAAkB,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACnD;AAED,eAAO,MAAM,oBAAoB,GAAI,iIASlC,0BAA0B;;;;8BAsFrB,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC;;;CAkDpC,CAAC"}
|
|
@@ -10,6 +10,33 @@ export const useMessageListScroll = ({ conversationId, userId, loadState, latest
|
|
|
10
10
|
useEffect(() => {
|
|
11
11
|
autoFillAttemptedRef.current = false;
|
|
12
12
|
}, [conversationId]);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (!moreOldLoading) {
|
|
15
|
+
autoFillAttemptedRef.current = false;
|
|
16
|
+
}
|
|
17
|
+
}, [moreOldLoading]);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (moreOldLoading ||
|
|
20
|
+
loadState.initLoading ||
|
|
21
|
+
!loadState.hasMoreOld ||
|
|
22
|
+
loadState.messageList.length === 0) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const scrollEl = scrollRef.current;
|
|
26
|
+
if (!scrollEl || scrollEl.scrollHeight > scrollEl.clientHeight) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (autoFillAttemptedRef.current)
|
|
30
|
+
return;
|
|
31
|
+
autoFillAttemptedRef.current = true;
|
|
32
|
+
getMoreOldMessages();
|
|
33
|
+
}, [
|
|
34
|
+
moreOldLoading,
|
|
35
|
+
loadState.initLoading,
|
|
36
|
+
loadState.hasMoreOld,
|
|
37
|
+
loadState.messageList.length,
|
|
38
|
+
getMoreOldMessages,
|
|
39
|
+
]);
|
|
13
40
|
const handleMarkConversationMessageAsRead = useCallback(() => {
|
|
14
41
|
var _a, _b, _c, _d;
|
|
15
42
|
const lastMessage = (_b = (_a = latestLoadState.current) === null || _a === void 0 ? void 0 : _a.messageList) === null || _b === void 0 ? void 0 : _b[0];
|
|
@@ -39,12 +66,6 @@ export const useMessageListScroll = ({ conversationId, userId, loadState, latest
|
|
|
39
66
|
const loadMoreOldMessage = useCallback(() => {
|
|
40
67
|
if (!loadState.hasMoreOld || moreOldLoading)
|
|
41
68
|
return;
|
|
42
|
-
const scrollEl = scrollRef.current;
|
|
43
|
-
if (scrollEl && scrollEl.scrollHeight <= scrollEl.clientHeight) {
|
|
44
|
-
if (autoFillAttemptedRef.current)
|
|
45
|
-
return;
|
|
46
|
-
autoFillAttemptedRef.current = true;
|
|
47
|
-
}
|
|
48
69
|
getMoreOldMessages();
|
|
49
70
|
}, [loadState.hasMoreOld, moreOldLoading, getMoreOldMessages]);
|
|
50
71
|
const { run: loadMoreNewMessage } = useDebounceFn(() => {
|