UNPKG

leancloud-realtime-plugin-typed-messages

Version:
3 lines (2 loc) 4.98 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define("typed-messages",t):((e=e||self).AV=e.AV||{},e.AV.initTypedMessages=t())}(this,(function(){"use strict";var e=function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e};function t(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var r=function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e};var n=function(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t};function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?i(Object(n),!0).forEach((function(r){e(t,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function s(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?a(Object(n),!0).forEach((function(r){e(t,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function u(e,t){var i=function(e){var t=e.AV,i=e.IM,a=function(e){function a(r){var n;if(!(r instanceof t.File))throw new TypeError("file must be an AV.File");if("string"!=typeof r.id)throw new Error("file must be saved before used to create a Message");return(n=e.call(this)||this)._file=r,n._lcfile={objId:r.id,url:r.url(),metaData:Object.assign(r.metaData()||{},{name:r.name()})},n}n(a,e);var s=a.prototype;return s.getFile=function(){return this._file},s.toJSON=function(){return o(o({},e.prototype.toJSON.call(this)),{},{file:this.getFile().toJSON()})},a._parseFileFromRawData=function(e){if(!e||!e._lcfile)throw new Error("malformed FileMessage content");var r=e._lcfile.objId;"string"!=typeof r&&(r="");var n=t.File.createWithoutData(r);return n.attributes=n.attributes||{},n._url=e._lcfile.url,n.attributes.url=n._url,n._metaData=e._lcfile.metaData||{},n.attributes.metaData=n._metaData,e._lcfile.metaData&&(n._name=e._lcfile.metaData.name,n.attributes.name=n._name),n},a.parse=function(e,t){var r=this._parseFileFromRawData(e);return i.TypedMessage.parse(e,t||new this(r))},r(a,[{key:"summary",get:function(){return"[".concat(this.constructor._summaryType,"] ").concat(this._file.name()||"").trim()}}]),a}(i.TypedMessage);return a._summaryType="文件",i.messageType(-6)(a),i.messageField("_lcfile")(a),i.IE10Compatible(a),a}({AV:e,IM:t}),a=function(e){var t=e.FileMessage,r=e.IM,i=function(e){function t(){return e.apply(this,arguments)||this}return n(t,e),t}(t);return i._summaryType="图片",r.messageType(-2)(i),r.IE10Compatible(i),i}({FileMessage:i,IM:t}),u=function(e){var t=e.FileMessage,r=e.IM,i=function(e){function t(){return e.apply(this,arguments)||this}return n(t,e),t}(t);return i._summaryType="语音",r.messageType(-3)(i),r.IE10Compatible(i),i}({FileMessage:i,IM:t}),c=function(e){var t=e.FileMessage,r=e.IM,i=function(e){function t(){return e.apply(this,arguments)||this}return n(t,e),t}(t);return i._summaryType="视频",r.messageType(-4)(i),r.IE10Compatible(i),i}({FileMessage:i,IM:t}),l=function(e){var t=e.AV,i=e.IM,o=function(e){function o(r){var n;if(!(r instanceof t.GeoPoint))throw new TypeError("geoPoint must be an AV.GeoPoint");(n=e.call(this)||this)._geoPoint=r;var i=r.latitude,o=r.longitude;return n._lcloc={latitude:i,longitude:o},n}n(o,e);var a=o.prototype;return a.getLocation=function(){return this._geoPoint},a.toJSON=function(){return s(s({},e.prototype.toJSON.call(this)),{},{location:this.getLocation().toJSON()})},o.parse=function(e,r){var n=e._lcloc,o=n.latitude,a=n.longitude,s=new t.GeoPoint({latitude:o,longitude:a});return i.TypedMessage.parse(e,r||new this(s))},r(o,[{key:"summary",get:function(){return"[位置] ".concat(this.text||"").trim()}}]),o}(i.TypedMessage);return i.messageType(-5)(o),i.messageField("_lcloc")(o),i.IE10Compatible(o),o}({AV:e,IM:t});return{TypedMessagesPlugin:{name:"leancloud-realtime-plugin-typed-messages",messageClasses:[i,a,u,c,l]},FileMessage:i,ImageMessage:a,AudioMessage:u,VideoMessage:c,LocationMessage:l}}return"undefined"!=typeof window&&window.AV&&Object.assign(window.AV,u(window.AV,window.AV)),u})); //# sourceMappingURL=typed-messages.min.js.map