imUtils.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. import {
  2. CustomType,
  3. } from "@/pages_im/constant";
  4. import {
  5. GroupAtType,
  6. MessageType,
  7. } from "@/pages_im/constant/imConstants";
  8. import dayjs from "dayjs";
  9. import {
  10. isThisYear
  11. } from "date-fns";
  12. import calendar from "dayjs/plugin/calendar";
  13. import relativeTime from "dayjs/plugin/relativeTime";
  14. import updateLocale from "dayjs/plugin/updateLocale";
  15. import "dayjs/locale/zh-cn";
  16. // 延迟引入 store,避免循环依赖和初始化阻塞
  17. let store;
  18. const getStore = () => {
  19. if (!store) {
  20. try {
  21. store = require('@/store').default;
  22. } catch (e) {
  23. console.warn("Store require failed in imUtils", e);
  24. }
  25. }
  26. return store;
  27. };
  28. // 延迟初始化 dayjs,避免 import 时立即执行带来的开销
  29. let dayjsInitialized = false;
  30. const initDayjs = () => {
  31. if (dayjsInitialized) return;
  32. dayjs.extend(calendar);
  33. dayjs.extend(relativeTime);
  34. dayjs.extend(updateLocale);
  35. dayjs.locale("zh-cn");
  36. dayjs.updateLocale("en", {
  37. calendar: {
  38. sameElse: "YYYY-MM-DD",
  39. },
  40. });
  41. dayjs.updateLocale("zh-cn", {
  42. calendar: {
  43. sameDay: "HH:mm",
  44. nextDay: "[明天]",
  45. nextWeek: "dddd",
  46. lastDay: "[昨天] HH:mm",
  47. lastWeek: "dddd HH:mm",
  48. sameElse: "YYYY年M月D日 HH:mm",
  49. },
  50. });
  51. dayjsInitialized = true;
  52. };
  53. export const formatMessageTime = (timestemp, keepSameYear = false) => {
  54. initDayjs();
  55. if (!timestemp) return "";
  56. const isRecent = dayjs().diff(timestemp, "day") < 7;
  57. const keepYear = keepSameYear || !isThisYear(timestemp);
  58. if (!isRecent && !keepYear) {
  59. return dayjs(timestemp).format("M月D日 HH:mm");
  60. }
  61. return dayjs(timestemp).calendar();
  62. };
  63. export const formatTime = (time, format) => {
  64. initDayjs();
  65. return dayjs(time).format(format);
  66. };
  67. export const formatHyperlink = (nickname, currentUserID) => {
  68. return `<a href="${currentUserID}" style="color:#0089FF; text-decoration:none;">${nickname}</a>`;
  69. };
  70. const regex = /\b(http[s]?:\/\/[^\s]+)\b/g;
  71. export const parseLink = (content) =>
  72. content.replace(regex, (match) => formatHyperlink(match, match));
  73. export const conversationSort = (conversationList) => {
  74. const arr = [];
  75. const filterArr = conversationList.filter(
  76. (c) => !arr.includes(c.conversationID) && arr.push(c.conversationID),
  77. );
  78. filterArr.sort((a, b) => {
  79. if (a.isPinned === b.isPinned) {
  80. const aCompare =
  81. a.draftTextTime > a.latestMsgSendTime ?
  82. a.draftTextTime :
  83. a.latestMsgSendTime;
  84. const bCompare =
  85. b.draftTextTime > b.latestMsgSendTime ?
  86. b.draftTextTime :
  87. b.latestMsgSendTime;
  88. if (aCompare > bCompare) {
  89. return -1;
  90. } else if (aCompare < bCompare) {
  91. return 1;
  92. } else {
  93. return 0;
  94. }
  95. } else if (a.isPinned && !b.isPinned) {
  96. return -1;
  97. } else {
  98. return 1;
  99. }
  100. });
  101. return filterArr;
  102. };
  103. export const parseAt = (atel, isParse = false) => {
  104. let mstr = atel.text;
  105. const pattern = /@\S+\s/g;
  106. const arr = mstr.match(pattern);
  107. const atUsersInfo = atel.atUsersInfo ?? [];
  108. arr?.map((match) => {
  109. const member = atUsersInfo.find(
  110. (user) => user.atUserID === match.slice(1, -1),
  111. );
  112. if (member && !isParse) {
  113. mstr = mstr.replace(
  114. match,
  115. formatHyperlink(`@${member.groupNickname} `, member.atUserID),
  116. );
  117. } else {
  118. mstr = mstr.replace(match, `@${member.groupNickname} `);
  119. }
  120. });
  121. return mstr;
  122. };
  123. const switchCustomMsg = (cMsg) => {
  124. switch (cMsg.customType) {
  125. case CustomType.MassMsg:
  126. return "[群发通知]";
  127. case CustomType.Call:
  128. return "[通话消息]";
  129. case CustomType.MeetingInvitation:
  130. return "[会议邀请]";
  131. default:
  132. return "";
  133. }
  134. };
  135. const switchCustomSysMsg = (payload) => {
  136. switch (payload.data) {
  137. case "startInquiry":
  138. return "[开始问诊]";
  139. case "startFollow":
  140. return "[开始随访]";
  141. case "finishInquiry":
  142. return "[结束问诊]";
  143. case "finishFollow":
  144. return "[结束随访]";
  145. case "order":
  146. return "[问诊订单]";
  147. case "prescribe":
  148. return "[电子处方单]";
  149. case "report":
  150. return "[问诊报告单]";
  151. case "follow":
  152. return "[随访单]";
  153. case "drugReport":
  154. return "[用药报告单]";
  155. case "package":
  156. return "[疗法消息]";
  157. case "couponPackage":
  158. return "[私域疗法券]";
  159. case "inquirySelect":
  160. return "[会诊消息]";
  161. case "course":
  162. return payload?.extension?.title || "[看课消息]";
  163. case "luckyBag":
  164. return "[福袋消息]";
  165. case "live":
  166. return "[直播消息]";
  167. default:
  168. return "[自定义消息]";
  169. }
  170. };
  171. export const sec2Time = (seconds) => {
  172. var theTime1 = 0; // min
  173. var theTime2 = 0; // hour
  174. var theTime3 = 0; // day
  175. if (seconds > 60) {
  176. theTime1 = parseInt(seconds / 60);
  177. seconds = parseInt(seconds % 60);
  178. if (theTime1 > 60) {
  179. theTime2 = parseInt(theTime1 / 60);
  180. theTime1 = parseInt(theTime1 % 60);
  181. if (theTime2 > 24) {
  182. theTime3 = parseInt(theTime2 / 24);
  183. theTime2 = parseInt(theTime2 % 24);
  184. }
  185. }
  186. }
  187. var result = "";
  188. if (seconds > 0) {
  189. result = "" + parseInt(seconds) + "秒";
  190. }
  191. if (theTime1 > 0) {
  192. result = "" + parseInt(theTime1) + "分钟" + result;
  193. }
  194. if (theTime2 > 0) {
  195. result = "" + parseInt(theTime2) + "小时" + result;
  196. }
  197. if (theTime3 > 0) {
  198. result = "" + parseInt(theTime3) + "天" + result;
  199. }
  200. return result;
  201. };
  202. export const parseMessageByType = (pmsg, currentUserID) => {
  203. let myID = currentUserID;
  204. let currentStore;
  205. if (!myID) {
  206. try {
  207. currentStore = getStore();
  208. if (currentStore && currentStore.getters) {
  209. myID = currentStore.getters.storeCurrentUserID;
  210. }
  211. } catch (e) {
  212. // console.warn("Store not available in parseMessageByType");
  213. }
  214. }
  215. const isSelf = (id) => id === myID;
  216. const getName = (user) => {
  217. return user.userID === myID ? "你" : user.nickname;
  218. };
  219. switch (pmsg.contentType) {
  220. case MessageType.TextMessage:
  221. return pmsg.textElem.content;
  222. case MessageType.AtTextMessage:
  223. return parseAt(pmsg.atTextElem, true);
  224. case MessageType.PictureMessage:
  225. return `[图片]`;
  226. case MessageType.VideoMessage:
  227. return `[视频]`;
  228. case MessageType.VoiceMessage:
  229. return `[语音]`;
  230. case MessageType.LocationMessage:
  231. return `[位置]`;
  232. case MessageType.CardMessage:
  233. return `[名片]`;
  234. case MessageType.MergeMessage:
  235. return `[聊天记录]`;
  236. case MessageType.FileMessage:
  237. return pmsg.fileElem.fileName;
  238. case MessageType.RevokeMessage:
  239. const data = JSON.parse(pmsg.notificationElem.detail);
  240. const revoker = isSelf(data.revokerID) ? "你" : data.revokerNickname;
  241. const sourcer = isSelf(data.sourceMessageSendID) ?
  242. "你" :
  243. data.sourceMessageSenderNickname;
  244. const isAdminRevoke = data.revokerID !== data.sourceMessageSendID;
  245. if (isAdminRevoke) {
  246. return `${revoker}撤回了一条${sourcer}的消息`;
  247. }
  248. return `${revoker}撤回了一条消息`;
  249. case MessageType.CustomMessage:
  250. const customEl = pmsg.customElem;
  251. const customData = JSON.parse(customEl.data);
  252. if (customData.customType) {
  253. return `${switchCustomMsg(customData)}`;
  254. }
  255. return `${switchCustomSysMsg(customData.payload)}`;
  256. case MessageType.QuoteMessage:
  257. return pmsg.quoteElem.text;
  258. case MessageType.FaceMessage:
  259. return `[表情]`;
  260. case MessageType.FriendAdded:
  261. return "你们已经是好友了,开始聊天吧~";
  262. case MessageType.MemberEnter:
  263. const enterDetails = JSON.parse(pmsg.notificationElem.detail);
  264. const enterUser = enterDetails.entrantUser;
  265. return `${getName(enterUser)}进入了群聊`;
  266. case MessageType.GroupCreated:
  267. const groupCreatedDetail = JSON.parse(pmsg.notificationElem.detail);
  268. const groupCreatedUser = groupCreatedDetail.opUser;
  269. return `${getName(groupCreatedUser)}创建了群聊`;
  270. case MessageType.MemberInvited:
  271. const inviteDetails = JSON.parse(pmsg.notificationElem.detail);
  272. const inviteOpUser = inviteDetails.opUser;
  273. const invitedUserList = inviteDetails.invitedUserList ?? [];
  274. let inviteStr = "";
  275. invitedUserList.find(
  276. (user, idx) => (inviteStr += getName(user) + "、") && idx > 3,
  277. );
  278. inviteStr = inviteStr.slice(0, -1);
  279. return `${getName(inviteOpUser)}邀请了${inviteStr}${
  280. invitedUserList.length > 3 ? "..." : ""
  281. }进入群聊`;
  282. case MessageType.MemberKicked:
  283. const kickDetails = JSON.parse(pmsg.notificationElem.detail);
  284. const kickOpUser = kickDetails.opUser;
  285. const kickdUserList = kickDetails.kickedUserList ?? [];
  286. let kickStr = "";
  287. kickdUserList.find(
  288. (user, idx) => (kickStr += getName(user) + "、") && idx > 3,
  289. );
  290. kickStr = kickStr.slice(0, -1);
  291. return `${getName(kickOpUser)}踢出了${kickStr}${
  292. kickdUserList.length > 3 ? "..." : ""
  293. }`;
  294. case MessageType.MemberQuit:
  295. const quitDetails = JSON.parse(pmsg.notificationElem.detail);
  296. const quitUser = quitDetails.quitUser;
  297. return `${getName(quitUser)}退出了群聊`;
  298. case MessageType.GroupInfoUpdated:
  299. const groupUpdateDetail = JSON.parse(pmsg.notificationElem.detail);
  300. const groupUpdateUser = groupUpdateDetail.opUser;
  301. let updateFiled = "群设置";
  302. if (groupUpdateDetail.group.notification) {
  303. updateFiled = "群公告";
  304. }
  305. if (groupUpdateDetail.group.groupName) {
  306. updateFiled = `群名称为 ${groupUpdateDetail.group.groupName}`;
  307. }
  308. if (groupUpdateDetail.group.faceURL) {
  309. updateFiled = "群头像";
  310. }
  311. if (groupUpdateDetail.group.introduction) {
  312. updateFiled = "群介绍";
  313. }
  314. return `${getName(groupUpdateUser)}修改了${updateFiled}`;
  315. case MessageType.GroupOwnerTransferred:
  316. const transferDetails = JSON.parse(pmsg.notificationElem.detail);
  317. const transferOpUser = transferDetails.opUser;
  318. const newOwner = transferDetails.newGroupOwner;
  319. return `${getName(transferOpUser)}将群主转让给${getName(newOwner)}`;
  320. case MessageType.GroupDismissed:
  321. const dismissDetails = JSON.parse(pmsg.notificationElem.detail);
  322. const dismissUser = dismissDetails.opUser;
  323. return `${getName(dismissUser)}解散了群聊`;
  324. case MessageType.GroupMuted:
  325. const GROUPMUTEDDetails = JSON.parse(pmsg.notificationElem.detail);
  326. const groupMuteOpUser = GROUPMUTEDDetails.opUser;
  327. return `${getName(groupMuteOpUser)}开启了全体禁言`;
  328. case MessageType.GroupCancelMuted:
  329. const GROUPCANCELMUTEDDetails = JSON.parse(pmsg.notificationElem.detail);
  330. const groupCancelMuteOpUser = GROUPCANCELMUTEDDetails.opUser;
  331. return `${getName(groupCancelMuteOpUser)}取消了全体禁言`;
  332. case MessageType.GroupMemberMuted:
  333. const gmMutedDetails = JSON.parse(pmsg.notificationElem.detail);
  334. const muteTime = sec2Time(gmMutedDetails.mutedSeconds);
  335. return `${getName(gmMutedDetails.opUser)}禁言了${getName(
  336. gmMutedDetails.mutedUser,
  337. )} ${muteTime}`;
  338. case MessageType.GroupMemberCancelMuted:
  339. const gmcMutedDetails = JSON.parse(pmsg.notificationElem.detail);
  340. return `${getName(gmcMutedDetails.opUser)}取消了禁言${getName(
  341. gmcMutedDetails.mutedUser,
  342. )}`;
  343. case MessageType.GroupAnnouncementUpdated:
  344. const groupAnnouncementUpdateDetail = JSON.parse(
  345. pmsg.notificationElem.detail,
  346. );
  347. const groupAnnouncementUpdateUser = groupAnnouncementUpdateDetail.opUser;
  348. return `${getName(groupAnnouncementUpdateUser)}修改了群公告`;
  349. case MessageType.GroupNameUpdated:
  350. const groupNameUpdateDetail = JSON.parse(pmsg.notificationElem.detail);
  351. const groupNameUpdateUser = groupNameUpdateDetail.opUser;
  352. return `${getName(groupNameUpdateUser)}修改了群名称为${
  353. groupNameUpdateDetail.group.groupName
  354. }`;
  355. case MessageType.OANotification:
  356. const customNoti = JSON.parse(pmsg.notificationElem.detail);
  357. return customNoti.text;
  358. case MessageType.BurnMessageChange:
  359. const burnDetails = JSON.parse(pmsg.notificationElem.detail);
  360. return `阅后即焚已${burnDetails.isPrivate ? "开启" : "关闭"}`;
  361. default:
  362. return "";
  363. }
  364. };
  365. export function caculateTimeago(dateTimeStamp, type) {
  366. initDayjs();
  367. const minute = 1000 * 60; // 把分,时,天,周,半个月,一个月用毫秒表示
  368. const hour = minute * 60;
  369. const day = hour * 24;
  370. const week = day * 7;
  371. const now = new Date().getTime(); // 获取当前时间毫秒
  372. const currentYear = new Date().getFullYear();
  373. let diffValue = now - dateTimeStamp; // 时间差
  374. const targetDate = new Date(dateTimeStamp);
  375. const timehours = targetDate.getHours().toString().padStart(2, '0');
  376. const timeminute = targetDate.getMinutes().toString().padStart(2, '0');
  377. let result = '';
  378. if (diffValue < 0) {
  379. diffValue=Math.abs(diffValue);
  380. }
  381. const minS = diffValue / 1000; // 计算时间差的秒
  382. const minC = diffValue / minute; // 计算时间差的分,时,天,周,月
  383. const hourC = diffValue / hour;
  384. const dayC = diffValue / day;
  385. const weekC = diffValue / week;
  386. //console.log("qxj minC:"+minC+" hourC:"+hourC+" dayC:"+dayC+" weekC:"+weekC);
  387. if (weekC >= 1 && weekC <= 4) {
  388. result = ` ${parseInt(`${weekC}`, 10)}周前`;
  389. }
  390. else if (dayC >= 1 && dayC <= 6) {
  391. result = ` ${parseInt(`${dayC}`, 10)}天前`;
  392. } else if (hourC >= 1 && hourC <= 23) {
  393. result = ` ${parseInt(`${hourC}`, 10)}小时前`;
  394. //result = `${timehours}:${timeminute}`;
  395. }
  396. else if (minC >= 1 && minC <= 59) {
  397. //result = ` ${parseInt(`${minC}`, 10)}分钟前`;
  398. result = ` ${timehours+":"+timeminute}`;
  399. }
  400. else if (diffValue >= 0 && diffValue <= minute) {
  401. result = ` ${timehours+":"+timeminute}`;
  402. }
  403. else {
  404. const datetime = new Date();
  405. datetime.setTime(dateTimeStamp);
  406. const Nyear = datetime.getFullYear();
  407. const Nmonth = datetime.getMonth() + 1 < 10 ? `0${datetime.getMonth() + 1}` : datetime.getMonth() + 1;
  408. const Ndate = datetime.getDate() < 10 ? `0${datetime.getDate()}` : datetime.getDate();
  409. return Nyear === currentYear ? `${Nmonth}月${Ndate}日` : `${Nyear}年${Nmonth}月${Ndate}日`;
  410. }
  411. return result;
  412. }
  413. export const formatConversionTime = (timestemp) => {
  414. return caculateTimeago(timestemp, 0);
  415. };
  416. export const secFormat = (sec) => {
  417. let h;
  418. let s;
  419. h = Math.floor(sec / 60);
  420. s = sec % 60;
  421. h += "";
  422. s += "";
  423. h = h.length === 1 ? "0" + h : h;
  424. s = s.length === 1 ? "0" + s : s;
  425. return h + ":" + s;
  426. };
  427. export const bytesToSize = (bytes) => {
  428. if (bytes === 0) return "0 B";
  429. var k = 1024,
  430. sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
  431. i = Math.floor(Math.log(bytes) / Math.log(k));
  432. return (bytes / Math.pow(k, i)).toPrecision(3) + " " + sizes[i];
  433. };
  434. export const tipMessaggeFormat = (msg, currentUserID) => {
  435. if (msg.contentType === MessageType.RevokeMessage) {
  436. let revoker, sourcer, isAdminRevoke;
  437. const data = JSON.parse(msg.notificationElem.detail);
  438. revoker = currentUserID === data.revokerID ? "你" : data.revokerNickname;
  439. isAdminRevoke = data.revokerID !== data.sourceMessageSendID;
  440. sourcer =
  441. data.sourceMessageSendID === currentUserID ?
  442. "你" :
  443. data.sourceMessageSenderNickname;
  444. if (isAdminRevoke) {
  445. return `${revoker}撤回了一条${sourcer}的消息`;
  446. }
  447. return `${revoker}撤回了一条消息`;
  448. }
  449. const getName = (user) =>
  450. user.userID === currentUserID ? "你" : user.nickname;
  451. const getUserID = (user) => user.userID;
  452. const parseInfo = (user) => formatHyperlink(getName(user), getUserID(user));
  453. switch (msg.contentType) {
  454. case MessageType.FriendAdded:
  455. return `你们已经是好友了~`;
  456. case MessageType.GroupCreated:
  457. const groupCreatedDetail = JSON.parse(msg.notificationElem.detail);
  458. const groupCreatedUser = groupCreatedDetail.opUser;
  459. return `${parseInfo(groupCreatedUser)}创建了群聊`;
  460. case MessageType.GroupInfoUpdated:
  461. const groupUpdateDetail = JSON.parse(msg.notificationElem.detail);
  462. const groupUpdateUser = groupUpdateDetail.opUser;
  463. let updateFiled = "群设置";
  464. if (groupUpdateDetail.group.notification) {
  465. updateFiled = "群公告";
  466. }
  467. if (groupUpdateDetail.group.groupName) {
  468. updateFiled = `群名称为 ${groupUpdateDetail.group.groupName}`;
  469. }
  470. if (groupUpdateDetail.group.faceURL) {
  471. updateFiled = "群头像";
  472. }
  473. if (groupUpdateDetail.group.introduction) {
  474. updateFiled = "群介绍";
  475. }
  476. return `${parseInfo(groupUpdateUser)}修改了${updateFiled}`;
  477. case MessageType.GroupOwnerTransferred:
  478. const transferDetails = JSON.parse(msg.notificationElem.detail);
  479. const transferOpUser = transferDetails.opUser;
  480. const newOwner = transferDetails.newGroupOwner;
  481. return `${parseInfo(transferOpUser)}转让群主给${parseInfo(newOwner)}`;
  482. case MessageType.MemberQuit:
  483. const quitDetails = JSON.parse(msg.notificationElem.detail);
  484. const quitUser = quitDetails.quitUser;
  485. return `${parseInfo(quitUser)}退出了群组`;
  486. case MessageType.MemberInvited:
  487. const inviteDetails = JSON.parse(msg.notificationElem.detail);
  488. const inviteOpUser = inviteDetails.opUser;
  489. const invitedUserList = inviteDetails.invitedUserList ?? [];
  490. let inviteStr = "";
  491. invitedUserList.find(
  492. (user, idx) => (inviteStr += parseInfo(user) + "、") && idx > 3,
  493. );
  494. inviteStr = inviteStr.slice(0, -1);
  495. return `${parseInfo(inviteOpUser)} 邀请了${inviteStr}${
  496. invitedUserList.length > 3 ? "..." : ""
  497. }加入群聊`;
  498. case MessageType.MemberKicked:
  499. const kickDetails = JSON.parse(msg.notificationElem.detail);
  500. const kickOpUser = kickDetails.opUser;
  501. const kickdUserList = kickDetails.kickedUserList ?? [];
  502. let kickStr = "";
  503. kickdUserList.find(
  504. (user, idx) => (kickStr += parseInfo(user) + "、") && idx > 3,
  505. );
  506. kickStr = kickStr.slice(0, -1);
  507. return `${parseInfo(kickOpUser)} 踢出了${kickStr}${
  508. kickdUserList.length > 3 ? "..." : ""
  509. }`;
  510. case MessageType.MemberEnter:
  511. const enterDetails = JSON.parse(msg.notificationElem.detail);
  512. const enterUser = enterDetails.entrantUser;
  513. return `${parseInfo(enterUser)}加入了群聊`;
  514. case MessageType.GroupDismissed:
  515. const dismissDetails = JSON.parse(msg.notificationElem.detail);
  516. const dismissUser = dismissDetails.opUser;
  517. return `${parseInfo(dismissUser)}解散了群聊`;
  518. case MessageType.GroupMuted:
  519. const groupMutedDetails = JSON.parse(msg.notificationElem.detail);
  520. const groupMuteOpUser = groupMutedDetails.opUser;
  521. return `${parseInfo(groupMuteOpUser)}开启了全体禁言`;
  522. case MessageType.GroupCancelMuted:
  523. const groupCancelMutedDetails = JSON.parse(msg.notificationElem.detail);
  524. const groupCancelMuteOpUser = groupCancelMutedDetails.opUser;
  525. return `${parseInfo(groupCancelMuteOpUser)}关闭了全体禁言`;
  526. case MessageType.GroupMemberMuted:
  527. const gmMutedDetails = JSON.parse(msg.notificationElem.detail);
  528. const muteTime = sec2Time(gmMutedDetails.mutedSeconds);
  529. return `${parseInfo(gmMutedDetails.opUser)}禁言了${parseInfo(
  530. gmMutedDetails.mutedUser,
  531. )} ${muteTime}`;
  532. case MessageType.GroupMemberCancelMuted:
  533. const gmcMutedDetails = JSON.parse(msg.notificationElem.detail);
  534. return `${parseInfo(gmcMutedDetails.opUser)}取消了禁言${parseInfo(
  535. gmcMutedDetails.mutedUser,
  536. )}`;
  537. case MessageType.GroupNameUpdated:
  538. const groupNameUpdateDetail = JSON.parse(msg.notificationElem.detail);
  539. const groupNameUpdateUser = groupNameUpdateDetail.opUser;
  540. return `${parseInfo(groupNameUpdateUser)}修改了群名称为${
  541. groupNameUpdateDetail.group.groupName
  542. }`;
  543. case MessageType.BurnMessageChange:
  544. const burnDetails = JSON.parse(msg.notificationElem.detail);
  545. return `阅后即焚已${burnDetails.isPrivate ? "开启" : "关闭"}`;
  546. case MessageType.OANotification:
  547. const customNoti = JSON.parse(msg.notificationElem.detail);
  548. return customNoti.text;
  549. default:
  550. return "";
  551. }
  552. };