conversation.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. <template>
  2. <view>
  3. <view>
  4. <view class="search" v-if="search_btn">
  5. <view @tap="openSearch">
  6. <icon type="search" size="12"></icon>
  7. <text>搜索</text>
  8. </view>
  9. </view>
  10. </view>
  11. <!-- <view class="chat_list_wraper" > -->
  12. <scroll-view scroll-y="true" :class="
  13. 'chat_list_wraper ' + (gotop ? (isIPX ? 'goTopX' : 'goTop') : 'goback')
  14. " :style="'padding-bottom: ' + (isIPX ? '270rpx' : '226rpx')">
  15. <view class="search_input" v-if="search_chats">
  16. <view>
  17. <icon type="search" size="12"></icon>
  18. <input placeholder="搜索" placeholder-style="color:#9B9B9B;line-height:21px;font-size:15px;"
  19. auto-focus confirm-type="search" type="text" @confirm="onSearch" @input="onInput"
  20. v-model="input_code" />
  21. <icon type="clear" size="12" @tap.stop="clearInput" v-if="show_clear"></icon>
  22. </view>
  23. <text @tap="cancel">取消</text>
  24. </view>
  25. <view v-for="(item, index) in conversationList" :key="index" class="chat_list" :data-item="item"
  26. @tap.stop="del_chat" @longpress="longpress">
  27. <swipe-delete>
  28. <!-- 通知模块 -->
  29. <!-- <view class="tap_mask" @tap.stop="into_inform" :data-item="item" v-if="item.chatType == 'INFORM'">
  30. <view class="list_box">
  31. <view class="list_left">
  32. <view class="list_pic">
  33. <view v-if="unReadTotalNotNum > 0" class="em-unread-spot2">
  34. {{ unReadTotalNotNum}}
  35. </view>
  36. <image :class="unReadTotalNotNum > 0 ? 'haveSpot' : ''" src="../static/inform.png">
  37. </image>
  38. </view>
  39. <view class="list_text">
  40. <text class="list_user"> 系统通知 </text>
  41. <text class="list_word"
  42. v-if="item.chatType == 'INFORM'">申请通知来自:{{ item.info.from }}</text>
  43. </view>
  44. </view>
  45. <view class="list_right">
  46. <text :data-username="item.username">{{ handleTime(item) }}</text>
  47. </view>
  48. </view>
  49. </view> -->
  50. <view class="tap_mask" @tap.stop="into_chatRoom" :data-item="JSON.stringify(item)">
  51. <!-- 消息列表 -->
  52. <view class="list_box">
  53. <view class="list_left" :data-username="item.username">
  54. <view class="list_pic">
  55. <view class="em-msgNum"
  56. v-if="item.unReadCount > 0 && !pushConfigData.includes(item.chatType === 'chat' ? item.username : item.info.to)">
  57. {{ item.unReadCount > 99 ? '99+':item.unReadCount}}
  58. </view>
  59. <image :src="showConversationAvatar(item)"></image>
  60. </view>
  61. <view class="list_text">
  62. <text class="list_user">{{ showConversationName(item) }}</text>
  63. <text class="list_word" v-if="item.msg.data[0].data">
  64. {{item.msg.data[0].data}}
  65. </text>
  66. <text class="list_word" v-if="item.msg.type == 'img'">[图片]</text>
  67. <text class="list_word" v-if="item.msg.type == 'audio'">[语音]</text>
  68. <text class="list_word" v-if="item.msg.type == 'file'">[附件]</text>
  69. <text class="list_word" v-if="item.msg.type == 'video'">[视频]</text>
  70. </view>
  71. </view>
  72. <view class="list_right">
  73. <text :data-username="item.username">{{ handleTime(item) }}</text>
  74. </view>
  75. </view>
  76. </view>
  77. </swipe-delete>
  78. </view>
  79. <long-press-modal :winSize="winSize" :popButton="popButton" @change="pickerMenuChange" :showPop="showPop"
  80. @hidePop="hidePop" :popStyle="popStyle" />
  81. <view v-if="conversationList && conversationList.length == 0" class="chat_noChat">
  82. <image class="ctbg" src="../static/ctbg.png"></image>
  83. 暂无聊天消息
  84. </view>
  85. <!-- </view> -->
  86. </scroll-view>
  87. <!-- bug: margin-bottom 不生效 需要加一个空标签-->
  88. <view style="height: 1px"></view>
  89. <view class="mask" @tap="close_mask" v-if="show_mask"></view>
  90. </view>
  91. </template>
  92. <script>
  93. const req = require("../../utils/request.js");
  94. let disp = require("../../hxChatSDK/utils/broadcast");
  95. let timeFormats = require("../../hxChatSDK/utils/timeFormat");
  96. var WebIM = require("../../hxChatSDK/utils/WebIM")["default"];
  97. let isfirstTime = true;
  98. import swipeDelete from "../../chat/components/chat/swipedelete/swipedelete";
  99. import longPressModal from "../../chat/components/chat/longPressModal/index";
  100. export default {
  101. data() {
  102. return {
  103. search_btn: true,
  104. search_chats: false,
  105. show_mask: false,
  106. yourname: "",
  107. unReadSpotNum: 0,
  108. unReadNoticeNum: 0,
  109. messageNum: 0,
  110. unReadTotalNotNum: 0,
  111. conversationList: [],
  112. show_clear: false,
  113. member: "",
  114. isIPX: false,
  115. gotop: false,
  116. input_code: "",
  117. groupName: {},
  118. winSize: {},
  119. popButton: ["删除该聊天"],
  120. showPop: false,
  121. popStyle: "",
  122. currentVal: '',
  123. pushConfigData: [],
  124. defaultAvatar: "../static/theme2x.png",
  125. defaultGroupAvatar: "../static/groupTheme.png"
  126. };
  127. },
  128. components: {
  129. swipeDelete,
  130. longPressModal,
  131. },
  132. props: {},
  133. onLoad() {
  134. this.getWindowSize();
  135. //监听加好友申请
  136. disp.on("em.subscribe", this.onChatPageSubscribe);
  137. //监听解散群
  138. disp.on("em.invite.deleteGroup", this.onChatPageDeleteGroup);
  139. //监听未读消息数
  140. disp.on("em.unreadspot", this.onChatPageUnreadspot);
  141. //监听未读加群“通知”
  142. disp.on("em.invite.joingroup", this.onChatPageJoingroup);
  143. //监听好友删除
  144. disp.on("em.contacts.remove", this.onChatPageRemoveContacts);
  145. //监听好友关系解除
  146. disp.on("em.unsubscribed", this.onChatPageUnsubscribed)
  147. if (!uni.getStorageSync('listGroup')) {
  148. this.listGroups()
  149. }
  150. if (!uni.getStorageSync('member')) {
  151. this.getRoster()
  152. }
  153. this.readJoinedGroupName()
  154. },
  155. onShow: function() {
  156. uni.hideHomeButton && uni.hideHomeButton();
  157. setTimeout(() => {
  158. this.getLocalConversationlist();
  159. }, 100)
  160. this.setData({
  161. unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ?
  162. "99+" : getApp().globalData.unReadMessageNum,
  163. messageNum: getApp().globalData.saveFriendList.length,
  164. unReadNoticeNum: getApp().globalData.saveGroupInvitedList.length,
  165. unReadTotalNotNum: getApp().globalData.saveFriendList.length +
  166. getApp().globalData.saveGroupInvitedList.length,
  167. });
  168. if (getApp().globalData.isIPX) {
  169. this.setData({
  170. isIPX: true,
  171. });
  172. }
  173. },
  174. onUnload() {
  175. //页面卸载同步取消onload中的订阅,防止重复订阅事件。
  176. disp.off('em.subscribe', this.onChatPageSubscribe)
  177. disp.off("em.invite.deleteGroup", this.onChatPageDeleteGroup)
  178. disp.off("em.unreadspot", this.onChatPageUnreadspot)
  179. disp.off("em.invite.joingroup", this.onChatPageJoingroup)
  180. disp.off("em.contacts.remove", this.onChatPageRemoveContacts)
  181. disp.off("em.unsubscribed", this.onChatPageUnsubscribed)
  182. },
  183. computed: {
  184. //会话头像展示
  185. showConversationAvatar() {
  186. // const friendUserInfoMap = getApp().globalData.friendUserInfoMap;
  187. return (item) => {
  188. if (item.chatType === 'singleChat' || item.chatType === 'chat') {
  189. // if (friendUserInfoMap.has(item.username) && friendUserInfoMap.get(item.username)?.avatarurl) {
  190. // return friendUserInfoMap.get(item.username).avatarurl
  191. // } else {
  192. // return this.defaultAvatar
  193. // }
  194. const imUserInfo = uni.getStorageSync("imUserInfo_" + item.username);
  195. if (imUserInfo && imUserInfo.avatar) {
  196. return imUserInfo.avatar;
  197. } else {
  198. return this.defaultAvatar;
  199. }
  200. } else if (item.chatType === 'groupchat' || item.chatType === 'chatRoom') {
  201. return this.defaultGroupAvatar
  202. }
  203. }
  204. },
  205. //会话name展示
  206. showConversationName() {
  207. // const friendUserInfoMap = getApp().globalData.friendUserInfoMap;
  208. return (item) => {
  209. if (item.chatType === 'singleChat' || item.chatType === 'chat') {
  210. // if (friendUserInfoMap.has(item.username) && friendUserInfoMap.get(item.username)?.nickname) {
  211. // return friendUserInfoMap.get(item.username).nickname
  212. // } else {
  213. // return item.username
  214. // }
  215. const imUserInfo = uni.getStorageSync("imUserInfo_" + item.username);
  216. if (imUserInfo && imUserInfo.nickName) {
  217. return imUserInfo.nickName;
  218. } else {
  219. return item.username;
  220. }
  221. } else if (item.chatType === 'groupchat' || item.chatType === 'chatRoom') {
  222. return item.groupName
  223. }
  224. }
  225. },
  226. //处理时间显示
  227. handleTime() {
  228. return (item) => {
  229. return timeFormats.timeFormat(item.time, 'mm/dd/hh:MM')
  230. }
  231. }
  232. },
  233. methods: {
  234. listGroups() {
  235. var me = this;
  236. return WebIM.conn.getGroup({
  237. limit: 50,
  238. success: function(res) {
  239. uni.setStorage({
  240. key: "listGroup",
  241. data: res.data,
  242. });
  243. me.readJoinedGroupName()
  244. me.getLocalConversationlist();
  245. },
  246. error: function(err) {
  247. console.log(err);
  248. },
  249. });
  250. },
  251. getRoster() {
  252. let me = this;
  253. let rosters = {
  254. success(roster) {
  255. console.log('roster', roster)
  256. var member = [];
  257. for (let i = 0; i < roster.length; i++) {
  258. if (roster[i].subscription == "both") {
  259. member.push(roster[i]);
  260. }
  261. }
  262. uni.setStorage({
  263. key: "member",
  264. data: member,
  265. });
  266. me.setData({
  267. member: member
  268. });
  269. //if(!systemReady){
  270. disp.fire("em.main.ready");
  271. //systemReady = true;
  272. //}
  273. me.getLocalConversationlist()
  274. me.setData({
  275. unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ?
  276. "99+" : getApp().globalData.unReadMessageNum,
  277. });
  278. },
  279. error(err) {
  280. console.log(err);
  281. },
  282. };
  283. WebIM.conn.getContacts(rosters);
  284. },
  285. readJoinedGroupName() {
  286. const joinedGroupList = uni.getStorageSync('listGroup')
  287. const groupList = joinedGroupList?.data || joinedGroupList || []
  288. let groupName = {};
  289. groupList.forEach((item) => {
  290. groupName[item.groupid] = item.groupname;
  291. });
  292. this.setData({
  293. groupName: groupName,
  294. });
  295. },
  296. // 包含陌生人版本
  297. getLocalConversationlist() {
  298. const myName = uni.getStorageSync("myUsername");
  299. const me = this;
  300. uni.getStorageInfo({
  301. success: function(res) {
  302. let storageKeys = res.keys;
  303. let newChatMsgKeys = [];
  304. let historyChatMsgKeys = [];
  305. let len = myName.length;
  306. storageKeys.forEach((item) => {
  307. if (item.slice(-len) == myName && item.indexOf("rendered_") == -1) {
  308. newChatMsgKeys.push(item);
  309. } else if (
  310. item.slice(-len) == myName &&
  311. item.indexOf("rendered_") > -1
  312. ) {
  313. historyChatMsgKeys.push(item);
  314. } else if (item === "INFORM") {
  315. newChatMsgKeys.push(item);
  316. }
  317. });
  318. me.packageConversation(newChatMsgKeys, historyChatMsgKeys);
  319. },
  320. });
  321. },
  322. //组件会话列表方法
  323. packageConversation(newChatMsgKeys, historyChatMsgKeys) {
  324. const me = this;
  325. const myName = uni.getStorageSync("myUsername");
  326. let conversationList = [];
  327. let lastChatMsg; //最后一条消息
  328. for (let i = historyChatMsgKeys.length; i > 0, i--;) {
  329. let index = newChatMsgKeys.indexOf(historyChatMsgKeys[i].slice(9));
  330. if (index > -1) {
  331. let newChatMsgs = uni.getStorageSync(newChatMsgKeys[index]) || [];
  332. if (newChatMsgs.length) {
  333. lastChatMsg = newChatMsgs[newChatMsgs.length - 1];
  334. lastChatMsg.unReadCount = newChatMsgs.length;
  335. newChatMsgKeys.splice(index, 1);
  336. } else {
  337. let historyChatMsgs = uni.getStorageSync(historyChatMsgKeys[i]);
  338. if (historyChatMsgs.length) {
  339. lastChatMsg = historyChatMsgs[historyChatMsgs.length - 1];
  340. }
  341. }
  342. } else {
  343. let historyChatMsgs = uni.getStorageSync(historyChatMsgKeys[i]);
  344. if (historyChatMsgs.length) {
  345. lastChatMsg = historyChatMsgs[historyChatMsgs.length - 1];
  346. }
  347. }
  348. if (
  349. lastChatMsg &&
  350. (lastChatMsg.chatType == "groupchat" ||
  351. lastChatMsg.chatType == "chatRoom")
  352. ) {
  353. lastChatMsg.groupName = me.groupName[lastChatMsg.info.to];
  354. }
  355. lastChatMsg && lastChatMsg.username != myName &&
  356. conversationList.push(lastChatMsg);
  357. }
  358. for (let i = newChatMsgKeys.length; i > 0, i--;) {
  359. let newChatMsgs = uni.getStorageSync(newChatMsgKeys[i]) || [];
  360. if (newChatMsgs.length) {
  361. lastChatMsg = newChatMsgs[newChatMsgs.length - 1];
  362. lastChatMsg.unReadCount = newChatMsgs.length;
  363. if (
  364. lastChatMsg.chatType == "groupchat" ||
  365. lastChatMsg.chatType == "chatRoom"
  366. ) {
  367. lastChatMsg.groupName = me.groupName[lastChatMsg.info.to];
  368. }
  369. lastChatMsg.username != myName && conversationList.push(lastChatMsg);
  370. }
  371. }
  372. conversationList.sort((a, b) => {
  373. return b.time - a.time;
  374. });
  375. this.setData({
  376. conversationList: conversationList,
  377. });
  378. console.log('消息》》》》', this.conversationList);
  379. },
  380. openSearch: function() {
  381. // this.setData({
  382. // search_btn: false,
  383. // search_chats: true,
  384. // gotop: true,
  385. // });
  386. this.into_singleChatRoom();
  387. },
  388. onSearch: function(val) {
  389. let searchValue = val.detail.value;
  390. var myName = uni.getStorageSync("myUsername");
  391. const me = this;
  392. let serchList = [];
  393. let conversationList = [];
  394. uni.getStorageInfo({
  395. success: function(res) {
  396. let storageKeys = res.keys;
  397. let chatKeys = [];
  398. let len = myName.length;
  399. storageKeys.forEach((item) => {
  400. if (item.slice(-len) == myName) {
  401. chatKeys.push(item);
  402. }
  403. });
  404. chatKeys.forEach((item, index) => {
  405. if (item.indexOf(searchValue) != -1) {
  406. serchList.push(item);
  407. }
  408. });
  409. let lastChatMsg = "";
  410. serchList.forEach((item, index) => {
  411. let chatMsgs = uni.getStorageSync(item) || [];
  412. if (chatMsgs.length) {
  413. lastChatMsg = chatMsgs[chatMsgs.length - 1];
  414. conversationList.push(lastChatMsg);
  415. }
  416. });
  417. me.setData({
  418. conversationList: conversationList
  419. });
  420. },
  421. });
  422. },
  423. cancel: function() {
  424. this.getLocalConversationlist();
  425. this.setData({
  426. search_btn: true,
  427. search_chats: false,
  428. unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ?
  429. "99+" : getApp().globalData.unReadMessageNum,
  430. gotop: false,
  431. });
  432. },
  433. clearInput: function() {
  434. this.setData({
  435. input_code: "",
  436. show_clear: false,
  437. });
  438. },
  439. onInput: function(e) {
  440. let inputValue = e.detail.value;
  441. if (inputValue) {
  442. this.setData({
  443. show_clear: true,
  444. });
  445. } else {
  446. this.setData({
  447. show_clear: false,
  448. });
  449. }
  450. },
  451. close_mask: function() {
  452. this.setData({
  453. search_btn: true,
  454. search_chats: false,
  455. show_mask: false,
  456. });
  457. },
  458. into_chatRoom: function(event) {
  459. let detail = JSON.parse(event.currentTarget.dataset.item);
  460. if (
  461. detail.chatType == "groupchat" ||
  462. detail.chatType == "chatRoom" ||
  463. detail.groupName
  464. ) {
  465. this.into_groupChatRoom(detail);
  466. } else {
  467. this.into_singleChatRoom(detail);
  468. }
  469. },
  470. // 单聊
  471. into_singleChatRoom: function(detail) {
  472. var my = uni.getStorageSync("myUsername");
  473. var nameList = {
  474. myName: my,
  475. your: detail.username,
  476. // your: 'RS_316923182326'
  477. };
  478. const friendUserInfoMap = getApp().globalData.friendUserInfoMap;
  479. if (friendUserInfoMap.has(nameList.your) && friendUserInfoMap.get(nameList.your)?.nickname) {
  480. nameList.yourNickName = friendUserInfoMap.get(nameList.your).nickname;
  481. }
  482. console.log('JSON.stringify(nameList)》》》》', JSON.stringify(nameList));
  483. uni.navigateTo({
  484. url: "../chatroom/chatroom?username=" + JSON.stringify(nameList),
  485. });
  486. },
  487. // 群聊 和 聊天室 (两个概念)
  488. into_groupChatRoom: function(detail) {
  489. var my = uni.getStorageSync("myUsername");
  490. var nameList = {
  491. myName: my,
  492. your: detail.groupName,
  493. groupId: detail.info.to,
  494. };
  495. uni.navigateTo({
  496. url: "../groupChatRoom/groupChatRoom?username=" + JSON.stringify(nameList),
  497. });
  498. },
  499. // into_inform: function() {
  500. // uni.redirectTo({
  501. // url: "../notification/notification",
  502. // });
  503. // },
  504. removeAndRefresh: function(event) {
  505. let removeId = event.currentTarget.dataset.item.info.from
  506. let ary = getApp().globalData.saveFriendList
  507. let idx
  508. if (ary.length > 0) {
  509. ary.forEach((v, k) => {
  510. if (v.from == removeId) {
  511. idx = k
  512. }
  513. })
  514. getApp().globalData.saveFriendList.splice(idx, 1);
  515. }
  516. uni.removeStorageSync('INFORM')
  517. },
  518. del_chat: function(event) {
  519. let detail = event.currentTarget.dataset.item;
  520. let nameList = {};
  521. let me = this;
  522. // 删除当前选中群组聊天列表
  523. if (detail.chatType == "groupchat" || detail.chatType == "chatRoom") {
  524. nameList = {
  525. your: detail.info.to,
  526. };
  527. //删除当前选中通知列表
  528. } else if (detail.chatType === "INFORM") {
  529. nameList = {
  530. your: "INFORM",
  531. };
  532. }
  533. //删除当前选中好友聊天列表
  534. else {
  535. nameList = {
  536. your: detail.username,
  537. };
  538. }
  539. var myName = uni.getStorageSync("myUsername");
  540. var currentPage = getCurrentPages();
  541. uni.showModal({
  542. title: "确认删除?",
  543. confirmText: "删除",
  544. success: function(res) {
  545. if (res.confirm) {
  546. uni.removeStorageSync(nameList.your + myName);
  547. uni.removeStorageSync("rendered_" + nameList.your + myName);
  548. nameList.your === 'INFORM' && me.removeAndRefresh(event);
  549. // if (Object.keys(currentPage[0]).length>0) {
  550. // currentPage[0].onShow();
  551. // }
  552. disp.fire("em.chat.session.remove");
  553. me.getLocalConversationlist();
  554. }
  555. },
  556. fail: function(err) {
  557. console.log('删除列表', err);
  558. },
  559. });
  560. },
  561. removeLocalStorage: function(yourname) {
  562. var myName = uni.getStorageSync("myUsername");
  563. uni.removeStorageSync(yourname + myName);
  564. uni.removeStorageSync("rendered_" + yourname + myName);
  565. },
  566. longpress: function(e) {
  567. //将当前选中的值存在data中方便后续操作
  568. this.currentVal = e
  569. let [touches, style, index] = [e.touches[0], "", e.currentTarget.dataset.index, ];
  570. /* 因 非H5端不兼容 style 属性绑定 Object ,所以拼接字符 */
  571. if (touches.clientY > this.winSize.height / 2) {
  572. style = `bottom:${this.winSize.height - touches.clientY}px;`;
  573. } else {
  574. style = `top:${touches.clientY}px;`;
  575. }
  576. if (touches.clientX > this.winSize.witdh / 2) {
  577. style += `right:${this.winSize.witdh - touches.clientX}px`;
  578. } else {
  579. style += `left:${touches.clientX}px`;
  580. }
  581. this.popStyle = style;
  582. // this.pickerUserIndex = Number(index);
  583. this.showShade = true;
  584. this.$nextTick(() => {
  585. setTimeout(() => {
  586. this.showPop = true;
  587. }, 10);
  588. });
  589. },
  590. /* 获取窗口尺寸 */
  591. getWindowSize() {
  592. uni.getSystemInfo({
  593. success: (res) => {
  594. this.winSize = {
  595. witdh: res.windowWidth,
  596. height: res.windowHeight,
  597. };
  598. },
  599. });
  600. },
  601. hidePop() {
  602. this.showPop = false;
  603. },
  604. pickerMenuChange() {
  605. this.del_chat(this.currentVal)
  606. },
  607. /* disp event callback function */
  608. onChatPageSubscribe() {
  609. this.getLocalConversationlist();
  610. this.setData({
  611. messageNum: getApp().globalData.saveFriendList.length,
  612. unReadTotalNotNum: getApp().globalData.saveFriendList.length +
  613. getApp().globalData.saveGroupInvitedList.length,
  614. });
  615. },
  616. onChatPageDeleteGroup(infos) {
  617. this.listGroups();
  618. this.getRoster();
  619. this.getLocalConversationlist();
  620. this.setData({
  621. messageNum: getApp().globalData.saveFriendList.length,
  622. });
  623. //如果会话存在则执行删除会话
  624. this.removeLocalStorage(infos.gid)
  625. },
  626. onChatPageUnreadspot(message) {
  627. this.getLocalConversationlist();
  628. let currentLoginUser = WebIM.conn.context.userId;
  629. let id = message && message.chatType === 'groupchat' ? message?.to : message?.from;
  630. let pushObj = uni.getStorageSync("pushStorageData");
  631. let pushAry = pushObj[currentLoginUser] || []
  632. this.setData({
  633. pushConfigData: pushAry,
  634. });
  635. // if (message && pushValue.includes(id)) return
  636. this.setData({
  637. unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ?
  638. "99+" : getApp().globalData.unReadMessageNum,
  639. });
  640. },
  641. onChatPageJoingroup() {
  642. this.setData({
  643. unReadNoticeNum: getApp().globalData.saveGroupInvitedList.length,
  644. unReadTotalNotNum: getApp().globalData.saveFriendList.length +
  645. getApp().globalData.saveGroupInvitedList.length,
  646. });
  647. this.getLocalConversationlist();
  648. },
  649. onChatPageRemoveContacts() {
  650. this.getLocalConversationlist();
  651. this.getRoster();
  652. },
  653. onChatPageUnsubscribed(message) {
  654. uni.showToast({
  655. title: `与${message.from}好友关系解除`,
  656. icon: "none",
  657. });
  658. }
  659. },
  660. };
  661. </script>
  662. <style>
  663. @import "./chat.css";
  664. </style>