@droppii-org/chat-sdk 0.1.36 → 0.1.38
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 +6 -4
- package/dist/context/ChatContext.d.ts.map +1 -1
- package/dist/context/ChatContext.js +33 -6
- package/dist/hooks/common/useIsSdkMessageReady.d.ts +2 -0
- package/dist/hooks/common/useIsSdkMessageReady.d.ts.map +1 -0
- package/dist/hooks/common/useIsSdkMessageReady.js +7 -0
- package/dist/hooks/global/useGlobalEvent.d.ts.map +1 -1
- package/dist/hooks/global/useGlobalEvent.js +2 -5
- 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,+CA8EnB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -9,20 +9,22 @@ 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 { useIsSdkMessageReady } from "../../hooks/common/useIsSdkMessageReady";
|
|
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
|
|
19
|
+
const { user } = useChatContext();
|
|
20
|
+
const authUserID = useAuthStore((state) => state.userID);
|
|
21
|
+
const isSdkReady = useIsSdkMessageReady();
|
|
19
22
|
const conversation = useBizConversationStore((state) => state.conversationData);
|
|
20
23
|
const selectedConversationId = useConversationStore((state) => state.selectedConversationId);
|
|
21
24
|
const conversationId = selectedConversationId || (conversation === null || conversation === void 0 ? void 0 : conversation.conversationId) || "";
|
|
22
25
|
const isGroupChat = conversation ? isBizGroupChat(conversation) : false;
|
|
23
|
-
const isSdkReady = connectStatus === ConnectStatus.Connected;
|
|
24
26
|
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));
|
|
27
|
+
const { scrollRef, loadMoreOldMessage, handleInfiniteScroll, scrollToBottomIfAtBottom, } = useMessageListScroll(Object.assign({ conversationId, userId: (user === null || user === void 0 ? void 0 : user.userID) || authUserID }, messageController));
|
|
26
28
|
const { loadState, moreOldLoading } = messageController;
|
|
27
29
|
const isMessageLoading = !conversationId || !isSdkReady || loadState.initLoading;
|
|
28
30
|
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,4CAgGnE,CAAC"}
|
|
@@ -12,7 +12,7 @@ const queryClient = new QueryClient();
|
|
|
12
12
|
export const ChatContext = createContext({
|
|
13
13
|
user: null,
|
|
14
14
|
connectStatus: ConnectStatus.Disconnected,
|
|
15
|
-
syncStatus: SyncStatus.
|
|
15
|
+
syncStatus: SyncStatus.Loading,
|
|
16
16
|
getSelfUserInfo: () => { },
|
|
17
17
|
updateConnectStatus: () => { },
|
|
18
18
|
updateSyncStatus: () => { },
|
|
@@ -20,18 +20,39 @@ export const ChatContext = createContext({
|
|
|
20
20
|
export const useChatContext = () => useContext(ChatContext);
|
|
21
21
|
export const ChatProvider = ({ children, config }) => {
|
|
22
22
|
const [connectStatus, setConnectStatus] = useState(ConnectStatus.Disconnected);
|
|
23
|
-
const [syncStatus, setSyncStatus] = useState(SyncStatus.
|
|
23
|
+
const [syncStatus, setSyncStatus] = useState(SyncStatus.Loading);
|
|
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,12 @@ 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
|
+
});
|
|
80
|
+
setSyncStatus(SyncStatus.Loading);
|
|
54
81
|
}
|
|
55
82
|
}, [config]);
|
|
56
83
|
return (_jsx(ChatContext.Provider, { value: {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIsSdkMessageReady.d.ts","sourceRoot":"","sources":["../../../src/hooks/common/useIsSdkMessageReady.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oBAAoB,eAMhC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useChatContext } from "../../context/ChatContext";
|
|
2
|
+
import { ConnectStatus, SyncStatus } from "../../types/chat";
|
|
3
|
+
export const useIsSdkMessageReady = () => {
|
|
4
|
+
const { connectStatus, syncStatus } = useChatContext();
|
|
5
|
+
return (connectStatus === ConnectStatus.Connected &&
|
|
6
|
+
syncStatus === SyncStatus.Success);
|
|
7
|
+
};
|
|
@@ -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,YAoT1B,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,6 @@ export const useGlobalEvent = () => {
|
|
|
143
143
|
};
|
|
144
144
|
const connectSuccessHandler = () => {
|
|
145
145
|
updateConnectStatus(ConnectStatus.Connected);
|
|
146
|
-
getSelfUserInfo();
|
|
147
146
|
};
|
|
148
147
|
const connectFailedHandler = () => {
|
|
149
148
|
updateConnectStatus(ConnectStatus.Disconnected);
|
|
@@ -153,11 +152,9 @@ export const useGlobalEvent = () => {
|
|
|
153
152
|
};
|
|
154
153
|
const syncFinishHandler = () => {
|
|
155
154
|
updateSyncStatus(SyncStatus.Success);
|
|
156
|
-
|
|
157
|
-
// getGroupListByReq();
|
|
155
|
+
getSelfUserInfo();
|
|
158
156
|
getConversationListByReq(false);
|
|
159
157
|
void refreshCurrentGroupState();
|
|
160
|
-
// getUnReadCountByReq();
|
|
161
158
|
};
|
|
162
159
|
const syncFailedHandler = () => {
|
|
163
160
|
updateSyncStatus(SyncStatus.Failed);
|