UNPKG

@uimkit/uikit-react

Version:

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

341 lines (336 loc) 16.1 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib = require('tslib'); var models = require('../../../types/models.js'); require('../../../types/events.js'); var decodeText = require('./decodeText.js'); var constants = require('../../../constants.js'); var utils = require('../../utils.js'); require('i18next'); // Handling system tip message display function handleTipMessageShowContext(t, message) { var _a, _b, _c, _d, _e; var options = { message: message, text: '', }; var userName = message.nick || ((_a = message === null || message === void 0 ? void 0 : message.tip) === null || _a === void 0 ? void 0 : _a.userIDList.join(',')); if (((_c = (_b = message === null || message === void 0 ? void 0 : message.tip) === null || _b === void 0 ? void 0 : _b.memberList) === null || _c === void 0 ? void 0 : _c.length) > 0) { userName = ''; (_e = (_d = message === null || message === void 0 ? void 0 : message.tip) === null || _d === void 0 ? void 0 : _d.memberList) === null || _e === void 0 ? void 0 : _e.map(function (user) { userName += "".concat((user === null || user === void 0 ? void 0 : user.nick) || (user === null || user === void 0 ? void 0 : user.userID), ","); return user; }); userName = userName.slice(0, -1); } switch (message.tip.operationType) { case models.GroupTipOperationType.MemberJoin: options.text = "".concat(userName, " ").concat(t('message.tip.Join in group')); break; case models.GroupTipOperationType.MemberQuit: options.text = "".concat(t('message.tip.member'), "\uFF1A").concat(userName, " ").concat(t('message.tip.quit group')); break; case models.GroupTipOperationType.MemberKickedOut: options.text = "".concat(t('message.tip.member'), "\uFF1A").concat(userName, " ").concat(t('message.tip.by')).concat(message.tip.operatorID).concat(t('message.tip.kicked out of group')); break; case models.GroupTipOperationType.MemberSetAdmin: options.text = "".concat(t('message.tip.member'), "\uFF1A").concat(userName, " ").concat(t('message.tip.become admin')); break; case models.GroupTipOperationType.MemberCanceledAdmin: options.text = "".concat(t('message.tip.member'), "\uFF1A").concat(userName, " ").concat(t('message.tip.by revoked administrator')); break; case models.GroupTipOperationType.GroupProfileUpdated: // options.text = `${userName} 修改群组资料`; options.text = handleTipGrpUpdated(t, message); break; case models.GroupTipOperationType.MemberProfileUpdated: message.tip.memberList.map(function (member) { if (member.muteTime > 0) { options.text = "".concat(t('message.tip.member'), "\uFF1A").concat(member.userID).concat(t('message.tip.muted')); } else { options.text = "".concat(t('message.tip.member'), "\uFF1A").concat(member.userID).concat(t('message.tip.unmuted')); } return member; }); break; default: options.text = "[".concat(t('message.tip.reminder message'), "]"); break; } return options; } function handleTipGrpUpdated(t, message) { var tip = message.tip; var newGroupProfile = tip.newGroupProfile; var operatorID = tip.operatorID; var text = ''; var name = Object.keys(newGroupProfile)[0]; switch (name) { case 'muteAllMembers': if (newGroupProfile[name]) { text = "".concat(t('message.tip.admin'), " ").concat(operatorID, " ").concat(t('message.tip.enable all staff mute')); } else { text = "".concat(t('message.tip.admin'), " ").concat(operatorID, " ").concat(t('message.tip.unmute everyone')); } break; case 'ownerID': text = "".concat(newGroupProfile[name], " ").concat(t('message.tip.become the new owner')); break; case 'groupName': text = "".concat(operatorID, " ").concat(t('message.tip.modify group name'), " ").concat(newGroupProfile[name]); break; case 'notification': text = "".concat(operatorID, " ").concat(t('message.tip.post a new announcement')); break; } return text; } // Parsing and handling text message display function handleTextMessageShowContext(item) { var options = { text: decodeText.decodeText(item.text), }; return options; } // Parsing and handling face message display function handleFaceMessageShowContext(item) { var face = { message: item, name: '', url: '', }; face.name = item.payload.data; if (item.payload.data.indexOf('@2x') < 0) { face.name = "".concat(face.name, "@2x"); } face.url = "https://web.sdk.qcloud.com/im/assets/face-elem/".concat(face.name, ".png"); return face; } // Parsing and handling location message display function handleLocationMessageShowContext(item) { var location = { lon: '', lat: '', href: '', url: '', description: '', message: item, }; location.lon = item.payload.longitude.toFixed(6); location.lat = item.payload.latitude.toFixed(6); location.href = 'https://map.qq.com/?type=marker&isopeninfowin=1&markertype=1&' + "pointx=".concat(location.lon, "&pointy=").concat(location.lat, "&name=").concat(item.payload.description); location.url = 'https://apis.map.qq.com/ws/staticmap/v2/?' + "center=".concat(location.lat, ",").concat(location.lon, "&zoom=10&size=300*150&maptype=roadmap&") + "markers=size:large|color:0xFFCCFF|label:k|".concat(location.lat, ",").concat(location.lon, "&") + 'key=UBNBZ-PTP3P-TE7DB-LHRTI-Y4YLE-VWBBD'; location.description = item.payload.description; return location; } // Parsing and handling image message display function handleImageMessageShowContext(item) { if (item.file) item.file.url = URL.createObjectURL(item.file); var url; if (item.image && item.image.infos) { if (item.image.infos.length === 1) { url = item.image.infos[0].url; } else if (item.image.infos.length > 1) { url = item.image.infos[1].url; } } return { progress: (item === null || item === void 0 ? void 0 : item.status) === constants.MESSAGE_STATUS.UNSEND && item.progress, url: url, message: item, }; } // Parsing and handling video message display function handleVideoMessageShowContext(item) { var _a, _b; return { progress: (item === null || item === void 0 ? void 0 : item.status) === constants.MESSAGE_STATUS.UNSEND && (item === null || item === void 0 ? void 0 : item.progress), url: (_a = item === null || item === void 0 ? void 0 : item.video) === null || _a === void 0 ? void 0 : _a.url, snapshot: (_b = item === null || item === void 0 ? void 0 : item.video) === null || _b === void 0 ? void 0 : _b.snapshot, message: item, }; } // Parsing and handling audio message display function handleAudioMessageShowContext(item) { return { progress: (item === null || item === void 0 ? void 0 : item.status) === constants.MESSAGE_STATUS.UNSEND && item.progress, url: item.audio.url, message: item, second: item.audio.duration, }; } // Parsing and handling file message display function handleFileMessageShowContext(item) { var size = ''; if (item.payload.fileSize >= 1024 * 1024) { size = "".concat((item.payload.fileSize / (1024 * 1024)).toFixed(2), " Mb"); } else if (item.payload.fileSize >= 1024) { size = "".concat((item.payload.fileSize / 1024).toFixed(2), " Kb"); } else { size = "".concat(item.payload.fileSize.toFixed(2), "B"); } return { progress: (item === null || item === void 0 ? void 0 : item.status) === constants.MESSAGE_STATUS.UNSEND && item.progress, url: item.payload.fileUrl, message: item, name: item.payload.fileName, size: size, }; } // Parsing and handling merger message display function handleMergerMessageShowContext(item) { return tslib.__assign({ message: item }, item[item.type]); } // Parse audio and video call messages function extractCallingInfoFromMessage(t, message) { var callingmessage = {}; var objectData = {}; try { callingmessage = utils.JSONStringToParse(message.calling.data); } catch (error) { callingmessage = {}; } if (callingmessage.businessID !== 1) { return ''; } try { objectData = utils.JSONStringToParse(callingmessage.data); } catch (error) { objectData = {}; } switch (callingmessage.actionType) { case 1: { if (objectData.call_end >= 0 && !callingmessage.groupID) { return "".concat(t('message.custom.talkTime'), "\uFF1A").concat(formatTime(objectData.call_end)); } if (callingmessage.groupID) { return "".concat(t('message.custom.groupCallEnd')); } if (objectData.data && objectData.data.cmd === 'switchToAudio') { return "".concat(t('message.custom.switchToAudioCall')); } if (objectData.data && objectData.data.cmd === 'switchToVideo') { return "".concat(t('message.custom.switchToVideoCall')); } return "".concat(t('message.custom.all')); } case 2: return "".concat(t('message.custom.cancel')); case 3: if (objectData.data && objectData.data.cmd === 'switchToAudio') { return "".concat(t('message.custom.switchToAudioCall')); } if (objectData.data && objectData.data.cmd === 'switchToVideo') { return "".concat(t('message.custom.switchToVideoCall')); } return "".concat(t('message.custom.accepted')); case 4: return "".concat(t('message.custom.rejected')); case 5: if (objectData.data && objectData.data.cmd === 'switchToAudio') { return "".concat(t('message.custom.switchToAudioCall')); } if (objectData.data && objectData.data.cmd === 'switchToVideo') { return "".concat(t('message.custom.switchToVideoCall')); } return "".concat(t('message.custom.noResp')); default: return ''; } } // Parsing and handling custom message display function handleCustomMessageShowContext(t, item) { return { message: item, custom: extractCallingInfoFromMessage(t, item) || (item === null || item === void 0 ? void 0 : item.calling) || "[".concat(t('message.custom.custom'), "]"), }; } // Parsing and handling system message display function translateGroupSystemNotice(t, message) { var groupName = message.group_system_notice.groupProfile.name || message.group_system_notice.groupProfile.groupID; switch (message.group_system_notice.operationType) { case 1: return "".concat(message.group_system_notice.operatorID, " ").concat(t('message.tip.申请加入群组'), "\uFF1A").concat(groupName); case 2: return "".concat(t('message.tip.成功加入群组'), "\uFF1A").concat(groupName); case 3: return "".concat(t('message.tip.申请加入群组'), "\uFF1A").concat(groupName, " ").concat(t('message.tip.被拒绝')); case 4: return "".concat(t('message.tip.你被管理员')).concat(message.group_system_notice.operatorID, " ").concat(t('message.tip.踢出群组'), "\uFF1A").concat(groupName); case 5: return "".concat(t('message.tip.群'), "\uFF1A").concat(groupName, " ").concat(t('message.tip.被'), " ").concat(message.group_system_notice.operatorID, " ").concat(t('message.tip.解散')); case 6: return "".concat(message.group_system_notice.operatorID, " ").concat(t('message.tip.创建群'), "\uFF1A").concat(groupName); case 7: return "".concat(message.group_system_notice.operatorID, " ").concat(t('message.tip.邀请你加群'), "\uFF1A").concat(groupName); case 8: return "".concat(t('message.tip.你退出群组'), "\uFF1A").concat(groupName); case 9: return "".concat(t('message.tip.你被')).concat(message.group_system_notice.operatorID, " ").concat(t('message.tip.设置为群'), "\uFF1A").concat(groupName, " ").concat(t('message.tip.的管理员')); case 10: return "".concat(t('message.tip.你被')).concat(message.group_system_notice.operatorID, " ").concat(t('message.tip.撤销群'), "\uFF1A").concat(groupName, " ").concat(t('message.tip.的管理员身份')); case 12: return "".concat(message.group_system_notice.operatorID, " ").concat(t('message.tip.邀请你加群'), "\uFF1A").concat(groupName); case 13: return "".concat(message.group_system_notice.operatorID, " ").concat(t('message.tip.同意加群'), "\uFF1A").concat(groupName); case 14: return "".concat(message.group_system_notice.operatorID, " ").concat(t('message.tip.拒接加群'), "\uFF1A").concat(groupName); case 255: return "".concat(t('message.tip.自定义群系统通知'), ": ").concat(message.group_system_notice.userDefinedField); default: return ''; } } function formatTime(secondTime) { var time = secondTime; var newTime; var hour; var minite; var seconds; if (time >= 3600) { hour = parseInt("".concat(time / 3600), 10) < 10 ? "0".concat(parseInt("".concat(time / 3600), 10)) : parseInt("".concat(time / 3600), 10); minite = parseInt("".concat((time % 60) / 60), 10) < 10 ? "0".concat(parseInt("".concat((time % 60) / 60), 10)) : parseInt("".concat((time % 60) / 60), 10); seconds = time % 3600 < 10 ? "0".concat(time % 3600) : time % 3600; if (seconds > 60) { minite = parseInt("".concat(seconds / 60), 10) < 10 ? "0".concat(parseInt("".concat(seconds / 60), 10)) : parseInt("".concat(seconds / 60), 10); seconds = seconds % 60 < 10 ? "0".concat(seconds % 60) : seconds % 60; } newTime = "".concat(hour, ":").concat(minite, ":").concat(seconds); } else if (time >= 60 && time < 3600) { minite = parseInt("".concat(time / 60), 10) < 10 ? "0".concat(parseInt("".concat(time / 60), 10)) : parseInt("".concat(time / 60), 10); seconds = time % 60 < 10 ? "0".concat(time % 60) : time % 60; newTime = "00:".concat(minite, ":").concat(seconds); } else if (time < 60) { seconds = time < 10 ? "0".concat(time) : time; newTime = "00:00:".concat(seconds); } return newTime; } exports.extractCallingInfoFromMessage = extractCallingInfoFromMessage; exports.formatTime = formatTime; exports.handleAudioMessageShowContext = handleAudioMessageShowContext; exports.handleCustomMessageShowContext = handleCustomMessageShowContext; exports.handleFaceMessageShowContext = handleFaceMessageShowContext; exports.handleFileMessageShowContext = handleFileMessageShowContext; exports.handleImageMessageShowContext = handleImageMessageShowContext; exports.handleLocationMessageShowContext = handleLocationMessageShowContext; exports.handleMergerMessageShowContext = handleMergerMessageShowContext; exports.handleTextMessageShowContext = handleTextMessageShowContext; exports.handleTipMessageShowContext = handleTipMessageShowContext; exports.handleVideoMessageShowContext = handleVideoMessageShowContext; exports.translateGroupSystemNotice = translateGroupSystemNotice; //# sourceMappingURL=index.js.map