whyuzeim 1.0.18 → 1.0.20
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/cjs/CustomChatView/index.js +21 -5
- package/cjs/HighlyCustomChat/index.js +112 -60
- package/cjs/Sidebar/CustomConversationItem/index.js +18 -2
- package/es/CustomChatView/index.js +21 -5
- package/es/HighlyCustomChat/index.js +113 -61
- package/es/Sidebar/CustomConversationItem/index.js +18 -2
- package/package.json +1 -1
|
@@ -119,14 +119,30 @@ var CustomChatView = function CustomChatView(props) {
|
|
|
119
119
|
var renderLongTextMsg = function renderLongTextMsg(msg) {
|
|
120
120
|
var _userInfo$uid2;
|
|
121
121
|
// 格式化消息时间
|
|
122
|
+
// 格式化消息时间
|
|
122
123
|
var formatMessageTime = function formatMessageTime(timestamp) {
|
|
123
124
|
if (!timestamp) return '';
|
|
124
125
|
var date = new Date(timestamp);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
var now = new Date();
|
|
127
|
+
// 判断是否是同一天
|
|
128
|
+
var isToday = date.toDateString() === now.toDateString();
|
|
129
|
+
if (isToday) {
|
|
130
|
+
// 当天消息只显示时分
|
|
131
|
+
return date.toLocaleString('zh-CN', {
|
|
132
|
+
hour: '2-digit',
|
|
133
|
+
minute: '2-digit',
|
|
134
|
+
hour12: false
|
|
135
|
+
});
|
|
136
|
+
} else {
|
|
137
|
+
// 非当天消息显示月日时分
|
|
138
|
+
return date.toLocaleString('zh-CN', {
|
|
139
|
+
month: '2-digit',
|
|
140
|
+
day: '2-digit',
|
|
141
|
+
hour: '2-digit',
|
|
142
|
+
minute: '2-digit',
|
|
143
|
+
hour12: false
|
|
144
|
+
});
|
|
145
|
+
}
|
|
130
146
|
};
|
|
131
147
|
var isMySelf = (msg === null || msg === void 0 ? void 0 : msg.bySelf) === true || (msg === null || msg === void 0 ? void 0 : msg.from.toLowerCase()) === ((_userInfo$uid2 = userInfo.uid) === null || _userInfo$uid2 === void 0 ? void 0 : _userInfo$uid2.toLowerCase());
|
|
132
148
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -14,6 +14,7 @@ var _slicedToArray = require('@babel/runtime-corejs3/helpers/esm/slicedToArray')
|
|
|
14
14
|
var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
|
|
15
15
|
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
16
16
|
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
17
|
+
var _setInterval = require('@babel/runtime-corejs3/core-js-stable/set-interval');
|
|
17
18
|
var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
|
|
18
19
|
var React = require('react');
|
|
19
20
|
var agoraChatUikit = require('agora-chat-uikit');
|
|
@@ -32,29 +33,33 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
32
33
|
var _useContext = React.useContext(context.Context);
|
|
33
34
|
_useContext.http;
|
|
34
35
|
var userInfo = _useContext.userInfo;
|
|
35
|
-
var _useState = React.useState(
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
var _useState = React.useState(true),
|
|
37
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
38
|
+
loading = _useState2[0],
|
|
39
|
+
setLoading = _useState2[1]; // 新增状态用于控制加载
|
|
40
|
+
var _useState3 = React.useState({
|
|
41
|
+
headerImageURL: "",
|
|
42
|
+
conversationName: "",
|
|
38
43
|
memberCount: 0,
|
|
39
|
-
chatType:
|
|
40
|
-
conversationId:
|
|
44
|
+
chatType: "singleChat",
|
|
45
|
+
conversationId: ""
|
|
41
46
|
}),
|
|
42
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
43
|
-
headerInfo = _useState2[0],
|
|
44
|
-
setHeaderInfo = _useState2[1];
|
|
45
|
-
var _useState3 = React.useState(undefined),
|
|
46
47
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
headerInfo = _useState4[0],
|
|
49
|
+
setHeaderInfo = _useState4[1];
|
|
50
|
+
var _useState5 = React.useState(undefined),
|
|
51
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
52
|
+
currentConversation = _useState6[0],
|
|
53
|
+
setCurrentConversation = _useState6[1];
|
|
49
54
|
var renderTxtMsg = function renderTxtMsg(msg) {
|
|
50
55
|
var _userInfo$uid;
|
|
51
56
|
var isMySelf = (msg === null || msg === void 0 ? void 0 : msg.bySelf) === true || (msg === null || msg === void 0 ? void 0 : msg.from.toLowerCase()) === ((_userInfo$uid = userInfo.uid) === null || _userInfo$uid === void 0 ? void 0 : _userInfo$uid.toLowerCase());
|
|
52
57
|
return /*#__PURE__*/React.createElement(agoraChatUikit.BaseMessage, {
|
|
53
|
-
bubbleType:
|
|
58
|
+
bubbleType: "none",
|
|
54
59
|
reaction: false,
|
|
55
60
|
select: false,
|
|
56
61
|
thread: false,
|
|
57
|
-
direction: isMySelf ?
|
|
62
|
+
direction: isMySelf ? "rtl" : "ltr",
|
|
58
63
|
renderUserProfile: function renderUserProfile() {
|
|
59
64
|
return null;
|
|
60
65
|
},
|
|
@@ -72,17 +77,32 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
72
77
|
var _userInfo$uid2;
|
|
73
78
|
// 格式化消息时间
|
|
74
79
|
var formatMessageTime = function formatMessageTime(timestamp) {
|
|
75
|
-
if (!timestamp) return
|
|
80
|
+
if (!timestamp) return "";
|
|
76
81
|
var date = new Date(timestamp);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
var now = new Date();
|
|
83
|
+
// 判断是否是同一天
|
|
84
|
+
var isToday = date.toDateString() === now.toDateString();
|
|
85
|
+
if (isToday) {
|
|
86
|
+
// 当天消息只显示时分
|
|
87
|
+
return date.toLocaleString("zh-CN", {
|
|
88
|
+
hour: "2-digit",
|
|
89
|
+
minute: "2-digit",
|
|
90
|
+
hour12: false
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
// 非当天消息显示月日时分
|
|
94
|
+
return date.toLocaleString("zh-CN", {
|
|
95
|
+
month: "2-digit",
|
|
96
|
+
day: "2-digit",
|
|
97
|
+
hour: "2-digit",
|
|
98
|
+
minute: "2-digit",
|
|
99
|
+
hour12: false
|
|
100
|
+
});
|
|
101
|
+
}
|
|
82
102
|
};
|
|
83
103
|
var isMySelf = (msg === null || msg === void 0 ? void 0 : msg.bySelf) === true || (msg === null || msg === void 0 ? void 0 : msg.from.toLowerCase()) === ((_userInfo$uid2 = userInfo.uid) === null || _userInfo$uid2 === void 0 ? void 0 : _userInfo$uid2.toLowerCase());
|
|
84
104
|
return /*#__PURE__*/React.createElement("div", {
|
|
85
|
-
className: "text-[var(--im-main-fontColor)] flex flex-col gap-1 ".concat(isMySelf ?
|
|
105
|
+
className: "text-[var(--im-main-fontColor)] flex flex-col gap-1 ".concat(isMySelf ? "items-end" : "items-start")
|
|
86
106
|
}, /*#__PURE__*/React.createElement("div", {
|
|
87
107
|
style: {
|
|
88
108
|
background: isMySelf ? "var(--im-msg-bubble-color-right)" : "var(--im-msg-bubble-color-left)",
|
|
@@ -100,7 +120,7 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
100
120
|
var _renderMessage = function renderMessage(msg) {
|
|
101
121
|
if (msg.type === "txt") {
|
|
102
122
|
return renderTxtMsg(msg);
|
|
103
|
-
} else if (msg.type ===
|
|
123
|
+
} else if (msg.type === "img") {
|
|
104
124
|
return /*#__PURE__*/React.createElement(agoraChatUikit.ImageMessage, {
|
|
105
125
|
reaction: false,
|
|
106
126
|
select: false,
|
|
@@ -115,7 +135,7 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
115
135
|
},
|
|
116
136
|
imageMessage: msg
|
|
117
137
|
});
|
|
118
|
-
} else if (msg.type ===
|
|
138
|
+
} else if (msg.type === "file") {
|
|
119
139
|
return /*#__PURE__*/React.createElement(agoraChatUikit.FileMessage, {
|
|
120
140
|
bubbleStyle: {
|
|
121
141
|
background: msg.bySelf ? "var(--im-msg-bubble-color-right)" : "var(--im-msg-bubble-color-left)",
|
|
@@ -136,7 +156,7 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
136
156
|
},
|
|
137
157
|
fileMessage: msg
|
|
138
158
|
});
|
|
139
|
-
} else if (msg.type ===
|
|
159
|
+
} else if (msg.type === "video") {
|
|
140
160
|
return /*#__PURE__*/React.createElement(agoraChatUikit.VideoMessage, {
|
|
141
161
|
reaction: false,
|
|
142
162
|
select: false,
|
|
@@ -155,7 +175,8 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
155
175
|
return undefined;
|
|
156
176
|
}
|
|
157
177
|
};
|
|
158
|
-
|
|
178
|
+
// 使用 useCallback 包装 getHeaderInfo 函数
|
|
179
|
+
var getHeaderInfo = React.useCallback(function () {
|
|
159
180
|
var _context;
|
|
160
181
|
var cvs = _findInstanceProperty(_context = agoraChatUikit.rootStore.conversationStore.conversationList).call(_context, function (cvs) {
|
|
161
182
|
return cvs.conversationId === props.conversationId;
|
|
@@ -177,9 +198,9 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
177
198
|
if (cvs.conversationId == (group === null || group === void 0 ? void 0 : group.groupid) && group !== null && group !== void 0 && (_group$info = group.info) !== null && _group$info !== void 0 && _group$info.custom) {
|
|
178
199
|
var _group$info2, _customObj$headimgurl, _group$info$affiliati, _group$info3, _ref, _ref2, _group$name, _group$info4;
|
|
179
200
|
var customObj = JSON.parse(group === null || group === void 0 || (_group$info2 = group.info) === null || _group$info2 === void 0 ? void 0 : _group$info2.custom);
|
|
180
|
-
var imageurl = (_customObj$headimgurl = customObj === null || customObj === void 0 ? void 0 : customObj.headimgurl) !== null && _customObj$headimgurl !== void 0 ? _customObj$headimgurl :
|
|
201
|
+
var imageurl = (_customObj$headimgurl = customObj === null || customObj === void 0 ? void 0 : customObj.headimgurl) !== null && _customObj$headimgurl !== void 0 ? _customObj$headimgurl : "";
|
|
181
202
|
var member = (_group$info$affiliati = group === null || group === void 0 || (_group$info3 = group.info) === null || _group$info3 === void 0 ? void 0 : _group$info3.affiliations_count) !== null && _group$info$affiliati !== void 0 ? _group$info$affiliati : 0;
|
|
182
|
-
var name = (_ref = (_ref2 = (_group$name = group === null || group === void 0 ? void 0 : group.name) !== null && _group$name !== void 0 ? _group$name : group === null || group === void 0 || (_group$info4 = group.info) === null || _group$info4 === void 0 ? void 0 : _group$info4.name) !== null && _ref2 !== void 0 ? _ref2 : cvs.name) !== null && _ref !== void 0 ? _ref :
|
|
203
|
+
var name = (_ref = (_ref2 = (_group$name = group === null || group === void 0 ? void 0 : group.name) !== null && _group$name !== void 0 ? _group$name : group === null || group === void 0 || (_group$info4 = group.info) === null || _group$info4 === void 0 ? void 0 : _group$info4.name) !== null && _ref2 !== void 0 ? _ref2 : cvs.name) !== null && _ref !== void 0 ? _ref : "";
|
|
183
204
|
setHeaderInfo(function (prevState) {
|
|
184
205
|
return _objectSpread(_objectSpread({}, prevState), {}, {
|
|
185
206
|
headerImageURL: imageurl,
|
|
@@ -199,8 +220,9 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
199
220
|
agoraChatUikit.rootStore.addressStore.getUserInfo(cvs.conversationId).then(function (value) {
|
|
200
221
|
if (value) {
|
|
201
222
|
var _value$avatarurl, _value$name;
|
|
202
|
-
var imageurl = (_value$avatarurl = value === null || value === void 0 ? void 0 : value.avatarurl) !== null && _value$avatarurl !== void 0 ? _value$avatarurl :
|
|
223
|
+
var imageurl = (_value$avatarurl = value === null || value === void 0 ? void 0 : value.avatarurl) !== null && _value$avatarurl !== void 0 ? _value$avatarurl : "";
|
|
203
224
|
var name = (_value$name = value === null || value === void 0 ? void 0 : value.name) !== null && _value$name !== void 0 ? _value$name : cvs.name;
|
|
225
|
+
console.log("the user info fecthed", name, imageurl);
|
|
204
226
|
setHeaderInfo(function (prevState) {
|
|
205
227
|
return _objectSpread(_objectSpread({}, prevState), {}, {
|
|
206
228
|
headerImageURL: imageurl,
|
|
@@ -211,8 +233,8 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
211
233
|
});
|
|
212
234
|
} else {
|
|
213
235
|
var _appUsersInfo$avataru, _ref3, _appUsersInfo$name;
|
|
214
|
-
var imageurl = (_appUsersInfo$avataru = appUsersInfo === null || appUsersInfo === void 0 ? void 0 : appUsersInfo.avatarurl) !== null && _appUsersInfo$avataru !== void 0 ? _appUsersInfo$avataru :
|
|
215
|
-
var name = (_ref3 = (_appUsersInfo$name = appUsersInfo === null || appUsersInfo === void 0 ? void 0 : appUsersInfo.name) !== null && _appUsersInfo$name !== void 0 ? _appUsersInfo$name : cvs.name) !== null && _ref3 !== void 0 ? _ref3 :
|
|
236
|
+
var imageurl = (_appUsersInfo$avataru = appUsersInfo === null || appUsersInfo === void 0 ? void 0 : appUsersInfo.avatarurl) !== null && _appUsersInfo$avataru !== void 0 ? _appUsersInfo$avataru : "";
|
|
237
|
+
var name = (_ref3 = (_appUsersInfo$name = appUsersInfo === null || appUsersInfo === void 0 ? void 0 : appUsersInfo.name) !== null && _appUsersInfo$name !== void 0 ? _appUsersInfo$name : cvs.name) !== null && _ref3 !== void 0 ? _ref3 : "";
|
|
216
238
|
setHeaderInfo(function (prevState) {
|
|
217
239
|
return _objectSpread(_objectSpread({}, prevState), {}, {
|
|
218
240
|
headerImageURL: imageurl,
|
|
@@ -221,27 +243,7 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
221
243
|
});
|
|
222
244
|
}
|
|
223
245
|
}
|
|
224
|
-
};
|
|
225
|
-
React.useEffect(function () {
|
|
226
|
-
if (props.conversationId) {
|
|
227
|
-
var _props$chatType;
|
|
228
|
-
var chattype = (_props$chatType = props.chatType) !== null && _props$chatType !== void 0 ? _props$chatType : 'singleChat';
|
|
229
|
-
var conversation = agoraChatUikit.rootStore.conversationStore.getConversation(chattype, props.conversationId);
|
|
230
|
-
if (!conversation) {
|
|
231
|
-
var newConversation = {
|
|
232
|
-
conversationId: props.conversationId,
|
|
233
|
-
chatType: props.chatType,
|
|
234
|
-
lastMessage: {},
|
|
235
|
-
unreadCount: 0
|
|
236
|
-
};
|
|
237
|
-
agoraChatUikit.rootStore.conversationStore.addConversation(newConversation);
|
|
238
|
-
setCurrentConversation(newConversation);
|
|
239
|
-
} else {
|
|
240
|
-
setCurrentConversation(conversation);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
getHeaderInfo();
|
|
244
|
-
}, []);
|
|
246
|
+
}, [props.conversationId]);
|
|
245
247
|
var customHeader = function customHeader() {
|
|
246
248
|
return /*#__PURE__*/React.createElement("div", {
|
|
247
249
|
className: "flex h-16 items-center bg-[var(--im-main-backgroundColor)] border-b border-[var(--im-border-10)] mx-4 justify-between"
|
|
@@ -249,19 +251,66 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
249
251
|
className: "flex items-center gap-4"
|
|
250
252
|
}, /*#__PURE__*/React.createElement("img", {
|
|
251
253
|
src: headerInfo.headerImageURL,
|
|
252
|
-
className: "size-8 ".concat(headerInfo.chatType ===
|
|
254
|
+
className: "size-8 ".concat(headerInfo.chatType === "groupChat" ? "rounded-md" : "rounded-full", " bg-blue")
|
|
253
255
|
}), /*#__PURE__*/React.createElement("div", {
|
|
254
256
|
className: "flex flex-col overflow-hidden flex-1"
|
|
255
257
|
}, /*#__PURE__*/React.createElement("p", {
|
|
256
258
|
className: "text-[var(--im-main-fontColor)] text-[20px] font-bold line-clamp-1 mr-[100px]"
|
|
257
|
-
}, headerInfo.conversationName), headerInfo.chatType ===
|
|
259
|
+
}, headerInfo.conversationName), headerInfo.chatType === "groupChat" && /*#__PURE__*/React.createElement("p", {
|
|
258
260
|
style: {
|
|
259
|
-
color:
|
|
261
|
+
color: "var(--im-third-fontColor)"
|
|
260
262
|
},
|
|
261
263
|
className: "text-sm"
|
|
262
264
|
}, headerInfo.memberCount, " members"))));
|
|
263
265
|
};
|
|
264
|
-
|
|
266
|
+
// First define initConversation with useCallback
|
|
267
|
+
var initConversation = React.useCallback(function () {
|
|
268
|
+
var _props$chatType;
|
|
269
|
+
if (!props.conversationId || !agoraChatUikit.rootStore.loginState) return;
|
|
270
|
+
var chattype = (_props$chatType = props.chatType) !== null && _props$chatType !== void 0 ? _props$chatType : "singleChat";
|
|
271
|
+
var conversation = agoraChatUikit.rootStore.conversationStore.getConversation(chattype, props.conversationId);
|
|
272
|
+
if (!conversation) {
|
|
273
|
+
var newConversation = {
|
|
274
|
+
conversationId: props.conversationId,
|
|
275
|
+
chatType: props.chatType,
|
|
276
|
+
lastMessage: {},
|
|
277
|
+
unreadCount: 0
|
|
278
|
+
};
|
|
279
|
+
agoraChatUikit.rootStore.conversationStore.addConversation(newConversation);
|
|
280
|
+
setCurrentConversation(newConversation);
|
|
281
|
+
} else {
|
|
282
|
+
setCurrentConversation(conversation);
|
|
283
|
+
}
|
|
284
|
+
}, [props.conversationId, props.chatType]);
|
|
285
|
+
// 使用 useEffect 设置初始状态和定期检查登录状态
|
|
286
|
+
React.useEffect(function () {
|
|
287
|
+
console.log("useEffect running", agoraChatUikit.rootStore.loginState);
|
|
288
|
+
// 初始检查登录状态
|
|
289
|
+
var currentLoginState = agoraChatUikit.rootStore.loginState;
|
|
290
|
+
setLoading(!currentLoginState);
|
|
291
|
+
if (currentLoginState && props.conversationId) {
|
|
292
|
+
initConversation();
|
|
293
|
+
getHeaderInfo();
|
|
294
|
+
}
|
|
295
|
+
var intervalId = _setInterval(function () {
|
|
296
|
+
// 如果登录状态发生变化
|
|
297
|
+
console.log("Agora login state:", agoraChatUikit.rootStore.loginState);
|
|
298
|
+
if (agoraChatUikit.rootStore.loginState && props.conversationId) {
|
|
299
|
+
setLoading(!agoraChatUikit.rootStore.loginState);
|
|
300
|
+
clearInterval(intervalId);
|
|
301
|
+
initConversation();
|
|
302
|
+
getHeaderInfo();
|
|
303
|
+
}
|
|
304
|
+
}, 1000); // 每秒检查一次
|
|
305
|
+
// 设置定时器定期检查登录状态
|
|
306
|
+
if (agoraChatUikit.rootStore.loginState) {
|
|
307
|
+
clearInterval(intervalId);
|
|
308
|
+
}
|
|
309
|
+
// 清理函数
|
|
310
|
+
return function () {
|
|
311
|
+
clearInterval(intervalId);
|
|
312
|
+
};
|
|
313
|
+
}, [getHeaderInfo, initConversation, props.conversationId]);
|
|
265
314
|
var handleSendMessage = /*#__PURE__*/function () {
|
|
266
315
|
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(text) {
|
|
267
316
|
var txtMessage;
|
|
@@ -276,7 +325,7 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
276
325
|
case 2:
|
|
277
326
|
_context2.prev = 2;
|
|
278
327
|
txtMessage = MessageSDK.message.create({
|
|
279
|
-
type:
|
|
328
|
+
type: "txt",
|
|
280
329
|
msg: text,
|
|
281
330
|
to: props.conversationId,
|
|
282
331
|
// Need to be the user ID of the current conversation
|
|
@@ -291,7 +340,7 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
291
340
|
case 9:
|
|
292
341
|
_context2.prev = 9;
|
|
293
342
|
_context2.t0 = _context2["catch"](2);
|
|
294
|
-
console.log(
|
|
343
|
+
console.log("send txt message failed", _context2.t0);
|
|
295
344
|
case 12:
|
|
296
345
|
case "end":
|
|
297
346
|
return _context2.stop();
|
|
@@ -319,8 +368,11 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
319
368
|
};
|
|
320
369
|
}();
|
|
321
370
|
return /*#__PURE__*/React.createElement("div", {
|
|
322
|
-
className: "bg-[var(--im-main-backgroundColor)] im-agent-mid ".concat((_props$className = props.className) !== null && _props$className !== void 0 ? _props$className :
|
|
323
|
-
},
|
|
371
|
+
className: "bg-[var(--im-main-backgroundColor)] im-agent-mid ".concat((_props$className = props.className) !== null && _props$className !== void 0 ? _props$className : "", " w-full h-full overflow-hidden flex flex-col")
|
|
372
|
+
}, loading ? /*#__PURE__*/React.createElement("div", {
|
|
373
|
+
className: "flex-1 flex items-center justify-center text-gray-500"
|
|
374
|
+
}, "Loading...") // 显示加载状态
|
|
375
|
+
: /*#__PURE__*/React.createElement(React.Fragment, null, showHeader === true && customHeader(), showHeader === false && currentConversation && props.renderHeader && props.renderHeader(currentConversation), /*#__PURE__*/React.createElement(agoraChatUikit.MessageList, {
|
|
324
376
|
className: "w-full flex-1",
|
|
325
377
|
conversation: {
|
|
326
378
|
conversationId: props.conversationId,
|
|
@@ -332,7 +384,7 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
332
384
|
messageProps: _objectSpread({}, type.commonMessageProps)
|
|
333
385
|
}), !props.renderInputView && /*#__PURE__*/React.createElement(agoraChatUikit.MessageInput, _extends({
|
|
334
386
|
enabledTyping: true,
|
|
335
|
-
placeHolder:
|
|
387
|
+
placeHolder: "",
|
|
336
388
|
conversation: {
|
|
337
389
|
conversationId: props.conversationId,
|
|
338
390
|
chatType: props.chatType
|
|
@@ -342,7 +394,7 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
342
394
|
onSendMessage: function onSendMessage(msg) {
|
|
343
395
|
afterSendMsg(msg);
|
|
344
396
|
}
|
|
345
|
-
})), props.renderInputView && currentConversation && props.renderInputView(currentConversation, handleSendMessage));
|
|
397
|
+
})), props.renderInputView && currentConversation && props.renderInputView(currentConversation, handleSendMessage)));
|
|
346
398
|
};
|
|
347
399
|
|
|
348
400
|
module.exports = HighlyCustomChat;
|
|
@@ -34,6 +34,10 @@ var CustomConversationItem = function CustomConversationItem(props) {
|
|
|
34
34
|
setName = _useState4[1];
|
|
35
35
|
var _useConversationConte = agoraChatUikit.useConversationContext(),
|
|
36
36
|
setCurrentConversation = _useConversationConte.setCurrentConversation;
|
|
37
|
+
var _useState5 = React.useState(true),
|
|
38
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
39
|
+
canShow = _useState6[0],
|
|
40
|
+
setCanShow = _useState6[1];
|
|
37
41
|
var client = agoraChatUikit.useClient();
|
|
38
42
|
cvs.chatType === "groupChat" && agoraChatUikit.rootStore.addressStore.getGroupInfo(cvs.conversationId);
|
|
39
43
|
React.useEffect(function () {
|
|
@@ -61,8 +65,15 @@ var CustomConversationItem = function CustomConversationItem(props) {
|
|
|
61
65
|
var userInfo = agoraChatUikit.rootStore.addressStore.appUsersInfo[cvs.conversationId];
|
|
62
66
|
if (!userInfo || !userInfo.avatarurl || !userInfo.name) {
|
|
63
67
|
client.fetchUserInfoById([cvs.conversationId], ["nickname", "avatarurl", "mail", "phone", "gender", "sign", "birth", "ext"]).then(function (res) {
|
|
68
|
+
var _res$data$cvs$convers;
|
|
64
69
|
setAvatar(res.data[cvs.conversationId].avatarurl);
|
|
65
70
|
setName(res.data[cvs.conversationId].nickname);
|
|
71
|
+
if ((_res$data$cvs$convers = res.data[cvs.conversationId]) !== null && _res$data$cvs$convers !== void 0 && _res$data$cvs$convers.exe) {
|
|
72
|
+
var _res$data$cvs$convers2;
|
|
73
|
+
var customObj = JSON.parse((_res$data$cvs$convers2 = res.data[cvs.conversationId]) === null || _res$data$cvs$convers2 === void 0 ? void 0 : _res$data$cvs$convers2.exe);
|
|
74
|
+
// 假设有一个字段 shouldShowInList 来判断是否展示
|
|
75
|
+
setCanShow((customObj === null || customObj === void 0 ? void 0 : customObj.certification) !== 2);
|
|
76
|
+
}
|
|
66
77
|
var tempUserInfo = agoraChatUikit.rootStore.addressStore.appUsersInfo[cvs.conversationId];
|
|
67
78
|
agoraChatUikit.rootStore.addressStore.appUsersInfo[cvs.conversationId] = _objectSpread(_objectSpread({}, tempUserInfo || {}), {}, {
|
|
68
79
|
userId: cvs.conversationId,
|
|
@@ -73,10 +84,15 @@ var CustomConversationItem = function CustomConversationItem(props) {
|
|
|
73
84
|
} else {
|
|
74
85
|
setAvatar(userInfo.avatarurl);
|
|
75
86
|
setName(userInfo.name);
|
|
87
|
+
if (userInfo !== null && userInfo !== void 0 && userInfo.exe) {
|
|
88
|
+
var customObj = JSON.parse(userInfo.exe);
|
|
89
|
+
// 假设有一个字段 shouldShowInList 来判断是否展示
|
|
90
|
+
setCanShow((customObj === null || customObj === void 0 ? void 0 : customObj.certification) !== 2);
|
|
91
|
+
}
|
|
76
92
|
}
|
|
77
93
|
}
|
|
78
94
|
}, [client, cvs, cvs.chatType, cvs.conversationId, http]);
|
|
79
|
-
return /*#__PURE__*/React.createElement(agoraChatUikit.ConversationItem, {
|
|
95
|
+
return canShow ? /*#__PURE__*/React.createElement(agoraChatUikit.ConversationItem, {
|
|
80
96
|
className: "yuze-conversationItem",
|
|
81
97
|
avatar: /*#__PURE__*/React.createElement("div", {
|
|
82
98
|
className: "yuze-conversationItem-avatar relative"
|
|
@@ -105,7 +121,7 @@ var CustomConversationItem = function CustomConversationItem(props) {
|
|
|
105
121
|
_onClick && _onClick();
|
|
106
122
|
setCurrentConversation(_objectSpread({}, cvs));
|
|
107
123
|
}
|
|
108
|
-
});
|
|
124
|
+
}) : null;
|
|
109
125
|
};
|
|
110
126
|
|
|
111
127
|
module.exports = CustomConversationItem;
|
|
@@ -117,14 +117,30 @@ var CustomChatView = function CustomChatView(props) {
|
|
|
117
117
|
var renderLongTextMsg = function renderLongTextMsg(msg) {
|
|
118
118
|
var _userInfo$uid2;
|
|
119
119
|
// 格式化消息时间
|
|
120
|
+
// 格式化消息时间
|
|
120
121
|
var formatMessageTime = function formatMessageTime(timestamp) {
|
|
121
122
|
if (!timestamp) return '';
|
|
122
123
|
var date = new Date(timestamp);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
var now = new Date();
|
|
125
|
+
// 判断是否是同一天
|
|
126
|
+
var isToday = date.toDateString() === now.toDateString();
|
|
127
|
+
if (isToday) {
|
|
128
|
+
// 当天消息只显示时分
|
|
129
|
+
return date.toLocaleString('zh-CN', {
|
|
130
|
+
hour: '2-digit',
|
|
131
|
+
minute: '2-digit',
|
|
132
|
+
hour12: false
|
|
133
|
+
});
|
|
134
|
+
} else {
|
|
135
|
+
// 非当天消息显示月日时分
|
|
136
|
+
return date.toLocaleString('zh-CN', {
|
|
137
|
+
month: '2-digit',
|
|
138
|
+
day: '2-digit',
|
|
139
|
+
hour: '2-digit',
|
|
140
|
+
minute: '2-digit',
|
|
141
|
+
hour12: false
|
|
142
|
+
});
|
|
143
|
+
}
|
|
128
144
|
};
|
|
129
145
|
var isMySelf = (msg === null || msg === void 0 ? void 0 : msg.bySelf) === true || (msg === null || msg === void 0 ? void 0 : msg.from.toLowerCase()) === ((_userInfo$uid2 = userInfo.uid) === null || _userInfo$uid2 === void 0 ? void 0 : _userInfo$uid2.toLowerCase());
|
|
130
146
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -12,8 +12,9 @@ import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
|
|
|
12
12
|
import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
|
|
13
13
|
import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
|
|
14
14
|
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
|
|
15
|
+
import _setInterval from '@babel/runtime-corejs3/core-js-stable/set-interval';
|
|
15
16
|
import _trimInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/trim';
|
|
16
|
-
import React, { useContext, useState, useEffect } from 'react';
|
|
17
|
+
import React, { useContext, useState, useCallback, useEffect } from 'react';
|
|
17
18
|
import { useSDK, rootStore, MessageList, MessageInput, ImageMessage, FileMessage, VideoMessage, BaseMessage } from 'agora-chat-uikit';
|
|
18
19
|
import { Context } from '../IM/context.js';
|
|
19
20
|
import { commonMessageInputConfig, commonMessageProps } from '../type.js';
|
|
@@ -30,29 +31,33 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
30
31
|
var _useContext = useContext(Context);
|
|
31
32
|
_useContext.http;
|
|
32
33
|
var userInfo = _useContext.userInfo;
|
|
33
|
-
var _useState = useState(
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
var _useState = useState(true),
|
|
35
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
36
|
+
loading = _useState2[0],
|
|
37
|
+
setLoading = _useState2[1]; // 新增状态用于控制加载
|
|
38
|
+
var _useState3 = useState({
|
|
39
|
+
headerImageURL: "",
|
|
40
|
+
conversationName: "",
|
|
36
41
|
memberCount: 0,
|
|
37
|
-
chatType:
|
|
38
|
-
conversationId:
|
|
42
|
+
chatType: "singleChat",
|
|
43
|
+
conversationId: ""
|
|
39
44
|
}),
|
|
40
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
41
|
-
headerInfo = _useState2[0],
|
|
42
|
-
setHeaderInfo = _useState2[1];
|
|
43
|
-
var _useState3 = useState(undefined),
|
|
44
45
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
headerInfo = _useState4[0],
|
|
47
|
+
setHeaderInfo = _useState4[1];
|
|
48
|
+
var _useState5 = useState(undefined),
|
|
49
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
50
|
+
currentConversation = _useState6[0],
|
|
51
|
+
setCurrentConversation = _useState6[1];
|
|
47
52
|
var renderTxtMsg = function renderTxtMsg(msg) {
|
|
48
53
|
var _userInfo$uid;
|
|
49
54
|
var isMySelf = (msg === null || msg === void 0 ? void 0 : msg.bySelf) === true || (msg === null || msg === void 0 ? void 0 : msg.from.toLowerCase()) === ((_userInfo$uid = userInfo.uid) === null || _userInfo$uid === void 0 ? void 0 : _userInfo$uid.toLowerCase());
|
|
50
55
|
return /*#__PURE__*/React.createElement(BaseMessage, {
|
|
51
|
-
bubbleType:
|
|
56
|
+
bubbleType: "none",
|
|
52
57
|
reaction: false,
|
|
53
58
|
select: false,
|
|
54
59
|
thread: false,
|
|
55
|
-
direction: isMySelf ?
|
|
60
|
+
direction: isMySelf ? "rtl" : "ltr",
|
|
56
61
|
renderUserProfile: function renderUserProfile() {
|
|
57
62
|
return null;
|
|
58
63
|
},
|
|
@@ -70,17 +75,32 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
70
75
|
var _userInfo$uid2;
|
|
71
76
|
// 格式化消息时间
|
|
72
77
|
var formatMessageTime = function formatMessageTime(timestamp) {
|
|
73
|
-
if (!timestamp) return
|
|
78
|
+
if (!timestamp) return "";
|
|
74
79
|
var date = new Date(timestamp);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
var now = new Date();
|
|
81
|
+
// 判断是否是同一天
|
|
82
|
+
var isToday = date.toDateString() === now.toDateString();
|
|
83
|
+
if (isToday) {
|
|
84
|
+
// 当天消息只显示时分
|
|
85
|
+
return date.toLocaleString("zh-CN", {
|
|
86
|
+
hour: "2-digit",
|
|
87
|
+
minute: "2-digit",
|
|
88
|
+
hour12: false
|
|
89
|
+
});
|
|
90
|
+
} else {
|
|
91
|
+
// 非当天消息显示月日时分
|
|
92
|
+
return date.toLocaleString("zh-CN", {
|
|
93
|
+
month: "2-digit",
|
|
94
|
+
day: "2-digit",
|
|
95
|
+
hour: "2-digit",
|
|
96
|
+
minute: "2-digit",
|
|
97
|
+
hour12: false
|
|
98
|
+
});
|
|
99
|
+
}
|
|
80
100
|
};
|
|
81
101
|
var isMySelf = (msg === null || msg === void 0 ? void 0 : msg.bySelf) === true || (msg === null || msg === void 0 ? void 0 : msg.from.toLowerCase()) === ((_userInfo$uid2 = userInfo.uid) === null || _userInfo$uid2 === void 0 ? void 0 : _userInfo$uid2.toLowerCase());
|
|
82
102
|
return /*#__PURE__*/React.createElement("div", {
|
|
83
|
-
className: "text-[var(--im-main-fontColor)] flex flex-col gap-1 ".concat(isMySelf ?
|
|
103
|
+
className: "text-[var(--im-main-fontColor)] flex flex-col gap-1 ".concat(isMySelf ? "items-end" : "items-start")
|
|
84
104
|
}, /*#__PURE__*/React.createElement("div", {
|
|
85
105
|
style: {
|
|
86
106
|
background: isMySelf ? "var(--im-msg-bubble-color-right)" : "var(--im-msg-bubble-color-left)",
|
|
@@ -98,7 +118,7 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
98
118
|
var _renderMessage = function renderMessage(msg) {
|
|
99
119
|
if (msg.type === "txt") {
|
|
100
120
|
return renderTxtMsg(msg);
|
|
101
|
-
} else if (msg.type ===
|
|
121
|
+
} else if (msg.type === "img") {
|
|
102
122
|
return /*#__PURE__*/React.createElement(ImageMessage, {
|
|
103
123
|
reaction: false,
|
|
104
124
|
select: false,
|
|
@@ -113,7 +133,7 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
113
133
|
},
|
|
114
134
|
imageMessage: msg
|
|
115
135
|
});
|
|
116
|
-
} else if (msg.type ===
|
|
136
|
+
} else if (msg.type === "file") {
|
|
117
137
|
return /*#__PURE__*/React.createElement(FileMessage, {
|
|
118
138
|
bubbleStyle: {
|
|
119
139
|
background: msg.bySelf ? "var(--im-msg-bubble-color-right)" : "var(--im-msg-bubble-color-left)",
|
|
@@ -134,7 +154,7 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
134
154
|
},
|
|
135
155
|
fileMessage: msg
|
|
136
156
|
});
|
|
137
|
-
} else if (msg.type ===
|
|
157
|
+
} else if (msg.type === "video") {
|
|
138
158
|
return /*#__PURE__*/React.createElement(VideoMessage, {
|
|
139
159
|
reaction: false,
|
|
140
160
|
select: false,
|
|
@@ -153,7 +173,8 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
153
173
|
return undefined;
|
|
154
174
|
}
|
|
155
175
|
};
|
|
156
|
-
|
|
176
|
+
// 使用 useCallback 包装 getHeaderInfo 函数
|
|
177
|
+
var getHeaderInfo = useCallback(function () {
|
|
157
178
|
var _context;
|
|
158
179
|
var cvs = _findInstanceProperty(_context = rootStore.conversationStore.conversationList).call(_context, function (cvs) {
|
|
159
180
|
return cvs.conversationId === props.conversationId;
|
|
@@ -175,9 +196,9 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
175
196
|
if (cvs.conversationId == (group === null || group === void 0 ? void 0 : group.groupid) && group !== null && group !== void 0 && (_group$info = group.info) !== null && _group$info !== void 0 && _group$info.custom) {
|
|
176
197
|
var _group$info2, _customObj$headimgurl, _group$info$affiliati, _group$info3, _ref, _ref2, _group$name, _group$info4;
|
|
177
198
|
var customObj = JSON.parse(group === null || group === void 0 || (_group$info2 = group.info) === null || _group$info2 === void 0 ? void 0 : _group$info2.custom);
|
|
178
|
-
var imageurl = (_customObj$headimgurl = customObj === null || customObj === void 0 ? void 0 : customObj.headimgurl) !== null && _customObj$headimgurl !== void 0 ? _customObj$headimgurl :
|
|
199
|
+
var imageurl = (_customObj$headimgurl = customObj === null || customObj === void 0 ? void 0 : customObj.headimgurl) !== null && _customObj$headimgurl !== void 0 ? _customObj$headimgurl : "";
|
|
179
200
|
var member = (_group$info$affiliati = group === null || group === void 0 || (_group$info3 = group.info) === null || _group$info3 === void 0 ? void 0 : _group$info3.affiliations_count) !== null && _group$info$affiliati !== void 0 ? _group$info$affiliati : 0;
|
|
180
|
-
var name = (_ref = (_ref2 = (_group$name = group === null || group === void 0 ? void 0 : group.name) !== null && _group$name !== void 0 ? _group$name : group === null || group === void 0 || (_group$info4 = group.info) === null || _group$info4 === void 0 ? void 0 : _group$info4.name) !== null && _ref2 !== void 0 ? _ref2 : cvs.name) !== null && _ref !== void 0 ? _ref :
|
|
201
|
+
var name = (_ref = (_ref2 = (_group$name = group === null || group === void 0 ? void 0 : group.name) !== null && _group$name !== void 0 ? _group$name : group === null || group === void 0 || (_group$info4 = group.info) === null || _group$info4 === void 0 ? void 0 : _group$info4.name) !== null && _ref2 !== void 0 ? _ref2 : cvs.name) !== null && _ref !== void 0 ? _ref : "";
|
|
181
202
|
setHeaderInfo(function (prevState) {
|
|
182
203
|
return _objectSpread(_objectSpread({}, prevState), {}, {
|
|
183
204
|
headerImageURL: imageurl,
|
|
@@ -197,8 +218,9 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
197
218
|
rootStore.addressStore.getUserInfo(cvs.conversationId).then(function (value) {
|
|
198
219
|
if (value) {
|
|
199
220
|
var _value$avatarurl, _value$name;
|
|
200
|
-
var imageurl = (_value$avatarurl = value === null || value === void 0 ? void 0 : value.avatarurl) !== null && _value$avatarurl !== void 0 ? _value$avatarurl :
|
|
221
|
+
var imageurl = (_value$avatarurl = value === null || value === void 0 ? void 0 : value.avatarurl) !== null && _value$avatarurl !== void 0 ? _value$avatarurl : "";
|
|
201
222
|
var name = (_value$name = value === null || value === void 0 ? void 0 : value.name) !== null && _value$name !== void 0 ? _value$name : cvs.name;
|
|
223
|
+
console.log("the user info fecthed", name, imageurl);
|
|
202
224
|
setHeaderInfo(function (prevState) {
|
|
203
225
|
return _objectSpread(_objectSpread({}, prevState), {}, {
|
|
204
226
|
headerImageURL: imageurl,
|
|
@@ -209,8 +231,8 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
209
231
|
});
|
|
210
232
|
} else {
|
|
211
233
|
var _appUsersInfo$avataru, _ref3, _appUsersInfo$name;
|
|
212
|
-
var imageurl = (_appUsersInfo$avataru = appUsersInfo === null || appUsersInfo === void 0 ? void 0 : appUsersInfo.avatarurl) !== null && _appUsersInfo$avataru !== void 0 ? _appUsersInfo$avataru :
|
|
213
|
-
var name = (_ref3 = (_appUsersInfo$name = appUsersInfo === null || appUsersInfo === void 0 ? void 0 : appUsersInfo.name) !== null && _appUsersInfo$name !== void 0 ? _appUsersInfo$name : cvs.name) !== null && _ref3 !== void 0 ? _ref3 :
|
|
234
|
+
var imageurl = (_appUsersInfo$avataru = appUsersInfo === null || appUsersInfo === void 0 ? void 0 : appUsersInfo.avatarurl) !== null && _appUsersInfo$avataru !== void 0 ? _appUsersInfo$avataru : "";
|
|
235
|
+
var name = (_ref3 = (_appUsersInfo$name = appUsersInfo === null || appUsersInfo === void 0 ? void 0 : appUsersInfo.name) !== null && _appUsersInfo$name !== void 0 ? _appUsersInfo$name : cvs.name) !== null && _ref3 !== void 0 ? _ref3 : "";
|
|
214
236
|
setHeaderInfo(function (prevState) {
|
|
215
237
|
return _objectSpread(_objectSpread({}, prevState), {}, {
|
|
216
238
|
headerImageURL: imageurl,
|
|
@@ -219,27 +241,7 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
219
241
|
});
|
|
220
242
|
}
|
|
221
243
|
}
|
|
222
|
-
};
|
|
223
|
-
useEffect(function () {
|
|
224
|
-
if (props.conversationId) {
|
|
225
|
-
var _props$chatType;
|
|
226
|
-
var chattype = (_props$chatType = props.chatType) !== null && _props$chatType !== void 0 ? _props$chatType : 'singleChat';
|
|
227
|
-
var conversation = rootStore.conversationStore.getConversation(chattype, props.conversationId);
|
|
228
|
-
if (!conversation) {
|
|
229
|
-
var newConversation = {
|
|
230
|
-
conversationId: props.conversationId,
|
|
231
|
-
chatType: props.chatType,
|
|
232
|
-
lastMessage: {},
|
|
233
|
-
unreadCount: 0
|
|
234
|
-
};
|
|
235
|
-
rootStore.conversationStore.addConversation(newConversation);
|
|
236
|
-
setCurrentConversation(newConversation);
|
|
237
|
-
} else {
|
|
238
|
-
setCurrentConversation(conversation);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
getHeaderInfo();
|
|
242
|
-
}, []);
|
|
244
|
+
}, [props.conversationId]);
|
|
243
245
|
var customHeader = function customHeader() {
|
|
244
246
|
return /*#__PURE__*/React.createElement("div", {
|
|
245
247
|
className: "flex h-16 items-center bg-[var(--im-main-backgroundColor)] border-b border-[var(--im-border-10)] mx-4 justify-between"
|
|
@@ -247,19 +249,66 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
247
249
|
className: "flex items-center gap-4"
|
|
248
250
|
}, /*#__PURE__*/React.createElement("img", {
|
|
249
251
|
src: headerInfo.headerImageURL,
|
|
250
|
-
className: "size-8 ".concat(headerInfo.chatType ===
|
|
252
|
+
className: "size-8 ".concat(headerInfo.chatType === "groupChat" ? "rounded-md" : "rounded-full", " bg-blue")
|
|
251
253
|
}), /*#__PURE__*/React.createElement("div", {
|
|
252
254
|
className: "flex flex-col overflow-hidden flex-1"
|
|
253
255
|
}, /*#__PURE__*/React.createElement("p", {
|
|
254
256
|
className: "text-[var(--im-main-fontColor)] text-[20px] font-bold line-clamp-1 mr-[100px]"
|
|
255
|
-
}, headerInfo.conversationName), headerInfo.chatType ===
|
|
257
|
+
}, headerInfo.conversationName), headerInfo.chatType === "groupChat" && /*#__PURE__*/React.createElement("p", {
|
|
256
258
|
style: {
|
|
257
|
-
color:
|
|
259
|
+
color: "var(--im-third-fontColor)"
|
|
258
260
|
},
|
|
259
261
|
className: "text-sm"
|
|
260
262
|
}, headerInfo.memberCount, " members"))));
|
|
261
263
|
};
|
|
262
|
-
|
|
264
|
+
// First define initConversation with useCallback
|
|
265
|
+
var initConversation = useCallback(function () {
|
|
266
|
+
var _props$chatType;
|
|
267
|
+
if (!props.conversationId || !rootStore.loginState) return;
|
|
268
|
+
var chattype = (_props$chatType = props.chatType) !== null && _props$chatType !== void 0 ? _props$chatType : "singleChat";
|
|
269
|
+
var conversation = rootStore.conversationStore.getConversation(chattype, props.conversationId);
|
|
270
|
+
if (!conversation) {
|
|
271
|
+
var newConversation = {
|
|
272
|
+
conversationId: props.conversationId,
|
|
273
|
+
chatType: props.chatType,
|
|
274
|
+
lastMessage: {},
|
|
275
|
+
unreadCount: 0
|
|
276
|
+
};
|
|
277
|
+
rootStore.conversationStore.addConversation(newConversation);
|
|
278
|
+
setCurrentConversation(newConversation);
|
|
279
|
+
} else {
|
|
280
|
+
setCurrentConversation(conversation);
|
|
281
|
+
}
|
|
282
|
+
}, [props.conversationId, props.chatType]);
|
|
283
|
+
// 使用 useEffect 设置初始状态和定期检查登录状态
|
|
284
|
+
useEffect(function () {
|
|
285
|
+
console.log("useEffect running", rootStore.loginState);
|
|
286
|
+
// 初始检查登录状态
|
|
287
|
+
var currentLoginState = rootStore.loginState;
|
|
288
|
+
setLoading(!currentLoginState);
|
|
289
|
+
if (currentLoginState && props.conversationId) {
|
|
290
|
+
initConversation();
|
|
291
|
+
getHeaderInfo();
|
|
292
|
+
}
|
|
293
|
+
var intervalId = _setInterval(function () {
|
|
294
|
+
// 如果登录状态发生变化
|
|
295
|
+
console.log("Agora login state:", rootStore.loginState);
|
|
296
|
+
if (rootStore.loginState && props.conversationId) {
|
|
297
|
+
setLoading(!rootStore.loginState);
|
|
298
|
+
clearInterval(intervalId);
|
|
299
|
+
initConversation();
|
|
300
|
+
getHeaderInfo();
|
|
301
|
+
}
|
|
302
|
+
}, 1000); // 每秒检查一次
|
|
303
|
+
// 设置定时器定期检查登录状态
|
|
304
|
+
if (rootStore.loginState) {
|
|
305
|
+
clearInterval(intervalId);
|
|
306
|
+
}
|
|
307
|
+
// 清理函数
|
|
308
|
+
return function () {
|
|
309
|
+
clearInterval(intervalId);
|
|
310
|
+
};
|
|
311
|
+
}, [getHeaderInfo, initConversation, props.conversationId]);
|
|
263
312
|
var handleSendMessage = /*#__PURE__*/function () {
|
|
264
313
|
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(text) {
|
|
265
314
|
var txtMessage;
|
|
@@ -274,7 +323,7 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
274
323
|
case 2:
|
|
275
324
|
_context2.prev = 2;
|
|
276
325
|
txtMessage = MessageSDK.message.create({
|
|
277
|
-
type:
|
|
326
|
+
type: "txt",
|
|
278
327
|
msg: text,
|
|
279
328
|
to: props.conversationId,
|
|
280
329
|
// Need to be the user ID of the current conversation
|
|
@@ -289,7 +338,7 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
289
338
|
case 9:
|
|
290
339
|
_context2.prev = 9;
|
|
291
340
|
_context2.t0 = _context2["catch"](2);
|
|
292
|
-
console.log(
|
|
341
|
+
console.log("send txt message failed", _context2.t0);
|
|
293
342
|
case 12:
|
|
294
343
|
case "end":
|
|
295
344
|
return _context2.stop();
|
|
@@ -317,8 +366,11 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
317
366
|
};
|
|
318
367
|
}();
|
|
319
368
|
return /*#__PURE__*/React.createElement("div", {
|
|
320
|
-
className: "bg-[var(--im-main-backgroundColor)] im-agent-mid ".concat((_props$className = props.className) !== null && _props$className !== void 0 ? _props$className :
|
|
321
|
-
},
|
|
369
|
+
className: "bg-[var(--im-main-backgroundColor)] im-agent-mid ".concat((_props$className = props.className) !== null && _props$className !== void 0 ? _props$className : "", " w-full h-full overflow-hidden flex flex-col")
|
|
370
|
+
}, loading ? /*#__PURE__*/React.createElement("div", {
|
|
371
|
+
className: "flex-1 flex items-center justify-center text-gray-500"
|
|
372
|
+
}, "Loading...") // 显示加载状态
|
|
373
|
+
: /*#__PURE__*/React.createElement(React.Fragment, null, showHeader === true && customHeader(), showHeader === false && currentConversation && props.renderHeader && props.renderHeader(currentConversation), /*#__PURE__*/React.createElement(MessageList, {
|
|
322
374
|
className: "w-full flex-1",
|
|
323
375
|
conversation: {
|
|
324
376
|
conversationId: props.conversationId,
|
|
@@ -330,7 +382,7 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
330
382
|
messageProps: _objectSpread({}, commonMessageProps)
|
|
331
383
|
}), !props.renderInputView && /*#__PURE__*/React.createElement(MessageInput, _extends({
|
|
332
384
|
enabledTyping: true,
|
|
333
|
-
placeHolder:
|
|
385
|
+
placeHolder: "",
|
|
334
386
|
conversation: {
|
|
335
387
|
conversationId: props.conversationId,
|
|
336
388
|
chatType: props.chatType
|
|
@@ -340,7 +392,7 @@ var HighlyCustomChat = function HighlyCustomChat(props) {
|
|
|
340
392
|
onSendMessage: function onSendMessage(msg) {
|
|
341
393
|
afterSendMsg(msg);
|
|
342
394
|
}
|
|
343
|
-
})), props.renderInputView && currentConversation && props.renderInputView(currentConversation, handleSendMessage));
|
|
395
|
+
})), props.renderInputView && currentConversation && props.renderInputView(currentConversation, handleSendMessage)));
|
|
344
396
|
};
|
|
345
397
|
|
|
346
398
|
export { HighlyCustomChat as default };
|
|
@@ -32,6 +32,10 @@ var CustomConversationItem = function CustomConversationItem(props) {
|
|
|
32
32
|
setName = _useState4[1];
|
|
33
33
|
var _useConversationConte = useConversationContext(),
|
|
34
34
|
setCurrentConversation = _useConversationConte.setCurrentConversation;
|
|
35
|
+
var _useState5 = useState(true),
|
|
36
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
37
|
+
canShow = _useState6[0],
|
|
38
|
+
setCanShow = _useState6[1];
|
|
35
39
|
var client = useClient();
|
|
36
40
|
cvs.chatType === "groupChat" && rootStore.addressStore.getGroupInfo(cvs.conversationId);
|
|
37
41
|
useEffect(function () {
|
|
@@ -59,8 +63,15 @@ var CustomConversationItem = function CustomConversationItem(props) {
|
|
|
59
63
|
var userInfo = rootStore.addressStore.appUsersInfo[cvs.conversationId];
|
|
60
64
|
if (!userInfo || !userInfo.avatarurl || !userInfo.name) {
|
|
61
65
|
client.fetchUserInfoById([cvs.conversationId], ["nickname", "avatarurl", "mail", "phone", "gender", "sign", "birth", "ext"]).then(function (res) {
|
|
66
|
+
var _res$data$cvs$convers;
|
|
62
67
|
setAvatar(res.data[cvs.conversationId].avatarurl);
|
|
63
68
|
setName(res.data[cvs.conversationId].nickname);
|
|
69
|
+
if ((_res$data$cvs$convers = res.data[cvs.conversationId]) !== null && _res$data$cvs$convers !== void 0 && _res$data$cvs$convers.exe) {
|
|
70
|
+
var _res$data$cvs$convers2;
|
|
71
|
+
var customObj = JSON.parse((_res$data$cvs$convers2 = res.data[cvs.conversationId]) === null || _res$data$cvs$convers2 === void 0 ? void 0 : _res$data$cvs$convers2.exe);
|
|
72
|
+
// 假设有一个字段 shouldShowInList 来判断是否展示
|
|
73
|
+
setCanShow((customObj === null || customObj === void 0 ? void 0 : customObj.certification) !== 2);
|
|
74
|
+
}
|
|
64
75
|
var tempUserInfo = rootStore.addressStore.appUsersInfo[cvs.conversationId];
|
|
65
76
|
rootStore.addressStore.appUsersInfo[cvs.conversationId] = _objectSpread(_objectSpread({}, tempUserInfo || {}), {}, {
|
|
66
77
|
userId: cvs.conversationId,
|
|
@@ -71,10 +82,15 @@ var CustomConversationItem = function CustomConversationItem(props) {
|
|
|
71
82
|
} else {
|
|
72
83
|
setAvatar(userInfo.avatarurl);
|
|
73
84
|
setName(userInfo.name);
|
|
85
|
+
if (userInfo !== null && userInfo !== void 0 && userInfo.exe) {
|
|
86
|
+
var customObj = JSON.parse(userInfo.exe);
|
|
87
|
+
// 假设有一个字段 shouldShowInList 来判断是否展示
|
|
88
|
+
setCanShow((customObj === null || customObj === void 0 ? void 0 : customObj.certification) !== 2);
|
|
89
|
+
}
|
|
74
90
|
}
|
|
75
91
|
}
|
|
76
92
|
}, [client, cvs, cvs.chatType, cvs.conversationId, http]);
|
|
77
|
-
return /*#__PURE__*/React.createElement(ConversationItem, {
|
|
93
|
+
return canShow ? /*#__PURE__*/React.createElement(ConversationItem, {
|
|
78
94
|
className: "yuze-conversationItem",
|
|
79
95
|
avatar: /*#__PURE__*/React.createElement("div", {
|
|
80
96
|
className: "yuze-conversationItem-avatar relative"
|
|
@@ -103,7 +119,7 @@ var CustomConversationItem = function CustomConversationItem(props) {
|
|
|
103
119
|
_onClick && _onClick();
|
|
104
120
|
setCurrentConversation(_objectSpread({}, cvs));
|
|
105
121
|
}
|
|
106
|
-
});
|
|
122
|
+
}) : null;
|
|
107
123
|
};
|
|
108
124
|
|
|
109
125
|
export { CustomConversationItem as default };
|