imCommon.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. import store from "@/store";
  2. import {
  3. CustomType,
  4. GroupSystemMessageTypes,
  5. AddFriendQrCodePrefix,
  6. AddGroupQrCodePrefix,
  7. } from "@/pages_im/constant";
  8. import {
  9. subUserOnlineStatus
  10. } from "../api/imApi";
  11. import IMSDK, {
  12. GroupAtType,
  13. MessageType,
  14. SessionType,
  15. } from "openim-uniapp-polyfill";
  16. import dayjs from "dayjs";
  17. import {
  18. isThisYear
  19. } from "date-fns";
  20. import calendar from "dayjs/plugin/calendar";
  21. import relativeTime from "dayjs/plugin/relativeTime";
  22. import updateLocale from "dayjs/plugin/updateLocale";
  23. import "dayjs/locale/zh-cn";
  24. dayjs.extend(calendar);
  25. dayjs.extend(relativeTime);
  26. dayjs.extend(updateLocale);
  27. dayjs.locale("zh-cn");
  28. dayjs.updateLocale("en", {
  29. calendar: {
  30. sameElse: "YYYY-MM-DD",
  31. },
  32. });
  33. dayjs.updateLocale("zh-cn", {
  34. calendar: {
  35. sameDay: "HH:mm",
  36. nextDay: "[明天]",
  37. nextWeek: "dddd",
  38. lastDay: "[昨天] HH:mm",
  39. lastWeek: "dddd HH:mm",
  40. sameElse: "YYYY年M月D日 HH:mm",
  41. },
  42. });
  43. export const formatMessageTime = (timestemp, keepSameYear = false) => {
  44. if (!timestemp) return "";
  45. const isRecent = dayjs().diff(timestemp, "day") < 7;
  46. const keepYear = keepSameYear || !isThisYear(timestemp);
  47. if (!isRecent && !keepYear) {
  48. return dayjs(timestemp).format("M月D日 HH:mm");
  49. }
  50. return dayjs(timestemp).calendar();
  51. };
  52. export const formatHyperlink = (nickname, currentUserID) => {
  53. return `<a href="${currentUserID}" style="color:#0089FF; text-decoration:none;">${nickname}</a>`;
  54. };
  55. const regex = /\b(http[s]?:\/\/[^\s]+)\b/g;
  56. export const parseLink = (content) =>
  57. content.replace(regex, (match) => formatHyperlink(match, match));
  58. const nomalTypes = [GroupAtType.AtAll, GroupAtType.AtAllAtMe, GroupAtType.AtMe];
  59. export const conversationSort = (conversationList) => {
  60. const arr = [];
  61. const filterArr = conversationList.filter(
  62. (c) => !arr.includes(c.conversationID) && arr.push(c.conversationID),
  63. );
  64. filterArr.sort((a, b) => {
  65. if (a.isPinned === b.isPinned) {
  66. const aCompare =
  67. a.draftTextTime > a.latestMsgSendTime ?
  68. a.draftTextTime :
  69. a.latestMsgSendTime;
  70. const bCompare =
  71. b.draftTextTime > b.latestMsgSendTime ?
  72. b.draftTextTime :
  73. b.latestMsgSendTime;
  74. if (aCompare > bCompare) {
  75. return -1;
  76. } else if (aCompare < bCompare) {
  77. return 1;
  78. } else {
  79. return 0;
  80. }
  81. } else if (a.isPinned && !b.isPinned) {
  82. return -1;
  83. } else {
  84. return 1;
  85. }
  86. });
  87. return filterArr;
  88. };
  89. export const parseAt = (atel, isParse = false) => {
  90. let mstr = atel.text;
  91. const pattern = /@\S+\s/g;
  92. const arr = mstr.match(pattern);
  93. const atUsersInfo = atel.atUsersInfo ?? [];
  94. arr?.map((match) => {
  95. const member = atUsersInfo.find(
  96. (user) => user.atUserID === match.slice(1, -1),
  97. );
  98. if (member && !isParse) {
  99. // mstr = mstr.replace(match, `<text class='parsed_at_el'> @${member.groupNickname}&nbsp;</text>`);
  100. // mstr = mstr.replace(match, `<a href="${member.atUserID}" style="color:#0089FF;text-decoration:none;">@${member.groupNickname}</a> `);
  101. mstr = mstr.replace(
  102. match,
  103. formatHyperlink(`@${member.groupNickname} `, member.atUserID),
  104. );
  105. } else {
  106. // mstr = mstr.replace(match, `<text class='parsed_at_el'> ${match}</text>`);
  107. mstr = mstr.replace(match, `@${member.groupNickname} `);
  108. }
  109. });
  110. return mstr;
  111. };
  112. const switchCustomMsg = (cMsg) => {
  113. switch (cMsg.customType) {
  114. case CustomType.MassMsg:
  115. return "[群发通知]";
  116. case CustomType.Call:
  117. return "[通话消息]";
  118. case CustomType.MeetingInvitation:
  119. return "[会议邀请]";
  120. default:
  121. return "";
  122. }
  123. };
  124. const switchCustomSysMsg = (payload) => {
  125. switch (payload.data) {
  126. case "startInquiry":
  127. return "[开始问诊]";
  128. case "startFollow":
  129. return "[开始随访]";
  130. case "finishInquiry":
  131. return "[结束问诊]";
  132. case "finishFollow":
  133. return "[结束随访]";
  134. case "order":
  135. return "[问诊订单]";
  136. case "prescribe":
  137. return "[电子处方单]";
  138. case "report":
  139. return "[问诊报告单]";
  140. case "follow":
  141. return "[随访单]";
  142. case "drugReport":
  143. return "[用药报告单]";
  144. case "package":
  145. return "[疗法消息]";
  146. case "couponPackage":
  147. return "[私域疗法券]";
  148. case "inquirySelect":
  149. return "[会诊消息]";
  150. case "course":
  151. return payload?.extension?.title || "[看课消息]";
  152. case "live":
  153. return "[直播消息]";
  154. default:
  155. return "[自定义消息]";
  156. }
  157. };
  158. export const sec2Time = (seconds) => {
  159. var theTime1 = 0; // min
  160. var theTime2 = 0; // hour
  161. var theTime3 = 0; // day
  162. if (seconds > 60) {
  163. theTime1 = parseInt(seconds / 60);
  164. seconds = parseInt(seconds % 60);
  165. if (theTime1 > 60) {
  166. theTime2 = parseInt(theTime1 / 60);
  167. theTime1 = parseInt(theTime1 % 60);
  168. if (theTime2 > 24) {
  169. theTime3 = parseInt(theTime2 / 24);
  170. theTime2 = parseInt(theTime2 % 24);
  171. }
  172. }
  173. }
  174. var result = "";
  175. if (seconds > 0) {
  176. result = "" + parseInt(seconds) + "秒";
  177. }
  178. if (theTime1 > 0) {
  179. result = "" + parseInt(theTime1) + "分钟" + result;
  180. }
  181. if (theTime2 > 0) {
  182. result = "" + parseInt(theTime2) + "小时" + result;
  183. }
  184. if (theTime3 > 0) {
  185. result = "" + parseInt(theTime3) + "天" + result;
  186. }
  187. return result;
  188. };
  189. export const parseMessageByType = (pmsg) => {
  190. const isSelf = (id) => id === store.getters.storeCurrentUserID;
  191. const getName = (user) => {
  192. return user.userID === store.getters.storeCurrentUserID ? "你" : user.nickname;
  193. };
  194. switch (pmsg.contentType) {
  195. case MessageType.TextMessage:
  196. return pmsg.textElem.content;
  197. case MessageType.AtTextMessage:
  198. return parseAt(pmsg.atTextElem, true);
  199. case MessageType.PictureMessage:
  200. return `[图片]`;
  201. case MessageType.VideoMessage:
  202. return `[视频]`;
  203. case MessageType.VoiceMessage:
  204. return `[语音]`;
  205. case MessageType.LocationMessage:
  206. return `[位置]`;
  207. case MessageType.CardMessage:
  208. return `[名片]`;
  209. case MessageType.MergeMessage:
  210. return `[聊天记录]`;
  211. case MessageType.FileMessage:
  212. return pmsg.fileElem.fileName;
  213. case MessageType.RevokeMessage:
  214. const data = JSON.parse(pmsg.notificationElem.detail);
  215. const revoker = isSelf(data.revokerID) ? "你" : data.revokerNickname;
  216. const sourcer = isSelf(data.sourceMessageSendID) ?
  217. "你" :
  218. data.sourceMessageSenderNickname;
  219. const isAdminRevoke = data.revokerID !== data.sourceMessageSendID;
  220. if (isAdminRevoke) {
  221. return `${revoker}撤回了一条${sourcer}的消息`;
  222. }
  223. return `${revoker}撤回了一条消息`;
  224. case MessageType.CustomMessage:
  225. const customEl = pmsg.customElem;
  226. const customData = JSON.parse(customEl.data);
  227. if (customData.customType) {
  228. return `${switchCustomMsg(customData)}`;
  229. }
  230. return `${switchCustomSysMsg(customData.payload)}`;
  231. case MessageType.QuoteMessage:
  232. return pmsg.quoteElem.text;
  233. case MessageType.FaceMessage:
  234. return `[表情]`;
  235. case MessageType.FriendAdded:
  236. return "你们已经是好友了,开始聊天吧~";
  237. case MessageType.MemberEnter:
  238. const enterDetails = JSON.parse(pmsg.notificationElem.detail);
  239. const enterUser = enterDetails.entrantUser;
  240. return `${getName(enterUser)}进入了群聊`;
  241. case MessageType.GroupCreated:
  242. const groupCreatedDetail = JSON.parse(pmsg.notificationElem.detail);
  243. const groupCreatedUser = groupCreatedDetail.opUser;
  244. return `${getName(groupCreatedUser)}创建了群聊`;
  245. case MessageType.MemberInvited:
  246. const inviteDetails = JSON.parse(pmsg.notificationElem.detail);
  247. const inviteOpUser = inviteDetails.opUser;
  248. const invitedUserList = inviteDetails.invitedUserList ?? [];
  249. let inviteStr = "";
  250. invitedUserList.find(
  251. (user, idx) => (inviteStr += getName(user) + "、") && idx > 3,
  252. );
  253. inviteStr = inviteStr.slice(0, -1);
  254. return `${getName(inviteOpUser)}邀请了${inviteStr}${
  255. invitedUserList.length > 3 ? "..." : ""
  256. }进入群聊`;
  257. case MessageType.MemberKicked:
  258. const kickDetails = JSON.parse(pmsg.notificationElem.detail);
  259. const kickOpUser = kickDetails.opUser;
  260. const kickdUserList = kickDetails.kickedUserList ?? [];
  261. let kickStr = "";
  262. kickdUserList.find(
  263. (user, idx) => (kickStr += getName(user) + "、") && idx > 3,
  264. );
  265. kickStr = kickStr.slice(0, -1);
  266. return `${getName(kickOpUser)}踢出了${kickStr}${
  267. kickdUserList.length > 3 ? "..." : ""
  268. }`;
  269. case MessageType.MemberQuit:
  270. const quitDetails = JSON.parse(pmsg.notificationElem.detail);
  271. const quitUser = quitDetails.quitUser;
  272. return `${getName(quitUser)}退出了群聊`;
  273. case MessageType.GroupInfoUpdated:
  274. const groupUpdateDetail = JSON.parse(pmsg.notificationElem.detail);
  275. const groupUpdateUser = groupUpdateDetail.opUser;
  276. let updateFiled = "群设置";
  277. if (groupUpdateDetail.group.notification) {
  278. updateFiled = "群公告";
  279. }
  280. if (groupUpdateDetail.group.groupName) {
  281. updateFiled = `群名称为 ${groupUpdateDetail.group.groupName}`;
  282. }
  283. if (groupUpdateDetail.group.faceURL) {
  284. updateFiled = "群头像";
  285. }
  286. if (groupUpdateDetail.group.introduction) {
  287. updateFiled = "群介绍";
  288. }
  289. return `${getName(groupUpdateUser)}修改了${updateFiled}`;
  290. case MessageType.GroupOwnerTransferred:
  291. const transferDetails = JSON.parse(pmsg.notificationElem.detail);
  292. const transferOpUser = transferDetails.opUser;
  293. const newOwner = transferDetails.newGroupOwner;
  294. return `${getName(transferOpUser)}将群主转让给${getName(newOwner)}`;
  295. case MessageType.GroupDismissed:
  296. const dismissDetails = JSON.parse(pmsg.notificationElem.detail);
  297. const dismissUser = dismissDetails.opUser;
  298. return `${getName(dismissUser)}解散了群聊`;
  299. case MessageType.GroupMuted:
  300. const GROUPMUTEDDetails = JSON.parse(pmsg.notificationElem.detail);
  301. const groupMuteOpUser = GROUPMUTEDDetails.opUser;
  302. return `${getName(groupMuteOpUser)}开启了全体禁言`;
  303. case MessageType.GroupCancelMuted:
  304. const GROUPCANCELMUTEDDetails = JSON.parse(pmsg.notificationElem.detail);
  305. const groupCancelMuteOpUser = GROUPCANCELMUTEDDetails.opUser;
  306. return `${getName(groupCancelMuteOpUser)}取消了全体禁言`;
  307. case MessageType.GroupMemberMuted:
  308. const gmMutedDetails = JSON.parse(pmsg.notificationElem.detail);
  309. const muteTime = sec2Time(gmMutedDetails.mutedSeconds);
  310. return `${getName(gmMutedDetails.opUser)}禁言了${getName(
  311. gmMutedDetails.mutedUser,
  312. )} ${muteTime}`;
  313. case MessageType.GroupMemberCancelMuted:
  314. const gmcMutedDetails = JSON.parse(pmsg.notificationElem.detail);
  315. return `${getName(gmcMutedDetails.opUser)}取消了禁言${getName(
  316. gmcMutedDetails.mutedUser,
  317. )}`;
  318. case MessageType.GroupAnnouncementUpdated:
  319. const groupAnnouncementUpdateDetail = JSON.parse(
  320. pmsg.notificationElem.detail,
  321. );
  322. const groupAnnouncementUpdateUser = groupAnnouncementUpdateDetail.opUser;
  323. return `${getName(groupAnnouncementUpdateUser)}修改了群公告`;
  324. case MessageType.GroupNameUpdated:
  325. const groupNameUpdateDetail = JSON.parse(pmsg.notificationElem.detail);
  326. const groupNameUpdateUser = groupNameUpdateDetail.opUser;
  327. return `${getName(groupNameUpdateUser)}修改了群名称为${
  328. groupNameUpdateDetail.group.groupName
  329. }`;
  330. case MessageType.OANotification:
  331. const customNoti = JSON.parse(pmsg.notificationElem.detail);
  332. return customNoti.text;
  333. case MessageType.BurnMessageChange:
  334. const burnDetails = JSON.parse(pmsg.notificationElem.detail);
  335. return `阅后即焚已${burnDetails.isPrivate ? "开启" : "关闭"}`;
  336. default:
  337. return "";
  338. }
  339. };
  340. export const formatConversionTime = (timestemp) => {
  341. return caculateTimeago(timestemp, 0);
  342. // const fromNowStr = dayjs(timestemp).fromNow();
  343. // console.log("qxj formatConversionTime fromNowStr:"+fromNowStr);
  344. // if (fromNowStr.includes("秒")) {
  345. // return "刚刚";
  346. // }
  347. // if (!fromNowStr.includes("秒") && !fromNowStr.includes("分钟")) {
  348. // return dayjs(timestemp).calendar();
  349. // }
  350. // return fromNowStr;
  351. };
  352. export function caculateTimeago(dateTimeStamp, type) {
  353. const minute = 1000 * 60; // 把分,时,天,周,半个月,一个月用毫秒表示
  354. const hour = minute * 60;
  355. const day = hour * 24;
  356. const week = day * 7;
  357. const now = new Date().getTime(); // 获取当前时间毫秒
  358. const currentYear = new Date().getFullYear();
  359. let diffValue = now - dateTimeStamp; // 时间差
  360. const targetDate = new Date(dateTimeStamp);
  361. const timehours = targetDate.getHours().toString().padStart(2, '0');
  362. const timeminute = targetDate.getMinutes().toString().padStart(2, '0');
  363. let result = '';
  364. if (diffValue < 0) {
  365. diffValue = Math.abs(diffValue);
  366. }
  367. const minS = diffValue / 1000; // 计算时间差的秒
  368. const minC = diffValue / minute; // 计算时间差的分,时,天,周,月
  369. const hourC = diffValue / hour;
  370. const dayC = diffValue / day;
  371. const weekC = diffValue / week;
  372. if (weekC >= 1 && weekC < 2) {
  373. result = ` ${parseInt(`${weekC}`, 10)}周前`;
  374. } else if (dayC >= 1 && dayC <= 3) {
  375. result = ` ${parseInt(`${dayC}`, 10)}天前`;
  376. } else if (hourC >= 1 && hourC <= 23) {
  377. result = ` ${parseInt(`${hourC}`, 10)}小时前`;
  378. //result = `${timehours}:${timeminute}`;
  379. } else if (minC >= 1 && minC <= 59) {
  380. //result = ` ${parseInt(`${minC}`, 10)}分钟前`;
  381. result = ` ${timehours+":"+timeminute}`;
  382. } else if (diffValue >= 0 && diffValue <= minute) {
  383. // const num = parseInt(`${minS}`, 10)
  384. // if (num == 0) {
  385. // result = '刚刚';
  386. // } else {
  387. // result = ` ${parseInt(`${minS}`, 10)}秒前`;
  388. // }
  389. result = ` ${timehours+":"+timeminute}`;
  390. } else {
  391. // if (type == 1) {
  392. // result = '';
  393. // }
  394. // else {
  395. const datetime = new Date();
  396. datetime.setTime(dateTimeStamp);
  397. const Nyear = datetime.getFullYear();
  398. const Nmonth = datetime.getMonth() + 1 < 10 ? `0${datetime.getMonth() + 1}` : datetime.getMonth() + 1;
  399. const Ndate = datetime.getDate() < 10 ? `0${datetime.getDate()}` : datetime.getDate();
  400. return Nyear === currentYear ? `${Nmonth}月${Ndate}日` : `${Nyear}年${Nmonth}月${Ndate}日`;
  401. //}
  402. }
  403. return result;
  404. }
  405. export const secFormat = (sec) => {
  406. let h;
  407. let s;
  408. h = Math.floor(sec / 60);
  409. s = sec % 60;
  410. h += "";
  411. s += "";
  412. h = h.length === 1 ? "0" + h : h;
  413. s = s.length === 1 ? "0" + s : s;
  414. return h + ":" + s;
  415. };
  416. export const bytesToSize = (bytes) => {
  417. if (bytes === 0) return "0 B";
  418. var k = 1024,
  419. sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
  420. i = Math.floor(Math.log(bytes) / Math.log(k));
  421. return (bytes / Math.pow(k, i)).toPrecision(3) + " " + sizes[i];
  422. };
  423. export const tipMessaggeFormat = (msg, currentUserID) => {
  424. if (msg.contentType === MessageType.RevokeMessage) {
  425. let revoker, sourcer, isAdminRevoke;
  426. const data = JSON.parse(msg.notificationElem.detail);
  427. revoker = currentUserID === data.revokerID ? "你" : data.revokerNickname;
  428. isAdminRevoke = data.revokerID !== data.sourceMessageSendID;
  429. sourcer =
  430. data.sourceMessageSendID === currentUserID ?
  431. "你" :
  432. data.sourceMessageSenderNickname;
  433. if (isAdminRevoke) {
  434. return `${revoker}撤回了一条${sourcer}的消息`;
  435. }
  436. return `${revoker}撤回了一条消息`;
  437. }
  438. const getName = (user) =>
  439. user.userID === currentUserID ? "你" : user.nickname;
  440. const getUserID = (user) => user.userID;
  441. const parseInfo = (user) => formatHyperlink(getName(user), getUserID(user));
  442. switch (msg.contentType) {
  443. case MessageType.FriendAdded:
  444. return `你们已经是好友了~`;
  445. case MessageType.GroupCreated:
  446. const groupCreatedDetail = JSON.parse(msg.notificationElem.detail);
  447. const groupCreatedUser = groupCreatedDetail.opUser;
  448. return `${parseInfo(groupCreatedUser)}创建了群聊`;
  449. case MessageType.GroupInfoUpdated:
  450. const groupUpdateDetail = JSON.parse(msg.notificationElem.detail);
  451. const groupUpdateUser = groupUpdateDetail.opUser;
  452. let updateFiled = "群设置";
  453. if (groupUpdateDetail.group.notification) {
  454. updateFiled = "群公告";
  455. }
  456. if (groupUpdateDetail.group.groupName) {
  457. updateFiled = `群名称为 ${groupUpdateDetail.group.groupName}`;
  458. }
  459. if (groupUpdateDetail.group.faceURL) {
  460. updateFiled = "群头像";
  461. }
  462. if (groupUpdateDetail.group.introduction) {
  463. updateFiled = "群介绍";
  464. }
  465. return `${parseInfo(groupUpdateUser)}修改了${updateFiled}`;
  466. case MessageType.GroupOwnerTransferred:
  467. const transferDetails = JSON.parse(msg.notificationElem.detail);
  468. const transferOpUser = transferDetails.opUser;
  469. const newOwner = transferDetails.newGroupOwner;
  470. return `${parseInfo(transferOpUser)}转让群主给${parseInfo(newOwner)}`;
  471. case MessageType.MemberQuit:
  472. const quitDetails = JSON.parse(msg.notificationElem.detail);
  473. const quitUser = quitDetails.quitUser;
  474. return `${parseInfo(quitUser)}退出了群组`;
  475. case MessageType.MemberInvited:
  476. const inviteDetails = JSON.parse(msg.notificationElem.detail);
  477. const inviteOpUser = inviteDetails.opUser;
  478. const invitedUserList = inviteDetails.invitedUserList ?? [];
  479. let inviteStr = "";
  480. invitedUserList.find(
  481. (user, idx) => (inviteStr += parseInfo(user) + "、") && idx > 3,
  482. );
  483. inviteStr = inviteStr.slice(0, -1);
  484. return `${parseInfo(inviteOpUser)} 邀请了${inviteStr}${
  485. invitedUserList.length > 3 ? "..." : ""
  486. }加入群聊`;
  487. case MessageType.MemberKicked:
  488. const kickDetails = JSON.parse(msg.notificationElem.detail);
  489. const kickOpUser = kickDetails.opUser;
  490. const kickdUserList = kickDetails.kickedUserList ?? [];
  491. let kickStr = "";
  492. kickdUserList.find(
  493. (user, idx) => (kickStr += parseInfo(user) + "、") && idx > 3,
  494. );
  495. kickStr = kickStr.slice(0, -1);
  496. return `${parseInfo(kickOpUser)} 踢出了${kickStr}${
  497. kickdUserList.length > 3 ? "..." : ""
  498. }`;
  499. case MessageType.MemberEnter:
  500. const enterDetails = JSON.parse(msg.notificationElem.detail);
  501. const enterUser = enterDetails.entrantUser;
  502. return `${parseInfo(enterUser)}加入了群聊`;
  503. case MessageType.GroupDismissed:
  504. const dismissDetails = JSON.parse(msg.notificationElem.detail);
  505. const dismissUser = dismissDetails.opUser;
  506. return `${parseInfo(dismissUser)}解散了群聊`;
  507. case MessageType.GroupMuted:
  508. const groupMutedDetails = JSON.parse(msg.notificationElem.detail);
  509. const groupMuteOpUser = groupMutedDetails.opUser;
  510. return `${parseInfo(groupMuteOpUser)}开启了全体禁言`;
  511. case MessageType.GroupCancelMuted:
  512. const groupCancelMutedDetails = JSON.parse(msg.notificationElem.detail);
  513. const groupCancelMuteOpUser = groupCancelMutedDetails.opUser;
  514. return `${parseInfo(groupCancelMuteOpUser)}关闭了全体禁言`;
  515. case MessageType.GroupMemberMuted:
  516. const gmMutedDetails = JSON.parse(msg.notificationElem.detail);
  517. const muteTime = sec2Time(gmMutedDetails.mutedSeconds);
  518. return `${parseInfo(gmMutedDetails.opUser)}禁言了${parseInfo(
  519. gmMutedDetails.mutedUser,
  520. )} ${muteTime}`;
  521. case MessageType.GroupMemberCancelMuted:
  522. const gmcMutedDetails = JSON.parse(msg.notificationElem.detail);
  523. return `${parseInfo(gmcMutedDetails.opUser)}取消了禁言${parseInfo(
  524. gmcMutedDetails.mutedUser,
  525. )}`;
  526. case MessageType.GroupNameUpdated:
  527. const groupNameUpdateDetail = JSON.parse(msg.notificationElem.detail);
  528. const groupNameUpdateUser = groupNameUpdateDetail.opUser;
  529. return `${parseInfo(groupNameUpdateUser)}修改了群名称为${
  530. groupNameUpdateDetail.group.groupName
  531. }`;
  532. case MessageType.BurnMessageChange:
  533. const burnDetails = JSON.parse(msg.notificationElem.detail);
  534. return `阅后即焚已${burnDetails.isPrivate ? "开启" : "关闭"}`;
  535. case MessageType.OANotification:
  536. const customNoti = JSON.parse(msg.notificationElem.detail);
  537. return customNoti.text;
  538. default:
  539. return "";
  540. }
  541. };
  542. export const getDesignatedUserOnlineState = (userID, targetID) => {
  543. return new Promise(async (resolve, reject) => {
  544. let status = 0;
  545. try {
  546. const data = await subUserOnlineStatus(userID, targetID);
  547. status = data.statusList[0].status;
  548. } catch (e) {
  549. reject(e);
  550. }
  551. // const onlineStr = switchOnline(
  552. // statusObj.status,
  553. // statusObj.detailPlatformStatus
  554. // );
  555. const onlineStr = status ? "在线" : "离线";
  556. resolve(onlineStr);
  557. });
  558. };
  559. export const markConversationAsRead = (conversation, fromChating = false) => {
  560. if (conversation.unreadCount !== 0) {
  561. IMSDK.asyncApi(
  562. IMSDK.IMMethods.MarkConversationMessageAsRead,
  563. IMSDK.uuid(),
  564. conversation.conversationID,
  565. );
  566. }
  567. const isNomalAtType = nomalTypes.includes(conversation.groupAtType);
  568. if (isNomalAtType) {
  569. console.log('ResetConversationGroupAtType', conversation.conversationID)
  570. IMSDK.asyncApi(
  571. IMSDK.IMMethods.ResetConversationGroupAtType,
  572. IMSDK.uuid(),
  573. conversation.conversationID,
  574. );
  575. }
  576. };
  577. export const prepareConversationState = (conversation, back2Tab = false, refreshChat = true) => {
  578. markConversationAsRead(conversation);
  579. if (conversation.conversationType === SessionType.WorkingGroup) {
  580. store.dispatch("conversation/getCurrentGroup", conversation.groupID);
  581. store.dispatch("conversation/getCurrentMemberInGroup", conversation.groupID);
  582. }
  583. store.dispatch("message/resetMessageState");
  584. store.commit("conversation/SET_CURRENT_CONVERSATION", conversation);
  585. let str = '/'
  586. // #ifdef APP-PLUS
  587. if (!conversation.sourceTypeList) {
  588. str = ''
  589. }
  590. // #endif
  591. let url = `${str}pages_im/pages/conversation/chating/index?back2Tab=${back2Tab}`;
  592. if (conversation.conversationType === SessionType.Notification) {
  593. url = "/pages_im/pages/conversation/notifyMessageList/index";
  594. }
  595. uni.navigateTo({
  596. url
  597. });
  598. };
  599. export const navigateToDesignatedConversation = (sourceID, sessionType, back2Tab = false, refreshChat = true) => {
  600. console.log("qxj navigateToDesignatedConversation back2Tab", back2Tab);
  601. return new Promise(async (resolve, reject) => {
  602. try {
  603. const {
  604. data
  605. } = await IMSDK.asyncApi(
  606. IMSDK.IMMethods.GetOneConversation,
  607. IMSDK.uuid(), {
  608. sessionType,
  609. sourceID
  610. }
  611. );
  612. prepareConversationState(data, back2Tab);
  613. resolve(data);
  614. } catch (e) {
  615. reject(e);
  616. }
  617. });
  618. };
  619. export const setConversation = (conversationID, exStr) => {
  620. return new Promise(async (resolve, reject) => {
  621. try {
  622. const {
  623. data
  624. } = await IMSDK.asyncApi(
  625. IMSDK.IMMethods.SetConversation,
  626. IMSDK.uuid(), {
  627. conversationID: conversationID,
  628. isPinned: false,
  629. ex: exStr
  630. }
  631. );
  632. console.log("qxj data:" + JSON.stringify(data));
  633. resolve();
  634. } catch (e) {
  635. reject(e);
  636. }
  637. });
  638. };
  639. export const scanQrCodeResult = (result) => {
  640. if (result?.includes(AddFriendQrCodePrefix)) {
  641. const userID = result.replace(AddFriendQrCodePrefix, "");
  642. uni.navigateTo({
  643. url: `/pages_im/pages/common/userCard/index?sourceID=${userID}&isScan=true`,
  644. });
  645. } else if (result?.includes(AddGroupQrCodePrefix)) {
  646. const groupID = result.replace(AddGroupQrCodePrefix, "");
  647. uni.navigateTo({
  648. url: `/pages_im/pages/common/groupCard/index?sourceID=${groupID}&isScan=true`,
  649. });
  650. } else {
  651. uni.$u.toast("未识别到有效内容");
  652. setTimeout(() => {
  653. uni.$emit("refreshScan", 1);
  654. }, 1500);
  655. }
  656. };
  657. export const callingModule = uni.requireNativePlugin("OUICalling");
  658. export const meetingModule = uni.requireNativePlugin("OUIMeeting");
  659. export const offlinePushInfo = {
  660. title: "好生活福满多",
  661. desc: "您有一条新消息",
  662. ex: "",
  663. iOSPushSound: "",
  664. iOSBadgeCount: true,
  665. };
  666. export const getOfflinePushInfo = (data) => {
  667. }
  668. export const getConversationContent = (message) => {
  669. if (
  670. !message.groupID ||
  671. GroupSystemMessageTypes.includes(message.contentType) ||
  672. message.sendID === store.getters.storeCurrentUserID ||
  673. message.contentType === MessageType.GroupAnnouncementUpdated
  674. ) {
  675. return parseMessageByType(message);
  676. }
  677. return `${message.senderNickname}:${parseMessageByType(message)}`;
  678. };
  679. export const meetingErrorHandle = ({
  680. errCode,
  681. errMsg
  682. }) => {
  683. let message = ""
  684. if (errCode === 1004) {
  685. message = "会议已结束或会议不存在!"
  686. } else if (errCode === 200001) {
  687. message = "您已在其他会议中!"
  688. }
  689. uni.$u.toast(message || errMsg);
  690. }