index.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. <template>
  2. <div
  3. :class="{
  4. 'tui-chat': true,
  5. 'tui-chat-h5': isMobile,
  6. }"
  7. @click="onMessageListBackgroundClick"
  8. >
  9. <!-- <JoinGroupCard /> -->
  10. <div class="tui-chat-main">
  11. <div
  12. v-if="isMerchantShow"
  13. class="tui-chat-safe-tips"
  14. style="text-align: right"
  15. @click="goGroup(currentConversationID)"
  16. >
  17. 进入店铺
  18. </div>
  19. <MessageGroupApplication
  20. v-if="isGroup"
  21. :key="props.groupID"
  22. :groupID="props.groupID"
  23. />
  24. <scroll-view
  25. id="messageScrollList"
  26. class="tui-message-list"
  27. style="background: #f1f1f1"
  28. scroll-y="true"
  29. :scroll-top="scrollTop"
  30. :scroll-into-view="`tui-${historyFirstMessageID}`"
  31. @scroll="handelScrollListScroll"
  32. >
  33. <p v-if="!isCompleted" class="message-more" @click="getHistoryMessageList">
  34. {{ TUITranslateService.t("TUIChat.查看更多") }}
  35. </p>
  36. <li
  37. v-for="(item, index) in messageList"
  38. :id="`tui-${item.ID}`"
  39. :key="item.vueForRenderKey"
  40. :class="'message-li ' + item.flow"
  41. >
  42. <MessageTimestamp
  43. :currTime="item.time"
  44. :prevTime="index > 0 ? messageList[index - 1].time : 0"
  45. />
  46. <div class="message-item" @click="toggleID = ''">
  47. <MessageTip
  48. v-if="item.type === TYPES.MSG_GRP_TIP || isCreateGroupCustomMessage(item)"
  49. :content="item.getMessageContent()"
  50. />
  51. <div
  52. v-else-if="!item.isRevoked && !isPluginMessage(item)"
  53. :id="`msg-bubble-${item.ID}`"
  54. class="message-bubble-container"
  55. @longpress="handleToggleMessageItem($event, item, index, true)"
  56. @touchstart="handleH5LongPress($event, item, index, 'touchstart')"
  57. @touchend="handleH5LongPress($event, item, index, 'touchend')"
  58. @mouseover="handleH5LongPress($event, item, index, 'touchend')"
  59. >
  60. <MessageBubble
  61. :messageItem="item"
  62. :content="item.getMessageContent()"
  63. :isAudioPlayed="audioPlayedMapping[item.ID]"
  64. :blinkMessageIDList="blinkMessageIDList"
  65. :isMultipleSelectMode="isMultipleSelectMode"
  66. :multipleSelectedMessageIDList="multipleSelectedMessageIDList"
  67. @resendMessage="resendMessage(item)"
  68. @blinkMessage="blinkMessage"
  69. @scrollTo="scrollTo"
  70. @changeSelectMessageIDList="changeSelectMessageIDList"
  71. @setReadReceiptPanelVisible="setReadReceiptPanelVisible"
  72. >
  73. <MessageText
  74. v-if="item.type === TYPES.MSG_TEXT"
  75. :content="item.getMessageContent()"
  76. />
  77. <ProgressMessage
  78. v-else-if="item.type === TYPES.MSG_IMAGE"
  79. :content="item.getMessageContent()"
  80. :messageItem="item"
  81. >
  82. <MessageImage
  83. :content="item.getMessageContent()"
  84. :messageItem="item"
  85. @previewImage="handleImagePreview(index)"
  86. />
  87. </ProgressMessage>
  88. <ProgressMessage
  89. v-else-if="item.type === TYPES.MSG_VIDEO"
  90. :content="item.getMessageContent()"
  91. :messageItem="item"
  92. >
  93. <MessageVideo :content="item.getMessageContent()" :messageItem="item" />
  94. </ProgressMessage>
  95. <MessageAudio
  96. v-else-if="item.type === TYPES.MSG_AUDIO"
  97. :content="item.getMessageContent()"
  98. :messageItem="item"
  99. :broadcastNewAudioSrc="broadcastNewAudioSrc"
  100. @setAudioPlayed="setAudioPlayed"
  101. @getGlobalAudioContext="getGlobalAudioContext"
  102. />
  103. <MessageRecord
  104. v-else-if="item.type === TYPES.MSG_MERGER"
  105. :renderData="item.payload"
  106. :messageItem="item"
  107. @assignMessageIDInUniapp="assignMessageIDInUniapp"
  108. />
  109. <MessageFile
  110. v-else-if="item.type === TYPES.MSG_FILE"
  111. :content="item.getMessageContent()"
  112. />
  113. <MessageFace
  114. v-else-if="item.type === TYPES.MSG_FACE"
  115. :content="item.getMessageContent()"
  116. />
  117. <MessageLocation
  118. v-else-if="item.type === TYPES.MSG_LOCATION"
  119. :content="item.getMessageContent()"
  120. />
  121. <MessageCustom
  122. class="MessageCustom"
  123. v-else-if="item.payload.data"
  124. :content="item.getMessageContent()"
  125. :messageItem="item"
  126. />
  127. </MessageBubble>
  128. </div>
  129. <MessagePlugin
  130. v-else-if="!item.isRevoked && isPluginMessage(item)"
  131. :message="item"
  132. @resendMessage="resendMessage"
  133. @handleToggleMessageItem="handleToggleMessageItem"
  134. @handleH5LongPress="handleH5LongPress"
  135. />
  136. <MessageRevoked
  137. v-else
  138. :isEdit="item.type === TYPES.MSG_TEXT"
  139. :messageItem="item"
  140. @messageEdit="handleEdit(item)"
  141. />
  142. <!-- message tool -->
  143. <MessageTool
  144. v-if="item.ID === toggleID"
  145. :class="{
  146. 'message-tool': true,
  147. 'message-tool-out': item.flow === 'out',
  148. 'message-tool-in': item.flow === 'in',
  149. }"
  150. :messageItem="item"
  151. :isMultipleSelectMode="isMultipleSelectMode"
  152. @toggleMultipleSelectMode="() => emits('toggleMultipleSelectMode')"
  153. />
  154. </div>
  155. </li>
  156. </scroll-view>
  157. <!-- scroll button -->
  158. <ScrollButton
  159. ref="scrollButtonInstanceRef"
  160. @scrollToLatestMessage="scrollToLatestMessage"
  161. />
  162. <Dialog
  163. v-if="reSendDialogShow"
  164. :show="reSendDialogShow"
  165. :isH5="!isPC"
  166. :center="true"
  167. :isHeaderShow="isPC"
  168. @submit="resendMessageConfirm()"
  169. @update:show="(e) => (reSendDialogShow = e)"
  170. >
  171. <p class="delDialog-title">
  172. {{ TUITranslateService.t("TUIChat.确认重发该消息?") }}
  173. </p>
  174. </Dialog>
  175. <!-- read receipt panel -->
  176. <ReadReceiptPanel
  177. v-if="isShowReadUserStatusPanel"
  178. :message="Object.assign({}, readStatusMessage)"
  179. @setReadReceiptPanelVisible="setReadReceiptPanelVisible"
  180. />
  181. <!-- simple message list -->
  182. <Drawer
  183. :visible="isShowSimpleMessageList"
  184. :overlayColor="'transparent'"
  185. :popDirection="'right'"
  186. >
  187. <SimpleMessageList
  188. :style="{ height: '100%' }"
  189. :isMounted="isShowSimpleMessageList"
  190. :messageID="simpleMessageListRenderMessageID"
  191. @closeOverlay="isShowSimpleMessageList = false"
  192. />
  193. </Drawer>
  194. </div>
  195. </div>
  196. </template>
  197. <script lang="ts" setup>
  198. import {
  199. ref,
  200. watch,
  201. nextTick,
  202. onMounted,
  203. onUnmounted,
  204. getCurrentInstance,
  205. } from "../../../adapter-vue";
  206. import TUIChatEngine, {
  207. IMessageModel,
  208. TUIStore,
  209. StoreName,
  210. TUITranslateService,
  211. TUIChatService,
  212. } from "@tencentcloud/chat-uikit-engine";
  213. import { throttle } from "lodash";
  214. import {
  215. setInstanceMapping,
  216. getBoundingClientRect,
  217. getScrollInfo,
  218. } from "@tencentcloud/universal-api";
  219. // import { JoinGroupCard } from '@tencentcloud/call-uikit-wechat';
  220. import Link from "./link";
  221. import SimpleMessageList from "./message-elements/simple-message-list/index.vue";
  222. import MessageGroupApplication from "./message-group-application/index.vue";
  223. import MessageText from "./message-elements/message-text.vue";
  224. import MessageImage from "./message-elements/message-image.vue";
  225. import MessageAudio from "./message-elements/message-audio.vue";
  226. import MessageRecord from "./message-elements/message-record/index.vue";
  227. import MessageFile from "./message-elements/message-file.vue";
  228. import MessageFace from "./message-elements/message-face.vue";
  229. import MessageCustom from "./message-elements/message-custom.vue";
  230. import MessageTip from "./message-elements/message-tip.vue";
  231. import MessageBubble from "./message-elements/message-bubble.vue";
  232. import MessageLocation from "./message-elements/message-location.vue";
  233. import MessageTimestamp from "./message-elements/message-timestamp.vue";
  234. import MessageVideo from "./message-elements/message-video.vue";
  235. import MessageTool from "./message-tool/index.vue";
  236. import MessageRevoked from "./message-tool/message-revoked.vue";
  237. import MessagePlugin from "../../../plugins/plugin-components/message-plugin.vue";
  238. import ReadReceiptPanel from "./read-receipt-panel/index.vue";
  239. import ScrollButton from "./scroll-button/index.vue";
  240. import { isPluginMessage } from "../../../plugins/plugin-components/index";
  241. import Dialog from "../../common/Dialog/index.vue";
  242. import Drawer from "../../common/Drawer/index.vue";
  243. import { Toast, TOAST_TYPE } from "../../common/Toast/index";
  244. import ProgressMessage from "../../common/ProgressMessage/index.vue";
  245. import { isCreateGroupCustomMessage } from "../utils/utils";
  246. import { isEnabledMessageReadReceiptGlobal } from "../utils/utils";
  247. import { isPC, isH5, isMobile } from "../../../utils/env";
  248. import chatStorage from "../utils/chatStorage";
  249. import { IAudioContext } from "../../../interface";
  250. import { requestConfig } from "../../../../app.config";
  251. import * as mesApi from "../../../../api/message/index";
  252. interface IEmits {
  253. (e: "closeInputToolBar"): void;
  254. (e: "handleEditor", message: IMessageModel, type: string): void;
  255. (key: "toggleMultipleSelectMode"): void;
  256. }
  257. interface IProps {
  258. isGroup: boolean;
  259. groupID: string;
  260. isNotInGroup: boolean;
  261. isMultipleSelectMode: boolean;
  262. }
  263. const emits = defineEmits<IEmits>();
  264. const props = withDefaults(defineProps<IProps>(), {
  265. isGroup: false,
  266. groupID: "",
  267. isNotInGroup: false,
  268. isMultipleSelectMode: false,
  269. });
  270. let selfAddValue = 0;
  271. let observer: any = null;
  272. let groupType: string | undefined;
  273. const sentReceiptMessageID = new Set<string>();
  274. const isOfficial = TUIStore.getData(StoreName.APP, "isOfficial");
  275. const thisInstance = getCurrentInstance()?.proxy || getCurrentInstance();
  276. const messageList = ref<IMessageModel[]>();
  277. const multipleSelectedMessageIDList = ref<string[]>([]);
  278. const isCompleted = ref(false);
  279. const currentConversationID = ref("");
  280. const toggleID = ref("");
  281. const scrollTop = ref(5000); // The initial number of messages is 15, and the maximum message height is 300.
  282. const TYPES = ref(TUIChatEngine.TYPES);
  283. const isLoadingMessage = ref(false);
  284. const isLongpressing = ref(false);
  285. const blinkMessageIDList = ref<string[]>([]);
  286. const messageTarget = ref<IMessageModel>();
  287. const scrollButtonInstanceRef = ref<InstanceType<typeof ScrollButton>>();
  288. const historyFirstMessageID = ref<string>("");
  289. const isShowSimpleMessageList = ref<boolean>(false);
  290. const simpleMessageListRenderMessageID = ref<string>();
  291. const audioPlayedMapping = ref<Record<string, boolean>>({});
  292. // audio control
  293. const broadcastNewAudioSrc = ref<string>("");
  294. const readStatusMessage = ref<IMessageModel>();
  295. const isShowReadUserStatusPanel = ref<boolean>(false);
  296. // Resend Message Dialog
  297. const reSendDialogShow = ref(false);
  298. const resendMessageData = ref();
  299. const scrollToBottom = () => {
  300. scrollTop.value += 300;
  301. // Solve the issue where swiping to the bottom for the first time after packaging Uniapp into an app has a delay,
  302. // which can be set to 300 ms.
  303. const timer = setTimeout(() => {
  304. scrollTop.value += 1;
  305. clearTimeout(timer);
  306. }, 300);
  307. };
  308. const onCurrentConversationIDUpdated = (conversationID: string) => {
  309. currentConversationID.value = conversationID;
  310. if (isEnabledMessageReadReceiptGlobal()) {
  311. const { groupProfile } = TUIStore.getConversationModel(conversationID) || {};
  312. groupType = groupProfile?.type;
  313. }
  314. if (Object.keys(audioPlayedMapping.value).length > 0) {
  315. // Synchronize storage about whether the audio has been played when converstaion switched
  316. chatStorage.setChatStorage("audioPlayedMapping", audioPlayedMapping.value);
  317. }
  318. };
  319. onMounted(() => {
  320. // Retrieve the information about whether the audio has been played from localStorage
  321. audioPlayedMapping.value = chatStorage.getChatStorage("audioPlayedMapping") || {};
  322. TUIStore.watch(StoreName.CHAT, {
  323. messageList: onMessageListUpdated,
  324. messageSource: onMessageSourceUpdated,
  325. isCompleted: onChatCompletedUpdated,
  326. });
  327. TUIStore.watch(StoreName.CONV, {
  328. currentConversationID: onCurrentConversationIDUpdated,
  329. });
  330. setInstanceMapping("messageList", thisInstance);
  331. uni.$on("scroll-to-bottom", scrollToLatestMessage);
  332. isMerchant();
  333. });
  334. const goGroup = async () => {
  335. let id = currentConversationID.value.slice(3);
  336. let res = await mesApi.default.getByOwnerId(id);
  337. console.log("123123", res);
  338. if (res.code == 200) {
  339. webUni.webView.navigateTo({
  340. url: `/subpages/my/product-orders/in-store-look?shopId=` + res.data.id,
  341. });
  342. }
  343. };
  344. const isMerchantShow = ref(false);
  345. const isMerchant = async () => {
  346. if (currentConversationID.value.includes("GROUP")) {
  347. isMerchantShow.value = false;
  348. } else {
  349. let id = currentConversationID.value.slice(3);
  350. let res = await mesApi.default.getUserInfo(id);
  351. if (res.data.userTypes.includes("2")) {
  352. isMerchantShow.value = true;
  353. } else {
  354. isMerchantShow.value = false;
  355. }
  356. }
  357. console.log("xxxxx");
  358. };
  359. onUnmounted(() => {
  360. TUIStore.unwatch(StoreName.CHAT, {
  361. messageList: onMessageListUpdated,
  362. isCompleted: onChatCompletedUpdated,
  363. });
  364. TUIStore.unwatch(StoreName.CONV, {
  365. currentConversationID: onCurrentConversationIDUpdated,
  366. });
  367. observer?.disconnect();
  368. observer = null;
  369. uni.$off("scroll-to-bottom");
  370. if (Object.keys(audioPlayedMapping.value).length > 0) {
  371. // Synchronize storage about whether the audio has been played when the component is unmounted
  372. chatStorage.setChatStorage("audioPlayedMapping", audioPlayedMapping.value);
  373. }
  374. });
  375. const handelScrollListScroll = throttle(
  376. function (e: Event) {
  377. scrollButtonInstanceRef.value?.judgeScrollOverOneScreen(e);
  378. },
  379. 500,
  380. { leading: true }
  381. );
  382. function getGlobalAudioContext(
  383. audioMap: Map<string, IAudioContext>,
  384. options?: { newAudioSrc: string }
  385. ) {
  386. if (options?.newAudioSrc) {
  387. broadcastNewAudioSrc.value = options.newAudioSrc;
  388. }
  389. }
  390. async function onMessageListUpdated(list: IMessageModel[]) {
  391. observer?.disconnect();
  392. messageList.value = list
  393. .filter((message) => !message.isDeleted)
  394. .map((message) => {
  395. message.vueForRenderKey = `${message.ID}`;
  396. return message;
  397. });
  398. const newLastMessage = messageList.value?.[messageList.value?.length - 1];
  399. if (messageTarget.value) {
  400. // scroll to target message
  401. scrollAndBlinkMessage(messageTarget.value);
  402. } else if (
  403. !isLoadingMessage.value &&
  404. !(
  405. scrollButtonInstanceRef.value?.isScrollButtonVisible &&
  406. newLastMessage?.flow === "in"
  407. )
  408. ) {
  409. // scroll to bottom
  410. nextTick(() => {
  411. scrollToBottom();
  412. });
  413. }
  414. if (isEnabledMessageReadReceiptGlobal()) {
  415. nextTick(() => bindIntersectionObserver());
  416. }
  417. }
  418. async function scrollToLatestMessage() {
  419. try {
  420. const { scrollHeight } = await getScrollInfo("#messageScrollList", "messageList");
  421. if (scrollHeight) {
  422. scrollTop.value === scrollHeight
  423. ? (scrollTop.value = scrollHeight + 1)
  424. : (scrollTop.value = scrollHeight);
  425. } else {
  426. scrollToBottom();
  427. }
  428. } catch (error) {
  429. scrollToBottom();
  430. }
  431. }
  432. async function onMessageSourceUpdated(message: IMessageModel) {
  433. messageTarget.value = message;
  434. scrollAndBlinkMessage(messageTarget.value);
  435. }
  436. function scrollAndBlinkMessage(message: IMessageModel) {
  437. if (messageList.value?.some((messageListItem) => messageListItem?.ID === message?.ID)) {
  438. nextTick(async () => {
  439. await scrollToTargetMessage(message);
  440. await blinkMessage(message?.ID);
  441. messageTarget.value = undefined;
  442. });
  443. }
  444. }
  445. function onChatCompletedUpdated(flag: boolean) {
  446. isCompleted.value = flag;
  447. }
  448. const getHistoryMessageList = () => {
  449. isLoadingMessage.value = true;
  450. const currentFirstMessageID = messageList.value?.[0]?.ID || "";
  451. TUIChatService.getMessageList().then(() => {
  452. nextTick(() => {
  453. historyFirstMessageID.value = currentFirstMessageID;
  454. const timer = setTimeout(() => {
  455. historyFirstMessageID.value = "";
  456. isLoadingMessage.value = false;
  457. clearTimeout(timer);
  458. }, 500);
  459. });
  460. });
  461. };
  462. const openComplaintLink = () => {};
  463. // toggle message
  464. const handleToggleMessageItem = (
  465. e: any,
  466. message: IMessageModel,
  467. index: number,
  468. isLongpress = false
  469. ) => {
  470. if (props.isMultipleSelectMode || props.isNotInGroup) {
  471. return;
  472. }
  473. if (isLongpress) {
  474. isLongpressing.value = true;
  475. }
  476. toggleID.value = message.ID;
  477. };
  478. // h5 long press
  479. let timer: number;
  480. const handleH5LongPress = (
  481. e: any,
  482. message: IMessageModel,
  483. index: number,
  484. type: string
  485. ) => {
  486. if (props.isMultipleSelectMode || props.isNotInGroup) {
  487. return;
  488. }
  489. if (!isH5) return;
  490. function longPressHandler() {
  491. clearTimeout(timer);
  492. handleToggleMessageItem(e, message, index, true);
  493. }
  494. function touchStartHandler() {
  495. timer = setTimeout(longPressHandler, 500);
  496. }
  497. function touchEndHandler() {
  498. clearTimeout(timer);
  499. }
  500. switch (type) {
  501. case "touchstart":
  502. touchStartHandler();
  503. break;
  504. case "touchend":
  505. touchEndHandler();
  506. setTimeout(() => {
  507. isLongpressing.value = false;
  508. }, 200);
  509. break;
  510. }
  511. };
  512. // reedit message
  513. const handleEdit = (message: IMessageModel) => {
  514. emits("handleEditor", message, "reedit");
  515. };
  516. const resendMessage = (message: IMessageModel) => {
  517. reSendDialogShow.value = true;
  518. resendMessageData.value = message;
  519. };
  520. const handleImagePreview = (index: number) => {
  521. if (!messageList.value) {
  522. return;
  523. }
  524. const imageMessageIndex: number[] = [];
  525. const imageMessageList: IMessageModel[] = messageList.value.filter((item, index) => {
  526. if (!item.isRevoked && !item.hasRiskContent && item.type === TYPES.value.MSG_IMAGE) {
  527. imageMessageIndex.push(index);
  528. return true;
  529. }
  530. return false;
  531. });
  532. uni.previewImage({
  533. current: imageMessageIndex.indexOf(index),
  534. urls: imageMessageList.map((message) => message.payload.imageInfoArray?.[2].url),
  535. // #ifdef APP-PLUS
  536. indicator: "number",
  537. // #endif
  538. });
  539. };
  540. const resendMessageConfirm = () => {
  541. reSendDialogShow.value = !reSendDialogShow.value;
  542. const messageModel = resendMessageData.value;
  543. messageModel.resendMessage();
  544. };
  545. function blinkMessage(messageID: string): Promise<void> {
  546. return new Promise((resolve) => {
  547. const index = blinkMessageIDList.value.indexOf(messageID);
  548. if (index < 0) {
  549. blinkMessageIDList.value.push(messageID);
  550. const timer = setTimeout(() => {
  551. blinkMessageIDList.value.splice(blinkMessageIDList.value.indexOf(messageID), 1);
  552. clearTimeout(timer);
  553. resolve();
  554. }, 3000);
  555. }
  556. });
  557. }
  558. function scrollTo(scrollHeight: number) {
  559. scrollTop.value = scrollHeight;
  560. }
  561. async function bindIntersectionObserver() {
  562. if (!messageList.value || messageList.value.length === 0) {
  563. return;
  564. }
  565. if (
  566. groupType === TYPES.value.GRP_AVCHATROOM ||
  567. groupType === TYPES.value.GRP_COMMUNITY
  568. ) {
  569. // AVCHATROOM and COMMUNITY chats do not monitor read receipts for messages.
  570. return;
  571. }
  572. observer?.disconnect();
  573. observer = uni
  574. .createIntersectionObserver(thisInstance, {
  575. threshold: [0.7],
  576. observeAll: true,
  577. // In Uni-app, the `safetip` is also included, so a negative margin is needed to exclude it.
  578. })
  579. .relativeTo("#messageScrollList", { top: -70 });
  580. observer?.observe(".message-li.in .message-bubble-container", (res: any) => {
  581. if (sentReceiptMessageID.has(res.id)) {
  582. return;
  583. }
  584. const matchingMessage = messageList.value.find((message: IMessageModel) => {
  585. return res.id.indexOf(message.ID) > -1;
  586. });
  587. if (
  588. matchingMessage &&
  589. matchingMessage.needReadReceipt &&
  590. matchingMessage.flow === "in" &&
  591. !matchingMessage.readReceiptInfo?.isPeerRead
  592. ) {
  593. TUIChatService.sendMessageReadReceipt([matchingMessage]);
  594. sentReceiptMessageID.add(res.id);
  595. }
  596. });
  597. }
  598. function setReadReceiptPanelVisible(visible: boolean, message?: IMessageModel) {
  599. if (visible && props.isNotInGroup) {
  600. return;
  601. }
  602. if (!visible) {
  603. readStatusMessage.value = undefined;
  604. } else {
  605. readStatusMessage.value = message;
  606. }
  607. isShowReadUserStatusPanel.value = visible;
  608. }
  609. async function scrollToTargetMessage(message: IMessageModel) {
  610. const targetMessageID = message.ID;
  611. const isTargetMessageInScreen =
  612. messageList.value && messageList.value.some((msg) => msg.ID === targetMessageID);
  613. if (targetMessageID && isTargetMessageInScreen) {
  614. const timer = setTimeout(async () => {
  615. try {
  616. const scrollViewRect = await getBoundingClientRect(
  617. "#messageScrollList",
  618. "messageList"
  619. );
  620. const originalMessageRect = await getBoundingClientRect(
  621. "#tui-" + targetMessageID,
  622. "messageList"
  623. );
  624. const { scrollTop } = await getScrollInfo("#messageScrollList", "messageList");
  625. const finalScrollTop =
  626. originalMessageRect.top + scrollTop - scrollViewRect.top - (selfAddValue++ % 2);
  627. scrollTo(finalScrollTop);
  628. clearTimeout(timer);
  629. } catch (error) {
  630. // todo
  631. }
  632. }, 500);
  633. } else {
  634. Toast({
  635. message: TUITranslateService.t("TUIChat.无法定位到原消息"),
  636. type: TOAST_TYPE.WARNING,
  637. });
  638. }
  639. }
  640. function onMessageListBackgroundClick() {
  641. emits("closeInputToolBar");
  642. }
  643. watch(
  644. () => props.isMultipleSelectMode,
  645. (newValue) => {
  646. if (!newValue) {
  647. changeSelectMessageIDList({
  648. type: "clearAll",
  649. messageID: "",
  650. });
  651. }
  652. }
  653. );
  654. function changeSelectMessageIDList({
  655. type,
  656. messageID,
  657. }: {
  658. type: "add" | "remove" | "clearAll";
  659. messageID: string;
  660. }) {
  661. // TODO need to delete this
  662. if (type === "clearAll") {
  663. multipleSelectedMessageIDList.value = [];
  664. } else if (type === "add" && !multipleSelectedMessageIDList.value.includes(messageID)) {
  665. multipleSelectedMessageIDList.value.push(messageID);
  666. } else if (type === "remove") {
  667. multipleSelectedMessageIDList.value = multipleSelectedMessageIDList.value.filter(
  668. (id) => id !== messageID
  669. );
  670. }
  671. }
  672. function mergeForwardMessage() {
  673. TUIStore.update(StoreName.CUSTOM, "multipleForwardMessageID", {
  674. isMergeForward: true,
  675. messageIDList: multipleSelectedMessageIDList.value,
  676. });
  677. }
  678. function oneByOneForwardMessage() {
  679. TUIStore.update(StoreName.CUSTOM, "multipleForwardMessageID", {
  680. isMergeForward: false,
  681. messageIDList: multipleSelectedMessageIDList.value,
  682. });
  683. }
  684. function assignMessageIDInUniapp(messageID: string) {
  685. simpleMessageListRenderMessageID.value = messageID;
  686. isShowSimpleMessageList.value = true;
  687. }
  688. function setAudioPlayed(messageID: string) {
  689. audioPlayedMapping.value[messageID] = true;
  690. }
  691. defineExpose({
  692. oneByOneForwardMessage,
  693. mergeForwardMessage,
  694. scrollToLatestMessage,
  695. });
  696. </script>
  697. <style lang="scss" scoped src="./style/index.scss"></style>