index.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. import IComponentServer from "../IComponentServer";
  2. import { TUIChatStoreType } from "../types";
  3. import store from "@/store";
  4. /**
  5. * class TUIChatServer
  6. *
  7. * TUIChat 逻辑主体
  8. */
  9. export default class TUIChatServer extends IComponentServer {
  10. public TUICore: any;
  11. public currentStore: any = {};
  12. public store = store.state.timStore;
  13. constructor(TUICore: any) {
  14. super();
  15. this.TUICore = (uni as any).$TUIKit;
  16. this.bindTIMEvent();
  17. this.updateStore();
  18. }
  19. /**
  20. * 组件销毁
  21. */
  22. public destroyed() {
  23. this.unbindTIMEvent();
  24. }
  25. /**
  26. * 数据监听回调
  27. *
  28. * @param {any} newValue 新数据
  29. * @param {any} oldValue 旧数据
  30. *
  31. */
  32. private updateStore() {
  33. this.getMessageList({
  34. conversationID: this.store.conversationID,
  35. count: 15,
  36. });
  37. store.commit("timStore/resetChat");
  38. }
  39. /**
  40. * /////////////////////////////////////////////////////////////////////////////////
  41. * //
  42. * // TIM 事件监听注册接口
  43. * //
  44. * /////////////////////////////////////////////////////////////////////////////////
  45. */
  46. private bindTIMEvent() {
  47. this.TUICore.on(
  48. uni.$TIM.EVENT.MESSAGE_RECEIVED,
  49. this.handleMessageReceived,
  50. this
  51. );
  52. this.TUICore.on(
  53. uni.$TIM.EVENT.MESSAGE_MODIFIED,
  54. this.handleMessageModified,
  55. this
  56. );
  57. this.TUICore.on(
  58. uni.$TIM.EVENT.MESSAGE_REVOKED,
  59. this.handleMessageRevoked,
  60. this
  61. );
  62. this.TUICore.on(
  63. uni.$TIM.EVENT.MESSAGE_READ_BY_PEER,
  64. this.handleMessageReadByPeer,
  65. this
  66. );
  67. this.TUICore.on(
  68. uni.$TIM.EVENT.GROUP_LIST_UPDATED,
  69. this.handleGroupListUpdated,
  70. this
  71. );
  72. }
  73. private unbindTIMEvent() {
  74. this.TUICore.off(
  75. uni.$TIM.EVENT.MESSAGE_RECEIVED,
  76. this.handleMessageReceived
  77. );
  78. this.TUICore.off(
  79. uni.$TIM.EVENT.MESSAGE_MODIFIED,
  80. this.handleMessageModified
  81. );
  82. this.TUICore.off(uni.$TIM.EVENT.MESSAGE_REVOKED, this.handleMessageRevoked);
  83. this.TUICore.off(
  84. uni.$TIM.EVENT.MESSAGE_READ_BY_PEER,
  85. this.handleMessageReadByPeer
  86. );
  87. this.TUICore.off(
  88. uni.$TIM.EVENT.GROUP_LIST_UPDATED,
  89. this.handleGroupListUpdated,
  90. this
  91. );
  92. }
  93. private handleMessageReceived(event: any) {
  94. event.data.forEach((item) => {
  95. if (item.conversationID === this.store.conversationID) {
  96. uni.$TUIKit.TUIConversationServer.setMessageRead(item.conversationID);
  97. if(item.cloudCustomData!=null&&item.cloudCustomData!=''){
  98. console.log("收到消息")
  99. console.log(item)
  100. try{
  101. var json=JSON.parse(item.cloudCustomData);
  102. store.commit("timStore/setType",json.type);
  103. store.commit("timStore/setImType", json.imType);
  104. store.commit("timStore/setOrderId",json.orderId);
  105. store.commit("timStore/setOrderType",json.orderType);
  106. store.commit("timStore/setFollowId",json.followId);
  107. if(json.type==="finishInquiry"){
  108. store.commit("timStore/setImType", 0);
  109. uni.navigateTo({ url: "/pages_order/pingOrder?orderId="+json.orderId })
  110. }
  111. else if(json.type==="startInquiry"){
  112. }
  113. else if(json.type==="inquiry"){
  114. }
  115. else if(json.type==="startFollow"){
  116. }
  117. else if(json.type==="follow"){
  118. }
  119. else if(json.type==="finishFollow"){
  120. }
  121. else if(json.type==="startDrugReport"){
  122. }
  123. else if(json.type==="finishDrugReport"){
  124. }
  125. else if(json.type==="drugReport"){
  126. }
  127. }
  128. catch(e){
  129. }
  130. const messageList = [...this.store.messageList, item];
  131. // 更新 messageList
  132. store.commit("timStore/setMessageList", messageList);
  133. }
  134. else{
  135. const messageList = [...this.store.messageList, item];
  136. // 更新 messageList
  137. store.commit("timStore/setMessageList", messageList);
  138. }
  139. }
  140. });
  141. }
  142. private handleMessageModified(event: any) {
  143. const middleData = this.store.messageList;
  144. this.store.messageList = [];
  145. this.store.messageList = middleData;
  146. }
  147. private handleMessageRevoked(event: any) {
  148. // const middleData = this.store.messageList;
  149. // this.store.messageList = [];
  150. // this.store.messageList = middleData;
  151. }
  152. private async handleMessageReadByPeer(event: any) {
  153. // sdk message 消息引用关系会自动更新
  154. const middleData = this.store.messageList;
  155. // 兼容小程序,在小程序中 setData 是异步
  156. //await store.commit("timStore/resetChat");
  157. await store.commit("timStore/setMessageList", middleData);
  158. }
  159. private handleGroupListUpdated(event: any) {
  160. event?.data.map((item: any) => {
  161. if (item?.groupID === this?.store?.conversation?.groupProfile?.groupID) {
  162. this.store.conversation.groupProfile = item;
  163. const midden = this.store.conversation;
  164. this.store.conversation = {};
  165. this.store.conversation = midden;
  166. }
  167. return item;
  168. });
  169. }
  170. /**
  171. * /////////////////////////////////////////////////////////////////////////////////
  172. * //
  173. * // 处理 TIM 接口参数及回调
  174. * //
  175. * /////////////////////////////////////////////////////////////////////////////////
  176. */
  177. /**
  178. * 创建消息生成参数
  179. *
  180. * @param {Object} content 消息体
  181. * @param {String} type 消息类型 text: 文本类型 file: 文件类型 face: 表情 location: 地址 custom: 自定义 merger: 合并 forward: 转发
  182. * @param {Callback} callback 回调函数
  183. * @param {any} to 发送的对象
  184. * @returns {options} 消息参数
  185. */
  186. public handleMessageOptions(
  187. content: any,
  188. type: string,
  189. callback?: any,
  190. to?: any
  191. ) {
  192. var customerData={
  193. type:this.store.type,
  194. imType:this.store.imType,
  195. orderId:this.store.orderId,
  196. followId:this.store.followId,
  197. orderType:this.store.orderType
  198. }
  199. const options: any = {
  200. cloudCustomData:JSON.stringify(customerData),
  201. to: "",
  202. conversationType: to?.type || this.store.conversation.type,
  203. payload: content,
  204. needReadReceipt: true,
  205. };
  206. if (type === "file" && callback) {
  207. options.onProgress = callback;
  208. }
  209. switch (options.conversationType) {
  210. case uni.$TIM.TYPES.CONV_C2C:
  211. options.to =
  212. to?.userProfile?.userID ||
  213. this.store.conversation?.userProfile?.userID ||
  214. "";
  215. break;
  216. case uni.$TIM.TYPES.CONV_GROUP:
  217. options.to =
  218. to?.groupProfile?.groupID ||
  219. this.store.conversation?.groupProfile?.groupID ||
  220. "";
  221. break;
  222. default:
  223. break;
  224. }
  225. return options;
  226. }
  227. /**
  228. * 处理异步函数
  229. *
  230. * @param {callback} callback 回调函数
  231. * @returns {Promise} 返回异步函数
  232. */
  233. public handlePromiseCallback(callback: any) {
  234. return new Promise<void>((resolve, reject) => {
  235. // const config = {
  236. // TUIName: 'TUIChat',
  237. // callback: () => {
  238. // callback && callback(resolve, reject);
  239. // },
  240. // };
  241. // this.TUICore.setAwaitFunc(config.TUIName, config.callback);
  242. });
  243. }
  244. /**
  245. * 文件上传进度函数处理
  246. *
  247. * @param {number} progress 文件上传进度 1表示完成
  248. * @param {message} message 文件消息
  249. */
  250. public handleUploadProgress(progress: number, message: any) {
  251. this.store.messageList.map((item: any) => {
  252. if (item.ID === message.ID) {
  253. item.progress = progress;
  254. }
  255. return item;
  256. });
  257. }
  258. /**
  259. * /////////////////////////////////////////////////////////////////////////////////
  260. * //
  261. * // 对外方法
  262. * //
  263. * /////////////////////////////////////////////////////////////////////////////////
  264. */
  265. // /**
  266. // * 发送文本消息
  267. // *
  268. // * @param {any} text 发送的消息
  269. // * @returns {Promise}
  270. // */
  271. /**
  272. * 发送文本消息
  273. *
  274. * @param {any} text 发送的消息
  275. * @returns {Promise}
  276. */
  277. public sendTextMessage(text: any): Promise<any> {
  278. return new Promise<void>(async (resolve, reject) => {
  279. try {
  280. const options = this.handleMessageOptions({ text }, "text");
  281. const message = this.TUICore.createTextMessage(options);
  282. // 优化写法
  283. const messageList = [...this.store.messageList, message];
  284. store.commit("timStore/setMessageList", messageList);
  285. const imResponse = await this.TUICore.sendMessage(message);
  286. this.store.messageList = this.store.messageList.map((item: any) => {
  287. if (item.ID === imResponse.data.message.ID) {
  288. return imResponse.data.message;
  289. }
  290. return item;
  291. });
  292. resolve(imResponse);
  293. } catch (error) {
  294. reject(error);
  295. const middleData = this.store.messageList;
  296. store.commit("timStore/resetChat");
  297. store.commit("timStore/setMessageList", middleData);
  298. }
  299. });
  300. }
  301. /**
  302. * 发送表情消息
  303. *
  304. * @param {Object} data 消息内容
  305. * @param {Number} data.index 表情索引
  306. * @param {String} data.data 额外数据
  307. * @returns {Promise}
  308. */
  309. public sendFaceMessage(data: any): Promise<any> {
  310. return new Promise<void>(async (resolve, reject) => {
  311. try {
  312. const options = this.handleMessageOptions(data, "face");
  313. const message = this.TUICore.createFaceMessage(options);
  314. // this.store.messageList.push(message);
  315. // 优化写法
  316. const messageList = [...this.store.messageList, message];
  317. store.commit("timStore/setMessageList", messageList);
  318. const imResponse = await this.TUICore.sendMessage(message);
  319. this.store.messageList = this.store.messageList.map((item: any) => {
  320. if (item.ID === imResponse.data.message.ID) {
  321. return imResponse.data.message;
  322. }
  323. return item;
  324. });
  325. resolve(imResponse);
  326. } catch (error) {
  327. reject(error);
  328. }
  329. });
  330. }
  331. /**
  332. * 发送图片消息
  333. *
  334. * @param {res} res 图片文件
  335. * @param {image} 图片尺寸
  336. * @returns {Promise}
  337. */
  338. public sendImageMessage(res: any, image: any): Promise<any> {
  339. return new Promise<void>(async (resolve, reject) => {
  340. try {
  341. const options = this.handleMessageOptions({ file: res }, "file");
  342. const message = this.TUICore.createImageMessage(options);
  343. console.log(111222)
  344. console.log(options)
  345. console.log(message)
  346. // todo 上屏图片消息在发送之前没有尺寸,本地获取补充
  347. message.payload.imageInfoArray[1].height = image.height;
  348. message.payload.imageInfoArray[1].width = image.width;
  349. const messageList = [...this.store.messageList, message];
  350. store.commit("timStore/setMessageList", messageList);
  351. const imResponse = await this.TUICore.sendMessage(message);
  352. this.store.messageList = this.store.messageList.map((item: any) => {
  353. if (item.ID === imResponse.data.message.ID) {
  354. return imResponse.data.message;
  355. }
  356. return item;
  357. });
  358. resolve(imResponse);
  359. } catch (error) {
  360. reject(error);
  361. }
  362. });
  363. }
  364. /**
  365. * 发送视频消息
  366. *
  367. * @param {Video} video 图片文件
  368. * @returns {Promise}
  369. */
  370. public sendVideoMessage(res: any, video: any): Promise<any> {
  371. return new Promise<void>(async (resolve, reject) => {
  372. try {
  373. const options = this.handleMessageOptions({ file: res }, "file");
  374. const message = this.TUICore.createVideoMessage(options);
  375. // todo 上屏图片消息在发送之前没有尺寸,本地获取补充
  376. // message.payload.imageInfoArray[1].height = video.height
  377. // message.payload.imageInfoArray[1].width = video.width
  378. const messageList = [...this.store.messageList, message];
  379. store.commit("timStore/setMessageList", messageList);
  380. const imResponse = await this.TUICore.sendMessage(message);
  381. this.store.messageList = this.store.messageList.map((item: any) => {
  382. if (item.ID === imResponse.data.message.ID) {
  383. return imResponse.data.message;
  384. }
  385. return item;
  386. });
  387. resolve(imResponse);
  388. } catch (error) {
  389. reject(error);
  390. }
  391. });
  392. }
  393. /**
  394. * 发送语音消息
  395. *
  396. * @param {audio} audio 音频文件
  397. * @returns {Promise}
  398. */
  399. public sendAudioMessage(audio: any): Promise<any> {
  400. return new Promise<void>(async (resolve, reject) => {
  401. try {
  402. const options = this.handleMessageOptions(
  403. { file: audio },
  404. "file",
  405. (progress: number) => {
  406. this.handleUploadProgress(progress, message);
  407. }
  408. );
  409. const message = this.TUICore.createAudioMessage(options);
  410. // todo 上屏图片消息在发送之前没有尺寸,待优化
  411. const messageList = [...this.store.messageList, message];
  412. store.commit("timStore/setMessageList", messageList);
  413. const imResponse = await this.TUICore.sendMessage(message);
  414. console.log("发送音频消息完成", imResponse);
  415. this.store.messageList = this.store.messageList.map((item: any) => {
  416. if (item.ID === imResponse.data.message.ID) {
  417. return imResponse.data.message;
  418. }
  419. return item;
  420. });
  421. resolve(imResponse);
  422. } catch (error) {
  423. reject(error);
  424. }
  425. });
  426. }
  427. /**
  428. * 发送文件消息
  429. *
  430. * @param {File} file 文件
  431. * @returns {Promise}
  432. */
  433. public sendFileMessage(file: any): Promise<any> {
  434. return this.handlePromiseCallback(async (resolve: any, reject: any) => {
  435. try {
  436. const options = this.handleMessageOptions(
  437. { file },
  438. "file",
  439. (progress: number) => {
  440. this.handleUploadProgress(progress, message);
  441. }
  442. );
  443. const message = this.TUICore.createFileMessage(options);
  444. this.currentStore.messageList.push(message);
  445. const imResponse = await this.TUICore.sendMessage(message);
  446. console.log("发送文件消息完成", imResponse);
  447. this.store.messageList = this.store.messageList.map((item: any) => {
  448. if (item.ID === imResponse.data.message.ID) {
  449. return imResponse.data.message;
  450. }
  451. return item;
  452. });
  453. resolve(imResponse);
  454. } catch (error) {
  455. reject(error);
  456. }
  457. });
  458. }
  459. /**
  460. * 发送自定义消息
  461. *
  462. * @param {Object} data 消息内容
  463. * @param {String} data.data 自定义消息的数据字段
  464. * @param {String} data.description 自定义消息的说明字段
  465. * @param {String} data.extension 自定义消息的扩展字段
  466. * @returns {Promise}
  467. */
  468. public sendCustomMessage(data: any): Promise<any> {
  469. return new Promise<void>(async (resolve, reject) => {
  470. try {
  471. const options = this.handleMessageOptions(data, "custom");
  472. const message = this.TUICore.createCustomMessage(options);
  473. const messageList = [...this.store.messageList, message];
  474. store.commit("timStore/setMessageList", messageList);
  475. const imResponse = await this.TUICore.sendMessage(message);
  476. console.log("发送自定义消息完成", imResponse);
  477. this.store.messageList = this.store.messageList.map((item: any) => {
  478. if (item.ID === imResponse.data.message.ID) {
  479. return imResponse.data.message;
  480. }
  481. return item;
  482. });
  483. resolve(imResponse);
  484. } catch (error) {
  485. reject(error);
  486. }
  487. });
  488. }
  489. /**
  490. * 发送地理位置消息
  491. *
  492. * @param {Object} data 消息内容
  493. * @param {String} data.description 地理位置描述信息
  494. * @param {Number} data.longitude 经度
  495. * @param {Number} data.latitude 纬度
  496. * @returns {Promise}
  497. */
  498. public sendLocationMessage(data: any): Promise<any> {
  499. return this.handlePromiseCallback(async (resolve: any, reject: any) => {
  500. try {
  501. const options = this.handleMessageOptions(data, "location");
  502. const message = this.TUICore.createLocationMessage(options);
  503. this.store.messageList.push(message);
  504. const imResponse = await this.TUICore.sendMessage(message);
  505. console.log("发送地理位置消息完成", imResponse);
  506. resolve(imResponse);
  507. } catch (error) {
  508. reject(error);
  509. }
  510. });
  511. }
  512. /**
  513. * 转发消息
  514. *
  515. * @param {message} message 消息实例
  516. * @param {any} to 转发的对象
  517. * @returns {Promise}
  518. */
  519. public forwardMessage(message: any, to: any): Promise<any> {
  520. return this.handlePromiseCallback(async (resolve: any, reject: any) => {
  521. try {
  522. const options = this.handleMessageOptions(message, "forward", {}, to);
  523. const imMessage = this.TUICore.createForwardMessage(options);
  524. const imResponse = await this.TUICore.sendMessage(imMessage);
  525. if (
  526. this.store.conversation.conversationID ===
  527. imResponse.data.message.conversationID
  528. ) {
  529. this.store.messageList.push(imResponse.data.message);
  530. }
  531. console.log("消息转发完成", imResponse);
  532. resolve(imResponse);
  533. } catch (error) {
  534. reject(error);
  535. }
  536. });
  537. }
  538. /**
  539. * 发送@ 提醒功能的文本消息
  540. *
  541. * @param {Object} data 消息内容
  542. * @param {String} data.text 文本消息
  543. * @param {Array} data.atUserList 需要 @ 的用户列表,如果需要 @ALL,请传入 TIM.TYPES.MSG_AT_ALL
  544. * @returns {message}
  545. *
  546. * - 注:此接口仅用于群聊
  547. */
  548. public sendTextAtMessage(data: Object) {
  549. return new Promise<void>(async (resolve, reject) => {
  550. try {
  551. const options = this.handleMessageOptions(data, "text");
  552. const message = this.TUICore.createTextAtMessage(options);
  553. this.currentStore.messageList.push(message);
  554. const imResponse = await this.TUICore.sendMessage(message);
  555. this.currentStore.messageList = this.currentStore.messageList.map(
  556. (item: any) => {
  557. if (item.ID === imResponse.data.message.ID) {
  558. return imResponse.data.message;
  559. }
  560. return item;
  561. }
  562. );
  563. resolve(imResponse);
  564. } catch (error) {
  565. reject(error);
  566. }
  567. });
  568. }
  569. /**
  570. * 发送合并消息
  571. *
  572. * @param {Object} data 消息内容
  573. * @param {Array.<Message>} data.messageList 合并的消息列表
  574. * @param {String} data.title 合并的标题
  575. * @param {String} data.abstractList 摘要列表,不同的消息类型可以设置不同的摘要信息
  576. * @param {String} data.compatibleText 兼容文本
  577. * @returns {Promise}
  578. */
  579. public sendMergerMessage(data: any): Promise<any> {
  580. return this.handlePromiseCallback(async (resolve: any, reject: any) => {
  581. try {
  582. const options = this.handleMessageOptions(data, "merger");
  583. const message = this.TUICore.createMergerMessage(options);
  584. this.currentStore.messageList.push(message);
  585. const imResponse = await this.TUICore.sendMessage(message);
  586. console.log("发送合并消息完成", imResponse);
  587. this.currentStore.messageList = this.currentStore.messageList.map(
  588. (item: any) => {
  589. if (item.ID === imResponse.data.message.ID) {
  590. return imResponse.data.message;
  591. }
  592. return item;
  593. }
  594. );
  595. resolve(imResponse);
  596. } catch (error) {
  597. reject(error);
  598. }
  599. });
  600. }
  601. /**
  602. * 获取 messageList
  603. *
  604. * @param {any} options 获取 messageList 参数
  605. * @param {Boolean} history 是否获取历史消息
  606. * @returns {Promise}
  607. */
  608. public async getMessageList(options: any, history?: Boolean) {
  609. return new Promise<void>(async (resolve, reject) => {
  610. try {
  611. const imResponse = await this.TUICore.getMessageList(options);
  612. let messageList;
  613. if (!history) {
  614. messageList = imResponse.data.messageList;
  615. } else {
  616. messageList = [
  617. ...imResponse.data.messageList,
  618. ...this.store.messageList,
  619. ];
  620. }
  621. this.currentStore.nextReqMessageID = imResponse.data.nextReqMessageID;
  622. this.currentStore.isCompleted = imResponse.data.isCompleted;
  623. store.commit("timStore/setMessageList", messageList);
  624. resolve(imResponse.data);
  625. } catch (error) {
  626. reject(error);
  627. }
  628. });
  629. }
  630. /**
  631. * 获取历史消息
  632. *
  633. * @returns {Promise}
  634. */
  635. public async getHistoryMessageList() {
  636. return new Promise<void>(async (resolve, reject) => {
  637. try {
  638. const options = {
  639. conversationID: this.store.conversation.conversationID,
  640. nextReqMessageID: this.currentStore.nextReqMessageID,
  641. count: 15,
  642. };
  643. let messageList = [];
  644. if (!this.currentStore.isCompleted) {
  645. messageList = await this.getMessageList(options, true);
  646. }
  647. resolve(messageList);
  648. } catch (error) {
  649. reject(error);
  650. }
  651. });
  652. }
  653. /**
  654. * 消息撤回
  655. *
  656. * @param {message} message 消息实例
  657. * @returns {Promise}
  658. */
  659. public revokeMessage(message: any): Promise<any> {
  660. return new Promise<void>(async (resolve, reject) => {
  661. try {
  662. const imResponse = await this.TUICore.revokeMessage(message);
  663. resolve(imResponse);
  664. } catch (error) {
  665. reject(error);
  666. }
  667. });
  668. }
  669. /**
  670. * 重发消息
  671. *
  672. * @param {message} message 消息实例
  673. * @returns {Promise}
  674. */
  675. public resendMessage(message: any): Promise<any> {
  676. return new Promise<void>(async (resolve, reject) => {
  677. try {
  678. const imResponse = await this.TUICore.resendMessage(message);
  679. console.log("消息重发完成", imResponse);
  680. let messageList = [];
  681. messageList = this.store.messageList.filter(
  682. (item: any) => item.ID !== message.ID
  683. );
  684. store.commit("timStore/setMessageList", messageList);
  685. resolve(imResponse);
  686. } catch (error) {
  687. reject(error);
  688. }
  689. });
  690. }
  691. /**
  692. * 删除消息
  693. *
  694. * @param {Array.<message>} messages 消息实例
  695. * @returns {Promise}
  696. */
  697. public deleteMessage(messages: any): Promise<any> {
  698. return new Promise<void>(async (resolve, reject) => {
  699. try {
  700. const imResponse = await this.TUICore.deleteMessage(messages);
  701. let messageList = [];
  702. messageList = this.store.messageList.filter(
  703. (item: any) => item.ID !== messages.ID
  704. );
  705. store.commit("timStore/setMessageList", messageList);
  706. resolve(imResponse);
  707. } catch (error) {
  708. reject(error);
  709. }
  710. });
  711. }
  712. }