this.BX=this.BX||{};this.BX.Messenger=this.BX.Messenger||{};this.BX.Messenger.Provider=this.BX.Messenger.Provider||{};(function(e,t,s,a,i){"use strict";var n=function(){babelHelpers.createClass(e,null,[{key:"create",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return new this(t)}}]);function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};babelHelpers.classCallCheck(this,e);if(babelHelpers.typeof(t.controller)==="object"&&t.controller){this.controller=t.controller}if(babelHelpers.typeof(t.store)==="object"&&t.store){this.store=t.store}this.option=babelHelpers.typeof(t.store)==="object"&&t.store?t.store:{};if(!(babelHelpers.typeof(this.option.handlingDialog)==="object"&&this.option.handlingDialog&&this.option.handlingDialog.chatId&&this.option.handlingDialog.dialogId)){this.option.handlingDialog=false}}babelHelpers.createClass(e,[{key:"getModuleId",value:function e(){return"im"}},{key:"getSubscriptionType",value:function e(){return a.PullClient.SubscriptionType.Server}},{key:"skipExecute",value:function e(t){var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(!a.optionImportant){if(this.option.skip){s.Logger.info("Pull: command skipped while loading messages",t);return true}if(!this.option.handlingDialog){return false}}if(typeof t.chatId!=="undefined"||typeof t.dialogId!=="undefined"){if(typeof t.chatId!=="undefined"&&parseInt(t.chatId)===parseInt(this.option.handlingDialog.chatId)){return false}if(typeof t.dialogId!=="undefined"&&t.dialogId.toString()===this.option.handlingDialog.dialogId.toString()){return false}return true}return false}},{key:"handleMessage",value:function e(t,s){this.handleMessageAdd(t,s)}},{key:"handleMessageChat",value:function e(t,s){this.handleMessageAdd(t,s)}},{key:"handleMessageAdd",value:function e(s,a){var n=this;if(this.skipExecute(s,a)){return false}if(s.chat&&s.chat[s.chatId]){this.store.dispatch("dialogues/update",{dialogId:s.dialogId,fields:s.chat[s.chatId]})}this.store.dispatch("recent/update",{id:s.dialogId,fields:{message:{id:s.message.id,text:s.message.text,date:s.message.date},counter:s.counter}});if(s.users){this.store.dispatch("users/set",t.VuexBuilderModel.convertToArray(s.users))}if(s.files){var l=this.controller.application.prepareFilesBeforeSave(t.VuexBuilderModel.convertToArray(s.files));l.forEach(function(e){if(l.length===1&&s.message.templateFileId&&n.store.state.files.index[s.chatId]&&n.store.state.files.index[s.chatId][s.message.templateFileId]){n.store.dispatch("files/update",{id:s.message.templateFileId,chatId:s.chatId,fields:e}).then(function(){n.controller.application.emit(i.EventType.dialog.scrollToBottom,{cancelIfScrollChange:true})})}else{n.store.dispatch("files/set",e)}})}var o=this.store.state.messages.collection[s.chatId];if(!o){o=[]}var d=false;if(s.message.templateId&&o.length>0){for(var r=o.length-1;r>=0;r--){if(o[r].id===s.message.templateId){d=true;break}}}if(d){this.store.dispatch("messages/update",{id:s.message.templateId,chatId:s.chatId,fields:babelHelpers.objectSpread({push:false},s.message,{sending:false,error:false})}).then(function(){n.controller.application.emit(i.EventType.dialog.scrollToBottom,{cancelIfScrollChange:s.message.senderId!==n.controller.application.getUserId()})})}else if(this.controller.application.isUnreadMessagesLoaded()){if(this.controller.application.getChatId()===s.chatId){this.store.commit("application/increaseDialogExtraCount")}this.store.dispatch("messages/setAfter",babelHelpers.objectSpread({push:false},s.message,{unread:true}))}this.controller.application.stopOpponentWriting({dialogId:s.dialogId,userId:s.message.senderId});if(s.message.senderId===this.controller.application.getUserId()){this.store.dispatch("messages/readMessages",{chatId:s.chatId}).then(function(e){n.store.dispatch("dialogues/update",{dialogId:s.dialogId,fields:{counter:0}})})}else{this.store.dispatch("dialogues/increaseCounter",{dialogId:s.dialogId,count:1})}}},{key:"handleMessageUpdate",value:function e(t,s,a){this.execMessageUpdateOrDelete(t,s,a)}},{key:"handleMessageDelete",value:function e(t,s,a){this.execMessageUpdateOrDelete(t,s,a)}},{key:"execMessageUpdateOrDelete",value:function e(t,s,a){var n=this;if(this.skipExecute(t,s)){return false}this.controller.application.stopOpponentWriting({dialogId:t.dialogId,userId:t.senderId});this.store.dispatch("messages/update",{id:t.id,chatId:t.chatId,fields:{text:a==="messageUpdate"?t.text:"",textOriginal:a==="messageUpdate"?t.textOriginal:"",params:t.params,blink:true}}).then(function(){n.controller.application.emit(i.EventType.dialog.scrollToBottom,{cancelIfScrollChange:true})});var l=this.store.getters["recent/get"](t.dialogId);if(a==="messageUpdate"&&l.element&&l.element.message.id===t.id){this.store.dispatch("recent/update",{id:t.dialogId,fields:{message:{id:t.id,text:t.text,date:l.element.message.date}}})}if(a==="messageDelete"&&l.element&&l.element.message.id===t.id){this.store.dispatch("recent/update",{id:t.dialogId,fields:{message:{id:t.id,text:"Message deleted",date:l.element.message.date}}})}}},{key:"handleMessageDeleteComplete",value:function e(t,s){if(this.skipExecute(t,s)){return false}this.store.dispatch("messages/delete",{id:t.id,chatId:t.chatId});this.controller.application.stopOpponentWriting({dialogId:t.dialogId,userId:t.senderId,action:false})}},{key:"handleMessageLike",value:function e(t,s){if(this.skipExecute(t,s)){return false}this.store.dispatch("messages/update",{id:t.id,chatId:t.chatId,fields:{params:{LIKE:t.users}}})}},{key:"handleChatOwner",value:function e(t,s){if(this.skipExecute(t,s)){return false}this.store.dispatch("dialogues/update",{dialogId:t.dialogId,fields:{ownerId:t.userId}})}},{key:"handleMessageParamsUpdate",value:function e(t,s){var a=this;if(this.skipExecute(t,s)){return false}this.store.dispatch("messages/update",{id:t.id,chatId:t.chatId,fields:{params:t.params}}).then(function(){a.controller.application.emit(i.EventType.dialog.scrollToBottom,{cancelIfScrollChange:true})})}},{key:"handleStartWriting",value:function e(t,s){if(this.skipExecute(t,s)){return false}this.controller.application.startOpponentWriting(t)}},{key:"handleReadMessage",value:function e(t,s){var a=this;if(this.skipExecute(t,s)){return false}this.store.dispatch("messages/readMessages",{chatId:t.chatId,readId:t.lastId}).then(function(e){a.store.dispatch("dialogues/update",{dialogId:t.dialogId,fields:{counter:t.counter}})});this.store.dispatch("recent/update",{id:t.dialogId,fields:{counter:t.counter}})}},{key:"handleReadMessageChat",value:function e(t,s){this.handleReadMessage(t,s)}},{key:"handleReadMessageOpponent",value:function e(t,s){this.execReadMessageOpponent(t,s)}},{key:"handleReadMessageChatOpponent",value:function e(t,s){this.execReadMessageOpponent(t,s)}},{key:"execReadMessageOpponent",value:function e(t,s){if(this.skipExecute(t,s)){return false}this.store.dispatch("dialogues/updateReaded",{dialogId:t.dialogId,userId:t.userId,userName:t.userName,messageId:t.lastId,date:t.date,action:true})}},{key:"handleUnreadMessageOpponent",value:function e(t,s){this.execUnreadMessageOpponent(t,s)}},{key:"handleUnreadMessageChatOpponent",value:function e(t,s){this.execUnreadMessageOpponent(t,s)}},{key:"execUnreadMessageOpponent",value:function e(t,s){if(this.skipExecute(t,s)){return false}this.store.dispatch("dialogues/updateReaded",{dialogId:t.dialogId,userId:t.userId,action:false})}},{key:"handleFileUpload",value:function e(s,a){var n=this;if(this.skipExecute(s,a)){return false}this.store.dispatch("files/set",this.controller.application.prepareFilesBeforeSave(t.VuexBuilderModel.convertToArray({file:s.fileParams}))).then(function(){n.controller.application.emit(i.EventType.dialog.scrollToBottom,{cancelIfScrollChange:true})})}},{key:"handleChatPin",value:function e(t,s){this.store.dispatch("recent/pin",{id:t.dialogId,action:t.active})}},{key:"handleChatHide",value:function e(t,s){this.store.dispatch("recent/delete",{id:t.dialogId})}},{key:"handleReadNotifyList",value:function e(t,s){this.store.dispatch("recent/update",{id:"notify",fields:{counter:t.counter}})}},{key:"handleUserInvite",value:function e(t,s){if(!t.invited){this.store.dispatch("users/update",{id:t.userId,fields:t.user})}}}]);return e}();var l=function(){babelHelpers.createClass(e,null,[{key:"create",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return new this(t)}}]);function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};babelHelpers.classCallCheck(this,e);if(babelHelpers.typeof(t.application)==="object"&&t.application){this.application=t.application}if(babelHelpers.typeof(t.controller)==="object"&&t.controller){this.controller=t.controller}if(babelHelpers.typeof(t.store)==="object"&&t.store){this.store=t.store}this.option=babelHelpers.typeof(t.store)==="object"&&t.store?t.store:{}}babelHelpers.createClass(e,[{key:"getModuleId",value:function e(){return"im"}},{key:"getSubscriptionType",value:function e(){return a.PullClient.SubscriptionType.Server}},{key:"handleChatUserAdd",value:function e(t){var s=Object.values(t.users).map(function(e){return babelHelpers.objectSpread({},e,{lastActivityDate:new Date})});this.store.commit("callApplication/common",{userCount:t.userCount});this.store.commit("users/set",s)}},{key:"handleChatUserLeave",value:function e(t){if(t.userId===this.controller.getUserId()&&t.dialogId===this.store.state.application.dialog.dialogId){this.application.kickFromCall()}this.store.commit("callApplication/common",{userCount:t.userCount})}},{key:"handleCallUserNameUpdate",value:function e(t){this.store.dispatch("users/update",{id:t.userId,fields:{name:t.name,lastActivityDate:new Date}})}},{key:"handleVideoconfShareUpdate",value:function e(t){if(t.dialogId===this.store.state.application.dialog.dialogId){this.application.changeVideoconfUrl(t.newLink)}}},{key:"handleMessageChat",value:function e(t){if(t.chatId===this.application.getChatId()&&!this.store.state.callApplication.common.showChat&&t.message.senderId!==this.controller.getUserId()){var s="";if(t.message.senderId===0||t.message.system==="Y"){s=t.message.text}else{var a=t.users[t.message.senderId].name;if(t.message.text===""&&Object.keys(t.files).length>0){s="".concat(a,": ").concat(this.controller.localize["BX_IM_COMPONENT_CALL_FILE"])}else if(t.message.text!==""){s="".concat(a,": ").concat(t.message.text)}}this.application.sendNewMessageNotify(s)}}}]);return e}();e.ImBasePullHandler=n;e.ImCallPullHandler=l})(this.BX.Messenger.Provider.Pull=this.BX.Messenger.Provider.Pull||{},BX,BX.Messenger.Lib,BX,BX.Messenger.Const);
//# sourceMappingURL=registry.bundle.map.js