Files
ruo-shan-cloud-pharmacy/miniprogram/package-live/volc-mini-sdk/utils/autoReply.js
T
陈誉午 994b267f5c feat: 电子药箱小程序 - 4Tab药品管理
- 电子药箱: 药品库存管理 + 手动录入 + 今日用药打卡
- 药品百科: 搜索 + 分类筛选 + 20种药品静态数据
- 惠教中心: 4条药品使用指南课程
- 我的: 家庭成员信息管理
- 自定义TabBar + navigation-bar组件
- SVG药品分类插图
2026-07-29 11:20:52 +08:00

1 line
17 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.truncateDisplayText=exports.suppressAutoReplyPanelOnInit=exports.shouldCountAddCommentForUnread=exports.scheduleAutoReplyFallback=exports.normalizeAutoReplyInfo=exports.mergeAutoReplyByAnchor=exports.isOwnAnchorComment=exports.isAutoReplyComment=exports.isAutoReplyAnchorVisible=exports.hasAutoReplyForPollingKey=exports.hasAutoReplyForAnchor=exports.getH5MsgIdCache=exports.getCommentAnchorKeys=exports.getAutoReplyPollingKey=exports.getAnchorPreviewParts=exports.expandAutoReplyComments=exports.clearH5MsgIdCache=exports.clearAllAutoReplyFallbackTimers=exports.cancelAutoReplyFallbackByAnchorKeys=exports.buildAutoReplyDisplayMeta=exports.buildAutoReplyComment=exports.addH5MsgIdToCache=exports.AUTO_REPLY_DISPLAY=void 0;var _comment=require("./comment");function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,o){if(e){if("string"==typeof e)return _arrayLikeToArray(e,o);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(e,o):void 0}}function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayLikeToArray(e,o){(null==o||o>e.length)&&(o=e.length);for(var t=0,n=new Array(o);t<o;t++)n[t]=e[t];return n}function ownKeys(e,o){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);o&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),t.push.apply(t,n)}return t}function _objectSpread(e){for(var o=1;o<arguments.length;o++){var t=null!=arguments[o]?arguments[o]:{};o%2?ownKeys(Object(t),!0).forEach(function(o){_defineProperty(e,o,t[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(o){Object.defineProperty(e,o,Object.getOwnPropertyDescriptor(t,o))})}return e}function _defineProperty(e,o,t){return(o=_toPropertyKey(o))in e?Object.defineProperty(e,o,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[o]=t,e}function _toPropertyKey(e){var o=_toPrimitive(e,"string");return"symbol"===_typeof(o)?o:String(o)}function _toPrimitive(e,o){if("object"!==_typeof(e)||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,o||"default");if("object"!==_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===o?String:Number)(e)}function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}var DEFAULT_ROBOT_NAME="智能助理",AUTO_REPLY_PANEL_FALLBACK_MS=8e3,ELLIPSIS="...",AUTO_REPLY_DISPLAY={ROBOT_NAME_MAX_LENGTH:5,ROBOT_NAME_AVATAR_MAX_LENGTH:10,KEYWORD_MAX_LENGTH:8,ANCHOR_PREVIEW_MAX_LENGTH:18,AUTO_DISMISS_SECONDS:3};exports.AUTO_REPLY_DISPLAY=AUTO_REPLY_DISPLAY;var truncateDisplayText=function(e,o){var t=String(e||"").trim();if(!t||o<=0)return t;var n=Array.from(t);return n.length<=o?t:"".concat(n.slice(0,o).join("")).concat(ELLIPSIS)};exports.truncateDisplayText=truncateDisplayText;var getAnchorPreviewParts=function(e){return e?{nick:String(e.AnchorNickname||"").trim(),question:String(e.AnchorTextContent||e.Keyword||"").trim()}:{nick:"",question:""}};exports.getAnchorPreviewParts=getAnchorPreviewParts;var buildAutoReplyDisplayMeta=function(e){var o,t,n=null==e||null===(o=e.Extra)||void 0===o?void 0:o._autoReplyInfo_;if(null==n||!n.IsAutoReply)return null;var r=getAnchorPreviewParts(n),l=r.nick,a=r.question,u=String(n.AutoReplyCommentRobotName||"").trim()||DEFAULT_ROBOT_NAME,i="";i=l&&a?"".concat(l,"").concat(a):l||a,i=truncateDisplayText(i,AUTO_REPLY_DISPLAY.ANCHOR_PREVIEW_MAX_LENGTH);var s=truncateDisplayText(u,AUTO_REPLY_DISPLAY.ROBOT_NAME_MAX_LENGTH),c=String(n.Keyword||"").trim(),p=truncateDisplayText(c,AUTO_REPLY_DISPLAY.KEYWORD_MAX_LENGTH),A=truncateDisplayText(a||c,AUTO_REPLY_DISPLAY.KEYWORD_MAX_LENGTH);return{hasAnchorPreview:Boolean(i),anchorPreviewText:i,anchorPreviewNick:l,anchorPreviewQuestion:a,robotNameDisplay:truncateDisplayText(u,AUTO_REPLY_DISPLAY.ROBOT_NAME_AVATAR_MAX_LENGTH),robotNameFooterDisplay:s,statusText:"".concat(s,"已回复"),avatarStatusText:"".concat(truncateDisplayText(u,AUTO_REPLY_DISPLAY.ROBOT_NAME_AVATAR_MAX_LENGTH),"已回复"),robotAvatar:String(n.AutoReplyCommentRobotAvatar||"").trim(),keyword:c,keywordDisplay:p,anchorQuoteDisplay:A,panelHeaderTitle:"".concat(s,"已回复"),panelQuestion:A?'关于"'.concat(A,'"的解答'):"智能助理的回复",noticeTitle:"".concat(u,"已回复该问题"),noticeDesc:A?'关于"'.concat(A,'"的回复'):"智能助理的回复",replyContent:String(n.ReplyContent||(null==e||null===(t=e.Extra)||void 0===t?void 0:t.TextContent)||"").trim()}};exports.buildAutoReplyDisplayMeta=buildAutoReplyDisplayMeta;var H5_MSG_ID_CACHE_KEY="livesaas_mini_h5_msg_id_cache",MAX_H5_MSG_ID_CACHE_SIZE=1e3,pendingAutoReplyFallbackTimers=new Map,pendingOwnAutoReplyExpansion=new Set,getAutoReplyPollingSource=function(e){var o,t;return(null==e||null===(o=e.Extra)||void 0===o?void 0:o.AutoReplyPolling)||(null==e?void 0:e.AutoReplyPolling)||(null==e||null===(t=e.MsgExtra)||void 0===t?void 0:t.AutoReplyPolling)},getAutoReplyPollingKey=function(e,o){return"".concat(e,"_").concat(o)};exports.getAutoReplyPollingKey=getAutoReplyPollingKey;var getServerAutoReplyAnchorMsgId=function(e,o){var t,n;return Number(null!==(t=e.ShowMessageAnchorId)&&void 0!==t?t:null==o||null===(n=o.Common)||void 0===n?void 0:n.MsgId)},getSourceValue=function(e,o){if(e&&"object"===_typeof(e))for(var t=0;t<o.length;t++){var n=e[o[t]];if(null!=n)return n}},getOptionalBoolean=function(e,o){var t=getSourceValue(e,o);return null!=t?Boolean(t):void 0},normalizeAutoReplyInfo=function(e,o){var t;if(!e||"object"!==_typeof(e))return null;var n=getSourceValue(e,["IsAutoReply","isAutoReply"]);if(0===n||!1===n||"0"===n)return null;var r=getSourceValue(e,["AutoReplyId","autoReplyId","Id","id"]),l=getSourceValue(e,["ReplyContent","replyContent","ReplyCommentContent","replyCommentContent","AutoReplyContent","autoReplyContent","Content","content","TextContent","textContent"]),a=getSourceValue(e,["Keyword","keyword","Question","question"]),u=Number(null!==(t=getSourceValue(e,["ShowMessageAnchorId","showMessageAnchorId","AnchorMsgId","anchorMsgId"]))&&void 0!==t?t:o);return r||l||a?{AutoReplyId:String(r||"".concat(o||Date.now())),ShowMessageAnchorId:Number.isFinite(u)?u:void 0,Keyword:a?String(a):void 0,ReplyContent:l?String(l):void 0,AutoReplyCommentRobotName:String(getSourceValue(e,["AutoReplyCommentRobotName","autoReplyCommentRobotName","RobotName","robotName"])||DEFAULT_ROBOT_NAME),AutoReplyCommentRobotAvatar:String(getSourceValue(e,["AutoReplyCommentRobotAvatar","autoReplyCommentRobotAvatar","RobotAvatar","robotAvatar","AvatarUrl","avatarUrl"])||""),AutoShowPanel:getOptionalBoolean(e,["AutoShowPanel","autoShowPanel"]),IsAutoReply:!0}:null};exports.normalizeAutoReplyInfo=normalizeAutoReplyInfo;var getStableAutoReplyMsgId=function(e){for(var o=0,t=String(e||""),n=0;n<t.length;n++)o=31*o+t.charCodeAt(n)>>>0;return-1*(o||1)},isAutoReplyComment=function(e){var o,t;return Boolean(null==e||null===(o=e.Extra)||void 0===o||null===(t=o._autoReplyInfo_)||void 0===t?void 0:t.IsAutoReply)};exports.isAutoReplyComment=isAutoReplyComment;var shouldCountAddCommentForUnread=function(e){return!isAutoReplyComment(e)};exports.shouldCountAddCommentForUnread=shouldCountAddCommentForUnread;var hasAutoReplyForPollingKey=function(e,o,t){if(null==o||null==t||!Number.isFinite(Number(o))||!Number.isFinite(Number(t)))return!1;var n=getAutoReplyPollingKey(o,t);return(e||[]).some(function(e){var r,l=null==e||null===(r=e.Extra)||void 0===r?void 0:r._autoReplyInfo_;return!(null==l||!l.IsAutoReply)&&(l.AutoReplyId===n||Number(l.SourceMsgId)===Number(o)&&Number(l.ServerShowMessageAnchorId)===Number(t))})};exports.hasAutoReplyForPollingKey=hasAutoReplyForPollingKey;var hasAutoReplyForAnchor=function(e,o){return hasAutoReplyForPollingKey(e,o,o)};exports.hasAutoReplyForAnchor=hasAutoReplyForAnchor;var buildAutoReplyComment=function(e,o){var t,n,r,l,a,u=e.ShowMessageAnchorId,i=e.ReplyContent||"智能助理已回复该问题",s=e.AutoReplyCommentRobotName||DEFAULT_ROBOT_NAME,c=(null==o||null===(t=o.Extra)||void 0===t?void 0:t.User)||{},p=c.Nickname?String(c.Nickname):"",A=null!=o&&null!==(n=o.Extra)&&void 0!==n&&n.TextContent?String(o.Extra.TextContent):"";return{Common:{H5MsgId:"auto_reply_".concat(e.AutoReplyId),MsgId:getStableAutoReplyMsgId(e.AutoReplyId),CreateTime:(null==o||null===(r=o.Common)||void 0===r?void 0:r.CreateTime)||Date.now(),_formerMsgId_:u},Extra:{ContentType:_comment.MessageContentType.Text,TextContent:i,TextContentExtra:[],User:{Nickname:s,Email:"",AvatarUrl:e.AutoReplyCommentRobotAvatar||""},IsDelete:!1,TextContentCn:"",IsSilence:0,TextContentEn:"",TextContentJp:"",TextContentKo:"",IsSelfLike:!1,LikeCount:0,IsPresenter:!1,_autoReplyInfo_:_objectSpread(_objectSpread({},e),{},{ReplyContent:i,ShowMessageAnchorId:u,SourceMsgId:null!==(l=e.SourceMsgId)&&void 0!==l?l:null==o||null===(a=o.Common)||void 0===a?void 0:a.MsgId,ServerShowMessageAnchorId:e.ServerShowMessageAnchorId,IsAutoReply:!0,AnchorNickname:p||e.AnchorNickname,AnchorTextContent:A||e.AnchorTextContent||e.Keyword})}}};exports.buildAutoReplyComment=buildAutoReplyComment;var getH5MsgIdCache=function(){try{var e=wx.getStorageSync(H5_MSG_ID_CACHE_KEY);if(e){var o=JSON.parse(e);return new Set(Array.isArray(o)?o.map(String):[])}}catch(e){console.warn("[autoReply] parse H5MsgId cache failed",e)}return new Set};exports.getH5MsgIdCache=getH5MsgIdCache;var addH5MsgIdToCache=function(e){if(null!=e&&""!==e)try{var o=getH5MsgIdCache();o.add(String(e));var t=Array.from(o),n=t.length>MAX_H5_MSG_ID_CACHE_SIZE?t.slice(-MAX_H5_MSG_ID_CACHE_SIZE):t;wx.setStorageSync(H5_MSG_ID_CACHE_KEY,JSON.stringify(n))}catch(e){console.warn("[autoReply] save H5MsgId cache failed",e)}};exports.addH5MsgIdToCache=addH5MsgIdToCache;var clearH5MsgIdCache=function(){try{wx.removeStorageSync(H5_MSG_ID_CACHE_KEY)}catch(e){console.warn("[autoReply] clear H5MsgId cache failed",e)}};exports.clearH5MsgIdCache=clearH5MsgIdCache;var isOwnComment=function(e,o){var t,n,r,l;if(1===(null==e||null===(t=e.Extra)||void 0===t?void 0:t.IsOwn)||!0===(null==e||null===(n=e.Extra)||void 0===n?void 0:n.IsOwn))return!0;var a=null==e||null===(r=e.Extra)||void 0===r||null===(l=r.User)||void 0===l?void 0:l.UserId;return null!=o&&null!=a&&String(a)===String(o)},isOwnAnchorComment=function(e,o){var t,n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];if(isOwnComment(e,o))return!0;var l=getH5MsgIdCache(),a=null==e||null===(t=e.Common)||void 0===t?void 0:t.MsgId,u=null==e||null===(n=e.Common)||void 0===n?void 0:n.H5MsgId;return!(null==a||!l.has(String(a)))||!(null==u||!l.has(String(u)))||(r||[]).some(function(e){var t,n;if(!isOwnComment(e,o))return!1;if(null!=a&&(null===(t=e.Common)||void 0===t?void 0:t.MsgId)===a)return!0;var r=null===(n=e.Common)||void 0===n?void 0:n.H5MsgId;return null!=a&&null!=r&&String(r)===String(a)||null!=u&&null!=r&&String(r)===String(u)})};exports.isOwnAnchorComment=isOwnAnchorComment;var isJustSentOwnComment=function(e,o){var t,n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],l=null==e||null===(t=e.Common)||void 0===t?void 0:t.MsgId,a=null==e||null===(n=e.Common)||void 0===n?void 0:n.H5MsgId;return(r||[]).some(function(e){var t,n,r;return!(!isOwnComment(e,o)||!e.isMock)&&(null!=l&&(null===(t=e.Common)||void 0===t?void 0:t.MsgId)===l||null!=a&&String(null===(n=e.Common)||void 0===n?void 0:n.H5MsgId)===String(a)||null!=l&&String(null===(r=e.Common)||void 0===r?void 0:r.H5MsgId)===String(l))})},getCommentAnchorKeys=function(e){var o,t,n=[],r=null==e||null===(o=e.Common)||void 0===o?void 0:o.MsgId,l=null==e||null===(t=e.Common)||void 0===t?void 0:t.H5MsgId;return null!=r&&n.push(String(r)),null==l||null!=r&&String(l)===String(r)||n.push(String(l)),n};exports.getCommentAnchorKeys=getCommentAnchorKeys;var cancelAutoReplyFallbackByAnchorKeys=function(e){(e||[]).forEach(function(e){var o=pendingAutoReplyFallbackTimers.get(e);null!=o&&(clearTimeout(o),pendingAutoReplyFallbackTimers.delete(e))})};exports.cancelAutoReplyFallbackByAnchorKeys=cancelAutoReplyFallbackByAnchorKeys;var clearAllAutoReplyFallbackTimers=function(){pendingAutoReplyFallbackTimers.forEach(function(e){clearTimeout(e)}),pendingAutoReplyFallbackTimers.clear()};exports.clearAllAutoReplyFallbackTimers=clearAllAutoReplyFallbackTimers;var scheduleAutoReplyFallback=function(e,o,t){var n,r,l,a,u;if(e&&o&&t){var i=getCommentAnchorKeys(t);if(0!==i.length){cancelAutoReplyFallbackByAnchorKeys(i);var s=Number(null===(n=t.Common)||void 0===n?void 0:n.MsgId),c=Number(null!==(r=o.ShowMessageAnchorId)&&void 0!==r?r:s),p=null!==(l=t.Extra)&&void 0!==l&&l.TextContent?String(t.Extra.TextContent):"",A=null!==(a=t.Extra)&&void 0!==a&&null!==(u=a.User)&&void 0!==u&&u.Nickname?String(t.Extra.User.Nickname):"",y=setTimeout(function(){cancelAutoReplyFallbackByAnchorKeys(i);var n=e.get("chat.chatList")||[];if(!hasAutoReplyForPollingKey(n,s,c)){var r=buildAutoReplyComment(_objectSpread(_objectSpread({},o),{},{AutoReplyId:getAutoReplyPollingKey(s,c),SourceMsgId:s,ServerShowMessageAnchorId:c,ShowMessageAnchorId:s,AutoShowPanel:!0,Keyword:o.Keyword||p,AnchorTextContent:o.AnchorTextContent||p,AnchorNickname:o.AnchorNickname||A}),t),l=mergeAutoReplyByAnchor(n,[r]);e.set("chat.chatList",l),e.set("chat.addComment",{data:[r],isSend:!0})}},AUTO_REPLY_PANEL_FALLBACK_MS);i.forEach(function(e){pendingAutoReplyFallbackTimers.set(e,y)})}}};exports.scheduleAutoReplyFallback=scheduleAutoReplyFallback;var suppressAutoReplyPanelOnInit=function(e,o){return o?(e||[]).map(function(e){var o,t=null==e||null===(o=e.Extra)||void 0===o?void 0:o._autoReplyInfo_;return null!=t&&t.IsAutoReply&&t.AutoShowPanel?_objectSpread(_objectSpread({},e),{},{Extra:_objectSpread(_objectSpread({},e.Extra),{},{_autoReplyInfo_:_objectSpread(_objectSpread({},t),{},{AutoShowPanel:!1})})}):e}):e};exports.suppressAutoReplyPanelOnInit=suppressAutoReplyPanelOnInit;var isAutoReplyAnchorVisible=function(e,o){var t,n;if(!isAutoReplyComment(e))return!0;var r=null===(t=e.Extra)||void 0===t||null===(n=t._autoReplyInfo_)||void 0===n?void 0:n.ShowMessageAnchorId;return null!=r&&(o||[]).some(function(e){var o,t,n;return Number(null===(o=e.Common)||void 0===o?void 0:o.MsgId)===Number(r)&&!(null!==(t=e.Extra)&&void 0!==t&&t.IsDelete)&&Boolean(null===(n=e.Extra)||void 0===n?void 0:n.TextContent)})};exports.isAutoReplyAnchorVisible=isAutoReplyAnchorVisible;var expandAutoReplyComments=function(e,o){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],n=arguments.length>3&&void 0!==arguments[3]&&arguments[3],r=[];return(e||[]).forEach(function(e){var l,a;r.push(e);var u=normalizeAutoReplyInfo(getAutoReplyPollingSource(e),null==e||null===(l=e.Common)||void 0===l?void 0:l.MsgId);if(u){var i=Number(null==e||null===(a=e.Common)||void 0===a?void 0:a.MsgId),s=getServerAutoReplyAnchorMsgId(u,e);if(Number.isFinite(i)&&Number.isFinite(s)){var c,p=getAutoReplyPollingKey(i,s),A=isOwnAnchorComment(e,o,t);if(A&&!n){var y=hasAutoReplyForPollingKey([].concat(_toConsumableArray(t),r),i,s);if(pendingOwnAutoReplyExpansion.has(i))pendingOwnAutoReplyExpansion.delete(i);else if(!y&&isJustSentOwnComment(e,o,t))return void pendingOwnAutoReplyExpansion.add(i);cancelAutoReplyFallbackByAnchorKeys(getCommentAnchorKeys(e))}hasAutoReplyForPollingKey([].concat(_toConsumableArray(t),r),i,s)||r.push(buildAutoReplyComment(_objectSpread(_objectSpread({},u),{},{AutoReplyId:p,SourceMsgId:i,ServerShowMessageAnchorId:s,ShowMessageAnchorId:i,AutoShowPanel:null!==(c=u.AutoShowPanel)&&void 0!==c?c:A}),e))}}}),r};exports.expandAutoReplyComments=expandAutoReplyComments;var mergeAutoReplyByAnchor=function(e,o){var t=_toConsumableArray(e||[]);return(o||[]).forEach(function(e){var o;if(isAutoReplyComment(e)){var n=null===(o=e.Extra._autoReplyInfo_)||void 0===o?void 0:o.ShowMessageAnchorId,r=t.findIndex(function(e){var o;return Number(null===(o=e.Common)||void 0===o?void 0:o.MsgId)===Number(n)});if(r<0)t.push(e);else{for(var l=r+1;l<t.length&&Number(null===(a=t[l].Extra)||void 0===a||null===(u=a._autoReplyInfo_)||void 0===u?void 0:u.ShowMessageAnchorId)===Number(n);){var a,u;l+=1}t.splice(l,0,e)}}else t.push(e)}),t};exports.mergeAutoReplyByAnchor=mergeAutoReplyByAnchor;