$=e.controller,"@"==$&&($=h[e.name]),n=v($,i),M[e.name]=n,K||g.data("$"+e.name+"Controller",n),e.controllerAs&&(i.$scope[e.controllerAs]=n)}),_=0,b=p.length;b>_;_++)try{w=p[_],w(w.isolateScope?S:t,g,h,w.require&&m(w.require,g,M),C)}catch(T){c(T,V(g))}varE=t;for(F&&(F.template||null===F.templateUrl)&&(E=S),e&&e(E,s.childNodes,n,u),_=d.length-1;_>=0;_--)try{w=d[_],w(w.isolateScope?S:t,g,h,w.require&&m(w.require,g,M),C)}catch(T){c(T,V(g))}}f=f||{};for(varw,$,M,x,k,E,I=-Number.MAX_VALUE,U=f.controllerDirectives,F=f.newIsolateScopeDirective,q=f.templateDirective,z=f.nonTlbTranscludeDirective,G=!1,K=!1,Z=o.$$element=pi(r),J=u,et=s,tt=0,nt=e.length;nt>tt;tt++){$=e[tt];varrt=$.$$start,at=$.$$end;if(rt&&(Z=P(r,rt,at)),x=n,I>$.priority)break;if((E=$.scope)&&(w=w||$,$.templateUrl||(W("new/isolated scope",F,$,Z),_(E)&&(F=$))),M=$.name,!$.templateUrl&&$.controller&&(E=$.controller,U=U||{},W("'"+M+"' controller",U[M],$,Z),U[M]=$),(E=$.transclude)&&(G=!0,$.$$tlb||(W("transclusion",z,$,Z),z=$),"element"==E?(K=!0,I=$.priority,x=P(r,rt,at),Z=o.$$element=pi(t.createComment(" "+M+": "+o[M]+" ")),r=Z[0],X(l,pi(R(x)),r),et=T(x,s,I,J&&J.name,{nonTlbTranscludeDirective:z})):(x=pi(dt(r)).contents(),Z.empty(),et=T(x,s))),$.template)if(W("template",q,$,Z),q=$,E=C($.template)?$.template(Z,o):$.template,E=it(E),$.replace){if(J=$,x=pi("<div>"+wi(E)+"</div>").contents(),r=x[0],1!=x.length||1!==r.nodeType)throwji("tplrt","Template for directive '{0}' must have exactly one root element. {1}",M,"");X(l,Z,r);varot={$attr:{}},st=D(r,[],ot),ct=e.splice(tt+1,e.length-(tt+1));F&&O(st),e=e.concat(st).concat(ct),j(o,ot),nt=e.length}elseZ.html(E);if($.templateUrl)W("template",q,$,Z),q=$,$.replace&&(J=$),g=H(e.splice(tt,e.length-tt),Z,o,l,et,p,d,{controllerDirectives:U,newIsolateScopeDirective:F,templateDirective:q,nonTlbTranscludeDirective:z}),nt=e.length;elseif($.compile)try{k=$.compile(Z,o,et),C(k)?h(null,k,rt,at):k&&h(k.pre,k.post,rt,at)}catch(lt){c(lt,V(Z))}$.terminal&&(g.terminal=!0,I=Math.max(I,$.priority))}returng.scope=w&&w.scope===!0,g.transclude=G&&et,g}functionO(e){for(vart=0,n=e.length;n>t;t++)e[t]=f(e[t],{$$isolateScope:!0})}functionq(t,i,a,s,l,u,p){if(i===l)returnnull;vard=null;if(r.hasOwnProperty(i))for(varh,m=e.get(i+o),g=0,y=m.length;y>g;g++)try{h=m[g],(s===n||s>h.priority)&&-1!=h.restrict.indexOf(a)&&(u&&(h=f(h,{$$start:u,$$end:p})),t.push(h),d=h)}catch(v){c(v)}returnd}functionj(e,t){varn=t.$attr,i=e.$attr,r=e.$$element;a(e,function(i,r){"$"!=r.charAt(0)&&(t[r]&&(i+=("style"===r?";":" ")+t[r]),e.$set(r,i,!0,n[r]))}),a(t,function(t,a){"class"==a?(A(r,t),e["class"]=(e["class"]?e["class"]+" ":"")+t):"style"==a?(r.attr("style",r.attr("style")+";"+t),e.style=(e.style?e.style+";":"")+t):"$"==a.charAt(0)||e.hasOwnProperty(a)||(e[a]=t,i[a]=n[a])})}functionH(e,t,n,i,r,o,s,c){varl,u,f=[],m=t[0],g=e.shift(),y=p({},g,{templateUrl:null,transclude:null,replace:null,$$originalDirective:g}),v=C(g.templateUrl)?g.templateUrl(t,n):g.templateUrl;returnt.empty(),d.get(M.getTrustedResourceUrl(v),{cache:h}).success(function(p){vard,h,b,w;if(p=it(p),g.replace){if(b=pi("<div>"+wi(p)+"</div>").contents(),d=b[0],1!=b.length||1!==d.nodeType)throwji("tplrt","Template for directive '{0}' must have exactly one root element. {1}",g.name,v);h={$attr:{}},X(i,t,d);var$=D(d,[],h);_(g.scope)&&O($),e=$.concat(e),j(n,h)}elsed=m,t.html(p);for(e.unshift(y),l=U(e,d,n,r,t,g,o,s,c),a(i,function(e,n){e==d&&(i[n]=t[0])}),u=E(t[0].childNodes,r);f.length;){varS=f.shift(),C=f.shift(),M=f.shift(),x=f.shift(),k=t[0];C!==m&&(k=dt(d),X(M,pi(C),k)),w=l.transclude?I(S,l.transclude):x,l(u,S,k,i,w)}f=null}).error(function(e,t,n,i){throwji("tpload","Failed to load template: {0}",i.url)}),function(e,t,n,i,r){f?(f.push(t),f.push(n),f.push(i),f.push(r)):l(u,t,n,i,r)}}functionz(e,t){varn=t.priority-e.priority;return0!==n?n:e.name!==t.name?e.name<t.name?-1:1:e.index-t.index}functionW(e,t,n,i){if(t)throwji("multidir","Multiple directives [{0}, {1}] asking for {2} on: {3}",t.name,n.name,e,V(i))}functionG(e,t){varn=i(t,!0);n&&e.push({priority:0,compile:g(function(e,t){vari=t
if(e===ir.RESOURCE_URL){if(a(t))returnt;thrownr("insecurl","Blocked loading resource from url not allowed by $sceDelegate policy. URL: {0}",t.toString())}if(e===ir.HTML)returnu(t);thrownr("unsafe","Attempting to use an unsafe value in a safe context.")}varu=function(){thrownr("unsafe","Attempting to use an unsafe value in a safe context.")};i.has("$sanitize")&&(u=i.get("$sanitize"));varp=o(),d={};returnd[ir.HTML]=o(p),d[ir.CSS]=o(p),d[ir.URL]=o(p),d[ir.JS]=o(p),d[ir.RESOURCE_URL]=o(d[ir.URL]),{trustAs:s,getTrusted:l,valueOf:c}}]}functionEn(){vare=!0;this.enabled=function(t){returnarguments.length&&(e=!!t),e},this.$get=["$parse","$sniffer","$sceDelegate",function(t,n,i){if(e&&n.msie&&n.msieDocumentMode<8)thrownr("iequirks","Strict Contextual Escaping does not support Internet Explorer version < 9 in quirks mode. You can fix this by adding the text <!doctype html> to the top of your HTML document. See http://docs.angularjs.org/api/ng.$sce for more information.");varr=N(ir);r.isEnabled=function(){returne},r.trustAs=i.trustAs,r.getTrusted=i.getTrusted,r.valueOf=i.valueOf,e||(r.trustAs=r.getTrusted=function(e,t){returnt},r.valueOf=m),r.parseAs=function(e,n){vari=t(n);returni.literal&&i.constant?i:function(t,n){returnr.getTrusted(e,i(t,n))}};varo=r.parseAs,s=r.getTrusted,c=r.trustAs;returna(ir,function(e,t){varn=oi(t);r[lt("parse_as_"+n)]=function(t){returno(e,t)},r[lt("get_trusted_"+n)]=function(t){returns(e,t)},r[lt("trust_as_"+n)]=function(t){returnc(e,t)}}),r}]}functionIn(){this.$get=["$window","$document",function(e,t){varn,i,r={},a=d((/android (\d+)/.exec(oi((e.navigator||{}).userAgent))||[])[1]),o=/Boxee/i.test((e.navigator||{}).userAgent),s=t[0]||{},c=s.documentMode,l=/^(Moz|webkit|O|ms)(?=[A-Z])/,u=s.body&&s.body.style,p=!1,f=!1;if(u){for(varhinu)if(i=l.exec(h)){n=i[0],n=n.substr(0,1).toUpperCase()+n.substr(1);break}n||(n="WebkitOpacity"inu&&"webkit"),p=!!("transition"inu||n+"Transition"inu),f=!!("animation"inu||n+"Animation"inu),!a||p&&f||(p=b(s.body.style.webkitTransition),f=b(s.body.style.webkitAnimation))}return{history:!(!e.history||!e.history.pushState||4>a||o),hashchange:"onhashchange"ine&&(!c||c>7),hasEvent:function(e){if("input"==e&&9==ui)return!1;if(y(r[e])){vart=s.createElement("div");r[e]="on"+eint}returnr[e]},csp:U(),vendorPrefix:n,transitions:p,animations:f,android:a,msie:ui,msieDocumentMode:c}}]}functionDn(){this.$get=["$rootScope","$browser","$q","$exceptionHandler",function(e,t,n,i){functionr(r,o,s){varc,l=n.defer(),u=l.promise,p=v(s)&&!s;returnc=t.defer(function(){try{l.resolve(r())}catch(t){l.reject(t),i(t)}finally{deletea[u.$$timeoutId]}p||e.$apply()},o),u.$$timeoutId=c,a[c]=l,u}vara={};returnr.cancel=function(e){returne&&e.$$timeoutIdina?(a[e.$$timeoutId].reject("canceled"),deletea[e.$$timeoutId],t.defer.cancel(e.$$timeoutId)):!1},r}]}functionPn(e){vart=e;returnui&&(rr.setAttribute("href",t),t=rr.href),rr.setAttribute("href",t),{href:rr.href,protocol:rr.protocol?rr.protocol.replace(/:$/,""):"",host:rr.host,search:rr.search?rr.search.replace(/^\?/,""):"",hash:rr.hash?rr.hash.replace(/^#/,""):"",hostname:rr.hostname,port:rr.port,pathname:"/"===rr.pathname.charAt(0)?rr.pathname:"/"+rr.pathname}}functionNn(e){vart=b(e)?Pn(e):e;returnt.protocol===ar.protocol&&t.host===ar.host}functionLn(){this.$get=g(e)}functionBn(e){functiont(i,r){if(_(i)){varo={};returna(i,function(e,n){o[n]=t(n,e)}),o}returne.factory(i+n,r)}varn="Filter";this.register=t,this.$get=["$injector",function(e){returnfunction(t){returne.get(t+n)}}],t("currency",On),t("date",Wn),t("filter",Un),t("json",Gn),t("limitTo",Kn),t("lowercase",ur),t("number",Rn),t("orderBy",Zn),t("uppercase",pr)}functionUn(){returnfunction(e,t,n){if(!S(e))returne;vari=typeofn,r=[];r.check=function(e){for(vart=0;t<r.length;t++)if(!r[t](e))return!1;return!0},"function"!==i&&(n="boolean"===i&&n?function(e,t){return_i.equals(e,t)}:function(e,t){returnt=(""+t).toLowerCase(),(""+e).toLowerCase().indexOf(t)>-1});vara=function(e,t){if("string"==typeoft&&"!"===t.charAt(0))return!a(e,t.substr(1));
})}}}),fr={};a(Pi,function(e,t){if("multiple"!=e){varn=Ut("ng-"+t);fr[n]=function(){return{priority:100,link:function(e,i,r){e.$watch(r[n],function(e){r.$set(t,!!e)})}}}}}),a(["src","srcset","href"],function(e){vart=Ut("ng-"+e);fr[t]=function(){return{priority:99,link:function(n,i,r){r.$observe(t,function(t){t&&(r.$set(e,t),ui&&i.prop(e,r[e]))})}}}});varhr={$addControl:h,$removeControl:h,$setValidity:h,$setDirty:h,$setPristine:h};Yn.$inject=["$element","$attrs","$scope"];varmr=function(e){return["$timeout",function(t){vari={name:"form",restrict:e?"EAC":"E",controller:Yn,compile:function(){return{pre:function(e,i,r,a){if(!r.action){varo=function(e){e.preventDefault?e.preventDefault():e.returnValue=!1};ki(i[0],"submit",o),i.on("$destroy",function(){t(function(){Ti(i[0],"submit",o)},0,!1)})}vars=i.parent().controller("form"),c=r.name||r.ngForm;c&&gn(e,c,a,c),s&&i.on("$destroy",function(){s.$removeControl(a),c&&gn(e,c,n,c),p(a,hr)})}}}};returni}]},gr=mr(),yr=mr(!0),vr=/^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/,_r=/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}$/,br=/^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/,wr={text:Jn,number:ei,url:ti,email:ni,radio:ii,checkbox:ri,hidden:h,button:h,submit:h,reset:h},$r=["$browser","$sniffer",function(e,t){return{restrict:"E",require:"?ngModel",link:function(n,i,r,a){a&&(wr[oi(r.type)]||wr.text)(n,i,r,a,t,e)}}}],Sr="ng-valid",Cr="ng-invalid",Mr="ng-pristine",xr="ng-dirty",kr=["$scope","$exceptionHandler","$attrs","$element","$parse",function(e,t,n,r,o){functions(e,t){t=t?"-"+J(t,"-"):"",r.removeClass((e?Cr:Sr)+t).addClass((e?Sr:Cr)+t)}this.$viewValue=Number.NaN,this.$modelValue=Number.NaN,this.$parsers=[],this.$formatters=[],this.$viewChangeListeners=[],this.$pristine=!0,this.$dirty=!1,this.$valid=!0,this.$invalid=!1,this.$name=n.name;varc=o(n.ngModel),l=c.assign;if(!l)throwi("ngModel")("nonassign","Expression '{0}' is non-assignable. Element: {1}",n.ngModel,V(r));this.$render=h,this.$isEmpty=function(e){returny(e)||""===e||null===e||e!==e};varu=r.inheritedData("$formController")||hr,p=0,d=this.$error={};r.addClass(Mr),s(!0),this.$setValidity=function(e,t){d[e]!==!t&&(t?(d[e]&&p--,p||(s(!0),this.$valid=!0,this.$invalid=!1)):(s(!1),this.$invalid=!0,this.$valid=!1,p++),d[e]=!t,s(t,e),u.$setValidity(e,t,this))},this.$setPristine=function(){this.$dirty=!1,this.$pristine=!0,r.removeClass(xr).addClass(Mr)},this.$setViewValue=function(n){this.$viewValue=n,this.$pristine&&(this.$dirty=!0,this.$pristine=!1,r.removeClass(Mr).addClass(xr),u.$setDirty()),a(this.$parsers,function(e){n=e(n)}),this.$modelValue!==n&&(this.$modelValue=n,l(e,n),a(this.$viewChangeListeners,function(e){try{e()}catch(n){t(n)}}))};varf=this;e.$watch(function(){vart=c(e);if(f.$modelValue!==t){varn=f.$formatters,i=n.length;for(f.$modelValue=t;i--;)t=n[i](t);f.$viewValue!==t&&(f.$viewValue=t,f.$render())}returnt})}],Tr=function(){return{require:["ngModel","^?form"],controller:kr,link:function(e,t,n,i){varr=i[0],a=i[1]||hr;a.$addControl(r),e.$on("$destroy",function(){a.$removeControl(r)})}}},Ar=g({require:"ngModel",link:function(e,t,n,i){i.$viewChangeListeners.push(function(){e.$eval(n.ngChange)})}}),Er=function(){return{require:"?ngModel",link:function(e,t,n,i){if(i){n.required=!0;varr=function(e){returnn.required&&i.$isEmpty(e)?voidi.$setValidity("required",!1):(i.$setValidity("required",!0),e)};i.$formatters.push(r),i.$parsers.unshift(r),n.$observe("required",function(){r(i.$viewValue)})}}}},Ir=function(){return{require:"ngModel",link:function(e,t,i,r){varo=/\/(.*)\//.exec(i.ngList),s=o&&newRegExp(o[1])||i.ngList||",",c=function(e){if(!y(e)){vart=[];returne&&a(e.split(s),function(e){e&&t.push(wi(e))}),t}};r.$parsers.push(c),r.$formatters.push(function(e){returnS(e)?e.join(", "):n}),r.$isEmpty=function(e){return!e||!e.length}}}},Dr=/^(true|false|\d+)$/,Pr=function(){return{priority:100,compile:function(e,t){returnDr.test(t.ngValue)?function(e,t,n){n.$set("value",e.$eval(n.ngValue))}:function(e,t,n){e.$watch(n.ngValue,function(e){n.$set("value",e)})}}}},Nr=Xn(functio
if(16==e.error_code||17==e.error_code){t.applyServerTime(bigStringInt(n).shiftRight(32).toString(10))&&this.updateSession();vars=this.updateSentMessage(e.bad_msg_id);this.pushResend(s.msg_id),this.ackMessage(n)}break;case"message":this.serverMessages.push(e.msg_id),this.processMessage(e.body,e.msg_id,i);break;case"new_session_created":this.ackMessage(n),this.processMessageAck(e.first_msg_id),this.applyServerSalt(e.server_salt),this.onSessionCreate(i,n);break;case"msgs_ack":for(vara=0;a<e.msg_ids.length;a++)this.processMessageAck(e.msg_ids[a]);break;case"msg_detailed_info":if(!this.sentMessages[e.msg_id]){this.ackMessage(e.answer_msg_id);break}case"msg_new_detailed_info":this.reqResendMessage(e.answer_msg_id);break;case"rpc_result":this.ackMessage(n);varc=e.req_msg_id,o=this.sentMessages[c];if(this.processMessageAck(c),o){varl=o.deferred;if("rpc_error"==e.result._){varu=this.processError(e.result);console.log(dT(),"Rpc error",u),l&&l.reject(u)}elsel&&(window._debugMode?console.log(dT(),"Rpc response",e.result):console.log(dT(),"Rpc response",e.result._),o.deferred.resolve(e.result)),o.isAPI&&(this.connectionInited=!0);deletethis.sentMessages[c]}break;default:this.ackMessage(n),d&&d(e)}},{getNetworker:function(e,t,n,i){returnnewp(e,t,n,i)},setUpdatesProcessor:function(e){d=e}}}]).factory("MtpApiManager",["AppConfigManager","MtpAuthorizer","MtpNetworkerFactory","ErrorService","$q",function(e,t,n,i,r){functiona(t,n){e.set({dc:t,user_auth:angular.extend({dcID:t},n)}),h=t}functiono(){returnc("auth.logOut").then(function(){e.remove("dc","user_auth"),h=!1},function(t){e.remove("dc","user_auth"),t&&401!=t.code&&e.remove("dc"+h+"_auth_key"),h=!1,t.handled=!0})}functions(i,a){a=a||{};varo=a.fileUpload||a.fileDownload?d:p;if(!i)thrownewException("get Networker without dcID");if(void0!==o[i])returnr.when(o[i]);vars="dc"+i+"_auth_key",c="dc"+i+"_server_salt";returne.get(s,c).then(function(l){if(void0!==o[i])returno[i];varu=l[0],p=l[1];if(u&&512==u.length){vard=bytesFromHex(u),f=bytesFromHex(p);returno[i]=n.getNetworker(i,d,f,a)}returna.createNetworker?t.auth(i).then(function(t){varr={};returnr[s]=bytesToHex(t.authKey),r[c]=bytesToHex(t.serverSalt),e.set(r),o[i]=n.getNetworker(i,t.authKey,t.serverSalt,a)},function(e){returnconsole.log("Get networker error",e,e.stack),r.reject(e)}):r.reject({type:"AUTH_KEY_EMPTY",code:401})})}functionc(t,n,a){a=a||{};varo,l,u=r.defer(),p=function(e){e?angular.isObject(e)||(e={message:e}):e={type:"ERROR_EMPTY"},u.reject(e),a.noErrorBox||(e.input=t,e.stack=e.stack||m,setTimeout(function(){e.handled||(i.show({error:e}),e.handled=!0)},100))};l=(o=a.dcID)?s(o,a):e.get("dc").then(function(e){returns(o=e||1,a)});vard,m=!1;if(l.then(function(i){return(d=i).wrapApiCall(t,n,a).then(function(e){u.resolve(e)},function(l){if(console.error(dT(),"Error",l.code,l.type,h,o),401==l.code&&h==o)e.remove("dc","user_auth");elseif(401==l.code&&h&&o!=h){if(void0===f[o]){varm=r.defer();c("auth.exportAuthorization",{dc_id:o},{noErrorBox:!0}).then(function(e){c("auth.importAuthorization",{id:e.id,bytes:e.bytes},{dcID:o,noErrorBox:!0}).then(function(){m.resolve()},function(e){m.reject(e)})},function(e){m.reject(e)}),f[o]=m.promise}f[o].then(function(){(d=i).wrapApiCall(t,n,a).then(function(e){u.resolve(e)},function(e){p(e)})},function(e){p(e)})}elseif(303==l.code){varg=l.type.match(/^(PHONE_MIGRATE_|NETWORK_MIGRATE_)(\d+)/)[2];g!=o&&(a.dcID?a.dcID=g:e.set({dc:h=g}),s(g,a).then(function(e){e.wrapApiCall(t,n,a).then(function(e){u.resolve(e)},function(e){p(e)})}))}elsep(l)})},function(e){p(e)}),!(m=m||(newError).stack))try{window.unexistingFunction()}catch(g){m=g.stack||""}returnu.promise}functionl(){returne.get("user_auth").then(function(e){returne.id||0})}functionu(){returnh||!1}varp={},d={},f={},h=!1;returne.get("dc").then(function(e){e&&(h=e)}),{getBaseDcID:u,getUserID:l,invokeApi:c,setUserAuth:a,logOut:o}}]).factory("MtpApiFileManager",["MtpApiManager","$q","$window",function(e,t,n){functioni(e,n,i){void0===_[e]&&(_[e]=[],b[e]=0);vara=_[e],o=t.defer();returna.push({cb:n,deferr
}t.action.user_id&&(t.action.user=a.getUser(t.action.user_id),t.action.userPhoto=a.getUserPhoto(t.action.user_id,"User"))}returnt.message&&t.message.length&&(t.richMessage=h.wrapRichText(t.message)),R[e]=t}functionB(e){for(vart=0;t<j.dialogs.length;t++)if(j.dialogs[t].peerID==e)return[j.dialogs[t],t];return[]}functionU(e){varn,i,r=P(e),s=a.getUser(e.from_id),c=a.getUserPhoto(e.from_id,"User"),l={},u=!1;if(e.message)u=e.message;elseif(e.media&&"messageMediaEmpty"!=e.media._)switch(e.media._){case"messageMediaPhoto":u="Photo";break;case"messageMediaVideo":u="Video";break;case"messageMediaDocument":u="Document";break;case"messageMediaGeo":u="Location";break;case"messageMediaContact":u="Contact";break;default:u="Attachment"}elseif("messageService"==e._)switch(e.action._){case"messageActionChatCreate":u="created the group";break;case"messageActionChatEditTitle":u="changed group name";break;case"messageActionChatEditPhoto":u="changed group photo";break;case"messageActionChatDeletePhoto":u="removed group photo";break;case"messageActionChatAddUser":u="invited user";break;case"messageActionChatDeleteUser":u="kicked user"}r>0?(l.title=(s.first_name||"")+(s.first_name&&s.last_name?" ":"")+(s.last_name||""),i=c,n=a.getUserString(r)):(l.title=(s.first_name||s.last_name||"Somebody")+" @ "+(o.getChat(-r).title||"Unknown chat"),i=o.getChatPhoto(-r,"Group"),n=o.getChatString(-r)),l.onclick=function(){t.$broadcast("history_focus",{peerString:n})},l.message=u,l.image=i.placeholder,l.key="msg"+e.id,l.tag=n,i.location&&!i.location.empty?f.downloadSmallFile(i.location,i.size).then(function(t){l.image=t,e.unread&&m.notify(l)}):m.notify(l)}varO={},R={},F={},q={},j={count:null,dialogs:[]},H={},z={},V={},W=e.when(),G=-1,K=g.createIndex(),Z={query:!1},X={},Y=[];returnm.start(),t.$on("apiUpdate",function(e,n){switch(n._){case"updateMessageID":z[n.id]=n.random_id;break;case"updateNewMessage":vari=n.message,r=P(i),a=q[r];if(void0!==a){varo=q[r].history[0];if(i.id<=o)return!1}elsea=q[r]={count:null,history:[],pending:[]};x([i]),null!==a.count&&a.count++,a.history.unshift(i.id);varc,l=z[i.id];l&&((c=D(l,i))&&t.$broadcast("history_update",{peerID:r}),deletez[i.id]),c||t.$broadcast("history_append",{peerID:r,messageID:i.id});varu,p=B(r);p.length?(u=p[0],j.dialogs.splice(p[1],1)):u={peerID:r,unread_count:0,top_message:!1},!i.out&&i.unread&&u.unread_count++,u.top_message=i.id,g.indexObject(r,s.getPeerSearchText(r),K),j.dialogs.unshift(u),t.$broadcast("dialogs_update",u),t.idle.isIDLE&&!i.out&&i.unread&&m.getPeerMuted(r).then(function(e){i.unread&&!e&&U(i)});break;case"updateReadMessages":vard,i,f,r,p,u,h={};for(f=0;f<n.messages.length;f++)d=n.messages[f],i=O[d],i&&i.unread&&(i.unread=!1,R[d]&&(R[d].unread=!1),F[d]&&(F[d].unread=!1),r=P(i),i.out||(p=B(r),p&&(h[r]=--p[0].unread_count),m.cancel("msg"+d)));angular.forEach(h,function(e,n){t.$broadcast("dialog_unread",{peerID:n,count:e})});break;case"updateDeleteMessages":vard,i,f,r,p,u,y,h={},v={};for(f=0;f<n.messages.length;f++)d=n.messages[f],i=O[d],i&&(r=P(i),y=v[r]||(v[r]={count:0,unread:0,msgs:{}}),!i.out&&i.unread&&(y.unread++,m.cancel("msg"+d)),y.count++,y.msgs[d]=!0,R[d]&&(R[d].DELETED=!0,deleteR[d]),F[d]&&(F[d].DELETED=!0,deleteF[d]),i.DELETED=!0,deleteO[d]);angular.forEach(v,function(e,n){vari=B(n);i&&e.unread&&(i[0].unread_count-=e.unread,t.$broadcast("dialog_unread",{peerID:n,count:i[0].unread_count}));varr=q[n];if(void0!==r){for(vara=[],o=[],s=0;s<r.history.length;s++)e.msgs[r.history[s]]||a.push(r.history[s]);r.history=a;for(vars=0;s<r.pending.length;s++)e.msgs[r.pending[s]]||o.push(r.pending[s]);r.pending=o,t.$broadcast("history_delete",{peerID:n,msgs:e.msgs})}})}}),{getDialogs:y,getHistory:_,getSearch:b,getMessage:w,readHistory:C,flushHistory:M,deleteMessages:$,saveMessages:x,sendText:k,sendFile:T,sendOther:A,forwardMessages:E,getMessagePeer:P,wrapForDialog:N,wrapForHistory:L}}]).service("AppPhotosManager",["$modal","$window","$rootScope","MtpApiFileManager","AppUsersManager",function(e,t,n,i,r){functiona(e){p[e.id]=e,angular.forEach(e.sizes,function(e){"photoCachedSi