@droppii-org/chat-sdk 0.6.42 → 0.6.43
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConversationPeerIdentity.d.ts","sourceRoot":"","sources":["../../../src/hooks/conversation/useConversationPeerIdentity.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"useConversationPeerIdentity.d.ts","sourceRoot":"","sources":["../../../src/hooks/conversation/useConversationPeerIdentity.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAMrE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAYhD,MAAM,WAAW,wBAAwB;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,GACtC,cAAc,gBAAgB,KAC7B,wBA2DF,CAAC"}
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
import { useEffect } from "react";
|
|
3
3
|
import { useTranslation } from "react-i18next";
|
|
4
4
|
import { DChatSDK } from "../../constants/sdk";
|
|
5
|
+
import { useChatContext } from "../../context/ChatContext";
|
|
5
6
|
import useAuthStore from "../../store/auth";
|
|
6
7
|
import useUsersInfoStore from "../../store/usersInfo";
|
|
8
|
+
import { ConnectStatus } from "../../types/chat";
|
|
7
9
|
import { PeerType } from "../../types/conversation";
|
|
8
10
|
import { isSupportSessionAgentView, resolveConversationDisplayName, resolvePeerBadgeLabel, resolveSupportSessionOwnerId, } from "../../utils/conversation";
|
|
9
11
|
import { useConversationAvatarUrl } from "./useConversationAvatarUrl";
|
|
12
|
+
// Backoff for a failed/empty owner lookup; a reconnect starts a fresh round.
|
|
13
|
+
const OWNER_FETCH_RETRY_DELAYS_MS = [2000, 5000, 10000];
|
|
10
14
|
/**
|
|
11
15
|
* Who the thread header/profile should present. A support group's
|
|
12
16
|
* showName/faceURL is the bot's, so an agent viewing someone else's session
|
|
@@ -16,20 +20,42 @@ export const useConversationPeerIdentity = (conversation) => {
|
|
|
16
20
|
var _a, _b;
|
|
17
21
|
const { t } = useTranslation("conversation-inbox");
|
|
18
22
|
const userID = useAuthStore((state) => state.userID);
|
|
23
|
+
const { connectStatus } = useChatContext();
|
|
19
24
|
const conversationAvatarUrl = useConversationAvatarUrl(conversation);
|
|
20
25
|
const ownerId = isSupportSessionAgentView(conversation, userID)
|
|
21
26
|
? resolveSupportSessionOwnerId(conversation)
|
|
22
27
|
: "";
|
|
23
28
|
const owner = useUsersInfoStore((state) => ownerId ? state.usersInfo[ownerId] : undefined);
|
|
24
29
|
useEffect(() => {
|
|
25
|
-
if (!ownerId || owner)
|
|
30
|
+
if (!ownerId || owner || connectStatus !== ConnectStatus.Connected)
|
|
26
31
|
return;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
let cancelled = false;
|
|
33
|
+
let retryTimer;
|
|
34
|
+
const fetchOwner = (attempt) => {
|
|
35
|
+
DChatSDK.getUsersInfo([ownerId])
|
|
36
|
+
.then(({ data }) => {
|
|
37
|
+
if (!(data === null || data === void 0 ? void 0 : data.length))
|
|
38
|
+
throw new Error("session owner not found");
|
|
39
|
+
if (!cancelled)
|
|
40
|
+
useUsersInfoStore.getState().upsertUsers(data);
|
|
41
|
+
})
|
|
42
|
+
.catch((error) => {
|
|
43
|
+
if (cancelled)
|
|
44
|
+
return;
|
|
45
|
+
const delay = OWNER_FETCH_RETRY_DELAYS_MS[attempt];
|
|
46
|
+
if (delay === undefined) {
|
|
47
|
+
console.error("Error fetching session owner info:", error);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
retryTimer = setTimeout(() => fetchOwner(attempt + 1), delay);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
fetchOwner(0);
|
|
54
|
+
return () => {
|
|
55
|
+
cancelled = true;
|
|
56
|
+
clearTimeout(retryTimer);
|
|
57
|
+
};
|
|
58
|
+
}, [ownerId, owner, connectStatus]);
|
|
33
59
|
if (ownerId) {
|
|
34
60
|
return {
|
|
35
61
|
displayName: ((_a = owner === null || owner === void 0 ? void 0 : owner.nickname) === null || _a === void 0 ? void 0 : _a.trim()) || t("thread_card.fallback_name"),
|