UNPKG

@uimkit/uikit-react

Version:

<img style="width:64px" src="https://mgmt.uimkit.chat/media/img/avatar.png"/>

72 lines (67 loc) 2.05 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var emojiMap = require('./emojiMap.js'); /** 传入messageBody(群系统消息SystemMessage,群提示消息GroupTip除外) * payload = { * msgType: 'TIMTextElem', * msgContent: { * text: 'AAA[龇牙]AAA[龇牙]AAA[龇牙AAA]' * } *} * */ function decodeText(text) { var renderDom = []; // 文本消息 var temp = text; var left = -1; var right = -1; while (temp !== '') { left = temp.indexOf('['); right = temp.indexOf(']'); switch (left) { case 0: if (right === -1) { renderDom.push({ name: 'text', text: temp, }); temp = ''; } else { var emojiKey = temp.slice(0, right + 1); if (emojiMap.emojiMap[emojiKey]) { renderDom.push({ name: 'img', src: emojiMap.emojiUrl + emojiMap.emojiMap[emojiKey], }); temp = temp.substring(right + 1); } else { renderDom.push({ name: 'text', text: '[', }); temp = temp.slice(1); } } break; case -1: renderDom.push({ name: 'text', text: temp, }); temp = ''; break; default: renderDom.push({ name: 'text', text: temp.slice(0, left), }); temp = temp.substring(left); break; } } return renderDom; } exports.decodeText = decodeText; //# sourceMappingURL=decodeText.js.map