index.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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. let personId = uni.getStorageSync("personId");
  333. if (personId != "001") {
  334. isMerchant();
  335. }
  336. });
  337. const goGroup = async () => {
  338. let id = currentConversationID.value.slice(3);
  339. let res = await mesApi.default.getByOwnerId(id);
  340. console.log("123123", res);
  341. if (res.code == 200) {
  342. webUni.webView.navigateTo({
  343. url: `/subpages/my/product-orders/in-store-look?shopId=` + res.data.id,
  344. });
  345. }
  346. };
  347. const isMerchantShow = ref(false);
  348. const isMerchant = async () => {
  349. if (currentConversationID.value.includes("GROUP")) {
  350. isMerchantShow.value = false;
  351. } else {
  352. let id = currentConversationID.value.slice(3);
  353. let res = await mesApi.default.getUserInfo(id);
  354. if (res.data.userTypes.includes("2")) {
  355. isMerchantShow.value = true;
  356. } else {
  357. isMerchantShow.value = false;
  358. }
  359. }
  360. console.log("xxxxx");
  361. };
  362. onUnmounted(() => {
  363. TUIStore.unwatch(StoreName.CHAT, {
  364. messageList: onMessageListUpdated,
  365. isCompleted: onChatCompletedUpdated,
  366. });
  367. TUIStore.unwatch(StoreName.CONV, {
  368. currentConversationID: onCurrentConversationIDUpdated,
  369. });
  370. observer?.disconnect();
  371. observer = null;
  372. uni.$off("scroll-to-bottom");
  373. if (Object.keys(audioPlayedMapping.value).length > 0) {
  374. // Synchronize storage about whether the audio has been played when the component is unmounted
  375. chatStorage.setChatStorage("audioPlayedMapping", audioPlayedMapping.value);
  376. }
  377. });
  378. const handelScrollListScroll = throttle(
  379. function (e: Event) {
  380. scrollButtonInstanceRef.value?.judgeScrollOverOneScreen(e);
  381. },
  382. 500,
  383. { leading: true }
  384. );
  385. function getGlobalAudioContext(
  386. audioMap: Map<string, IAudioContext>,
  387. options?: { newAudioSrc: string }
  388. ) {
  389. if (options?.newAudioSrc) {
  390. broadcastNewAudioSrc.value = options.newAudioSrc;
  391. }
  392. }
  393. async function onMessageListUpdated(list: IMessageModel[]) {
  394. observer?.disconnect();
  395. messageList.value = list
  396. .filter((message) => !message.isDeleted)
  397. .map((message) => {
  398. message.vueForRenderKey = `${message.ID}`;
  399. return message;
  400. });
  401. const newLastMessage = messageList.value?.[messageList.value?.length - 1];
  402. if (messageTarget.value) {
  403. // scroll to target message
  404. scrollAndBlinkMessage(messageTarget.value);
  405. } else if (
  406. !isLoadingMessage.value &&
  407. !(
  408. scrollButtonInstanceRef.value?.isScrollButtonVisible &&
  409. newLastMessage?.flow === "in"
  410. )
  411. ) {
  412. // scroll to bottom
  413. nextTick(() => {
  414. scrollToBottom();
  415. });
  416. }
  417. if (isEnabledMessageReadReceiptGlobal()) {
  418. nextTick(() => bindIntersectionObserver());
  419. }
  420. }
  421. async function scrollToLatestMessage() {
  422. try {
  423. const { scrollHeight } = await getScrollInfo("#messageScrollList", "messageList");
  424. if (scrollHeight) {
  425. scrollTop.value === scrollHeight
  426. ? (scrollTop.value = scrollHeight + 1)
  427. : (scrollTop.value = scrollHeight);
  428. } else {
  429. scrollToBottom();
  430. }
  431. } catch (error) {
  432. scrollToBottom();
  433. }
  434. }
  435. async function onMessageSourceUpdated(message: IMessageModel) {
  436. messageTarget.value = message;
  437. scrollAndBlinkMessage(messageTarget.value);
  438. }
  439. function scrollAndBlinkMessage(message: IMessageModel) {
  440. if (messageList.value?.some((messageListItem) => messageListItem?.ID === message?.ID)) {
  441. nextTick(async () => {
  442. await scrollToTargetMessage(message);
  443. await blinkMessage(message?.ID);
  444. messageTarget.value = undefined;
  445. });
  446. }
  447. }
  448. function onChatCompletedUpdated(flag: boolean) {
  449. isCompleted.value = flag;
  450. }
  451. const getHistoryMessageList = () => {
  452. isLoadingMessage.value = true;
  453. const currentFirstMessageID = messageList.value?.[0]?.ID || "";
  454. TUIChatService.getMessageList().then(() => {
  455. nextTick(() => {
  456. historyFirstMessageID.value = currentFirstMessageID;
  457. const timer = setTimeout(() => {
  458. historyFirstMessageID.value = "";
  459. isLoadingMessage.value = false;
  460. clearTimeout(timer);
  461. }, 500);
  462. });
  463. });
  464. };
  465. const openComplaintLink = () => {};
  466. // toggle message
  467. const handleToggleMessageItem = (
  468. e: any,
  469. message: IMessageModel,
  470. index: number,
  471. isLongpress = false
  472. ) => {
  473. if (props.isMultipleSelectMode || props.isNotInGroup) {
  474. return;
  475. }
  476. if (isLongpress) {
  477. isLongpressing.value = true;
  478. }
  479. toggleID.value = message.ID;
  480. };
  481. // h5 long press
  482. let timer: number;
  483. const handleH5LongPress = (
  484. e: any,
  485. message: IMessageModel,
  486. index: number,
  487. type: string
  488. ) => {
  489. if (props.isMultipleSelectMode || props.isNotInGroup) {
  490. return;
  491. }
  492. if (!isH5) return;
  493. function longPressHandler() {
  494. clearTimeout(timer);
  495. handleToggleMessageItem(e, message, index, true);
  496. }
  497. function touchStartHandler() {
  498. timer = setTimeout(longPressHandler, 500);
  499. }
  500. function touchEndHandler() {
  501. clearTimeout(timer);
  502. }
  503. switch (type) {
  504. case "touchstart":
  505. touchStartHandler();
  506. break;
  507. case "touchend":
  508. touchEndHandler();
  509. setTimeout(() => {
  510. isLongpressing.value = false;
  511. }, 200);
  512. break;
  513. }
  514. };
  515. // reedit message
  516. const handleEdit = (message: IMessageModel) => {
  517. emits("handleEditor", message, "reedit");
  518. };
  519. const resendMessage = (message: IMessageModel) => {
  520. reSendDialogShow.value = true;
  521. resendMessageData.value = message;
  522. };
  523. const handleImagePreview = (index: number) => {
  524. if (!messageList.value) {
  525. return;
  526. }
  527. const imageMessageIndex: number[] = [];
  528. const imageMessageList: IMessageModel[] = messageList.value.filter((item, index) => {
  529. if (!item.isRevoked && !item.hasRiskContent && item.type === TYPES.value.MSG_IMAGE) {
  530. imageMessageIndex.push(index);
  531. return true;
  532. }
  533. return false;
  534. });
  535. uni.previewImage({
  536. current: imageMessageIndex.indexOf(index),
  537. urls: imageMessageList.map((message) => message.payload.imageInfoArray?.[2].url),
  538. // #ifdef APP-PLUS
  539. indicator: "number",
  540. // #endif
  541. });
  542. };
  543. const resendMessageConfirm = () => {
  544. reSendDialogShow.value = !reSendDialogShow.value;
  545. const messageModel = resendMessageData.value;
  546. messageModel.resendMessage();
  547. };
  548. function blinkMessage(messageID: string): Promise<void> {
  549. return new Promise((resolve) => {
  550. const index = blinkMessageIDList.value.indexOf(messageID);
  551. if (index < 0) {
  552. blinkMessageIDList.value.push(messageID);
  553. const timer = setTimeout(() => {
  554. blinkMessageIDList.value.splice(blinkMessageIDList.value.indexOf(messageID), 1);
  555. clearTimeout(timer);
  556. resolve();
  557. }, 3000);
  558. }
  559. });
  560. }
  561. function scrollTo(scrollHeight: number) {
  562. scrollTop.value = scrollHeight;
  563. }
  564. async function bindIntersectionObserver() {
  565. if (!messageList.value || messageList.value.length === 0) {
  566. return;
  567. }
  568. if (
  569. groupType === TYPES.value.GRP_AVCHATROOM ||
  570. groupType === TYPES.value.GRP_COMMUNITY
  571. ) {
  572. // AVCHATROOM and COMMUNITY chats do not monitor read receipts for messages.
  573. return;
  574. }
  575. observer?.disconnect();
  576. observer = uni
  577. .createIntersectionObserver(thisInstance, {
  578. threshold: [0.7],
  579. observeAll: true,
  580. // In Uni-app, the `safetip` is also included, so a negative margin is needed to exclude it.
  581. })
  582. .relativeTo("#messageScrollList", { top: -70 });
  583. observer?.observe(".message-li.in .message-bubble-container", (res: any) => {
  584. if (sentReceiptMessageID.has(res.id)) {
  585. return;
  586. }
  587. const matchingMessage = messageList.value.find((message: IMessageModel) => {
  588. return res.id.indexOf(message.ID) > -1;
  589. });
  590. if (
  591. matchingMessage &&
  592. matchingMessage.needReadReceipt &&
  593. matchingMessage.flow === "in" &&
  594. !matchingMessage.readReceiptInfo?.isPeerRead
  595. ) {
  596. TUIChatService.sendMessageReadReceipt([matchingMessage]);
  597. sentReceiptMessageID.add(res.id);
  598. }
  599. });
  600. }
  601. function setReadReceiptPanelVisible(visible: boolean, message?: IMessageModel) {
  602. if (visible && props.isNotInGroup) {
  603. return;
  604. }
  605. if (!visible) {
  606. readStatusMessage.value = undefined;
  607. } else {
  608. readStatusMessage.value = message;
  609. }
  610. isShowReadUserStatusPanel.value = visible;
  611. }
  612. async function scrollToTargetMessage(message: IMessageModel) {
  613. const targetMessageID = message.ID;
  614. const isTargetMessageInScreen =
  615. messageList.value && messageList.value.some((msg) => msg.ID === targetMessageID);
  616. if (targetMessageID && isTargetMessageInScreen) {
  617. const timer = setTimeout(async () => {
  618. try {
  619. const scrollViewRect = await getBoundingClientRect(
  620. "#messageScrollList",
  621. "messageList"
  622. );
  623. const originalMessageRect = await getBoundingClientRect(
  624. "#tui-" + targetMessageID,
  625. "messageList"
  626. );
  627. const { scrollTop } = await getScrollInfo("#messageScrollList", "messageList");
  628. const finalScrollTop =
  629. originalMessageRect.top + scrollTop - scrollViewRect.top - (selfAddValue++ % 2);
  630. scrollTo(finalScrollTop);
  631. clearTimeout(timer);
  632. } catch (error) {
  633. // todo
  634. }
  635. }, 500);
  636. } else {
  637. Toast({
  638. message: TUITranslateService.t("TUIChat.无法定位到原消息"),
  639. type: TOAST_TYPE.WARNING,
  640. });
  641. }
  642. }
  643. function onMessageListBackgroundClick() {
  644. emits("closeInputToolBar");
  645. }
  646. watch(
  647. () => props.isMultipleSelectMode,
  648. (newValue) => {
  649. if (!newValue) {
  650. changeSelectMessageIDList({
  651. type: "clearAll",
  652. messageID: "",
  653. });
  654. }
  655. }
  656. );
  657. function changeSelectMessageIDList({
  658. type,
  659. messageID,
  660. }: {
  661. type: "add" | "remove" | "clearAll";
  662. messageID: string;
  663. }) {
  664. // TODO need to delete this
  665. if (type === "clearAll") {
  666. multipleSelectedMessageIDList.value = [];
  667. } else if (type === "add" && !multipleSelectedMessageIDList.value.includes(messageID)) {
  668. multipleSelectedMessageIDList.value.push(messageID);
  669. } else if (type === "remove") {
  670. multipleSelectedMessageIDList.value = multipleSelectedMessageIDList.value.filter(
  671. (id) => id !== messageID
  672. );
  673. }
  674. }
  675. function mergeForwardMessage() {
  676. TUIStore.update(StoreName.CUSTOM, "multipleForwardMessageID", {
  677. isMergeForward: true,
  678. messageIDList: multipleSelectedMessageIDList.value,
  679. });
  680. }
  681. function oneByOneForwardMessage() {
  682. TUIStore.update(StoreName.CUSTOM, "multipleForwardMessageID", {
  683. isMergeForward: false,
  684. messageIDList: multipleSelectedMessageIDList.value,
  685. });
  686. }
  687. function assignMessageIDInUniapp(messageID: string) {
  688. simpleMessageListRenderMessageID.value = messageID;
  689. isShowSimpleMessageList.value = true;
  690. }
  691. function setAudioPlayed(messageID: string) {
  692. audioPlayedMapping.value[messageID] = true;
  693. }
  694. defineExpose({
  695. oneByOneForwardMessage,
  696. mergeForwardMessage,
  697. scrollToLatestMessage,
  698. });
  699. </script>
  700. <style lang="scss" scoped src="./style/index.scss"></style>