@uimkit/uikit-react
Version:
<img style="width:64px" src="https://mgmt.uimkit.chat/media/img/avatar.png"/>
68 lines (65 loc) • 1.95 kB
JavaScript
import { emojiMap, emojiUrl } from './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[emojiKey]) {
renderDom.push({
name: 'img',
src: emojiUrl + 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;
}
export { decodeText };
//# sourceMappingURL=decodeText.js.map