diff --git a/app.manifest b/app.manifest index e53eb609..54375d2c 100644 --- a/app.manifest +++ b/app.manifest @@ -1,5 +1,5 @@ CACHE MANIFEST -# Time: Wed Oct 15 2014 22:22:13 GMT+0400 (MSK) +# Time: Wed Oct 15 2014 23:29:16 GMT+0400 (MSK) CACHE: diff --git a/js/app.js b/js/app.js index f28152ee..af5a4db3 100644 --- a/js/app.js +++ b/js/app.js @@ -12,7 +12,7 @@ return s(n,t[0],t),n};return{scope:!1,link:function(e,t,n){var i=n.playlist,a=n. for(var i=goog.math.Long.fromNumber(Math.pow(n,8)),a=goog.math.Long.ZERO,o=0;or){var c=goog.math.Long.fromNumber(Math.pow(n,r));a=a.multiply(c).add(goog.math.Long.fromNumber(s))}else a=a.multiply(i),a=a.add(goog.math.Long.fromNumber(s))}return a},goog.math.Long.TWO_PWR_16_DBL_=65536,goog.math.Long.TWO_PWR_24_DBL_=1<<24,goog.math.Long.TWO_PWR_32_DBL_=goog.math.Long.TWO_PWR_16_DBL_*goog.math.Long.TWO_PWR_16_DBL_,goog.math.Long.TWO_PWR_31_DBL_=goog.math.Long.TWO_PWR_32_DBL_/2,goog.math.Long.TWO_PWR_48_DBL_=goog.math.Long.TWO_PWR_32_DBL_*goog.math.Long.TWO_PWR_16_DBL_,goog.math.Long.TWO_PWR_64_DBL_=goog.math.Long.TWO_PWR_32_DBL_*goog.math.Long.TWO_PWR_32_DBL_,goog.math.Long.TWO_PWR_63_DBL_=goog.math.Long.TWO_PWR_64_DBL_/2,goog.math.Long.ZERO=goog.math.Long.fromInt(0),goog.math.Long.ONE=goog.math.Long.fromInt(1),goog.math.Long.NEG_ONE=goog.math.Long.fromInt(-1),goog.math.Long.MAX_VALUE=goog.math.Long.fromBits(-1,2147483647),goog.math.Long.MIN_VALUE=goog.math.Long.fromBits(0,-2147483648),goog.math.Long.TWO_PWR_24_=goog.math.Long.fromInt(1<<24),goog.math.Long.prototype.toInt=function(){return this.low_},goog.math.Long.prototype.toNumber=function(){return this.high_*goog.math.Long.TWO_PWR_32_DBL_+this.getLowBitsUnsigned()},goog.math.Long.prototype.toString=function(e){var t=e||10;if(2>t||t>36)throw Error("radix out of range: "+t);if(this.isZero())return"0";if(this.isNegative()){if(this.equals(goog.math.Long.MIN_VALUE)){var n=goog.math.Long.fromNumber(t),i=this.div(n),a=i.multiply(n).subtract(this);return i.toString(t)+a.toInt().toString(t)}return"-"+this.negate().toString(t)}for(var o=goog.math.Long.fromNumber(Math.pow(t,6)),a=this,r="";;){var s=a.div(o),c=a.subtract(s.multiply(o)).toInt(),l=c.toString(t);if(a=s,a.isZero())return l+r;for(;l.length<6;)l="0"+l;r=""+l+r}},goog.math.Long.prototype.getHighBits=function(){return this.high_},goog.math.Long.prototype.getLowBits=function(){return this.low_},goog.math.Long.prototype.getLowBitsUnsigned=function(){return this.low_>=0?this.low_:goog.math.Long.TWO_PWR_32_DBL_+this.low_},goog.math.Long.prototype.getNumBitsAbs=function(){if(this.isNegative())return this.equals(goog.math.Long.MIN_VALUE)?64:this.negate().getNumBitsAbs();for(var e=0!=this.high_?this.high_:this.low_,t=31;t>0&&0==(e&1<0},goog.math.Long.prototype.greaterThanOrEqual=function(e){return this.compare(e)>=0},goog.math.Long.prototype.compare=function(e){if(this.equals(e))return 0;var t=this.isNegative(),n=e.isNegative();return t&&!n?-1:!t&&n?1:this.subtract(e).isNegative()?-1:1},goog.math.Long.prototype.negate=function(){return this.equals(goog.math.Long.MIN_VALUE)?goog.math.Long.MIN_VALUE:this.not().add(goog.math.Long.ONE)},goog.math.Long.prototype.add=function(e){var t=this.high_>>>16,n=65535&this.high_,i=this.low_>>>16,a=65535&this.low_,o=e.high_>>>16,r=65535&e.high_,s=e.low_>>>16,c=65535&e.low_,l=0,d=0,u=0,p=0;return p+=a+c,u+=p>>>16,p&=65535,u+=i+s,d+=u>>>16,u&=65535,d+=n+r,l+=d>>>16,d&=65535,l+=t+o,l&=65535,goog.math.Long.fromBits(u<<16|p,l<<16|d)},goog.math.Long.prototype.subtract=function(e){return this.add(e.negate())},goog.math.Long.prototype.multiply=function(e){if(this.isZero())return goog.math.Long.ZERO;if(e.isZero())return goog.math.Long.ZERO;if(this.equals(goog.math.Long.MIN_VALUE))return e.isOdd()?goog.math.Long.MIN_VALUE:goog.math.Long.ZERO;if(e.equals(goog.math.Long.MIN_VALUE))return this.isOdd()?goog.math.Long.MIN_VALUE:goog.math.Long.ZERO;if(this.isNegative())return e.isNegative()?this.negate().multiply(e.negate()):this.negate().multiply(e).negate();if(e.isNegative())return this.multiply(e.negate()).negate();if(this.lessThan(goog.math.Long.TWO_PWR_24_)&&e.lessThan(goog.math.Long.TWO_PWR_24_))return goog.math.Long.fromNumber(this.toNumber()*e.toNumber());var t=this.high_>>>16,n=65535&this.high_,i=this.low_>>>16,a=65535&this.low_,o=e.high_>>>16,r=65535&e.high_,s=e.low_>>>16,c=65535&e.low_,l=0,d=0,u=0,p=0;return p+=a*c,u+=p>>>16,p&=65535,u+=i*c,d+=u>>>16,u&=65535,u+=a*s,d+=u>>>16,u&=65535,d+=n*c,l+=d>>>16,d&=65535,d+=i*s,l+=d>>>16,d&=65535,d+=a*r,l+=d>>>16,d&=65535,l+=t*c+n*s+i*r+a*o,l&=65535,goog.math.Long.fromBits(u<<16|p,l<<16|d)},goog.math.Long.prototype.div=function(e){if(e.isZero())throw Error("division by zero");if(this.isZero())return goog.math.Long.ZERO;if(this.equals(goog.math.Long.MIN_VALUE)){if(e.equals(goog.math.Long.ONE)||e.equals(goog.math.Long.NEG_ONE))return goog.math.Long.MIN_VALUE;if(e.equals(goog.math.Long.MIN_VALUE))return goog.math.Long.ONE;var t=this.shiftRight(1),n=t.div(e).shiftLeft(1);if(n.equals(goog.math.Long.ZERO))return e.isNegative()?goog.math.Long.ONE:goog.math.Long.NEG_ONE;var i=this.subtract(e.multiply(n)),a=n.add(i.div(e));return a}if(e.equals(goog.math.Long.MIN_VALUE))return goog.math.Long.ZERO;if(this.isNegative())return e.isNegative()?this.negate().div(e.negate()):this.negate().div(e).negate();if(e.isNegative())return this.div(e.negate()).negate();for(var o=goog.math.Long.ZERO,i=this;i.greaterThanOrEqual(e);){for(var n=Math.max(1,Math.floor(i.toNumber()/e.toNumber())),r=Math.ceil(Math.log(n)/Math.LN2),s=48>=r?1:Math.pow(2,r-48),c=goog.math.Long.fromNumber(n),l=c.multiply(e);l.isNegative()||l.greaterThan(i);)n-=s,c=goog.math.Long.fromNumber(n),l=c.multiply(e);c.isZero()&&(c=goog.math.Long.ONE),o=o.add(c),i=i.subtract(l)}return o},goog.math.Long.prototype.modulo=function(e){return this.subtract(this.div(e).multiply(e))},goog.math.Long.prototype.not=function(){return goog.math.Long.fromBits(~this.low_,~this.high_)},goog.math.Long.prototype.and=function(e){return goog.math.Long.fromBits(this.low_&e.low_,this.high_&e.high_)},goog.math.Long.prototype.or=function(e){return goog.math.Long.fromBits(this.low_|e.low_,this.high_|e.high_)},goog.math.Long.prototype.xor=function(e){return goog.math.Long.fromBits(this.low_^e.low_,this.high_^e.high_)},goog.math.Long.prototype.shiftLeft=function(e){if(e&=63,0==e)return this;var t=this.low_;if(32>e){var n=this.high_;return goog.math.Long.fromBits(t<>>32-e)}return goog.math.Long.fromBits(0,t<e){var n=this.low_;return goog.math.Long.fromBits(n>>>e|t<<32-e,t>>e)}return goog.math.Long.fromBits(t>>e-32,t>=0?0:-1)},goog.math.Long.prototype.shiftRightUnsigned=function(e){if(e&=63,0==e)return this;var t=this.high_;if(32>e){var n=this.low_;return goog.math.Long.fromBits(n>>>e|t<<32-e,t>>>e)}return 32==e?goog.math.Long.fromBits(t,0):goog.math.Long.fromBits(t>>>e-32,0)};var _logTimer=(new Date).getTime();TLSerialization.prototype.createBuffer=function(){this.buffer=new ArrayBuffer(this.maxLength),this.intView=new Int32Array(this.buffer),this.byteView=new Uint8Array(this.buffer)},TLSerialization.prototype.getArray=function(){var e=new ArrayBuffer(this.offset),t=new Int32Array(e);return t.set(this.intView.subarray(0,this.offset/4)),t},TLSerialization.prototype.getBuffer=function(){return this.getArray().buffer},TLSerialization.prototype.getBytes=function(){for(var e=[],t=0;t>>",e.toString(16),e,t),this.checkLength(4),this.intView[this.offset/4]=e,this.offset+=4},TLSerialization.prototype.storeInt=function(e,t){this.writeInt(e,(t||"")+":int")},TLSerialization.prototype.storeBool=function(e,t){e?this.writeInt(2574415285,(t||"")+":bool"):this.writeInt(3162085175,(t||"")+":bool")},TLSerialization.prototype.storeLongP=function(e,t,n){this.writeInt(t,(n||"")+":long[low]"),this.writeInt(e,(n||"")+":long[high]")},TLSerialization.prototype.storeLong=function(e,t){if(angular.isArray(e))return 2==e.length?this.storeLongP(e[0],e[1],t):this.storeIntBytes(e,64,t);var n=bigStringInt(e).divideAndRemainder(bigint(4294967296));this.writeInt(intToUint(n[1].intValue()),(t||"")+":long[low]"),this.writeInt(intToUint(n[0].intValue()),(t||"")+":long[high]")},TLSerialization.prototype.storeDouble=function(e){var t=new ArrayBuffer(8),n=new Int32Array(t),i=new Float64Array(t);i[0]=e,this.writeInt(n[0],(field||"")+":double[low]"),this.writeInt(n[1],(field||"")+":double[high]")},TLSerialization.prototype.storeString=function(e,t){this.debug&&console.log(">>>",e,(t||"")+":string");var n=unescape(encodeURIComponent(e));this.checkLength(n.length+8);var i=n.length;253>=i?this.byteView[this.offset++]=i:(this.byteView[this.offset++]=254,this.byteView[this.offset++]=255&i,this.byteView[this.offset++]=(65280&i)>>8,this.byteView[this.offset++]=(16711680&i)>>16);for(var a=0;i>a;a++)this.byteView[this.offset++]=n.charCodeAt(a);for(;this.offset%4;)this.byteView[this.offset++]=0},TLSerialization.prototype.storeBytes=function(e,t){this.debug&&console.log(">>>",bytesToHex(e),(t||"")+":bytes"),this.checkLength(e.length+8);var n=e.length;253>=n?this.byteView[this.offset++]=n:(this.byteView[this.offset++]=254,this.byteView[this.offset++]=255&n,this.byteView[this.offset++]=(65280&n)>>8,this.byteView[this.offset++]=(16711680&n)>>16);for(var i=0;n>i;i++)this.byteView[this.offset++]=e[i];for(;this.offset%4;)this.byteView[this.offset++]=0},TLSerialization.prototype.storeIntBytes=function(e,t,n){var i=e.length;if(t%32||8*i!=t)throw new Error("Invalid bits: "+t+", "+e.length);this.debug&&console.log(">>>",bytesToHex(e),(n||"")+":int"+t),this.checkLength(i);for(var a=0;i>a;a++)this.byteView[this.offset++]=e[a]},TLSerialization.prototype.storeRawBytes=function(e,t){var n=e.length;this.debug&&console.log(">>>",bytesToHex(e),t||""),this.checkLength(n);for(var i=0;n>i;i++)this.byteView[this.offset++]=e[i]},TLSerialization.prototype.storeMethod=function(e,t){var n,i=this.mtproto?Config.Schema.MTProto:Config.Schema.API,a=!1;for(n=0;n=4*this.intView.length)throw new Error("Nothing to fetch: "+e);var t=this.intView[this.offset/4];return this.debug&&console.log("<<<",t.toString(16),t,e),this.offset+=4,t},TLDeserialization.prototype.fetchInt=function(e){return this.readInt((e||"")+":int")},TLDeserialization.prototype.fetchDouble=function(e){var t=new ArrayBuffer(8),n=new Int32Array(t),i=new Float64Array(t);return n[0]=this.readInt((e||"")+":double[low]"),n[1]=this.readInt((e||"")+":double[high]"),i[0]},TLDeserialization.prototype.fetchLong=function(e){var t=this.readInt((e||"")+":long[low]"),n=this.readInt((e||"")+":long[high]"),i=bigint(n).shiftLeft(32).add(bigint(t)).toString();return i},TLDeserialization.prototype.fetchBool=function(e){var t=this.readInt((e||"")+":bool");return 2574415285==t?!0:3162085175==t?!1:(this.offset-=4,this.fetchObject("Object",e))},TLDeserialization.prototype.fetchString=function(e){var t=this.byteView[this.offset++];if(254==t)var t=this.byteView[this.offset++]|this.byteView[this.offset++]<<8|this.byteView[this.offset++]<<16;for(var n="",i=0;t>i;i++)n+=String.fromCharCode(this.byteView[this.offset++]);for(;this.offset%4;)this.offset++;try{var a=decodeURIComponent(escape(n))}catch(o){var a=n}return this.debug&&console.log("<<<",a,(e||"")+":string"),a},TLDeserialization.prototype.fetchBytes=function(e){var t=this.byteView[this.offset++];if(254==t)var t=this.byteView[this.offset++]|this.byteView[this.offset++]<<8|this.byteView[this.offset++]<<16;for(var n=[],i=0;t>i;i++)n.push(this.byteView[this.offset++]);for(;this.offset%4;)this.offset++;return this.debug&&console.log("<<<",bytesToHex(n),(e||"")+":bytes"),n},TLDeserialization.prototype.fetchIntBytes=function(e,t){if(e%32)throw new Error("Invalid bits: "+e);for(var n=e/8,i=[],a=0;n>a;a++)i.push(this.byteView[this.offset++]);return this.debug&&console.log("<<<",bytesToHex(i),(t||"")+":int"+e),i},TLDeserialization.prototype.fetchRawBytes=function(e,t){e===!1&&(e=this.readInt((t||"")+"_length"));for(var n=[],i=0;e>i;i++)n.push(this.byteView[this.offset++]);return this.debug&&console.log("<<<",bytesToHex(n),t||""),n},TLDeserialization.prototype.fetchObject=function(e,t){switch(e){case"int":return this.fetchInt(t);case"long":return this.fetchLong(t);case"int128":return this.fetchIntBytes(128,t);case"int256":return this.fetchIntBytes(256,t);case"int512":return this.fetchIntBytes(512,t);case"string":return this.fetchString(t);case"bytes":return this.fetchBytes(t);case"double":return this.fetchDouble(t);case"Bool":return this.fetchBool(t)}if(t=t||e||"Object","Vector"==e.substr(0,6)||"vector"==e.substr(0,6)){if("V"==e.charAt(0)){var n=this.readInt(t+"[id]");if(481674261!=n)throw new Error("Invalid vector constructor "+n)}var i=this.readInt(t+"[count]"),a=[];if(i>0)for(var o=e.substr(7,e.length-8),r=0;i>r;r++)a.push(this.fetchObject(o,t+"["+r+"]"));return a}var s=this.mtproto?Config.Schema.MTProto:Config.Schema.API,c=!1,l=!1;if("%"==e.charAt(0)){var d=e.substr(1);for(r=0;r=97&&e.charAt(0)<=122){for(r=0;rDownload").css({position:"absolute",top:1,left:1}).attr("href",e).attr("target","_blank").attr("download",i).appendTo("body");a[0].dataset.downloadurl=[n,i,e].join(":"),a[0].click(),t(function(){a.remove()},100)}e.URL=e.URL||e.webkitURL,e.BlobBuilder=e.BlobBuilder||e.WebKitBlobBuilder||e.MozBlobBuilder;var p=!0;try{o([],"")}catch(m){p=!1}return{isAvailable:i,copy:a,write:r,getFileWriter:c,getFakeFileWriter:l,chooseSave:s,getUrl:d,download:u}}]).service("IdbFileStorage",["$q","$window","FileManager",function(e,t,n){function i(){return p}function a(){if(c)return c;try{var t=indexedDB.open(l,u),n=e.defer(),i=function(e){e.createObjectStore(d)};if(!t)throw new Exception}catch(a){return p=!1,e.reject(a)}return t.onsuccess=function(){db=t.result,db.onerror=function(e){p=!1,console.error("Error creating/accessing IndexedDB database",e),n.reject(e)},db.setVersion&&db.version!=u?db.setVersion(u).onsuccess=function(){i(db),n.resolve(db)}:n.resolve(db)},t.onerror=function(e){p=!1,console.error("Error creating/accessing IndexedDB database",e),n.reject(e)},t.onupgradeneeded=function(e){i(e.target.result)},c=n.promise}function o(t,n){return a().then(function(i){try{var a=e.defer(),o=i.transaction([d],IDBTransaction.READ_WRITE||"readwrite").objectStore(d),r=o.put(n,t)}catch(s){return p=!1,e.reject(s)}return r.onsuccess=function(){a.resolve(n)},r.onerror=function(e){a.reject(e)},a.promise})}function r(t){return a().then(function(n){var i=e.defer(),a=n.transaction([d],IDBTransaction.READ||"readonly").objectStore(d),o=a.get(t);return o.onsuccess=function(e){void 0===e.target.result?i.reject():i.resolve(e.target.result)},o.onerror=function(e){i.reject(e)},i.promise})}function s(t,i){var a=n.getFakeFileWriter(i,function(e){o(t,e)});return e.when(a)}t.indexedDB=t.indexedDB||t.webkitIndexedDB||t.mozIndexedDB||t.OIndexedDB||t.msIndexedDB,t.IDBTransaction=t.IDBTransaction||t.webkitIDBTransaction||t.OIDBTransaction||t.msIDBTransaction;var c,l="cachedFiles",d="files",u=1,p=void 0!==t.indexedDB&&void 0!==t.IDBTransaction;return a(),{isAvailable:i,saveFile:o,getFile:r,getFileWriter:s}}]).service("TmpfsFileStorage",["$q","$window","FileManager",function(e,t,n){function i(){if(c)return c;if(!t.requestFileSystem)return c=e.reject({type:"FS_BROWSER_UNSUPPORTED",description:"requestFileSystem not present"});var n=e.defer();return t.requestFileSystem(t.TEMPORARY,524288e3,function(e){cachedFs=e,n.resolve()},function(e){l=!1,n.reject(e)}),c=n.promise}function a(){return l}function o(t,n){return n=n||1,i().then(function(){var i=e.defer();return cachedFs.root.getFile(t,{create:!1},function(e){e.file(function(t){t.size>=n?i.resolve(e):i.reject(new Error("FILE_NOT_FOUND"))},function(e){console.log(dT(),"error",e),i.reject(e)})},function(){i.reject(new Error("FILE_NOT_FOUND"))}),i.promise})}function r(e,t){return s(e).then(function(e){return n.write(e,t).then(function(){return e.finalize()})})}function s(t){return i().then(function(){var i=e.defer();return cachedFs.root.getFile(t,{create:!0},function(e){n.getFileWriter(e).then(function(t){t.finalize=function(){return e},i.resolve(t)},function(e){l=!1,i.reject(e)})},function(e){l=!1,i.reject(e)}),i.promise})}t.requestFileSystem=t.requestFileSystem||t.webkitRequestFileSystem;var c,l=void 0!==t.requestFileSystem;return i(),{isAvailable:a,saveFile:r,getFile:o,getFileWriter:s}}]).service("MemoryFileStorage",["$q","FileManager",function(e,t){function n(){return!0}function i(t){return r[t]?e.when(r[t]):e.reject(new Error("FILE_NOT_FOUND"))}function a(t,n){return e.when(r[t]=n)}function o(n,i){var o=t.getFakeFileWriter(i,function(e){a(n,e)});return e.when(o)}var r={};return{isAvailable:n,saveFile:a,getFile:i,getFileWriter:o}}]).service("CryptoWorker",["$timeout","$q",function(e,t){function n(e,n){console.log(dT(),"CW start",e);var r=t.defer();return o[a]=r,n.task=e,n.taskID=a,i.postMessage(n),a++,r.promise}var i=window.Worker&&new Worker("js/lib/crypto_worker.js")||!1,a=0,o={};return i&&(i.onmessage=function(e){var t=o[e.data.taskID];void 0!==t&&(console.log(dT(),"CW done"),t.resolve(e.data.result),delete o[e.data.taskID])},i.onerror=function(e){console.error("CW error",e,e.stack),i=!1}),{sha1Hash:function(t){return e(function(){return sha1Hash(t)})},aesEncrypt:function(t,n,i){return e(function(){return aesEncrypt(t,n,i)})},aesDecrypt:function(t,n,i){return e(function(){return aesDecrypt(t,n,i)})},factorize:function(t){return i?n("factorize",{bytes:t}):e(function(){return pqPrimeFactorization(t)})},modPow:function(t,a,o){return i?n("mod-pow",{x:t,y:a,m:o}):e(function(){return bytesModPow(t,a,o)})}}}]).service("AppRuntimeManager",["$window",function(e){return{reload:function(){try{location.reload()}catch(t){}e.chrome&&chrome.runtime&&chrome.runtime.reload&&chrome.runtime.reload()},focus:function(){window.navigator.mozApps&&document.hidden?window.navigator.mozApps.getSelf().onsuccess=function(){this.result.launch()}:(window.chrome&&chrome.app&&chrome.app.window&&chrome.app.window.current().focus(),window.focus())}}}]),angular.module("izhukov.mtproto",["izhukov.utils"]).factory("MtpDcConfigurator",function(){function e(e){if(void 0===n[e]){var i,a,o=!1;for(i=0;ir[0]||i[0]==r[0]&&i[1]>=r[1])&&(r=[i[0],i[1]+4]),i=r,longFromInts(r[0],r[1])}function n(t,n){var o=t-Math.floor((n||tsNow())/1e3),r=Math.abs(a-o)>10;return e.set({server_time_offset:o}),i=[0,0],a=o,console.log(dT(),"Apply server time",t,n,o,r),r}var i=[0,0],a=0;return e.get("server_time_offset").then(function(e){e&&(a=e)}),{generateID:t,applyServerTime:n}}]).factory("MtpAuthorizer",["MtpDcConfigurator","MtpRsaKeysManager","MtpSecureRandom","MtpTimeManager","CryptoWorker","$http","$q","$timeout",function(e,t,n,i,a,o,r,s){function c(t,n){var a=n.byteLength,s=new Int32Array(n),c=new TLSerialization;c.storeLongP(0,0,"auth_key_id"),c.storeLong(i.generateID(),"msg_id"),c.storeInt(a,"request_length");var l=c.getBuffer(),d=new Int32Array(l),u=l.byteLength,p=new ArrayBuffer(u+a),m=new Int32Array(p);m.set(d),m.set(s,d.length),delete o.defaults.headers.post["Content-Type"],delete o.defaults.headers.common.Accept,"ArrayBufferView"in window||f&&!(30>f)||(m=m.buffer);var h;try{h=o.post("http://"+e.chooseServer(t)+"/apiw1",m,{responseType:"arraybuffer",transformRequest:null})}catch(g){h=r.reject(g)}return h.then(function(e){if(!e.data||!e.data.byteLength)return r.reject({code:406,type:"NETWORK_BAD_RESPONSE"});try{{var t=new TLDeserialization(e.data,{mtproto:!0});t.fetchLong("auth_key_id"),t.fetchLong("msg_id"),t.fetchInt("msg_len")}}catch(n){return r.reject({code:406,type:"NETWORK_BAD_RESPONSE",originalError:n})}return rng_seed_time(),t},function(e){return e.message||e.type||(e={code:406,type:"NETWORK_BAD_REQUEST",originalError:e}),r.reject(e)})}function l(e){var n=e.deferred,i=new TLSerialization({mtproto:!0});i.storeMethod("req_pq",{nonce:e.nonce}),console.log(dT(),"Send req_pq",bytesToHex(e.nonce)),c(e.dcID,i.getBuffer()).then(function(i){var o=i.fetchObject("ResPQ");if("resPQ"!=o._)throw new Error("resPQ response invalid: "+o._);if(!bytesCmp(e.nonce,o.nonce))throw new Error("resPQ nonce mismatch");if(e.serverNonce=o.server_nonce,e.pq=o.pq,e.fingerprints=o.server_public_key_fingerprints,console.log(dT(),"Got ResPQ",bytesToHex(e.serverNonce),bytesToHex(e.pq),e.fingerprints),e.publicKey=t.select(e.fingerprints),!e.publicKey)throw new Error("No public key found");console.log(dT(),"PQ factorization start",e.pq),a.factorize(e.pq).then(function(t){e.p=t[0],e.q=t[1],console.log(dT(),"PQ factorization done",t[2]),d(e)},function(e){console.log("Worker error",e,e.stack),n.reject(e)})},function(e){console.log(dT(),"req_pq error",e.message),n.reject(e)}),s(function(){t.prepare()})}function d(e){var t=e.deferred;e.newNonce=new Array(32),n.nextBytes(e.newNonce);var i=new TLSerialization({mtproto:!0});i.storeObject({_:"p_q_inner_data",pq:e.pq,p:e.p,q:e.q,nonce:e.nonce,server_nonce:e.serverNonce,new_nonce:e.newNonce},"P_Q_inner_data","DECRYPTED_DATA");var a=sha1Hash(i.getBuffer()).concat(i.getBytes()),o=new TLSerialization({mtproto:!0});o.storeMethod("req_DH_params",{nonce:e.nonce,server_nonce:e.serverNonce,p:e.p,q:e.q,public_key_fingerprint:e.publicKey.fingerprint,encrypted_data:rsaEncrypt(e.publicKey,a)}),console.log(dT(),"Send req_DH_params"),c(e.dcID,o.getBuffer()).then(function(n){var i=n.fetchObject("Server_DH_Params","RESPONSE");if("server_DH_params_fail"!=i._&&"server_DH_params_ok"!=i._)return t.reject(new Error("Server_DH_Params response invalid: "+i._)),!1;if(!bytesCmp(e.nonce,i.nonce))return t.reject(new Error("Server_DH_Params nonce mismatch")),!1;if(!bytesCmp(e.serverNonce,i.server_nonce))return t.reject(new Error("Server_DH_Params server_nonce mismatch")),!1;if("server_DH_params_fail"==i._){var a=sha1Hash(e.newNonce).slice(-16);return bytesCmp(a,i.new_nonce_hash)?(t.reject(new Error("server_DH_params_fail")),!1):(t.reject(new Error("server_DH_params_fail new_nonce_hash mismatch")),!1)}try{u(e,i.encrypted_answer)}catch(o){return t.reject(o),!1}p(e)},function(e){t.reject(e)})}function u(e,t){e.localTime=tsNow(),e.tmpAesKey=sha1Hash(e.newNonce.concat(e.serverNonce)).concat(sha1Hash(e.serverNonce.concat(e.newNonce)).slice(0,12)),e.tmpAesIv=sha1Hash(e.serverNonce.concat(e.newNonce)).slice(12).concat(sha1Hash([].concat(e.newNonce,e.newNonce)),e.newNonce.slice(0,4));var n=aesDecrypt(t,e.tmpAesKey,e.tmpAesIv),a=n.slice(0,20),o=n.slice(20),r=bytesToArrayBuffer(o),s=new TLDeserialization(r,{mtproto:!0}),c=s.fetchObject("Server_DH_inner_data");if("server_DH_inner_data"!=c._)throw new Error("server_DH_inner_data response invalid: "+constructor);if(!bytesCmp(e.nonce,c.nonce))throw new Error("server_DH_inner_data nonce mismatch");if(!bytesCmp(e.serverNonce,c.server_nonce))throw new Error("server_DH_inner_data serverNonce mismatch");console.log(dT(),"Done decrypting answer"),e.g=c.g,e.dhPrime=c.dh_prime,e.gA=c.g_a,e.serverTime=c.server_time,e.retry=0;var l=s.getOffset();if(!bytesCmp(a,sha1Hash(o.slice(0,l))))throw new Error("server_DH_inner_data SHA1-hash mismatch");i.applyServerTime(e.serverTime,e.localTime)}function p(e){var t=e.deferred,i=bytesFromHex(e.g.toString(16));e.b=new Array(256),n.nextBytes(e.b),a.modPow(i,e.b,e.dhPrime).then(function(n){var i=new TLSerialization({mtproto:!0});i.storeObject({_:"client_DH_inner_data",nonce:e.nonce,server_nonce:e.serverNonce,retry_id:[0,e.retry++],g_b:n},"Client_DH_Inner_Data");var o=sha1Hash(i.getBuffer()).concat(i.getBytes()),r=aesEncrypt(o,e.tmpAesKey,e.tmpAesIv),s=new TLSerialization({mtproto:!0});s.storeMethod("set_client_DH_params",{nonce:e.nonce,server_nonce:e.serverNonce,encrypted_data:r}),console.log(dT(),"Send set_client_DH_params"),c(e.dcID,s.getBuffer()).then(function(n){var i=n.fetchObject("Set_client_DH_params_answer");return"dh_gen_ok"!=i._&&"dh_gen_retry"!=i._&&"dh_gen_fail"!=i._?(t.reject(new Error("Set_client_DH_params_answer response invalid: "+i._)),!1):bytesCmp(e.nonce,i.nonce)?bytesCmp(e.serverNonce,i.server_nonce)?void a.modPow(e.gA,e.b,e.dhPrime).then(function(n){var a=sha1Hash(n),o=a.slice(0,8),r=a.slice(-8);switch(console.log(dT(),"Got Set_client_DH_params_answer",i._),i._){case"dh_gen_ok":var s=sha1Hash(e.newNonce.concat([1],o)).slice(-16);if(!bytesCmp(s,i.new_nonce_hash1))return t.reject(new Error("Set_client_DH_params_answer new_nonce_hash1 mismatch")),!1;var c=bytesXor(e.newNonce.slice(0,8),e.serverNonce.slice(0,8));e.authKeyID=r,e.authKey=n,e.serverSalt=c,t.resolve(e);break;case"dh_gen_retry":var l=sha1Hash(e.newNonce.concat([2],o)).slice(-16);return bytesCmp(l,i.new_nonce_hash2)?p(e):(t.reject(new Error("Set_client_DH_params_answer new_nonce_hash2 mismatch")),!1);case"dh_gen_fail":var d=sha1Hash(e.newNonce.concat([3],o)).slice(-16);return bytesCmp(d,i.new_nonce_hash3)?(t.reject(new Error("Set_client_DH_params_answer fail")),!1):(t.reject(new Error("Set_client_DH_params_answer new_nonce_hash3 mismatch")),!1) }},function(e){t.reject(e)}):(t.reject(new Error("Set_client_DH_params_answer server_nonce mismatch")),!1):(t.reject(new Error("Set_client_DH_params_answer nonce mismatch")),!1)},function(e){t.reject(e)})},function(e){t.reject(e)})}function m(t){if(void 0!==g[t])return g[t];for(var n=[],i=0;16>i;i++)n.push(nextRandomInt(255));if(!e.chooseServer(t))return r.reject(new Error("No server found for dc "+t));var a={dcID:t,nonce:n,deferred:r.defer()};return s(function(){l(a)}),g[t]=a.deferred.promise,g[t]["catch"](function(){delete g[t]}),g[t]}var h=navigator.userAgent.match(/Chrome\/(\d+(\.\d+)?)/),f=h&&parseFloat(h[1])||!1,g={};return{auth:m}}]).factory("MtpNetworkerFactory",["MtpDcConfigurator","MtpTimeManager","MtpSecureRandom","Storage","CryptoWorker","$http","$q","$timeout","$interval","$rootScope",function(e,t,n,i,a,o,r,s,c,l){function d(e,t,n,i){i=i||{},this.dcID=e,this.iii=p++,this.authKey=t,this.authKeyID=sha1Hash(t).slice(-8),this.serverSalt=n,this.upload=i.fileUpload||i.fileDownload||!1,this.updateSession(),this.currentRequests=0,this.checkConnectionPeriod=0,this.sentMessages={},this.serverMessages=[],this.clientMessages=[],this.pendingMessages={},this.pendingAcks=[],this.pendingResends=[],this.connectionInited=!1,this.pendingTimeouts=[],this.longPollInt=c(this.checkLongPoll.bind(this),1e4),this.checkLongPoll(),m||(m=!0,l.offline=!0,l.offlineConnecting=!0),Config.Navigator.mobile&&this.setupMobileSleep()}var u,p=0,m=!1,h=navigator.userAgent.match(/Chrome\/(\d+(\.\d+)?)/),f=h&&parseFloat(h[1])||!1;return l.retryOnline=function(){$(document.body).trigger("online")},d.prototype.updateSession=function(){this.seqNo=0,this.sessionID=new Array(8),n.nextBytes(this.sessionID)},d.prototype.setupMobileSleep=function(){var e=this;l.$watch("idle.isIDLE",function(t){t?e.sleepAfter=tsNow()+3e4:(delete e.sleepAfter,e.checkLongPoll())}),l.$on("push_received",function(){e.sleepAfter&&(e.sleepAfter=tsNow()+3e4,e.checkLongPoll())})},d.prototype.updateSentMessage=function(e){var n=this.sentMessages[e];if(!n)return!1;var i=this;if(n.container){var a=[];angular.forEach(n.inner,function(e){var t=i.updateSentMessage(e);t&&a.push(t.msg_id)}),n.inner=a}return n.msg_id=t.generateID(),n.seq_no=this.generateSeqNo(n.notContentRelated||n.container),this.sentMessages[n.msg_id]=n,delete i.sentMessages[e],n},d.prototype.generateSeqNo=function(e){var t=2*this.seqNo;return e||(t++,this.seqNo++),t},d.prototype.wrapMtpCall=function(e,n,i){var a=new TLSerialization({mtproto:!0});a.storeMethod(e,n);var o=t.generateID(),r=this.generateSeqNo(),s={msg_id:o,seq_no:r,body:a.getBytes()};return Config.Modes.debug&&console.log(dT(),"MT call",e,n,o,r),this.pushMessage(s,i)},d.prototype.wrapMtpMessage=function(e,n){n=n||{};var i=new TLSerialization({mtproto:!0});i.storeObject(e,"Object");var a=t.generateID(),o=this.generateSeqNo(n.notContentRelated),r={msg_id:a,seq_no:o,body:i.getBytes()};return Config.Modes.debug&&console.log(dT(),"MT message",e,a,o),this.pushMessage(r,n)},d.prototype.wrapApiCall=function(e,n,i){var a=new TLSerialization(i);this.connectionInited||(a.storeInt(479200567,"invokeWithLayer18"),a.storeInt(1769565673,"initConnection"),a.storeInt(Config.App.id,"api_id"),a.storeString(navigator.userAgent||"Unknown UserAgent","device_model"),a.storeString(navigator.platform||"Unknown Platform","system_version"),a.storeString(Config.App.version,"app_version"),a.storeString(navigator.language||"en","lang_code")),i.afterMessageID&&(a.storeInt(3416209197,"invokeAfterMsg"),a.storeLong(i.afterMessageID,"msg_id")),i.resultType=a.storeMethod(e,n);var o=t.generateID(),r=this.generateSeqNo(),s={msg_id:o,seq_no:r,body:a.getBytes(),isAPI:!0};return Config.Modes.debug?console.log(dT(),"Api call",e,n,o,r,i):console.log(dT(),"Api call",e),this.pushMessage(s,i)},d.prototype.checkLongPoll=function(){var e=this.cleanupSent();if(this.longPollPending&&tsNow()t.sleepAfter)||t.sendLongPoll()})},d.prototype.sendLongPoll=function(){var e=25e3,t=this;this.longPollPending=tsNow()+e,this.wrapMtpCall("http_wait",{max_delay:0,wait_after:0,max_wait:e},{noResponse:!0,longPoll:!0}).then(function(){delete t.longPollPending,s(t.checkLongPoll.bind(t),0)},function(){console.log("Long-poll failed")})},d.prototype.pushMessage=function(e,t){var n=r.defer();return this.sentMessages[e.msg_id]=angular.extend(e,t||{},{deferred:n}),this.pendingMessages[e.msg_id]=0,t&&t.noShedule||this.sheduleRequest(),angular.isObject(t)&&(t.messageID=e.msg_id),n.promise},d.prototype.pushResend=function(e,t){var n=t?tsNow()+t:0,i=this.sentMessages[e];if(i.container)for(var a=0;a=c)&&((o=u.sentMessages[t])&&(r.push(o),s+=o.body.length+32,o.isAPI?l=!0:o.longPoll&&(d=!0)),delete u.pendingMessages[t])}),l&&!d){var p=new TLSerialization({mtproto:!0});p.storeMethod("http_wait",{max_delay:0,wait_after:0,max_wait:1e3}),r.push({msg_id:t.generateID(),seq_no:this.generateSeqNo(),body:p.getBytes()})}if(r.length){var m=[];if(r.length>1){var h=new TLSerialization({mtproto:!0,startMaxLength:s+64});h.storeInt(1945237724,"CONTAINER[id]"),h.storeInt(r.length,"CONTAINER[count]");for(var f=[],n=0;nf)||(a=a.buffer);var s;try{s=o.post("http://"+e.chooseServer(n.dcID)+"/apiw1",a,{responseType:"arraybuffer",transformRequest:null})}catch(c){s=r.reject(c)}return s.then(function(e){return e.data&&e.data.byteLength?e:r.reject({code:406,type:"NETWORK_BAD_RESPONSE"})},function(e){return e.message||e.type||(e={code:406,type:"NETWORK_BAD_REQUEST"}),r.reject(e)})})},d.prototype.parseResponse=function(e){var t=this,n=new TLDeserialization(e),i=n.fetchIntBytes(64,"auth_key_id");if(!bytesCmp(i,this.authKeyID))throw new Error("Invalid server auth_key_id: "+bytesToHex(i));var o=n.fetchIntBytes(128,"msg_key"),r=e.byteLength-n.getOffset(),s=n.fetchRawBytes(r,"encrypted_data");return this.getDecryptedMessage(o,s).then(function(e){var n=bytesToArrayBuffer(e),i=new TLDeserialization(n,{mtproto:!0}),r=(i.fetchIntBytes(64,"salt"),i.fetchIntBytes(64,"session_id")),s=i.fetchLong("message_id"),c=i.fetchInt("seq_no"),l=i.fetchRawBytes(!1,"message_data"),d=i.getOffset();return a.sha1Hash(e.slice(0,d)).then(function(e){if(!bytesCmp(o,e.slice(-16)))throw new Error("server msgKey mismatch");var n=bytesToArrayBuffer(l),i={mtproto:!0,override:{mt_message:function(e,t){e.msg_id=this.fetchLong(t+"[msg_id]"),e.seqno=this.fetchInt(t+"[seqno]"),e.bytes=this.fetchInt(t+"[bytes]");var n=this.getOffset();try{e.body=this.fetchObject("Object",t+"[body]")}catch(i){console.error(dT(),"parse error",i.message,i.stack),e.body={_:"parse_error",error:i}}this.offset!=n+e.bytes&&(console.warn(dT(),"set offset",this.offset,n,e.bytes),console.log(dT(),e),this.offset=n+e.bytes)},mt_rpc_result:function(e,n){e.req_msg_id=this.fetchLong(n+"[req_msg_id]");var i=t.sentMessages[e.req_msg_id],a=i&&i.resultType||"Object";e.result=this.fetchObject(a,n+"[result]")}}},a=new TLDeserialization(n,i),d=a.fetchObject("","INPUT");return{response:d,messageID:s,sessionID:r,seqNo:c}})})},d.prototype.applyServerSalt=function(e){var t=longToBytes(e),n={};return n["dc"+this.dcID+"_server_salt"]=bytesToHex(t),i.set(n),this.serverSalt=t,!0},d.prototype.sheduleRequest=function(e){this.offline&&this.checkConnection("forced shedule");var t=tsNow()+e;return e&&this.nextReq&&this.nextReq<=t?!1:(s.cancel(this.nextReqPromise),this.nextReqPromise=s(this.performSheduledRequest.bind(this),e||0),void(this.nextReq=t))},d.prototype.onSessionCreate=function(){},d.prototype.ackMessage=function(e){this.pendingAcks.push(e),this.sheduleRequest(3e4)},d.prototype.reqResendMessage=function(e){console.log(dT(),"Req resend",e),this.pendingResends.push(e),this.sheduleRequest(100)},d.prototype.cleanupSent=function(){var e=this,t=!1;return angular.forEach(this.sentMessages,function(n,i){if(n.notContentRelated&&void 0===e.pendingMessages[i])delete e.sentMessages[i];else if(n.container){for(var a=0;ao;o++)this.processMessage(e.messages[o],n,i);break;case"bad_server_salt":console.log(dT(),"Bad server salt",e);var r=this.sentMessages[e.bad_msg_id];if(!r||r.seq_no!=e.bad_msg_seqno)throw console.log(e.bad_msg_id,e.bad_msg_seqno),new Error("Bad server salt for invalid message");this.applyServerSalt(e.new_server_salt),this.pushResend(e.bad_msg_id),this.ackMessage(n);break;case"bad_msg_notification":console.log(dT(),"Bad msg notification",e);var r=this.sentMessages[e.bad_msg_id];if(!r||r.seq_no!=e.bad_msg_seqno)throw console.log(e.bad_msg_id,e.bad_msg_seqno),new Error("Bad msg notification for invalid message");if(16==e.error_code||17==e.error_code){t.applyServerTime(bigStringInt(n).shiftRight(32).toString(10))&&(console.log(dT(),"Update session"),this.updateSession());var s=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(var o=0;o5?"[.."+e.result.length+"..]":e.result),console.log(dT(),"Rpc response",h)}r.deferred.resolve(e.result)}r.isAPI&&(this.connectionInited=!0)}delete this.sentMessages[d]}break;default:this.ackMessage(n),u&&u(e)}},{getNetworker:function(e,t,n,i){return new d(e,t,n,i)},setUpdatesProcessor:function(e){u=e}}}]),angular.module("izhukov.mtproto.wrapper",["izhukov.utils","izhukov.mtproto"]).factory("MtpApiManager",["Storage","MtpAuthorizer","MtpNetworkerFactory","ErrorService","$q",function(e,t,n,i,a){function o(t,n){e.set({dc:t,user_auth:angular.extend({dcID:t},n)}),h=t}function r(){return c("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})}function s(i,o){o=o||{};var r=o.fileUpload||o.fileDownload?p:u;if(!i)throw new Exception("get Networker without dcID");if(void 0!==r[i])return a.when(r[i]);var s="dc"+i+"_auth_key",c="dc"+i+"_server_salt";return e.get(s,c).then(function(l){if(void 0!==r[i])return r[i];var d=l[0],u=l[1];if(d&&512==d.length){var p=bytesFromHex(d),m=bytesFromHex(u);return r[i]=n.getNetworker(i,p,m,o)}return o.createNetworker?t.auth(i).then(function(t){var a={};return a[s]=bytesToHex(t.authKey),a[c]=bytesToHex(t.serverSalt),e.set(a),r[i]=n.getNetworker(i,t.authKey,t.serverSalt,o)},function(e){return console.log("Get networker error",e,e.stack),a.reject(e)}):a.reject({type:"AUTH_KEY_EMPTY",code:401})})}function c(t,n,o){o=o||{};var r,l,d=a.defer(),u=function(e){e?angular.isObject(e)||(e={message:e}):e={type:"ERROR_EMPTY"},d.reject(e),o.noErrorBox||(e.input=t,e.stack=e.stack||(new Error).stack,setTimeout(function(){e.handled||(i.show({error:e}),e.handled=!0)},100))};l=(r=o.dcID)?s(r,o):e.get("dc").then(function(e){return s(r=e||2,o)});var p,f=!1;if(l.then(function(i){return(p=i).wrapApiCall(t,n,o).then(function(e){d.resolve(e)},function(l){if(console.error(dT(),"Error",l.code,l.type,h,r),401==l.code&&h==r)e.remove("dc","user_auth"),u(l);else if(401==l.code&&h&&r!=h){if(void 0===m[r]){var f=a.defer();c("auth.exportAuthorization",{dc_id:r},{noErrorBox:!0}).then(function(e){c("auth.importAuthorization",{id:e.id,bytes:e.bytes},{dcID:r,noErrorBox:!0}).then(function(){f.resolve()},function(e){f.reject(e)})},function(e){f.reject(e)}),m[r]=f.promise}m[r].then(function(){(p=i).wrapApiCall(t,n,o).then(function(e){d.resolve(e)},function(e){u(e)})},function(e){u(e)})}else if(303==l.code){var g=l.type.match(/^(PHONE_MIGRATE_|NETWORK_MIGRATE_|USER_MIGRATE_)(\d+)/)[2];g!=r&&(o.dcID?o.dcID=g:e.set({dc:h=g}),s(g,o).then(function(e){e.wrapApiCall(t,n,o).then(function(e){d.resolve(e)},function(e){u(e)})}))}else u(l)})},function(e){u(e)}),!(f=f||(new Error).stack))try{window.unexistingFunction()}catch(g){f=g.stack||""}return d.promise}function l(){return e.get("user_auth").then(function(e){return e.id||0})}function d(){return h||!1}var u={},p={},m={},h=!1;return e.get("dc").then(function(e){e&&(h=e)}),{getBaseDcID:d,getUserID:l,invokeApi:c,getNetworker:s,setUserAuth:o,logOut:r}}]).factory("MtpApiFileManager",["MtpApiManager","$q","FileManager","IdbFileStorage","TmpfsFileStorage","MemoryFileStorage",function(e,t,n,i,a,o){function r(e,n,i){void 0===v[e]&&(v[e]=[],b[e]=0);var a=v[e],o=t.defer();return a.push({cb:n,deferred:o,activeDelta:i}),s(e),o.promise}function s(e){var t=v[e];if(b[e]>=w||!t||!t.length)return!1;var n=t.shift(),i=n.activeDelta||1;b[e]+=i;$++;n.cb().then(function(t){b[e]-=i,s(e),n.deferred.resolve(t)},function(t){b[e]-=i,s(e),n.deferred.reject(t)})}function c(e){switch(e._){case"inputVideoFileLocation":return"video"+e.id+".mp4";case"inputDocumentFileLocation":return"doc"+e.id;case"inputAudioFileLocation":return"audio"+e.id}return e.volume_id||console.trace("Empty location",e),e.volume_id+"_"+e.local_id+"_"+e.secret+".jpg"}function l(e){if(!e)return!1;var t=c(e);return y[t]||!1}function d(){return a.isAvailable()?a:i.isAvailable()?i:o}function u(e,t){var i=c(e),a="image/jpeg";return g[i]||(g[i]=d().saveFile(i,t).then(function(e){return y[i]=n.getUrl(e,a)})),g[i]}function p(i){if(!n.isAvailable())return t.reject({type:"BROWSER_BLOB_NOT_SUPPORTED"});var a=c(i),o="image/jpeg",s=g[a]||_[a];if(s)return s;var l=d();return _[a]=l.getFile(a).then(function(e){return y[a]=n.getUrl(e,o)},function(){var t=r(i.dc_id,function(){return e.invokeApi("upload.getFile",{location:angular.extend({},i,{_:"inputFileLocation"}),offset:0,limit:0},{dcID:i.dc_id,fileDownload:!0,createNetworker:!0})});return l.getFileWriter(a,o).then(function(e){return t.then(function(t){return n.write(e,t.bytes).then(function(){return y[a]=n.getUrl(e.finalize(),o)})})})})}function m(i,a,o,s){if(!n.isAvailable())return t.reject({type:"BROWSER_BLOB_NOT_SUPPORTED"});s=s||{};var l=c(a),u=s.toFileEntry||null,p=g[l]||_[l],m=d();if(p)return u?p.then(function(){return m.getFile(l).then(function(e){return n.copy(e,u)})}):p;var h,f=t.defer(),v=!1,b=!1,w=s.mime||"image/jpeg",$=function(e){f.reject(e),$=angular.noop,h&&h.truncate(0)};return m.getFile(l).then(function(e){u?n.copy(e,u).then(function(){f.resolve()},$):f.resolve(y[l]=n.getUrl(e,w))},function(){var s=u?n.getFileWriter(u):m.getFileWriter(l,w);s.then(function(s){h=s;for(var c,d=524288,p=t.when(),m=0;o>m;m+=d)c=t.defer(),function(c,p,m,h){return r(i,function(){return v?t.when():e.invokeApi("upload.getFile",{location:a,offset:p,limit:d},{dcID:i,fileDownload:!0,createNetworker:!0})},6).then(function(e){h.then(function(){return v?t.when():n.write(s,e.bytes).then(function(){m.resolve()},$).then(function(){c?(b=!0,u?f.resolve():f.resolve(y[l]=n.getUrl(s.finalize(),w))):f.notify({done:p+d,total:o})})})})}(m+d>=o,m,c,p),p=c.promise})}),f.promise.cancel=function(){v||b||(v=!0,delete _[l],$({type:"DOWNLOAD_CANCELED"}))},u||(_[l]=f.promise),f.promise}function h(n){var i=n.size,a=i>102400?524288:32768,o=i>=10485760,r=Math.ceil(i/a),s=!1,c=!1,l=0;if(r>1500)return t.reject({type:"FILE_TOO_BIG"});var d,u=[nextRandomInt(4294967295),nextRandomInt(4294967295)],p=t.defer(),m=function(e){p.reject(e),m=angular.noop},h=0,g={_:o?"inputFileBig":"inputFile",id:u,parts:r,name:n.name,md5_checksum:""},_=t.when();for(d=0;i>d;d+=a)!function(d,h){_=_.then(function(){var _=t.defer(),y=new FileReader,v=n.slice(d,d+a);return y.onloadend=function(t){if(!s&&t.target.readyState==FileReader.DONE){var n=f=f.then(function(){return e.invokeApi(o?"upload.saveBigFilePart":"upload.saveFilePart",{file_id:u,file_part:h,file_total_parts:r,bytes:bytesFromArrayBuffer(t.target.result)},{startMaxLength:a+256,fileUpload:!0})},m);n.then(function(){l++,_.resolve(),l>=r?(p.resolve(g),c=!0):(console.log(dT(),"Progress",l*a/i),p.notify({done:l*a,total:i}))},m)}},y.readAsArrayBuffer(v),_.promise})}(d,h++);return p.promise.cancel=function(){console.log("cancel upload",s,c),s||c||(s=!0,m({type:"UPLOAD_CANCELED"}))},p.promise}var f=t.when(),g={},_={},y={},v={},b={},w=5,$=0;return{getCachedFile:l,downloadFile:m,downloadSmallFile:p,saveSmallFile:u,uploadFile:h}}]),angular.module("myApp",["ngRoute","ngSanitize","ngTouch","ui.bootstrap","mediaPlayer","izhukov.utils","izhukov.mtproto","izhukov.mtproto.wrapper","myApp.filters","myApp.services","myApp.templates","myApp.directives","myApp.controllers"]).config(["$locationProvider","$routeProvider","$compileProvider","StorageProvider",function(e,t,n,i){var a,o,r,s,c,l,d,u={},p={};for(o=0;o=1e3?void o.resolve(r):void this["continue"]()},t.onerror=function(e){console.log("phonebook error",e,e.type,e.message),o.reject(e)},o.promise}return{isAvailable:a,openPhonebookImport:o,getPhonebookContacts:r}}]).service("AppChatsManager",["$rootScope","$modal","_","MtpApiFileManager","MtpApiManager","AppUsersManager","RichTextProcessor",function(e,t,n,i,a,o,r){function s(e){angular.forEach(e,c)}function c(e){angular.isObject(e)&&(e.rTitle=r.wrapRichText(e.title,{noLinks:!0,noLinebreaks:!0})||n("chat_title_deleted"),void 0===f[e.id]?f[e.id]=e:safeReplaceObject(f[e.id],e),void 0!==g[e.id]&&safeReplaceObject(g[e.id],e&&e.photo&&e.photo.photo_small||{empty:!0}))}function l(e){return f[e]||{id:e,deleted:!0}}function d(e){return angular.isObject(f[e])}function u(e,t){var n=l(e);return void 0===g[e]&&(g[e]=n&&n.photo&&n.photo.photo_small||{empty:!0}),{placeholder:"img/placeholders/"+t+"Avatar"+(Math.abs(e)%4+1)+"@2x.png",location:g[e]}}function p(e){l(e);return"g"+e}function m(e,t){var n=angular.copy(t),i=l(e);return n.participants&&"chatParticipants"==n.participants._&&a.getUserID().then(function(e){angular.forEach(n.participants.participants,function(t){t.user=o.getUser(t.user_id),t.inviter=o.getUser(t.inviter_id),t.canKick=e!=t.user_id&&(e==n.participants.admin_id||e==t.inviter_id)})}),n.thumb={placeholder:"img/placeholders/GroupAvatar"+(Math.abs(e)%4+1)+"@2x.png",location:i&&i.photo&&i.photo.photo_small,width:120,height:120,size:0},n.peerString=p(e),n.chat=i,n}function h(n){var i=e.$new();i.chatID=n;t.open({templateUrl:templateUrl("chat_modal"),controller:"ChatModalController",scope:i,windowClass:"chat_modal_window mobile_modal"})}var f={},g={};return e.openChat=h,{saveApiChats:s,saveApiChat:c,getChat:l,getChatPhoto:u,getChatString:p,hasChat:d,wrapForFull:m,openChat:h} }]).service("AppPeersManager",["AppUsersManager","AppChatsManager",function(e,t){return{getInputPeer:function(e){var t="u"==e.charAt(0),n=e.substr(1).split("_");return t?{_:"inputPeerForeign",user_id:n[0],access_hash:n[1]}:{_:"inputPeerChat",chat_id:n[0]}},getInputPeerByID:function(t){return t>0?{_:"inputPeerForeign",user_id:t,access_hash:e.getUser(t).access_hash||0}:0>t?{_:"inputPeerChat",chat_id:-t}:void 0},getPeerSearchText:function(n){var i;if(n>0)i=e.getUserSearchText(n);else if(0>n){var a=t.getChat(-n);i=a.title||""}return i},getOutputPeer:function(e){return e>0?{_:"peerUser",user_id:e}:{_:"peerChat",chat_id:-e}},getPeerID:function(e){if(angular.isObject(e))return e.user_id?e.user_id:-e.chat_id;var t="u"==e.charAt(0),n=e.substr(1).split("_");return t?n[0]:-n[0]||0},getPeer:function(n){return n>0?e.getUser(n):t.getChat(-n)},getPeerPhoto:function(n,i,a){return n>0?e.getUserPhoto(n,i):t.getChatPhoto(-n,a)}}}]).service("SearchIndexManager",function(){function e(){return{shortIndexes:{},fullTexts:{}}}function t(e){e=e.replace(a," ").replace(o,"").toLowerCase();for(var t in r)r.hasOwnProperty(t)&&(e=e.replace(r[t],t));return e}function n(e,n,i){if(void 0!==i.fullTexts[e])return!1;if(n=t(n),!n.length)return!1;var a=i.shortIndexes;i.fullTexts[e]=n,angular.forEach(n.split(" "),function(t){var n,i,o=Math.min(t.length,3);for(i=1;o>=i;i++)n=t.substr(0,i),void 0===a[n]?a[n]=[e]:a[n].push(e)})}function i(e,n){var i=n.shortIndexes,a=n.fullTexts;e=t(e);var o,r,s,c,l,d=e.split(" "),u=!1;for(r=0;ro.length)&&(u=o)}for(o={},s=0;s,<\s]+/g,o=/^\s+|\s$/g,r={a:/[åáâäà]/g,e:/[éêëè]/g,i:/[íîïì]/g,o:/[óôöò]/g,u:/[úûüù]/g,c:/ç/g,ss:/ß/g};return{createIndex:e,indexObject:n,cleanSearchText:t,search:i}}).service("AppMessagesManager",["$q","$rootScope","$location","$filter","ApiUpdatesManager","AppUsersManager","AppChatsManager","AppPeersManager","AppPhotosManager","AppVideoManager","AppDocsManager","AppAudioManager","MtpApiManager","MtpApiFileManager","RichTextProcessor","NotificationsManager","SearchIndexManager","PeersSelectService","Storage","_",function(e,t,n,i,a,o,r,s,c,l,d,u,p,m,h,f,g,_,y,v){function b(t,n,i){var a=K;if(angular.isString(t)&&t.length){if(!i||tt.query!==t){tt.query=t;var c=g.search(t,et);tt.dialogs=[],angular.forEach(K.dialogs,function(e){c[e.peerID]&&tt.dialogs.push(e)}),tt.count=tt.dialogs.length}a=tt}else tt.query=!1;var l=0;if(n>0)for(l=0;la.dialogs[l].top_message);l++);return null!==a.count&&a.dialogs.length==a.count||a.dialogs.length>=l+(i||1)?e.when({count:a.count,dialogs:a.dialogs.slice(l,l+(i||20))}):(i=i||20,p.invokeApi("messages.getDialogs",{offset:l,limit:i,max_id:n||0}).then(function(e){if(o.saveApiUsers(e.users),r.saveApiChats(e.chats),E(e.messages),n>0)for(l=0;la.dialogs[l].top_message);l++);return a.count=e.count||e.dialogs.length,a.dialogs.splice(l,a.dialogs.length-l),angular.forEach(e.dialogs,function(e){var t=s.getPeerID(e.peer),n=s.getPeerSearchText(t);g.indexObject(t,n,et),a.dialogs.push({peerID:t,top_message:e.top_message,unread_count:e.unread_count}),void 0===G[t]&&(G[t]={count:null,history:[e.top_message],pending:[]}),f.savePeerSettings(t,e.notify_settings)}),{count:a.count,dialogs:a.dialogs.slice(l,l+i)}}))}function w(e,t,n,i){return p.invokeApi("messages.getHistory",{peer:e,offset:i||0,limit:n||0,max_id:t||0}).then(function(e){return o.saveApiUsers(e.users),r.saveApiChats(e.chats),E(e.messages),e})}function $(e,t,n,i){return w(e,t,n).then(function(a){i.count=a.count||a.messages.length;var o=0;if(t>0)for(o=0;oi.history[o]);o++);return i.history.splice(o,i.history.length-o),angular.forEach(a.messages,function(e){i.history.push(e.id)}),n-=a.messages.length,n>0&&i.history.length0)for(d=!0,l=0;lc.history[l]){d=!1;break}}else{var h=q(r);if(h&&h[0]&&h[0].unread_count>1){var f=h[0].unread_count;(p=f>50)?(i=10,u=6,l=f-u):(i=Math.max(10,o,f+2),u=f)}else Config.Mobile&&(i=20)}return!d&&(null!==c.count&&c.history.length==c.count||c.history.length>=l+(i||1))?(a?(a=Math.min(l,a),l=Math.max(0,l-a),i+=a):i=i||(l?20:o||5),e.when({count:c.count,history:m.concat(c.history.slice(l,l+i)),unreadOffset:u,unreadSkip:p})):(a||i||(i=o||20),d&&(l=0),a||p||n&&-1==c.history.indexOf(n)?(a&&(l=-a,i+=a),w(t,n,i,l).then(function(e){c.count=e.count||e.messages.length;var t=[];return angular.forEach(e.messages,function(e){t.push(e.id)}),{count:c.count,history:m.concat(t),unreadOffset:u,unreadSkip:p}})):$(t,n,i,c).then(function(){if(l=0,n>0)for(l=0;lc.history[l]);l++);return{count:c.count,history:m.concat(c.history.slice(l,l+i)),unreadOffset:u,unreadSkip:p}}))}function C(t,n,i,a,c){var l=[],d=!n,u=s.getPeerID(t),m={peer:u,filter:i},h=d&&angular.equals(nt,m);if(d&&!h&&(nt=m,it=[]),!a&&!n){var f=G[u];if(void 0!==f&&f.history.length){var g,_,y={},v=c||20;switch(i._){case"inputMessagesFilterPhotos":y.messageMediaPhoto=!0;break;case"inputMessagesFilterVideo":y.messageMediaVideo=!0;break;case"inputMessagesFilterPhotoVideo":y.messageMediaPhoto=!0,y.messageMediaVideo=!0;break;case"inputMessagesFilterDocument":y.messageMediaDocument=!0;break;case"inputMessagesFilterAudio":y.messageMediaAudio=!0}for(g=0;g=v)));g++);}if(l.length=v));g++);}return l.length||1e3==c?(d&&(it=listMergeSorted(it,l)),e.when({count:null,history:l})):p.invokeApi("messages.search",{peer:t,q:n||"",filter:i||{_:"inputMessagesFilterEmpty"},min_date:0,max_date:0,limit:c||20,max_id:a||0}).then(function(e){o.saveApiUsers(e.users),r.saveApiChats(e.chats),E(e.messages);var t=e.count||e.messages.length;return l=[],angular.forEach(e.messages,function(e){l.push(e.id)}),d&&(it=listMergeSorted(it,l)),{count:t,history:l}})}function S(e){return z[e]||{deleted:!0}}function M(e){return p.invokeApi("messages.deleteMessages",{id:e}).then(function(e){return a.processUpdateMessage({_:"updateShort",update:{_:"updateDeleteMessages",messages:e}}),e})}function x(t,n,i){return a.processUpdateMessage({_:"updates",seq:n.seq,updates:[]})?n.offset?p.invokeApi(i,{peer:t,offset:n.offset,max_id:0,read_contents:!0}).then(function(e){return x(t,e,i)}):e.when():!1}function A(e){var n=s.getPeerID(e),i=G[n],a=q(n);if(!a[0]||!a[0].unread_count){if(!i||!i.history.length)return!1;var o,r,c=!1;for(l=i.history.length;l>=0;l--)if(o=i.history[l],r=z[o],r&&!r.out&&r.unread){c=!0;break}if(!c)return!1}if(i.readPromise)return i.readPromise;if(i.readPromise=p.invokeApi("messages.readHistory",{peer:e,offset:0,max_id:0,read_contents:!0}).then(function(t){return x(e,t,"messages.readHistory")}).then(function(){a[0]&&(a[0].unread_count=0,t.$broadcast("dialog_unread",{peerID:n,count:0}),t.$broadcast("messages_read"))})["finally"](function(){delete i.readPromise}),i&&i.history.length){var o,r,l,n,a;for(l=0;l=0?(r="photo",c="photo."+i.type.split("/")[1]):"video/"==i.type.substr(0,6)?(r="video",c="video.mp4"):"audio/"==i.type.substr(0,6)?(r="audio",c="audio."+i.type.split("/")[1]||"mp3"):(r="document",c="document."+i.type.split("/")[1]):(r="document",c="document."+i.type.split("/")[1]),i.name||(i.name=c),void 0===h&&(h=G[n]={count:null,history:[],pending:[]}),p.getUserID().then(function(o){var c={_:"messageMediaPending",type:r,file_name:i.name,size:i.size,progress:{percent:1,total:i.size}},g={_:"message",id:l,from_id:o,to_id:s.getOutputPeer(n),flags:3,date:tsNow(!0)+at,message:"",media:c,random_id:u,pending:!0},_=function(e){var n=V[l];e?(g.error=!0,n&&(n.error=!0)):(delete g.error,n&&delete n.error),t.$broadcast("messages_pending")};g.send=function(){var o=e.defer();J.then(function(){var e=!1,s=m.uploadFile(i);s.then(function(t){e=!0;var n;switch(r){case"photo":n={_:"inputMediaUploadedPhoto",file:t};break;case"video":n={_:"inputMediaUploadedVideo",file:t,duration:0,w:0,h:0,mime_type:i.type};break;case"audio":n={_:"inputMediaUploadedAudio",file:t,duration:0,mime_type:i.type};break;case"document":default:n={_:"inputMediaUploadedDocument",file:t,file_name:i.name,mime_type:i.type}}p.invokeApi("messages.sendMedia",{peer:f,media:n,random_id:d}).then(function(e){g.date=e.message.date,g.id=e.message.id,g.media=e.message.media,a.processUpdateMessage({_:"updates",users:e.users,chats:e.chats,seq:e.seq,updates:[{_:"updateMessageID",random_id:u,id:e.message.id},{_:"updateNewMessage",message:g,pts:e.pts}]})},function(){_(!0)})},function(){_(!0)},function(e){c.progress.done=e.done,c.progress.percent=Math.max(1,Math.floor(100*e.done/e.total)),t.$broadcast("history_update",{peerID:n})}),c.progress.cancel=function(){e||(o.resolve(),s.cancel(),L(u))},s["finally"](function(){o.resolve()})}),J=o.promise},E([g]),h.pending.unshift(l),t.$broadcast("history_append",{peerID:n,messageID:l,my:!0}),g.send()}),X[u]=[n,l]}function P(e,n){var i=Q--,o=[nextRandomInt(4294967295),nextRandomInt(4294967295)],r=bigint(o[0]).shiftLeft(32).add(bigint(o[1])).toString(),l=G[e],d=s.getInputPeerByID(e);void 0===l&&(l=G[e]={count:null,history:[],pending:[]}),p.getUserID().then(function(u){var m;switch(n._){case"inputMediaContact":m=angular.extend({},n,{_:"messageMediaContact"});break;case"inputMediaPhoto":m={photo:c.getPhoto(n.id.id)}}var h={_:"message",id:i,from_id:u,to_id:s.getOutputPeer(e),flags:3,date:tsNow(!0)+at,message:"",media:m,random_id:r,pending:!0},f=function(e){var n=V[i];e?(h.error=!0,n&&(n.error=!0)):(delete h.error,n&&delete n.error),t.$broadcast("messages_pending")};h.send=function(){p.invokeApi("messages.sendMedia",{peer:d,media:n,random_id:o}).then(function(e){h.date=e.message.date,h.id=e.message.id,h.media=e.message.media,a.processUpdateMessage({_:"updates",users:e.users,chats:e.chats,seq:e.seq,updates:[{_:"updateMessageID",random_id:r,id:e.message.id},{_:"updateNewMessage",message:h,pts:e.pts}]})},function(){f(!0)})},E([h]),l.pending.unshift(i),t.$broadcast("history_append",{peerID:e,messageID:i,my:!0}),h.send()}),X[r]=[e,i]}function N(e,t){return t=t.sort(),p.invokeApi("messages.forwardMessages",{peer:s.getInputPeerByID(e),id:t}).then(function(e){var t=[];angular.forEach(e.messages,function(n){t.push({_:"updateNewMessage",message:n,pts:e.pts})}),a.processUpdateMessage({_:"updates",users:e.users,chats:e.chats,seq:e.seq,updates:t})})}function L(e){var t=X[e];if(console.log("pending",e,t),t){var n,i=t[0],o=t[1],r=G[i];for(a.processUpdateMessage({_:"updateShort",update:{_:"updateDeleteMessages",messages:[o]}}),n=0;nt?t:e.out||2&e.flags?t:e.from_id}function F(e,t){var n=-1!=t;if(n&&void 0!==W[e])return W[e];var i=angular.copy(z[e])||{id:e};return i.fromUser=o.getUser(i.from_id),(i.chatID=i.to_id.chat_id)?(i.peerID=-i.chatID,i.peerData=r.getChat(i.chatID),i.peerString=r.getChatString(i.chatID)):(i.peerID=i.out?i.to_id.user_id:i.from_id,i.peerData=o.getUser(i.peerID),i.peerString=o.getUserString(i.peerID)),i.peerPhoto=s.getPeerPhoto(i.peerID,"User","Group"),i.unreadCount=t,"messageService"==i._&&i.action.user_id&&(i.action.user=o.getUser(i.action.user_id)),i.message&&i.message.length&&(i.richMessage=h.wrapRichText(i.message.substr(0,64),{noLinks:!0,noLinebreaks:!0})),i.dateText=ct(i.date),n&&(W[e]=i),i}function B(e){if(void 0!==V[e])return V[e];var t=angular.copy(z[e])||{id:e};if(t.media&&void 0!==t.media.progress&&(t.media.progress=z[e].media.progress),t.media)switch(t.media._){case"messageMediaPhoto":t.media.photo=c.wrapForHistory(t.media.photo.id);break;case"messageMediaVideo":t.media.video=l.wrapForHistory(t.media.video.id);break;case"messageMediaDocument":t.media.document=d.wrapForHistory(t.media.document.id);break;case"messageMediaAudio":t.media.audio=u.wrapForHistory(t.media.audio.id);break;case"messageMediaContact":t.media.rFullName=h.wrapRichText(t.media.first_name+" "+(t.media.last_name||""),{noLinks:!0,noLinebreaks:!0});break;case"messageMediaEmpty":delete t.media}else if(t.action)switch(t.action._){case"messageActionChatEditPhoto":t.action.photo=c.wrapForHistory(t.action.photo.id);break;case"messageActionChatCreate":case"messageActionChatEditTitle":t.action.rTitle=h.wrapRichText(t.action.title,{noLinks:!0,noLinebreaks:!0})||v("chat_title_deleted")}return t.message&&t.message.length&&(t.richMessage=h.wrapRichText(t.message)),V[e]=t}function R(e,t){if(!e||!e.length)return!1;var n,i,a,o,r,s,c,l=0,d=e.length,u=d,p=!1,m=!Config.Mobile;for(t>0?u=Math.min(t,d):0>t&&(l=Math.max(0,u+t)),n=l;u>n;n++){if(o=e[n],i=Math.floor((o.date+j)/86400),c=r&&r.grouped,s=o.grouped,i===a?o.needDate&&(delete o.needDate,p=!0):(!n||r)&&(o.needDate||(o.needDate=!0,p=!0)),r&&o.from_id==r.from_id&&!r.fwd_from_id==!o.fwd_from_id&&!r.action&&!o.action&&o.date0?(l.title=(s.first_name||"")+(s.first_name&&s.last_name?" ":"")+(s.last_name||""),i=c,n=o.getUserString(a)):(l.title=(s.first_name||s.last_name||v("conversation_unknown_user_raw"))+" @ "+(r.getChat(-a).title||v("conversation_unknown_chat_raw")),i=r.getChatPhoto(-a,"Group"),n=r.getChatString(-a)),l.title=h.wrapPlainText(l.title),l.onclick=function(){t.$broadcast("history_focus",{peerString:n})},l.message=d,l.image=i.placeholder,l.key="msg"+e.id,l.tag=n,i.location&&!i.location.empty?m.downloadSmallFile(i.location,i.size).then(function(t){l.image=t,e.unread&&f.notify(l)}):f.notify(l)}var j,z={},V={},W={},G={},K={count:null,dialogs:[]},X={},Z={},Y={},J=e.when(),Q=-1,et=g.createIndex(),tt={query:!1},nt={},it=[],at=0,ot=tsNow(!0),rt=ot-ot%86400,st=new Date;y.get("server_time_offset").then(function(e){e&&(at=e)});var ct=i("dateOrTime");return st.setHours(0),st.setMinutes(0),st.setSeconds(0),j=rt-Math.floor(+st/1e3),f.start(),window.navigator.mozSetMessageHandler&&window.navigator.mozSetMessageHandler("activity",function(e){var n=e.source;console.log(dT(),"Received activity",n.name,n.data),"share"===n.name&&n.data.blobs.length>0&&_.selectPeer({confirm_type:"EXT_SHARE_PEER"}).then(function(e){var i=s.getPeerID(e);angular.forEach(n.data.blobs,function(e){D(i,e,{isMedia:!0})}),t.$broadcast("history_focus",{peerString:e})})}),t.$on("apiUpdate",function(e,n){switch(n._){case"updateMessageID":Z[n.id]=n.random_id;break;case"updateNewMessage":var i=n.message,a=O(i),r=G[a];if(void 0!==r){{G[a].history[0]}if(-1!=G[a].history.indexOf(i.id))return!1;r.history.unshift(i.id),r.history.sort(function(e,t){return t-e})}else r=G[a]={count:null,history:[i.id],pending:[]};E([i]),i.out||o.forceUserOnline(i.from_id),null!==r.count&&r.count++;var c,l=Z[i.id];l&&((c=U(l,i))&&t.$broadcast("history_update",{peerID:a}),delete Z[i.id]),c||t.$broadcast("history_append",{peerID:a,messageID:i.id});var d,u=q(a);u.length?(d=u[0],K.dialogs.splice(u[1],1)):d={peerID:a,unread_count:0,top_message:!1},!i.out&&i.unread&&d.unread_count++,d.top_message=i.id,g.indexObject(a,s.getPeerSearchText(a),et),K.dialogs.unshift(d),t.$broadcast("dialogs_update",d),(Config.Mobile&&t.selectedPeerID!=a||t.idle.isIDLE)&&!i.out&&i.unread&&f.getPeerMuted(a).then(function(e){i.unread&&!e&&H(i)});break;case"updateReadMessages":var p,i,m,a,u,d,h={},_=!1;for(m=0;m0&&o.forceUserOnline(a):(u=q(a),u&&(h[a]=--u[0].unread_count),f.cancel("msg"+p)));angular.forEach(h,function(e,n){t.$broadcast("dialog_unread",{peerID:n,count:e})}),_&&t.$broadcast("messages_read");break;case"updateDeleteMessages":var p,i,m,a,u,d,y,h={},v={};for(m=0;mo&&(i=e,a=o)}),i}function d(e,t,n){return a.invokeApi("photos.getUserPhotos",{user_id:e,offset:0,limit:n||20,max_id:t||0}).then(function(e){r.saveApiUsers(e.users);for(var t=[],n=0;nn/i?o.height=parseInt(a.h*n/a.w):(o.width=parseInt(a.w*i/a.h),o.width>n&&(o.height=parseInt(o.height*n/o.width),o.width=n)),o.location=a.location,o.size=a.size):(o.width=100,o.height=100),t.thumb=o,t}function h(e){var n=m(e),i=$(window).width()-(Config.Mobile?20:36),a=$(t).height()-150,o=l(n,i,a),s={placeholder:"img/placeholders/PhotoThumbModal.gif"};return i>800&&(i-=200),s.width=i,s.height=a,o&&"photoSizeEmpty"!=o._&&(o.w/o.h>i/a?s.height=parseInt(o.h*i/o.w):(s.width=parseInt(o.w*a/o.h),s.width>i&&(s.height=parseInt(s.height*i/s.width),s.width=i)),!Config.Mobile&&s.width>=o.w&&s.height>=o.h&&(s.width=o.w,s.height=o.h),s.modalWidth=Math.max(s.width,Math.min(400,i)),s.location=o.location,s.size=o.size),n.full=s,n.fromUser=r.getUser(n.user_id),n}function f(t,n){if(!t||"0"===t)return!1;var a=i.$new(!0);a.photoID=t,0>n?a.userID=-n:a.messageID=n;e.open({templateUrl:templateUrl("photo_modal"),controller:a.userID?"UserpicModalController":"PhotoModalController",scope:a,windowClass:"photo_modal_window"})}function g(e){var n=_[e],i="jpg",a="image/jpeg",r="photo"+e+"."+i,c=$(window).width()-36,d=$(t).height()-150,u=l(n,c,d),p={_:"inputFileLocation",volume_id:u.location.volume_id,local_id:u.location.local_id,secret:u.location.secret};s.chooseSave(r,i,a).then(function(e){e&&o.downloadFile(u.location.dc_id,p,u.size,{mime:a,toFileEntry:e}).then(function(){console.log("file save done")},function(e){console.log("photo download failed",e)})},function(){o.downloadFile(u.location.dc_id,p,u.size,{mime:a}).then(function(e){s.download(e,a,r)},function(e){console.log("photo download failed",e)})})}var _={},y=$(window).width(),v=$(window).height();return i.preloadPhoto=u,i.openPhoto=f,{savePhoto:c,preloadPhoto:u,getUserPhotos:d,getPhoto:p,wrapForHistory:m,wrapForFull:h,openPhoto:f,downloadPhoto:g}}]).service("AppVideoManager",["$rootScope","$modal","$window","$timeout","MtpApiFileManager","AppUsersManager","FileManager",function(e,t,n,i,a,o,r){function s(e){p[e.id]=e,e.thumb&&"photoCachedSize"==e.thumb._&&(a.saveSmallFile(e.thumb.location,e.thumb.bytes),e.thumb.size=e.thumb.bytes.length,delete e.thumb.bytes,e.thumb._="photoSize")}function c(e){if(void 0!==m[e])return m[e];var t=angular.copy(p[e]),n=Math.min(h-80,Config.Mobile?210:200),i=Math.min(f-100,Config.Mobile?210:200),a=t.thumb,o={placeholder:"img/placeholders/VideoThumbConversation.gif",width:n,height:i};return a&&"photoSizeEmpty"!=a._&&(a.w/a.h>n/i?o.height=parseInt(a.h*n/a.w):(o.width=parseInt(a.w*i/a.h),o.width>n&&(o.height=parseInt(o.height*n/o.width),o.width=n)),o.location=a.location,o.size=a.size),t.thumb=o,m[e]=t}function l(e){var t=c(e),i=Math.min($(window).width()-60,542),a=$(n).height()-150,r={placeholder:"img/placeholders/VideoThumbModal.gif",width:i,height:a};return t.w&&t.h?t.w>t.h?r.height=parseInt(t.h*i/t.w):(r.width=parseInt(t.w*a/t.h),r.width>i&&(r.height=parseInt(r.height*i/r.width),r.width=i)):r.height=r.width=Math.min(i,a),t.full=r,t.fullThumb=angular.copy(t.thumb),t.fullThumb.width=r.width,t.fullThumb.height=r.height,t.fromUser=o.getUser(t.user_id),t}function d(n,i){var a=e.$new(!0);a.videoID=n,a.messageID=i;t.open({templateUrl:templateUrl("video_modal"),controller:"VideoModalController",scope:a,windowClass:"video_modal_window"})}function u(t,n,i){function o(t){console.log("dl progress",t),c.progress.done=t.done,c.progress.percent=Math.max(1,Math.floor(100*t.done/t.total)),e.$broadcast("history_update")}var s=p[t],c=m[t]||s||{},l={_:"inputVideoFileLocation",id:t,access_hash:n||s.access_hash};c.progress={enabled:!0,percent:1,total:s.size};var d="mp4",u="video/mpeg4",h="video"+t+"."+d;r.chooseSave(h,d,u).then(function(e){if(e){var t=a.downloadFile(s.dc_id,l,s.size,{mime:u,toFileEntry:e});t.then(function(){delete c.progress,console.log("file save done")},function(e){console.log("video download failed",e),c.progress.enabled=!1},o),c.progress.cancel=t.cancel}},function(){var e=a.downloadFile(s.dc_id,l,s.size,{mime:u});e.then(function(e){return delete c.progress,i?void window.open(e,"_blank"):void r.download(e,u,h)},function(e){console.log("video download failed",e),c.progress.enabled=!1},o),c.progress.cancel=e.cancel})}var p={},m={},h=$(window).width(),f=$(window).height();return e.openVideo=d,e.downloadVideo=u,{saveVideo:s,wrapForHistory:c,wrapForFull:l,openVideo:d}}]).service("AppDocsManager",["$rootScope","$modal","$window","$timeout","MtpApiFileManager","FileManager",function(e,t,n,i,a,o){function r(e){l[e.id]=e,e.thumb&&"photoCachedSize"==e.thumb._&&(a.saveSmallFile(e.thumb.location,e.thumb.bytes),e.thumb.size=e.thumb.bytes.length,delete e.thumb.bytes,e.thumb._="photoSize")}function s(e){if(void 0!==d[e])return d[e];var t=angular.copy(l[e]),n="image/gif"==t.mime_type,i="audio/"==t.mime_type.substr(0,6),a=n?Math.min(u-80,260):100,o=n?Math.min(p-100,260):100,r=t.thumb,s={width:a,height:o};return r&&"photoSizeEmpty"!=r._?(r.w/r.h>a/o?s.height=parseInt(r.h*a/r.w):(s.width=parseInt(r.w*o/r.h),s.width>a&&(s.height=parseInt(s.height*a/s.width),s.width=a)),s.location=r.location,s.size=r.size):s=!1,t.thumb=s,t.canDownload=!(window.chrome&&chrome.fileSystem&&chrome.fileSystem.chooseEntry),t.withPreview=t.canDownload&&t.mime_type.match(/^(image\/|application\/pdf)/)?1:0,n&&t.thumb?t.isSpecial="gif":i&&(t.isSpecial="audio"),d[e]=t}function c(t,n){function i(t){console.log("dl progress",t),s.progress.done=t.done,s.progress.percent=Math.max(1,Math.floor(100*t.done/t.total)),e.$broadcast("history_update")}var r=l[t],s=d[t]||r||{},c={_:"inputDocumentFileLocation",id:t,access_hash:r.access_hash},u=(r.file_name.split(".",2)||[])[1]||"";o.chooseSave(r.file_name,u,r.mime_type).then(function(e){if(e){s.progress={enabled:!0,percent:1,total:r.size};var t=a.downloadFile(r.dc_id,c,r.size,{mime:r.mime_type,toFileEntry:e});t.then(function(){delete s.progress,console.log("file save done")},function(e){console.log("document download failed",e),s.progress.enabled=!1},i),s.progress.cancel=t.cancel}},function(){s.progress={enabled:!0,percent:1,total:r.size};var e=a.downloadFile(r.dc_id,c,r.size,{mime:r.mime_type});e.then(function(e){switch(delete s.progress,s.url=e,n){case 1:window.open(e,"_blank");break;default:o.download(e,r.mime_type,r.file_name)}},function(e){console.log("document download failed",e),s.progress.enabled=!1},i),s.progress.cancel=e.cancel})}var l={},d={},u=$(window).width(),p=$(window).height();return e.downloadDoc=c,{saveDoc:r,wrapForHistory:s,downloadDoc:c}}]).service("AppAudioManager",["$rootScope","$modal","$window","$timeout","$sce","MtpApiFileManager",function(e,t,n,i,a,o){function r(e){l[e.id]=e}function s(e){if(void 0!==d[e])return d[e];var t=angular.copy(l[e]);return d[e]=t}function c(t,n){function r(t){console.log("dl progress",t),c.progress.done=t.done,c.progress.percent=Math.max(1,Math.floor(100*t.done/t.total)),e.$broadcast("history_update")}var s=l[t],c=d[t]||s||{},u={_:"inputAudioFileLocation",id:t,access_hash:n||s.access_hash};c.progress={enabled:!0,percent:1,total:s.size};var p=o.downloadFile(s.dc_id,u,s.size,{mime:"audio/ogg"});return p.then(function(t){delete c.progress,c.url=a.trustAsResourceUrl(t),c.autoplay=!0,i(function(){console.log("disable autoplay"),delete c.autoplay,e.$broadcast("history_update")},1e3)},function(e){console.log("audio download failed",e),c.progress.enabled=!1},r),c.progress.cancel=p.cancel,p}var l={},d={};return e.openAudio=c,{saveAudio:r,wrapForHistory:s,openAudio:c}}]).service("ExternalResourcesManager",["$q","$http",function(e,t){function n(e){return void 0!==i[e]?i[e]:i[e]=t.get(e,{responseType:"blob",transformRequest:null}).then(function(e){return window.URL=window.URL||window.webkitURL,window.URL.createObjectURL(e.data)})}var i={};return{downloadImage:n}}]).service("ApiUpdatesManager",["$rootScope","MtpNetworkerFactory","AppUsersManager","AppChatsManager","AppPeersManager","MtpApiManager",function(e,t,n,i,a,o){function r(){var e=f.seq+1,t=g[e];t&&(console.log(dT(),"pop pending update",e,t),c(t)&&delete g[e])}function s(){m||l()}function c(e){if(e.seq){if(!u(e.seq,e.seq_start))return g[e.seq_start||e.seq]=e,!1;e.date&&(f.date=e.date)}switch(e._){case"updatesTooLong":s();break;case"updateShort":d(e.update);break;case"updateShortMessage":if(!n.hasUser(e.from_id)){console.log("User not found",e.from_id,"getDiff"),s();break}d({_:"updateNewMessage",message:{_:"message",id:e.id,from_id:e.from_id,to_id:a.getOutputPeer(o.getUserID()),flags:1,date:e.date,message:e.message,media:{_:"messageMediaEmpty"}},pts:e.pts});break;case"updateShortChatMessage":if(!n.hasUser(e.from_id)||!i.hasChat(e.chat_id)){console.log("User or chat not found",e.from_id,e.chat_id,"getDiff"),s();break}d({_:"updateNewMessage",message:{_:"message",id:e.id,from_id:e.from_id,to_id:a.getOutputPeer(-e.chat_id),flags:1,date:e.date,message:e.message,media:{_:"messageMediaEmpty"}},pts:e.pts});break;case"updatesCombined":case"updates":n.saveApiUsers(e.users),i.saveApiChats(e.chats);for(var t,c,l,t=0;t=h.seqAwaiting&&(console.log(dT(),"cancel pending getDiff",h.seqAwaiting),clearTimeout(h.timeout),h=!1),!0}function l(){m=!0,h&&(clearTimeout(h.timeout),h=!1),o.invokeApi("updates.getDifference",{pts:f.pts,date:f.date,qts:0}).then(function(e){if("updates.differenceEmpty"==e._)return console.log(dT(),"apply empty diff",e.seq),f.date=e.date,f.seq=e.seq,m=!1,r(),!1;n.saveApiUsers(e.users),i.saveApiChats(e.chats),angular.forEach(e.other_updates,function(e){d(e)}),angular.forEach(e.new_messages,function(e){d({_:"updateNewMessage",message:e,pts:f.pts})});var t=e.intermediate_state||e.state;f.seq=t.seq,f.pts=t.pts,f.date=t.date,console.log(dT(),"apply diff",f.seq,f.pts),"updates.differenceSlice"==e._?l(!0):m=!1})}function d(t){t.pts&&(f.pts=t.pts),e.$broadcast("apiUpdate",t)}function u(e,t){return(t=t||e)?m?(console.log(dT(),"Seq decline",t),!1):t!=f.seq+1?(t>f.seq&&(console.warn(dT(),"Seq hole",t,h&&h.seqAwaiting),h||(h={seqAwaiting:t,timeout:setTimeout(function(){l()},5e3)})),!1):(f.seq=e,!0):!0}function p(){t.setUpdatesProcessor(c),o.invokeApi("updates.getState",{noErrorBox:!0}).then(function(e){f.seq=e.seq,f.pts=e.pts,f.date=e.date,m=!1})}var m=!0,h=!1,f={},g={};return{processUpdateMessage:c,attach:p}}]).service("RichTextProcessor",["$sce","$sanitize",function(e,t){function n(e){return e.replace(/&/g,"&").replace(/([^\#-~| |!])/g,function(e){return"&#"+e.charCodeAt(0)+";"}).replace(//g,">")}function i(e){for(var t,n,i,a,o=0;o-1)return n=Math.floor(t/a),i=t%a,{category:o,row:n,column:i};return console.error("emoji not found in spritesheet",e),null}function a(a,o){if(!a||!a.length)return"";o=o||{},a=a.replace(/\ufe0f/g,"",a);for(var s,u,p,m=a,g=[],_=!1;s=m.match(h);)g.push(n(m.substr(0,s.index))),s[1]?o.noLinks?g.push(n(s[0])):s[3]?g.push('',n(s[3]+s[4]),""):g.push('',n(s[2]+"://"+s[4]),""):s[5]?g.push(o.noLinebreaks?" ":"
"):s[6]?(r=c[s[6]])&&(p=i(r))?(u=n(l[r][1][0]),_=!0,g.push('',":",u,":")):g.push(n(s[6])):s[8]&&(o.noLinks?g.push(s[7],n(s[8])):g.push(s[7],'',n(s[8]),"")),m=m.substr(s.index+s[0].length);if(g.push(n(m)),a=t(g.join("")),_&&(a=a.replace(//g,'')),!o.noLinks){var y=a.match(f),v=y&&y[1];if(v){var b=Config.Modes.chrome_packed?"webview":"iframe";a=a+'
<'+b+' type="text/html" frameborder="0" src="http://www.youtube.com/embed/'+v+'?autoplay=0&controls=2">
"}}return e.trustAs("html",a)}function o(e,t){if(u)return e;if(!e||!e.length)return"";t=t||{},e=e.replace(/\ufe0f/g,"",e);for(var n,i,a=e,e=[];n=a.match(h);)e.push(a.substr(0,n.index)),e.push(n[6]?(r=c[n[6]])&&(i=l[r][1][0])?":"+i+":":n[0]:n[0]),a=a.substr(n.index+n[0].length);return e.push(a),e.join("")}var r,s=[],c={},l=Config.Emoji,d=18,u=-1!=navigator.userAgent.search(/OS X|iPhone|iPad|iOS|Android/i);for(r in l)s.push(l[r][0]),c[l[r][0]]=r;var p="a-z\\u00c0-\\u00d6\\u00d8-\\u00f6\\u00f8-\\u00ff\\u0100-\\u024f\\u0253\\u0254\\u0256\\u0257\\u0259\\u025b\\u0263\\u0268\\u026f\\u0272\\u0289\\u028b\\u02bb\\u0300-\\u036f\\u1e00-\\u1eff\\u0400-\\u04ff\\u0500-\\u0527\\u2de0-\\u2dff\\ua640-\\ua69f\\u0591-\\u05bf\\u05c1-\\u05c2\\u05c4-\\u05c5\\u05c7\\u05d0-\\u05ea\\u05f0-\\u05f4\\ufb1d-\\ufb28\\ufb2a-\\ufb36\\ufb38-\\ufb3c\\ufb3e\\ufb40-\\ufb41\\ufb43-\\ufb44\\ufb46-\\ufb4f\\u0610-\\u061a\\u0620-\\u065f\\u066e-\\u06d3\\u06d5-\\u06dc\\u06de-\\u06e8\\u06ea-\\u06ef\\u06fa-\\u06fc\\u06ff\\u0750-\\u077f\\u08a0\\u08a2-\\u08ac\\u08e4-\\u08fe\\ufb50-\\ufbb1\\ufbd3-\\ufd3d\\ufd50-\\ufd8f\\ufd92-\\ufdc7\\ufdf0-\\ufdfb\\ufe70-\\ufe74\\ufe76-\\ufefc\\u200c\\u0e01-\\u0e3a\\u0e40-\\u0e4e\\u1100-\\u11ff\\u3130-\\u3185\\uA960-\\uA97F\\uAC00-\\uD7AF\\uD7B0-\\uD7FF\\u3003\\u3005\\u303b\\uff21-\\uff3a\\uff41-\\uff5a\\uff66-\\uff9f\\uffa1-\\uffdc",m="0-9._"+p,h=new RegExp("((?:(ftp|https?)://|(?:mailto:)?([A-Za-z0-9._%+-]+@))(\\S*\\.\\S*[^\\s.;,(){}<>\"']))|(\\n)|("+s.join("|")+")|(^|\\s)(#["+m+"]{3,20})","i"),f=/(?:https?:\/\/)?(?:www\.)?youtu(?:|.be|be.com|.b)(?:\/v\/|\/watch\\?v=|e\/|(?:\/\??#)?\/watch(?:.+)v=)(.{11})(?:\&[^\s]*)?/;return{wrapRichText:a,wrapPlainText:o}}]).service("IdleManager",["$rootScope","$window","$timeout",function(e,t,n){function i(){r||(r=!0,$(t).on("blur focus keydown mousedown touchstart",a),setTimeout(function(){a({type:"blur"})},0))}function a(i){"mousemove"==i.type&&$(t).off("mousemove",a);var r="blur"==i.type||"timeout"==i.type?!0:!1;n.cancel(o),r||(o=n(function(){a({type:"timeout"})},3e4)),e.idle.isIDLE!=r&&(e.$apply(function(){e.idle.isIDLE=r}),r&&"timeout"==i.type&&$(t).on("mousemove",a))}e.idle={isIDLE:!1};var o,r=!1;return{start:i}}]).service("StatusManager",["$timeout","$rootScope","MtpApiManager","IdleManager",function(e,t,n){function i(){c||(c=!0,t.$watch("idle.isIDLE",o),t.$watch("offline",o))}function a(e){var i=tsNow();if(!(e&&!s||!e&&5e4>i-s||t.offline))return s=e?0:i,n.invokeApi("account.updateStatus",{offline:e},{noErrorBox:!0})}function o(){r&&e.cancel(r),t.idle.isIDLE?r=e(function(){a(!0)},5e3):(a(!1),r=e(o,6e4))}var r,s=0,c=!1;return{start:i}}]).service("NotificationsManager",["$rootScope","$window","$timeout","$interval","$q","_","MtpApiManager","AppPeersManager","IdleManager","Storage","AppRuntimeManager",function(e,t,n,i,a,o,r,s,c,l,d){function u(e){return void 0!==E[e]?E[e]:E[e]=r.invokeApi("account.getNotifySettings",{peer:{_:"inputNotifyPeer",peer:s.getInputPeerByID(e)}})}function p(e,t){E[e]=a.when(t)}function m(e,t){p(e,t);var n=angular.copy(t);return n._="inputPeerNotifySettings",r.invokeApi("account.updateNotifySettings",{peer:{_:"inputNotifyPeer",peer:s.getInputPeerByID(e)},settings:n})}function h(e){return u(e).then(function(e){return"peerNotifySettings"==e._&&1e3*e.mute_until>tsNow()})}function f(){if(w(),!S)return!1;"Notification"in window&&"granted"!==Notification.permission&&"denied"!==Notification.permission&&$(t).on("click",g);try{$(t).on("beforeunload",b)}catch(e){}}function g(){Notification.requestPermission(),$(t).off("click",g)}function _(e){return Config.Navigator.ffos?e.image="https://raw.githubusercontent.com/zhukov/webogram/master/app/img/icons/icon60.png":e.image||(e.image="img/icons/icon60.png"),A++,!S||"Notification"in window&&"granted"!==Notification.permission?!1:(l.get("notify_nosound","notify_volume").then(function(e){(!e[0]&&e[1]===!1||e[1]>0)&&y(e[1]||.5)}),void l.get("notify_nodesktop","notify_novibrate").then(function(t){if(t[0]){if(T&&!t[1])return void navigator.vibrate([200,100,200])}else{var n,i=++x,a=e.key||"k"+i;if("Notification"in window)n=new Notification(e.title,{icon:e.image||"",body:e.message||"",tag:e.tag||""});else{if(!("mozNotification"in navigator))return;n=navigator.mozNotification.createNotification(e.title,e.message||"",e.image||"")}n.onclick=function(){n.close(),d.focus(),b(),e.onclick&&e.onclick()},n.onclose=function(){delete M[a],b()},n.show&&n.show(),M[a]=n}}))}function y(e){var t="img/sound_a.wav",n=$("#notify_sound").html('');n.find("audio")[0].volume=e}function v(e){var t=M[e];if(t){A>0&&A--;try{t.close&&t.close()}catch(n){}delete A[e]}}function b(){angular.forEach(M,function(e){try{e.close&&e.close()}catch(t){}}),M={},A=0}function w(){if(L)return!1;if(navigator.push&&Config.Navigator.ffos&&Config.Modes.packed){var e=navigator.push.register();e.onsuccess=function(){clearTimeout(O),console.log(dT(),"Push registered",e.result),L=e.result,r.invokeApi("account.registerDevice",{token_type:4,token:L,device_model:navigator.userAgent||"Unknown UserAgent",system_version:navigator.platform||"Unknown Platform",app_version:Config.App.version,app_sandbox:!1,lang_code:navigator.language||"en"})},e.onerror=function(e){console.error("Push register error",e,e.toString()),O=setTimeout(w,U),U=Math.min(3e4,1.5*U)}}}function k(){return T}navigator.vibrate=navigator.vibrate||navigator.mozVibrate||navigator.webkitVibrate;var C,S="Notification"in window||"mozNotification"in navigator,M={},x=0,A=0,T=!!navigator.vibrate,E={},I=$('link[rel="icon"]:first'),D=$(''),P=o.pluralize("page_title_pluralize_notifications"),N=document.title;e.$watch("idle.isIDLE",function(e){i.cancel(C),e?(N=document.title,C=i(function(){var e=tsNow();if(!A||e%2e3>1e3){document.title=N;var t=$('link[rel="icon"]:first');-1!=t.attr("href").indexOf("favicon_unread")&&t.replaceWith(I)}else document.title=P(A),$('link[rel="icon"]:first').replaceWith(D)},1e3)):(document.title=N,$('link[rel="icon"]:first').replaceWith(I),b())}),e.$on("apiUpdate",function(e,t){switch(t._){case"updateNotifySettings":if("notifyPeer"==t.peer._){var n=s.getPeerID(t.peer.peer);p(n,t.notify_settings)}}});var L=!1;return window.navigator.mozSetMessageHandler&&(window.navigator.mozSetMessageHandler("push",function(t){console.log(dT(),"received push",t),e.$broadcast("push_received")}),window.navigator.mozSetMessageHandler("push-register",function(e){console.log(dT(),"received push",e),L=!1,w()})),{start:f,notify:_,cancel:v,clear:b,getPeerSettings:u,getPeerMuted:h,savePeerSettings:p,updatePeerSettings:m,getVibrateSupport:k,testSound:y};var U,O}]).service("ErrorService",["$rootScope","$modal","$window",function(e,t,n){function i(n,i){if(r>=2)return console.log("Skip error box, too many open",r,n,i),!1;i=i||{};var a=e.$new();angular.extend(a,n),r++;var o=t.open({templateUrl:templateUrl("error_modal"),scope:a,windowClass:i.windowClass||"error_modal_window"});return o.result["finally"](function(){r--}),o}function a(e,t){return i({title:e,description:t})}function o(n,i){i=i||{};var a=e.$new();angular.extend(a,n);var o=t.open({templateUrl:templateUrl("confirm_modal"),scope:a,windowClass:i.windowClass||"confirm_modal_window"});return o.result}var r=0;return n.safeConfirm=function(e,t){"string"==typeof e&&(e={message:e}),o(e).then(function(e){t(e||!0)},function(){t(!1)})},{show:i,alert:a,confirm:o}}]).service("PeersSelectService",["$rootScope","$modal",function(e,t){function n(n){var i=e.$new();return n&&angular.extend(i,n),t.open({templateUrl:templateUrl("peer_select"),controller:"PeerSelectController",scope:i,windowClass:"peer_select_window mobile_modal"}).result}return{selectPeer:n}}]).service("ContactsSelectService",["$rootScope","$modal",function(e,t){function n(n,i){i=i||{};var a=e.$new();return a.multiSelect=n,angular.extend(a,i),!a.action&&n&&(a.action="select"),t.open({templateUrl:templateUrl("contacts_modal"),controller:"ContactsModalController",scope:a,windowClass:"contacts_modal_window mobile_modal"}).result}return{selectContacts:function(e){return n(!0,e)},selectContact:function(e){return n(!1,e)}}}]).service("ChangelogNotifyService",["Storage","$rootScope","$http","$modal",function(e,t,n,i){function a(e,t){"string"!=typeof e&&(e=""),"string"!=typeof t&&(t=""),e=e.replace(/^\s+|\s+$/g,"").split("."),t=t.replace(/^\s+|\s+$/g,"").split(".");var n,i=Math.max(e.length,t.length);for(n=0;i>n;n++)if(e[n]!=t[n])return e[n]>t[n]?1:-1;return 0}function o(){e.get("last_version").then(function(t){t!=Config.App.version&&(t&&r(t),e.set({last_version:Config.App.version}))})}function r(e){var n=t.$new();n.lastVersion=e,n.canShowVersion=function(t){return n.lastVersion===!1||void 0===n.lastVersion?!0:a(t,e)>=0},i.open({controller:"ChangelogModalController",templateUrl:templateUrl("changelog_modal"),scope:n,windowClass:"changelog_modal_window mobile_modal"})}return{checkUpdate:o,showChangelog:r}}]),angular.module("myApp.controllers",["myApp.i18n"]).controller("AppWelcomeController",["$scope","$location","MtpApiManager","ErrorService","ChangelogNotifyService",function(e,t,n,i,a){n.getUserID().then(function(n){n?t.url("/im"):e.showWelcome=!0}),a.checkUpdate()}]).controller("AppLoginController",["$scope","$rootScope","$location","$timeout","$modal","$modalStack","MtpApiManager","ErrorService","NotificationsManager","ChangelogNotifyService","IdleManager","_",function(e,t,n,i,a,o,r,s,c,l,d,u){function p(){var t=(navigator.language||"").toLowerCase(),n=Config.LangCountries[t],i=!Config.Navigator.mobile;if(m(-1==["en","en-us","en-uk"].indexOf(t)?void 0!==n?n:t.indexOf("-")>0?t.split("-")[1].toUpperCase():"US":"US"),i){var a=e.credentials.phone_country;r.invokeApi("help.getNearestDc",{},{dcID:2,createNetworker:!0}).then(function(t){a==e.credentials.phone_country&&m(t.country),t.nearest_dc!=t.this_dc&&r.getNetworker(t.nearest_dc,{createNetworker:!0})})}}function m(e){var t,n;for(t=0;to&&!a.indexOf(i)&&(o=i.length,r=u(Config.CountryCodes[t][1]+"_raw"));e.credentials.phone_full=a,e.credentials.phone_country_name=r||u("login_controller_unknown_country_raw")}function g(e){r.setUserAuth(y.dcID,{expires:e.expires,id:e.user.id}),i.cancel(b),n.url("/im")}function _(){i.cancel(b),e.credentials.viaApp||(--e.callPending.remaining?b=i(_,1e3):(e.callPending.success=!1,r.invokeApi("auth.sendCall",{phone_number:e.credentials.phone_full,phone_code_hash:e.credentials.phone_code_hash},y).then(function(){e.callPending.success=!0})))}o.dismissAll(),d.start(),r.getUserID().then(function(e){return e?void n.url("/im"):void 0});var y={dcID:2,createNetworker:!0},v=!1;e.credentials={phone_country:"",phone_country_name:"",phone_number:"",phone_full:""},e.progress={},e.callPending={},e.chooseCountry=function(){var e=a.open({templateUrl:templateUrl("country_select_modal"),controller:"CountrySelectModalController",windowClass:"countries_modal_window mobile_modal"});e.result.then(h)},e.$watch("credentials.phone_country",f),e.$watch("credentials.phone_number",f),p();var b;e.sendCode=function(){i.cancel(b),s.confirm({type:"LOGIN_PHONE_CORRECT",country_code:e.credentials.phone_country,phone_number:e.credentials.phone_number}).then(function(){e.progress.enabled=!0,onContentLoaded(function(){e.$broadcast("ui_height")});var n=tsNow();r.invokeApi("auth.sendCode",{phone_number:e.credentials.phone_full,sms_type:5,api_id:Config.App.id,api_hash:Config.App.hash},y).then(function(t){e.progress.enabled=!1,e.credentials.phone_code_hash=t.phone_code_hash,e.credentials.phone_occupied=t.phone_registered,e.credentials.viaApp="auth.sentAppCode"==t._,e.callPending.remaining=t.send_call_timeout||60,e.error={},_(),onContentLoaded(function(){e.$broadcast("ui_height")})},function(t){switch(e.progress.enabled=!1,console.log("sendCode error",t),t.type){case"NETWORK_BAD_REQUEST":"https:"==location.protocol&&(s.confirm({type:"HTTPS_MIXED_FAIL"}).then(function(){location=location.toString().replace(/^https:/,"http:")}),t.handled=!0);break;case"PHONE_NUMBER_INVALID":e.error={field:"phone"},t.handled=!0}})["finally"](function(){(t.idle.isIDLE||tsNow()-n>6e4)&&c.notify({title:"Telegram",message:"Your authorization key was successfully generated! Open the app to log in.",tag:"auth_key"})})})},e.sendSms=function(){e.credentials.viaApp&&(delete e.credentials.viaApp,r.invokeApi("auth.sendSms",{phone_number:e.credentials.phone_full,phone_code_hash:e.credentials.phone_code_hash},y).then(_))},e.editPhone=function(){i.cancel(b),delete e.credentials.phone_code_hash,delete e.credentials.phone_unoccupied,delete e.credentials.phone_code_valid,delete e.credentials.viaApp,delete e.callPending.remaining,delete e.callPending.success},e.logIn=function(t){var n="auth.signIn",i={phone_number:e.credentials.phone_full,phone_code_hash:e.credentials.phone_code_hash,phone_code:e.credentials.phone_code};t&&(n="auth.signUp",angular.extend(i,{first_name:e.credentials.first_name,last_name:e.credentials.last_name})),e.progress.enabled=!0,r.invokeApi(n,i,y).then(g,function(t){if(e.progress.enabled=!1,400==t.code&&"PHONE_NUMBER_UNOCCUPIED"==t.type)return t.handled=!0,e.credentials.phone_code_valid=!0,void(e.credentials.phone_unoccupied=!0);if(400==t.code&&"PHONE_NUMBER_OCCUPIED"==t.type)return t.handled=!0,e.logIn(!1);switch(t.type){case"FIRSTNAME_INVALID":e.error={field:"first_name"},t.handled=!0;break;case"LASTNAME_INVALID":e.error={field:"last_name"},t.handled=!0;break;case"PHONE_CODE_INVALID":e.error={field:"phone_code"},delete e.credentials.phone_code_valid,t.handled=!0}})},l.checkUpdate()}]).controller("AppIMController",["$scope","$location","$routeParams","$modal","$rootScope","$modalStack","MtpApiManager","AppUsersManager","ContactsSelectService","ChangelogNotifyService","ErrorService","AppRuntimeManager",function(e,t,n,i,a,o,r,s,c,l,d,u){function p(){if(n.q){if(n.q!==m&&(e.search.query=m=n.q,e.search.messages=!0,void 0!==e.curDialog))return!1}else m=!1;e.curDialog={peer:n.p||!1,messageID:n.m||!1}}e.$on("$routeUpdate",p),e.$on("history_focus",function(n,i){o.dismissAll(),i.peerString==e.curDialog.peer&&i.messageID==e.curDialog.messageID?e.$broadcast(i.messageID?"ui_history_change_scroll":"ui_history_focus"):t.url("/im?p="+i.peerString+(i.messageID?"&m="+i.messageID:""))}),e.isLoggedIn=!0,e.isEmpty={},e.search={},e.historyFilter={mediaType:!1},e.historyPeer={},e.historyState={selectActions:!1,typing:[]},e.openSettings=function(){i.open({templateUrl:templateUrl("settings_modal"),controller:"SettingsModalController",windowClass:"settings_modal_window mobile_modal"})},e.openContacts=function(){c.selectContact().then(function(t){e.dialogSelect(s.getUserString(t))})},e.openGroup=function(){c.selectContacts({action:"new_group"}).then(function(t){if(1==t.length)e.dialogSelect(s.getUserString(t[0]));else if(t.length>1){var n=a.$new();n.userIDs=t,i.open({templateUrl:templateUrl("chat_create_modal"),controller:"ChatCreateModalController",scope:n,windowClass:"group_edit_modal_window mobile_modal"})}})},e.importContact=function(){s.openImportContact().then(function(e){e&&a.$broadcast("history_focus",{peerString:s.getUserString(e)})})},e.dialogSelect=function(e,t){var n={peerString:e};t&&(n.messageID=t),a.$broadcast("history_focus",n)},e.logOut=function(){d.confirm({type:"LOGOUT"}).then(function(){r.logOut().then(function(){location.hash="/login",u.reload()})})},e.showPeerInfo=function(){e.curDialog.peerID>0?a.openUser(e.curDialog.peerID):e.curDialog.peerID<0&&a.openChat(-e.curDialog.peerID)},e.toggleEdit=function(){e.$broadcast("history_edit_toggle")},e.selectedFlush=function(){e.$broadcast("history_edit_flush")},e.toggleMedia=function(t){e.$broadcast("history_media_toggle",t)},e.returnToRecent=function(){e.$broadcast("history_return_recent")},e.toggleSearch=function(){e.$broadcast("dialogs_search_toggle")},p();var m=!1;l.checkUpdate()}]).controller("AppImDialogsController",["$scope","$location","$q","$timeout","$routeParams","MtpApiManager","AppUsersManager","AppChatsManager","AppMessagesManager","AppPeersManager","PhonebookContactsService","ErrorService",function(e,t,n,i,a,o,r,s,c,l,d,u){function p(a){var r,s=e.search.messages&&e.search.query.length>0,l=++b;return i.cancel(k),s?(k=a?n.when():i(angular.noop,500),r=k.then(function(){return c.getSearch({_:"inputPeerEmpty"},e.search.query,{_:"inputMessagesFilterEmpty"},y)})):r=c.getDialogs(e.search.query,y),r.then(function(e){if(l!=b)return n.reject();if(s){var t=[];angular.forEach(e.history,function(e){var n=c.getMessage(e),i=c.getMessagePeer(n);t.push({peerID:i,top_message:e,unread_count:-1})}),e={count:e.count,dialogs:t}}return e},function(e){return"NETWORK_BAD_REQUEST"==e.type&&"https:"==location.protocol&&(u.confirm({type:"HTTPS_MIXED_FAIL"}).then(function(){location=location.toString().replace(/^https:/,"http:")}),e.handled=!0),401==e.code&&(o.logOut()["finally"](function(){t.url("/login")}),e.handled=!0),n.reject()})}function m(t){_=0,y=0,v=!1,w={},g=!1,p(t).then(function(t){e.dialogs=[],e.contacts=[],e.foundUsers=[],t.dialogs.length&&(_+=t.dialogs.length,y=t.dialogs[t.dialogs.length-1].top_message,v=null===t.count||_=5&&o.invokeApi("contacts.search",{q:e.search.query,limit:10}).then(function(n){console.log(e.search.query,n),r.saveApiUsers(n.users),t==b&&(e.foundUsers=[],angular.forEach(n.results,function(t){var n=t.user_id;void 0===w[n]&&e.foundUsers.push({userID:n,user:r.getUser(n),peerString:r.getUserString(n)})}))},function(e){400==e.code&&(e.handled=!0)})}function f(){return!g||v&&_?v||e.search.messages||!e.search.query&&e.dialogs.length?void p().then(function(t){t.dialogs.length&&(_+=t.dialogs.length,y=t.dialogs[t.dialogs.length-1].top_message,v=null===t.count||_-1?(i=e.peerHistories[o],o&&(e.peerHistories.splice(o,1),e.peerHistories.unshift(i)),i):(i={peerID:t,messages:[]},e.peerHistories.unshift(i),a=e.peerHistories.length-r,a>0&&e.peerHistories.splice(r-1,a),i)}function g(t){var n;for(n=0;n=0;o--)r=i.history[o],r>O&&P.messages.push(s.wrapForHistory(r));i.history.length?(O=i.history.length>=a?i.history[0]:0,s.regroupWrappedHistory(P.messages,-a)&&e.$broadcast("messages_regroup"),delete e.state.empty,e.$broadcast("ui_history_append")):O=0,e.skippedHistory=L=O>0,j&&b()}})}}function b(){if(N){if(V)return void(j=!0);j=!1,H=!0;var t=R,n=q,i=e.historyFilter.mediaType&&{_:B[e.historyFilter.mediaType]},a=Config.Mobile?20:0,o=i?s.getSearch(e.curDialog.inputPeer,"",i,U,a):s.getHistory(e.curDialog.inputPeer,U,a);o.then(function(i){H=!1,t==R&&n==q&&(angular.forEach(i.history,function(e){P.messages.unshift(s.wrapForHistory(e))}),N=null===i.count||i.history.length&&P.messages.length=i-1?t.history[0]:0,U=t.history[t.history.length-1],e.skippedHistory=L=O>0,N=null===t.count||n&&nt;for(o=0;o0){var t=[];angular.forEach(e.selectedMsgs,function(e,n){t.push(n)}),s.deleteMessages(t).then(function(){S()})}}function A(){if(e.selectedCount>0){var t=[];angular.forEach(e.selectedMsgs,function(e,n){t.push(n)}),d.selectPeer({confirm_type:"FORWARD_PEER"}).then(function(e){var n=c.getPeerID(e);s.forwardMessages(n,t).then(function(){S(),i.$broadcast("history_focus",{peerString:e})})})}}function T(){e.historyState.selectActions?S():(e.historyState.selectActions=!0,e.$broadcast("ui_panel_update"))}function E(t){e.historyFilter.mediaType=t||!1,P.messages=[],e.state.empty=!0,w()}function I(){e.historyFilter.mediaType?E():e.curDialog.messageID?i.$broadcast("history_focus",{peerString:e.curDialog.peer}):w(!0)}e.$watch("curDialog",h),l.attach(),u.start(),p.start(),e.peerHistories=[],e.skippedHistory=!1,e.selectedMsgs={},e.selectedCount=0,e.historyState.selectActions=!1,e.missedCount=0,e.state={},e.toggleMessage=C,e.selectedDelete=x,e.selectedForward=A,e.selectedCancel=S,e.selectedFlush=M,e.toggleEdit=T,e.toggleMedia=E,e.returnToRecent=I,e.$on("history_edit_toggle",T),e.$on("history_edit_flush",M),e.$on("history_media_toggle",function(e,t){E(t)}),e.$on("history_return_recent",I);var D,P=!1,N=!1,L=!1,U=0,O=0,F=!1,B={photos:"inputMessagesFilterPhotos",video:"inputMessagesFilterVideo",documents:"inputMessagesFilterDocument",audio:"inputMessagesFilterAudio"},R=0,q=0,H=!1,j=!1,z=0,V=!1,W=!1;e.$on("history_update",angular.noop);var G={};e.$on("history_append",function(t,a){var o=g(a.peerID);if(o){var r=a.peerID==e.curDialog.peerID;if(r){if(e.historyFilter.mediaType||e.skippedHistory)return void(a.my?I():e.missedCount++);delete e.state.empty}o.messages.push(s.wrapForHistory(a.messageID)),s.regroupWrappedHistory(o.messages,-3)&&e.$broadcast("messages_regroup"),r&&(e.historyState.typing.splice(0,e.historyState.typing.length),e.$broadcast("ui_history_append_new",{my:a.my}),a.my&&e.historyUnreadAfter&&(delete e.historyUnreadAfter,e.$broadcast("messages_unread_after")),i.idle.isIDLE||n(function(){s.readHistory(e.curDialog.inputPeer)}))}}),e.$on("history_delete",function(t,n){var i=g(n.peerID);if(i){var a,o=[];for(a=0;a=0?i+n:0,s=++v,c=r>=g.length?d():e.when();c.then(function(){s==v&&(t.messageID=g[r],t.photoID=o.getMessage(t.messageID).media.photo.id,t.photo=a.wrapForFull(t.photoID),u())})}function d(){return b?b:b=o.getSearch(m,h,f,_).then(function(e){e.history.length?(_=e.history[e.history.length-1],g=g.concat(e.history),y=g.length0,t.nav.hasPrev=y||e0}if(t.photo=a.wrapForFull(t.photoID),t.nav={},t.download=function(){a.downloadPhoto(t.photoID)},(!t.messageID||Config.Mobile)&&(t.nav.next=function(){i.close()}),t.messageID){if(t.forward=function(){var e=t.messageID;s.selectPeer({confirm_type:"FORWARD_PEER"}).then(function(t){var i=r.getPeerID(t);o.forwardMessages(i,[e]).then(function(){n.$broadcast("history_focus",{peerString:t})})})},Config.Mobile)return t.canForward=!0,void(t.canDelete=!0);t["delete"]=function(){var e=t.messageID;c.confirm({type:"MESSAGE_DELETE"}).then(function(){o.deleteMessages([e])})};var p=o.getMessagePeer(o.getMessage(t.messageID)),m=r.getInputPeerByID(p),h="",f={_:"inputMessagesFilterPhotos"},g=[t.messageID],_=t.messageID,y=!0;u(),o.getSearch(m,h,f,0,1e3).then(function(e){e.history.indexOf(t.messageID)>=0&&(g=e.history,_=g[g.length-1],u())});var v=0,b=!1;t.nav.next=function(){return t.nav.hasNext?void l(-1):!1},t.nav.prev=function(){return t.nav.hasPrev?void l(1):!1},t.$on("history_delete",function(e,n){if(n.peerID==p){if(n.msgs[t.messageID])if(t.nav.hasNext)t.nav.next();else{if(!t.nav.hasPrev)return i.dismiss();t.nav.prev()}for(var a=[],o=0;o=0?i+n:0,r=++_,s=o>=h.length?u():e.when();s.then(function(){r==_&&(t.photoID=h[o],t.photo=a.wrapForFull(t.photoID),p())})}function u(){return y?y:y=a.getUserPhotos(m,f).then(function(e){f=e.photos[e.photos.length-1],h=h.concat(e.photos),g=h.length0,t.nav.hasPrev=g||e=0&&(h=e.photos,f=h[h.length-1],g=h.length0&&Math.ceil(10*i[3])||0:5,t.notify.canVibrate=l.getVibrateSupport(),t.notify.vibrate=!i[4],t.notify.volumeOf4=function(){return 1+Math.ceil((t.notify.volume-1)/3.3)},t.toggleSound=function(){t.notify.volume=t.notify.volume?0:5};var a;t.$watch("notify.volume",function(e,t){if(e!==t){var i=e/10;c.set({notify_volume:i}),c.remove("notify_nosound"),l.clear(),a&&n.cancel(a),a=n(function(){l.testSound(i)},500)}}),t.toggleDesktop=function(){t.notify.desktop=!t.notify.desktop,t.notify.desktop?c.remove("notify_nodesktop"):c.set({notify_nodesktop:!0})},t.toggleVibrate=function(){t.notify.vibrate=!t.notify.vibrate,t.notify.vibrate?c.remove("notify_novibrate"):c.set({notify_novibrate:!0})},t.toggleCtrlEnter=function(n){t.send.enter=n,t.send.enter?c.remove("send_ctrlenter"):c.set({send_ctrlenter:!0}),e.$broadcast("settings_changed")}}),t.openChangelog=function(){p.showChangelog(!1)}}]).controller("ChangelogModalController",["$scope","$modal",function(e,t){e.changeUsername=function(){t.open({templateUrl:templateUrl("username_edit_modal"),controller:"UsernameEditModalController",windowClass:"username_edit_modal_window mobile_modal"})}}]).controller("ProfileEditModalController",["$scope","$modalInstance","AppUsersManager","MtpApiManager",function(e,t,n,i){e.profile={},e.error={},i.getUserID().then(function(t){e.profile=n.getUser(t)}),e.updateProfile=function(){e.profile.updating=!0,i.invokeApi("account.updateProfile",{first_name:e.profile.first_name||"",last_name:e.profile.last_name||""}).then(function(i){e.error={},n.saveApiUser(i),t.close()},function(n){switch(n.type){case"FIRSTNAME_INVALID":e.error={field:"first_name"},n.handled=!0;break;case"LASTNAME_INVALID":e.error={field:"last_name"},n.handled=!0;break;case"NAME_NOT_MODIFIED":n.handled=!0,t.close()}})["finally"](function(){delete e.profile.updating})}}]).controller("UsernameEditModalController",["$scope","$modalInstance","AppUsersManager","MtpApiManager",function(e,t,n,i){e.profile={},e.error={},i.getUserID().then(function(t){e.profile=angular.copy(n.getUser(t))}),e.updateUsername=function(){e.profile.updating=!0,i.invokeApi("account.updateUsername",{username:e.profile.username||""}).then(function(i){e.checked={},n.saveApiUser(i),t.close()},function(e){"USERNAME_NOT_MODIFIED"==e.type&&(e.handled=!0,t.close())})["finally"](function(){delete e.profile.updating})},e.$watch("profile.username",function(t){return t.length?void i.invokeApi("account.checkUsername",{username:t||""}).then(function(n){e.profile.username==t&&(e.checked=n?{success:!0}:{error:!0})},function(n){if(e.profile.username==t)switch(n.type){case"USERNAME_INVALID":e.checked={error:!0},n.handled=!0}}):void(e.checked={})})}]).controller("ContactsModalController",["$scope","$modal","$modalInstance","AppUsersManager","ErrorService",function(e,t,n,i){function a(){e.selectedContacts={},e.selectedCount=0}function o(t){i.getContacts(t).then(function(n){e.contacts=[],e.slice.limit=20,angular.forEach(n,function(t){var n={userID:t,user:i.getUser(t),userPhoto:i.getUserPhoto(t,"User")};e.contacts.push(n)}),e.contactsEmpty=t?!1:!e.contacts.length,e.$broadcast("contacts_change")})}if(e.contacts=[],e.search={},e.slice={limit:20,limitDelta:20},a(),e.disabledContacts={},e.disabled)for(var r=0;r0){var t=[];return angular.forEach(e.selectedContacts,function(e,n){t.push(n)}),n.close(t)}},e.deleteSelected=function(){if(e.selectedCount>0){var t=[];angular.forEach(e.selectedContacts,function(e,n){t.push(n)}),i.deleteContacts(t).then(function(){e.toggleEdit(!1)})}},e.importContact=function(){i.openImportContact()}}]).controller("PeerSelectController",["$scope","$modalInstance","$q","AppPeersManager","ErrorService",function(e,t,n,i,a){e.dialogSelect=function(o){var r;if(e.confirm_type){var s=i.getPeerID(o),c=i.getPeer(s);r=a.confirm({type:e.confirm_type,peer_id:s,peer_data:c})}else r=n.when();r.then(function(){t.close(o)})},e.toggleSearch=function(){e.$broadcast("dialogs_search_toggle")}}]).controller("ChatCreateModalController",["$scope","$modalInstance","$rootScope","MtpApiManager","AppUsersManager","AppChatsManager","ApiUpdatesManager",function(e,t,n,i,a,o,r){e.group={name:""},e.createGroup=function(){if(e.group.name){e.group.creating=!0;var t=[];return angular.forEach(e.userIDs,function(e){t.push({_:"inputUserContact",user_id:e})}),i.invokeApi("messages.createChat",{title:e.group.name,users:t}).then(function(e){r.processUpdateMessage({_:"updates",seq:e.seq,users:e.users,chats:e.chats,updates:[{_:"updateNewMessage",message:e.message,pts:e.pts}]});var t=o.getChatString(e.message.to_id.chat_id);n.$broadcast("history_focus",{peerString:t})})["finally"](function(){delete e.group.creating})}}}]).controller("ChatEditModalController",["$scope","$modalInstance","$rootScope","MtpApiManager","AppUsersManager","AppChatsManager","ApiUpdatesManager",function(e,t,n,i,a,o,r){var s=o.getChat(e.chatID);e.group={name:s.title},e.updateGroup=function(){return e.group.name?e.group.name==s.title?t.close():(e.group.updating=!0,i.invokeApi("messages.editChatTitle",{chat_id:e.chatID,title:e.group.name}).then(function(t){r.processUpdateMessage({_:"updates",seq:t.seq,users:t.users,chats:t.chats,updates:[{_:"updateNewMessage",message:t.message,pts:t.pts}]});var i=o.getChatString(e.chatID);n.$broadcast("history_focus",{peerString:i})})["finally"](function(){delete e.group.updating})):void 0}}]).controller("ImportContactModalController",["$scope","$modalInstance","$rootScope","AppUsersManager","ErrorService","PhonebookContactsService",function(e,t,n,i,a,o){void 0===e.importContact&&(e.importContact={}),e.phonebookAvailable=o.isAvailable(),e.doImport=function(){e.importContact&&e.importContact.phone&&(e.progress={enabled:!0},i.importContact(e.importContact.phone,e.importContact.first_name||"",e.importContact.last_name||"").then(function(e){e||a.show({error:{code:404,type:"USER_NOT_USING_TELEGRAM"}}),t.close(e)})["finally"](function(){delete e.progress.enabled}))},e.importPhonebook=function(){o.openPhonebookImport().result.then(function(e){e?t.close(e[0]):t.dismiss()})}}]).controller("CountrySelectModalController",["$scope","$modalInstance","$rootScope","SearchIndexManager","_",function(e,t,n,i,a){e.search={},e.slice={limit:20,limitDelta:20};for(var o=i.createIndex(),r=0;r5184e5?o="shortDate":a>432e5&&(o="EEE"),t[e]=n(i,o)}}]).filter("time",["$filter",function(e){var t={},n=e("date"),i=Config.Mobile?"shortTime":"mediumTime";return function(e){return t[e]?t[e]:t[e]=n(1e3*e,i)}}]).filter("myDate",["$filter",function(e){var t={},n=e("date");return function(e){return t[e]?t[e]:t[e]=n(1e3*e,"fullDate")}}]).filter("duration",[function(){return function(e){e=parseInt(e),isNaN(e)&&(e=0);var t=e%60,n=Math.floor((e-t)/60);return 10>t&&(t="0"+t),n+":"+t}}]).filter("phoneNumber",[function(){return function(e){var t=" ";return e=(e||"").replace(/\D/g,""),"7"==e.charAt(0)&&11==e.length?"+"+e.charAt(0)+t+"("+e.substr(1,3)+")"+t+e.substr(4,3)+"-"+e.substr(7,2)+"-"+e.substr(9,2):"+"+e}}]).filter("formatSize",[function(){return function(e){return e?1024>e?e+" b":1048576>e?Math.round(e/1024*10)/10+" Kb":Math.round(e/1048576*100)/100+" Mb":"0"}}]).filter("formatSizeProgress",["$filter","_",function(e,t){return function(n){var i=e("formatSize")(n.done),a=i.split(" "),o=e("formatSize")(n.total),r=o.split(" ");return r[1]===a[1]?t("format_size_progress_mulitple",{done:a[0],total:r[0],parts:a[1]||""}):t("format_size_progress",{done:i,total:o})}}]).filter("nl2br",[function(){return function(e){return e.replace(/\n/g,"
")}}]).filter("richText",["$filter",function(e){return function(t){return e("linky")(t,"_blank").replace(/\n| /g,"
")}}]).filter("relativeTime",["$filter","_",function(e,t){var n=t.pluralize("relative_time_pluralize_minutes_ago"),i=t.pluralize("relative_time_pluralize_hours_ago");return function(a){var o=1e3*a,r=Math.abs(tsNow()-o);if(6e4>r)return t("relative_time_just_now");if(3e6>r){var s=Math.ceil(r/6e4);return n(s)}if(1e7>r){var c=Math.ceil(r/36e5);return i(c)}return e("dateOrTime")(a)}}]),angular.module("myApp.i18n",["izhukov.utils"]).factory("_",["$rootScope","$locale",function(e,t){function n(e,t){return e.replace(l,function(i,a,o){var r=t[a];return void 0===r?(console.warn("[i18n] missing param "+a+' for message "'+e+'"'),""):(void 0!==o&&(r=n(r,o.split("|"))),r.toString().trim())})}function i(e){return e.replace(/&/g,"&").replace(/([^\#-~| |!\n\*])/g,function(e){return"&#"+e.charCodeAt(0)+";"}).replace(//g,">")}function a(e){return e=e.replace(/\*\*(.+?)\*\*/g,"$1").replace(/\n/g,"
")}function o(e,t){var o=!1,l=e;if("_raw"===e.substr(-4)&&(o=!0,e=e.substr(0,e.length-4)),s.hasOwnProperty(e))l=s[e];else{if(!c.hasOwnProperty(e))return console.warn("[i18n] missing key "+e),e;l=c[e],console.warn("[i18n] missing locale key "+r+" / "+e)}return o||(l=i(l)),"_md"==e.substr(-3)&&(l=a(l)),arguments.length>1&&("string"==typeof t?(Array.prototype.shift.apply(arguments),l=n(l,arguments)):l=n(l,t)),l}var r=Config.I18n.locale,s=Config.I18n.messages,c=Config.I18n.fallback_messages,l=/\{\s*([a-zA-Z\d\-_]+)(?:\s*:\s*(.*?))?\s*\}/g;return o.locale=function(){return r},o.pluralize=function(n){var i=e.$eval(o(n+"_raw"));return function(e){return(i[t.pluralCat(e)]||"").replace("{}",e)}},o}]).filter("i18n",["_",function(e){return function(t,n){return e(t+"_raw",n)}}]).directive("ngPluralize",["_",function(e){return{restrict:"EA",priority:1,compile:function(t){var n=t.attr("when"),i=e(n+"_raw");t.attr("when",i)}}}]).directive("myI18n",["_",function(e){return{restrict:"EA",compile:function(t){var n=t.children('my-i18n-param:not([name]), [my-i18n-param=""]:not([name])').map(function(e,t){return t.outerHTML}).toArray();t.children('my-i18n-param[name], [my-i18n-param]:not([my-i18n-param=""]), [my-i18n-param][name]').each(function(e,t){n[angular.element(t).attr("my-i18n-param")||angular.element(t).attr("name")]=t.outerHTML}),t.children("my-i18n-param").remove();var i=t.attr("my-i18n")||t.attr("msgid")?t:t.children("my-i18n-format, [my-i18n-format]");i.each(function(t,i){var a=angular.element(i),o=a.attr("my-i18n")||a.attr("msgid")||a.attr("my-i18n-format")||a.html().replace(/\s+/g," ").trim(),r=e(o,n);a.html(r)})}}}]),angular.module("myApp.templates",[]).run(["$templateCache",function(e){e.put("partials/desktop/audio_player.html",'
\n \n
\n \n \n \n \n
\n \n \n \n
\n
\n
\n \n \n
\n
\n
\n
\n
\n
\n
\n
\n
\n \n
'),e.put("partials/desktop/changelog_modal.html",'
\n\n \n\n \n\n
\n'),e.put("partials/desktop/chat_create_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/desktop/chat_edit_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/desktop/chat_modal.html",'
\n\n \n\n \n\n
\n'),e.put("partials/desktop/confirm_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/desktop/contacts_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/desktop/country_select_modal.html",'
\n\n \n\n \n\n
\n'),e.put("partials/desktop/dialog.html",'\n\n
\n
\n \n \n
\n\n
\n \n
\n\n
\n\n
\n \n \n \n \n
\n\n
\n
\n \n
\n
\n \n {{((dialogMessage.out || dialogMessage.peerID < 0) && (dialogMessage.message.length || dialogMessage.media && dialogMessage.media._ != \'messageMediaEmpty\')) ? \':\' : \'\'}}\n \n\n \n \n \n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n \n\n \n \n \n \n \n \n \n\n \n
\n
\n\n
\n
\n'),e.put("partials/desktop/edit_contact_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/desktop/error_modal.html",'
\n\n \n\n \n\n
\n'),e.put("partials/desktop/full_gif.html",'\n\n
\n\n \n \n\n
\n\n
\n\n
\n
\n
\n
\n
\n\n
\n
GIF
\n
\n
\n\n
\n\n
'),e.put("partials/desktop/full_photo.html",'
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n \n \n \n
\n
\n
\n
\n
\n
'),e.put("partials/desktop/full_video.html",'
\n
\n
\n
\n
\n
\n
\n
\n
\n \n
\n
\n \n \n
\n
\n
\n
\n
\n
'),e.put("partials/desktop/head.html",'
\n \n
\n'),e.put("partials/desktop/im.html",'
\n\n
\n\n
\n\n
\n
\n \n \n\n
\n
\n \n \n
\n
\n
\n\n
\n
\n
\n\n
\n

\n

\n \n \n
\n\n
\n \n \n
\n\n
\n
\n \n
\n\n \n\n
\n
\n
\n
\n\n
\n\n
\n
\n

\n

\n \n
\n
\n
\n\n
\n \n
\n\n
\n
\n\n
\n\n
\n
\n\n \n \n\n \n \n \n \n \n \n\n
\n

\n

\n

\n

\n\n

\n
\n \n \n
\n
\n \n \n \n \n \n
\n

\n
\n\n
\n\n
\n\n
\n\n
\n\n
\n\n
\n
\n
\n \n \n \n \n
\n\n
\n
\n
\n
\n
\n\n
\n\n
\n\n
\n \n \n \n \n \n {{historyState.typing.length - 2}}\n \n
\n
\n\n
\n\n
\n\n
\n\n
\n\n
\n
\n \n \n \n \n \n
\n \n \n \n
\n
\n\n
\n\n
\n\n
\n
\n \n \n
\n
\n \n
\n
\n\n
\n
\n \n
\n\n
\n \n \n
\n\n
\n \n \n
\n\n
\n \n
\n\n \n
\n
\n\n
\n\n
\n\n
\n\n
\n
\n\n
\n\n
\n\n
\n\n
'),e.put("partials/desktop/import_contact_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/desktop/lang_footer.html",''),e.put("partials/desktop/login.html",'
\n\n\n\n\n'),e.put("partials/desktop/message.html",'
\n\n\n
\n\n
\n
\n \n \n
\n\n \n \n \n\n
\n\n
\n
\n \n
\n\n \n \n \n\n \n\n \n\n
\n \n \n
\n\n
\n\n \n\n
\n \n
\n \n
\n
\n\n
\n\n
\n
\n
\n
\n
\n
\n
\n\n
\n\n
\n
\n\n
\n
\n\n
\n\n'),e.put("partials/desktop/message_attach_audio.html",'
\n
\n
\n'),e.put("partials/desktop/message_attach_contact.html",'
\n \n
\n \n \n
\n
\n
'),e.put("partials/desktop/message_attach_document.html",'
\n\n
\n\n
\n
\n
\n\n
\n\n \n \n
\n \n
\n
\n\n
\n
\n \n \n \n
\n
\n \n \n
\n
\n \n
\n
\n
\n
\n
\n
\n
\n\n
\n
\n'),e.put("partials/desktop/message_attach_map.html",'\n \n'),e.put("partials/desktop/message_attach_pending.html",'
\n \n
\n
\n \n \n
\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n'),e.put("partials/desktop/message_attach_photo.html",'\n \n'),e.put("partials/desktop/message_attach_video.html",'
\n \n \n \n \n \n\n
\n
\n \n \n \n
\n
\n \n \n
\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n'),e.put("partials/desktop/message_service.html",'\n \n \n \n «»\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n \n\n'),e.put("partials/desktop/peer_select.html",'
\n\n \n\n \n\n
\n'),e.put("partials/desktop/photo_modal.html",'
\n\n \n\n
\n'),e.put("partials/desktop/profile_edit_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/desktop/settings_modal.html",'\n'),e.put("partials/desktop/user_modal.html",'
\n\n \n\n \n\n
\n'),e.put("partials/desktop/username_edit_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/desktop/video_modal.html",'
\n\n \n\n
\n'),e.put("partials/desktop/welcome.html",'
\n\n
\n\n
\n \n\n

\n\n
\n

\n

\n
\n
\n \n
\n
\n\n \n\n\n\n
\n'),e.put("partials/mobile/audio_player.html",'
\n \n
\n \n \n \n \n
\n \n \n \n
\n
\n
\n \n \n
\n
\n
\n
\n
\n
\n
\n
\n
\n \n
'),e.put("partials/mobile/changelog_modal.html",'
\n\n \n\n \n\n
\n'),e.put("partials/mobile/chat_create_modal.html",'
\n\n
\n \n
\n\n \n\n
'),e.put("partials/mobile/chat_edit_modal.html",'
\n\n
\n \n
\n\n \n\n
'),e.put("partials/mobile/chat_modal.html",'
\n\n
\n \n
\n\n \n\n
\n'),e.put("partials/mobile/confirm_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/mobile/contacts_modal.html",'
\n\n
\n \n
\n\n \n\n
\n'),e.put("partials/mobile/country_select_modal.html",'
\n\n
\n \n
\n\n \n\n
\n'),e.put("partials/mobile/dialog.html",'\n\n
\n
\n \n \n
\n\n
\n \n
\n\n
\n\n
\n \n \n \n \n
\n\n
\n
\n \n
\n
\n \n {{((dialogMessage.out || dialogMessage.peerID < 0) && (dialogMessage.message.length || dialogMessage.media && dialogMessage.media._ != \'messageMediaEmpty\')) ? \':\' : \'\'}}\n \n\n \n \n \n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n \n\n \n \n \n \n \n \n \n\n \n
\n
\n\n
\n
\n'),e.put("partials/mobile/edit_contact_modal.html",'
\n\n
\n \n
\n\n \n\n
'),e.put("partials/mobile/error_modal.html",'
\n\n \n\n \n\n
\n'),e.put("partials/mobile/full_gif.html",'\n\n
\n\n \n \n\n
\n\n
\n\n
\n
\n
\n
\n
\n\n
\n
GIF
\n
\n
\n\n
\n\n
'),e.put("partials/mobile/full_photo.html",'
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n \n \n \n
\n
\n
\n
\n
\n
'),e.put("partials/mobile/full_video.html",'
\n
\n
\n
\n
\n
\n
\n
\n
\n \n
\n
\n \n \n
\n
\n
\n
\n
\n
'),e.put("partials/mobile/head.html",'
\n \n
\n'),e.put("partials/mobile/im.html",'
\n\n
\n\n
\n\n
\n
\n \n\n
\n
\n \n \n
\n
\n
\n\n
\n\n
\n

\n

\n \n \n
\n\n
\n \n \n
\n\n
\n
\n \n
\n\n \n\n
\n
\n\n
\n
\n \n
\n\n
\n
\n\n
\n\n
\n
\n
\n \n \n \n \n
\n\n
\n
\n
\n
\n
\n\n
\n\n
\n\n
\n\n
\n\n
\n
\n \n \n
\n
\n\n
\n\n
\n\n
\n
\n\n
\n
\n \n
\n\n
\n \n \n
\n\n
\n \n
\n\n \n
\n
\n\n
\n\n
\n\n
\n\n
\n
\n\n
\n\n
\n\n
'),e.put("partials/mobile/import_contact_modal.html",'
\n\n
\n \n
\n\n \n\n \n\n
'),e.put("partials/mobile/login.html",'
\n\n\n\n\n'),e.put("partials/mobile/message.html",'
\n\n\n
\n\n
\n
\n \n \n
\n\n \n \n \n\n
\n\n
\n \n\n \n\n
\n \n \n
\n\n
\n\n \n\n
\n \n \n
\n\n
\n\n
\n
\n
\n
\n
\n
\n
\n\n
\n\n
\n
\n\n
\n
\n\n
\n\n'),e.put("partials/mobile/message_attach_audio.html",'
\n
\n
\n'),e.put("partials/mobile/message_attach_contact.html",'
\n \n
\n \n \n
\n
\n
'),e.put("partials/mobile/message_attach_document.html",'
\n\n
\n\n
\n
\n
\n\n
\n\n \n \n
\n \n
\n
\n\n
\n
\n \n \n \n
\n
\n \n \n
\n
\n \n
\n
\n
\n
\n
\n
\n
\n\n
\n
\n'),e.put("partials/mobile/message_attach_map.html",'\n \n'),e.put("partials/mobile/message_attach_pending.html",'
\n \n
\n
\n \n \n
\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n'),e.put("partials/mobile/message_attach_photo.html",'\n \n'),e.put("partials/mobile/message_attach_video.html",''),e.put("partials/mobile/message_service.html",'\n \n \n \n «»\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n \n\n'),e.put("partials/mobile/peer_select.html",'
\n\n
\n \n
\n\n \n\n
\n'),e.put("partials/mobile/phonebook_modal.html",'
\n\n
\n \n
\n\n \n\n \n\n
\n'),e.put("partials/mobile/photo_modal.html",'
\n\n \n\n
\n'),e.put("partials/mobile/profile_edit_modal.html",'
\n\n
\n \n
\n\n \n\n
'),e.put("partials/mobile/settings_modal.html",'\n'),e.put("partials/mobile/user_modal.html",'
\n\n
\n \n
\n\n \n\n
\n'),e.put("partials/mobile/username_edit_modal.html",'
\n\n
\n \n
\n\n \n\n
'),e.put("partials/mobile/video_modal.html",'
\n\n \n\n
\n'),e.put("partials/mobile/welcome.html",'
\n\n
\n\n
\n \n\n

\n\n
\n

\n

\n
\n
\n \n
\n
\n\n \n\n\n\n
\n') +if(l.to_id.chat_id&&!i.hasChat(l.to_id.chat_id))return console.log("Chat not found",l.to_id.chat_id,"getDiff"),s(),!1}angular.forEach(e.updates,function(e){d(e)});break;default:console.warn(dT(),"Unknown update message",e)}return r(),h&&f.seq>=h.seqAwaiting&&(console.log(dT(),"cancel pending getDiff",h.seqAwaiting),clearTimeout(h.timeout),h=!1),!0}function l(){m=!0,h&&(clearTimeout(h.timeout),h=!1),o.invokeApi("updates.getDifference",{pts:f.pts,date:f.date,qts:0}).then(function(e){if("updates.differenceEmpty"==e._)return console.log(dT(),"apply empty diff",e.seq),f.date=e.date,f.seq=e.seq,m=!1,r(),!1;n.saveApiUsers(e.users),i.saveApiChats(e.chats),angular.forEach(e.other_updates,function(e){d(e)}),angular.forEach(e.new_messages,function(e){d({_:"updateNewMessage",message:e,pts:f.pts})});var t=e.intermediate_state||e.state;f.seq=t.seq,f.pts=t.pts,f.date=t.date,console.log(dT(),"apply diff",f.seq,f.pts),"updates.differenceSlice"==e._?l(!0):m=!1})}function d(t){t.pts&&(f.pts=t.pts),e.$broadcast("apiUpdate",t)}function u(e,t){return(t=t||e)?m?(console.log(dT(),"Seq decline",t),!1):t!=f.seq+1?(t>f.seq&&(console.warn(dT(),"Seq hole",t,h&&h.seqAwaiting),h||(h={seqAwaiting:t,timeout:setTimeout(function(){l()},5e3)})),!1):(f.seq=e,!0):!0}function p(){t.setUpdatesProcessor(c),o.invokeApi("updates.getState",{noErrorBox:!0}).then(function(e){f.seq=e.seq,f.pts=e.pts,f.date=e.date,m=!1})}var m=!0,h=!1,f={},g={};return{processUpdateMessage:c,attach:p}}]).service("RichTextProcessor",["$sce","$sanitize",function(e,t){function n(e){return e.replace(/&/g,"&").replace(/([^\#-~| |!])/g,function(e){return"&#"+e.charCodeAt(0)+";"}).replace(//g,">")}function i(e){for(var t,n,i,a,o=0;o-1)return n=Math.floor(t/a),i=t%a,{category:o,row:n,column:i};return console.error("emoji not found in spritesheet",e),null}function a(a,o){if(!a||!a.length)return"";o=o||{},a=a.replace(/\ufe0f/g,"",a);for(var s,u,p,m=a,g=[],_=!1;s=m.match(h);)g.push(n(m.substr(0,s.index))),s[1]?o.noLinks?g.push(n(s[0])):s[3]?g.push('',n(s[3]+s[4]),""):g.push('',n(s[2]+"://"+s[4]),""):s[5]?g.push(o.noLinebreaks?" ":"
"):s[6]?(r=c[s[6]])&&(p=i(r))?(u=n(l[r][1][0]),_=!0,g.push('',":",u,":")):g.push(n(s[6])):s[8]&&(o.noLinks?g.push(s[7],n(s[8])):g.push(s[7],'',n(s[8]),"")),m=m.substr(s.index+s[0].length);if(g.push(n(m)),a=t(g.join("")),_&&(a=a.replace(//g,'')),!o.noLinks){var y=a.match(f),v=y&&y[1];if(v){var b=Config.Modes.chrome_packed?"webview":"iframe";a=a+'
<'+b+' type="text/html" frameborder="0" src="http://www.youtube.com/embed/'+v+'?autoplay=0&controls=2">
"}}return e.trustAs("html",a)}function o(e,t){if(u)return e;if(!e||!e.length)return"";t=t||{},e=e.replace(/\ufe0f/g,"",e);for(var n,i,a=e,e=[];n=a.match(h);)e.push(a.substr(0,n.index)),e.push(n[6]?(r=c[n[6]])&&(i=l[r][1][0])?":"+i+":":n[0]:n[0]),a=a.substr(n.index+n[0].length);return e.push(a),e.join("")}var r,s=[],c={},l=Config.Emoji,d=18,u=-1!=navigator.userAgent.search(/OS X|iPhone|iPad|iOS|Android/i);for(r in l)s.push(l[r][0]),c[l[r][0]]=r;var p="a-z\\u00c0-\\u00d6\\u00d8-\\u00f6\\u00f8-\\u00ff\\u0100-\\u024f\\u0253\\u0254\\u0256\\u0257\\u0259\\u025b\\u0263\\u0268\\u026f\\u0272\\u0289\\u028b\\u02bb\\u0300-\\u036f\\u1e00-\\u1eff\\u0400-\\u04ff\\u0500-\\u0527\\u2de0-\\u2dff\\ua640-\\ua69f\\u0591-\\u05bf\\u05c1-\\u05c2\\u05c4-\\u05c5\\u05c7\\u05d0-\\u05ea\\u05f0-\\u05f4\\ufb1d-\\ufb28\\ufb2a-\\ufb36\\ufb38-\\ufb3c\\ufb3e\\ufb40-\\ufb41\\ufb43-\\ufb44\\ufb46-\\ufb4f\\u0610-\\u061a\\u0620-\\u065f\\u066e-\\u06d3\\u06d5-\\u06dc\\u06de-\\u06e8\\u06ea-\\u06ef\\u06fa-\\u06fc\\u06ff\\u0750-\\u077f\\u08a0\\u08a2-\\u08ac\\u08e4-\\u08fe\\ufb50-\\ufbb1\\ufbd3-\\ufd3d\\ufd50-\\ufd8f\\ufd92-\\ufdc7\\ufdf0-\\ufdfb\\ufe70-\\ufe74\\ufe76-\\ufefc\\u200c\\u0e01-\\u0e3a\\u0e40-\\u0e4e\\u1100-\\u11ff\\u3130-\\u3185\\uA960-\\uA97F\\uAC00-\\uD7AF\\uD7B0-\\uD7FF\\u3003\\u3005\\u303b\\uff21-\\uff3a\\uff41-\\uff5a\\uff66-\\uff9f\\uffa1-\\uffdc",m="0-9._"+p,h=new RegExp("((?:(ftp|https?)://|(?:mailto:)?([A-Za-z0-9._%+-]+@))(\\S*\\.\\S*[^\\s.;,(){}<>\"']))|(\\n)|("+s.join("|")+")|(^|\\s)(#["+m+"]{3,20})","i"),f=/(?:https?:\/\/)?(?:www\.)?youtu(?:|.be|be.com|.b)(?:\/v\/|\/watch\\?v=|e\/|(?:\/\??#)?\/watch(?:.+)v=)(.{11})(?:\&[^\s]*)?/;return{wrapRichText:a,wrapPlainText:o}}]).service("IdleManager",["$rootScope","$window","$timeout",function(e,t,n){function i(){r||(r=!0,$(t).on("blur focus keydown mousedown touchstart",a),setTimeout(function(){a({type:"blur"})},0))}function a(i){"mousemove"==i.type&&$(t).off("mousemove",a);var r="blur"==i.type||"timeout"==i.type?!0:!1;n.cancel(o),r||(o=n(function(){a({type:"timeout"})},3e4)),e.idle.isIDLE!=r&&(e.$apply(function(){e.idle.isIDLE=r}),r&&"timeout"==i.type&&$(t).on("mousemove",a))}e.idle={isIDLE:!1};var o,r=!1;return{start:i}}]).service("StatusManager",["$timeout","$rootScope","MtpApiManager","IdleManager",function(e,t,n){function i(){c||(c=!0,t.$watch("idle.isIDLE",o),t.$watch("offline",o))}function a(e){var i=tsNow();if(!(e&&!s||!e&&5e4>i-s||t.offline))return s=e?0:i,n.invokeApi("account.updateStatus",{offline:e},{noErrorBox:!0})}function o(){r&&e.cancel(r),t.idle.isIDLE?r=e(function(){a(!0)},5e3):(a(!1),r=e(o,6e4))}var r,s=0,c=!1;return{start:i}}]).service("NotificationsManager",["$rootScope","$window","$timeout","$interval","$q","_","MtpApiManager","AppPeersManager","IdleManager","Storage","AppRuntimeManager",function(e,t,n,i,a,o,r,s,c,l,d){function u(e){return void 0!==E[e]?E[e]:E[e]=r.invokeApi("account.getNotifySettings",{peer:{_:"inputNotifyPeer",peer:s.getInputPeerByID(e)}})}function p(e,t){E[e]=a.when(t)}function m(e,t){p(e,t);var n=angular.copy(t);return n._="inputPeerNotifySettings",r.invokeApi("account.updateNotifySettings",{peer:{_:"inputNotifyPeer",peer:s.getInputPeerByID(e)},settings:n})}function h(e){return u(e).then(function(e){return"peerNotifySettings"==e._&&1e3*e.mute_until>tsNow()})}function f(){if(w(),!S)return!1;"Notification"in window&&"granted"!==Notification.permission&&"denied"!==Notification.permission&&$(t).on("click",g);try{$(t).on("beforeunload",b)}catch(e){}}function g(){Notification.requestPermission(),$(t).off("click",g)}function _(e){return Config.Navigator.ffos?e.image="https://raw.githubusercontent.com/zhukov/webogram/master/app/img/icons/icon60.png":e.image||(e.image="img/icons/icon60.png"),A++,!S||"Notification"in window&&"granted"!==Notification.permission?!1:(l.get("notify_nosound","notify_volume").then(function(e){(!e[0]&&e[1]===!1||e[1]>0)&&y(e[1]||.5)}),void l.get("notify_nodesktop","notify_novibrate").then(function(t){if(t[0]){if(T&&!t[1])return void navigator.vibrate([200,100,200])}else{var n,i=++x,a=e.key||"k"+i;if("Notification"in window)n=new Notification(e.title,{icon:e.image||"",body:e.message||"",tag:e.tag||""});else{if(!("mozNotification"in navigator))return;n=navigator.mozNotification.createNotification(e.title,e.message||"",e.image||"")}n.onclick=function(){n.close(),d.focus(),b(),e.onclick&&e.onclick()},n.onclose=function(){delete M[a],b()},n.show&&n.show(),M[a]=n}}))}function y(e){var t="img/sound_a.wav",n=$("#notify_sound").html('');n.find("audio")[0].volume=e}function v(e){var t=M[e];if(t){A>0&&A--;try{t.close&&t.close()}catch(n){}delete A[e]}}function b(){angular.forEach(M,function(e){try{e.close&&e.close()}catch(t){}}),M={},A=0}function w(){if(L)return!1;if(navigator.push&&Config.Navigator.ffos&&Config.Modes.packed){var e=navigator.push.register();e.onsuccess=function(){clearTimeout(O),console.log(dT(),"Push registered",e.result),L=e.result,r.invokeApi("account.registerDevice",{token_type:4,token:L,device_model:navigator.userAgent||"Unknown UserAgent",system_version:navigator.platform||"Unknown Platform",app_version:Config.App.version,app_sandbox:!1,lang_code:navigator.language||"en"})},e.onerror=function(e){console.error("Push register error",e,e.toString()),O=setTimeout(w,U),U=Math.min(3e4,1.5*U)}}}function k(){return T}navigator.vibrate=navigator.vibrate||navigator.mozVibrate||navigator.webkitVibrate;var C,S="Notification"in window||"mozNotification"in navigator,M={},x=0,A=0,T=!!navigator.vibrate,E={},I=$('link[rel="icon"]:first'),D=$(''),P=o.pluralize("page_title_pluralize_notifications"),N=document.title;e.$watch("idle.isIDLE",function(e){i.cancel(C),e?(N=document.title,C=i(function(){var e=tsNow();if(!A||e%2e3>1e3){document.title=N;var t=$('link[rel="icon"]:first');-1!=t.attr("href").indexOf("favicon_unread")&&t.replaceWith(I)}else document.title=P(A),$('link[rel="icon"]:first').replaceWith(D)},1e3)):(document.title=N,$('link[rel="icon"]:first').replaceWith(I),b())}),e.$on("apiUpdate",function(e,t){switch(t._){case"updateNotifySettings":if("notifyPeer"==t.peer._){var n=s.getPeerID(t.peer.peer);p(n,t.notify_settings)}}});var L=!1;return window.navigator.mozSetMessageHandler&&(window.navigator.mozSetMessageHandler("push",function(t){console.log(dT(),"received push",t),e.$broadcast("push_received")}),window.navigator.mozSetMessageHandler("push-register",function(e){console.log(dT(),"received push",e),L=!1,w()})),{start:f,notify:_,cancel:v,clear:b,getPeerSettings:u,getPeerMuted:h,savePeerSettings:p,updatePeerSettings:m,getVibrateSupport:k,testSound:y};var U,O}]).service("ErrorService",["$rootScope","$modal","$window",function(e,t,n){function i(n,i){if(r>=2)return console.log("Skip error box, too many open",r,n,i),!1;i=i||{};var a=e.$new();angular.extend(a,n),r++;var o=t.open({templateUrl:templateUrl("error_modal"),scope:a,windowClass:i.windowClass||"error_modal_window"});return o.result["finally"](function(){r--}),o}function a(e,t){return i({title:e,description:t})}function o(n,i){i=i||{};var a=e.$new();angular.extend(a,n);var o=t.open({templateUrl:templateUrl("confirm_modal"),scope:a,windowClass:i.windowClass||"confirm_modal_window"});return o.result}var r=0;return n.safeConfirm=function(e,t){"string"==typeof e&&(e={message:e}),o(e).then(function(e){t(e||!0)},function(){t(!1)})},{show:i,alert:a,confirm:o}}]).service("PeersSelectService",["$rootScope","$modal",function(e,t){function n(n){var i=e.$new();return n&&angular.extend(i,n),t.open({templateUrl:templateUrl("peer_select"),controller:"PeerSelectController",scope:i,windowClass:"peer_select_window mobile_modal"}).result}return{selectPeer:n}}]).service("ContactsSelectService",["$rootScope","$modal",function(e,t){function n(n,i){i=i||{};var a=e.$new();return a.multiSelect=n,angular.extend(a,i),!a.action&&n&&(a.action="select"),t.open({templateUrl:templateUrl("contacts_modal"),controller:"ContactsModalController",scope:a,windowClass:"contacts_modal_window mobile_modal"}).result}return{selectContacts:function(e){return n(!0,e)},selectContact:function(e){return n(!1,e)}}}]).service("ChangelogNotifyService",["Storage","$rootScope","$http","$modal",function(e,t,n,i){function a(e,t){"string"!=typeof e&&(e=""),"string"!=typeof t&&(t=""),e=e.replace(/^\s+|\s+$/g,"").split("."),t=t.replace(/^\s+|\s+$/g,"").split(".");var n,i=Math.max(e.length,t.length);for(n=0;i>n;n++)if(e[n]!=t[n])return e[n]>t[n]?1:-1;return 0}function o(){e.get("last_version").then(function(t){t!=Config.App.version&&(t&&r(t),e.set({last_version:Config.App.version}))})}function r(e){var n=t.$new();n.lastVersion=e,n.canShowVersion=function(t){return n.lastVersion===!1||void 0===n.lastVersion?!0:a(t,e)>=0},i.open({controller:"ChangelogModalController",templateUrl:templateUrl("changelog_modal"),scope:n,windowClass:"changelog_modal_window mobile_modal"})}return{checkUpdate:o,showChangelog:r}}]),angular.module("myApp.controllers",["myApp.i18n"]).controller("AppWelcomeController",["$scope","$location","MtpApiManager","ErrorService","ChangelogNotifyService",function(e,t,n,i,a){n.getUserID().then(function(n){n?t.url("/im"):e.showWelcome=!0}),a.checkUpdate()}]).controller("AppLoginController",["$scope","$rootScope","$location","$timeout","$modal","$modalStack","MtpApiManager","ErrorService","NotificationsManager","ChangelogNotifyService","IdleManager","_",function(e,t,n,i,a,o,r,s,c,l,d,u){function p(){var t=(navigator.language||"").toLowerCase(),n=Config.LangCountries[t],i=!Config.Navigator.mobile;if(m(-1==["en","en-us","en-uk"].indexOf(t)?void 0!==n?n:t.indexOf("-")>0?t.split("-")[1].toUpperCase():"US":"US"),i){var a=e.credentials.phone_country;r.invokeApi("help.getNearestDc",{},{dcID:2,createNetworker:!0}).then(function(t){a==e.credentials.phone_country&&m(t.country),t.nearest_dc!=t.this_dc&&r.getNetworker(t.nearest_dc,{createNetworker:!0})})}}function m(e){var t,n;for(t=0;to&&!a.indexOf(i)&&(o=i.length,r=u(Config.CountryCodes[t][1]+"_raw"));e.credentials.phone_full=a,e.credentials.phone_country_name=r||u("login_controller_unknown_country_raw")}function g(e){r.setUserAuth(y.dcID,{expires:e.expires,id:e.user.id}),i.cancel(b),n.url("/im")}function _(){i.cancel(b),e.credentials.viaApp||(--e.callPending.remaining?b=i(_,1e3):(e.callPending.success=!1,r.invokeApi("auth.sendCall",{phone_number:e.credentials.phone_full,phone_code_hash:e.credentials.phone_code_hash},y).then(function(){e.callPending.success=!0})))}o.dismissAll(),d.start(),r.getUserID().then(function(e){return e?void n.url("/im"):void 0});var y={dcID:2,createNetworker:!0},v=!1;e.credentials={phone_country:"",phone_country_name:"",phone_number:"",phone_full:""},e.progress={},e.callPending={},e.chooseCountry=function(){var e=a.open({templateUrl:templateUrl("country_select_modal"),controller:"CountrySelectModalController",windowClass:"countries_modal_window mobile_modal"});e.result.then(h)},e.$watch("credentials.phone_country",f),e.$watch("credentials.phone_number",f),p();var b;e.sendCode=function(){i.cancel(b),s.confirm({type:"LOGIN_PHONE_CORRECT",country_code:e.credentials.phone_country,phone_number:e.credentials.phone_number}).then(function(){e.progress.enabled=!0,onContentLoaded(function(){e.$broadcast("ui_height")});var n=tsNow();r.invokeApi("auth.sendCode",{phone_number:e.credentials.phone_full,sms_type:5,api_id:Config.App.id,api_hash:Config.App.hash},y).then(function(t){e.progress.enabled=!1,e.credentials.phone_code_hash=t.phone_code_hash,e.credentials.phone_occupied=t.phone_registered,e.credentials.viaApp="auth.sentAppCode"==t._,e.callPending.remaining=t.send_call_timeout||60,e.error={},_(),onContentLoaded(function(){e.$broadcast("ui_height")})},function(t){switch(e.progress.enabled=!1,console.log("sendCode error",t),t.type){case"NETWORK_BAD_REQUEST":"https:"==location.protocol&&(s.confirm({type:"HTTPS_MIXED_FAIL"}).then(function(){location=location.toString().replace(/^https:/,"http:")}),t.handled=!0);break;case"PHONE_NUMBER_INVALID":e.error={field:"phone"},t.handled=!0}})["finally"](function(){(t.idle.isIDLE||tsNow()-n>6e4)&&c.notify({title:"Telegram",message:"Your authorization key was successfully generated! Open the app to log in.",tag:"auth_key"})})})},e.sendSms=function(){e.credentials.viaApp&&(delete e.credentials.viaApp,r.invokeApi("auth.sendSms",{phone_number:e.credentials.phone_full,phone_code_hash:e.credentials.phone_code_hash},y).then(_))},e.editPhone=function(){i.cancel(b),delete e.credentials.phone_code_hash,delete e.credentials.phone_unoccupied,delete e.credentials.phone_code_valid,delete e.credentials.viaApp,delete e.callPending.remaining,delete e.callPending.success},e.logIn=function(t){var n="auth.signIn",i={phone_number:e.credentials.phone_full,phone_code_hash:e.credentials.phone_code_hash,phone_code:e.credentials.phone_code};t&&(n="auth.signUp",angular.extend(i,{first_name:e.credentials.first_name,last_name:e.credentials.last_name})),e.progress.enabled=!0,r.invokeApi(n,i,y).then(g,function(t){if(e.progress.enabled=!1,400==t.code&&"PHONE_NUMBER_UNOCCUPIED"==t.type)return t.handled=!0,e.credentials.phone_code_valid=!0,void(e.credentials.phone_unoccupied=!0);if(400==t.code&&"PHONE_NUMBER_OCCUPIED"==t.type)return t.handled=!0,e.logIn(!1);switch(t.type){case"FIRSTNAME_INVALID":e.error={field:"first_name"},t.handled=!0;break;case"LASTNAME_INVALID":e.error={field:"last_name"},t.handled=!0;break;case"PHONE_CODE_INVALID":e.error={field:"phone_code"},delete e.credentials.phone_code_valid,t.handled=!0}})},l.checkUpdate()}]).controller("AppIMController",["$scope","$location","$routeParams","$modal","$rootScope","$modalStack","MtpApiManager","AppUsersManager","ContactsSelectService","ChangelogNotifyService","ErrorService","AppRuntimeManager",function(e,t,n,i,a,o,r,s,c,l,d,u){function p(){if(n.q){if(n.q!==m&&(e.search.query=m=n.q,e.search.messages=!0,void 0!==e.curDialog))return!1}else m=!1;e.curDialog={peer:n.p||!1,messageID:n.m||!1}}e.$on("$routeUpdate",p),e.$on("history_focus",function(n,i){o.dismissAll(),i.peerString==e.curDialog.peer&&i.messageID==e.curDialog.messageID?e.$broadcast(i.messageID?"ui_history_change_scroll":"ui_history_focus"):t.url("/im?p="+i.peerString+(i.messageID?"&m="+i.messageID:""))}),e.isLoggedIn=!0,e.isEmpty={},e.search={},e.historyFilter={mediaType:!1},e.historyPeer={},e.historyState={selectActions:!1,typing:[]},e.openSettings=function(){i.open({templateUrl:templateUrl("settings_modal"),controller:"SettingsModalController",windowClass:"settings_modal_window mobile_modal"})},e.openContacts=function(){c.selectContact().then(function(t){e.dialogSelect(s.getUserString(t))})},e.openGroup=function(){c.selectContacts({action:"new_group"}).then(function(t){if(1==t.length)e.dialogSelect(s.getUserString(t[0]));else if(t.length>1){var n=a.$new();n.userIDs=t,i.open({templateUrl:templateUrl("chat_create_modal"),controller:"ChatCreateModalController",scope:n,windowClass:"group_edit_modal_window mobile_modal"})}})},e.importContact=function(){s.openImportContact().then(function(e){e&&a.$broadcast("history_focus",{peerString:s.getUserString(e)})})},e.dialogSelect=function(e,t){var n={peerString:e};t&&(n.messageID=t),a.$broadcast("history_focus",n)},e.logOut=function(){d.confirm({type:"LOGOUT"}).then(function(){r.logOut().then(function(){location.hash="/login",u.reload()})})},e.showPeerInfo=function(){e.curDialog.peerID>0?a.openUser(e.curDialog.peerID):e.curDialog.peerID<0&&a.openChat(-e.curDialog.peerID)},e.toggleEdit=function(){e.$broadcast("history_edit_toggle")},e.selectedFlush=function(){e.$broadcast("history_edit_flush")},e.toggleMedia=function(t){e.$broadcast("history_media_toggle",t)},e.returnToRecent=function(){e.$broadcast("history_return_recent")},e.toggleSearch=function(){e.$broadcast("dialogs_search_toggle")},p();var m=!1;l.checkUpdate()}]).controller("AppImDialogsController",["$scope","$location","$q","$timeout","$routeParams","MtpApiManager","AppUsersManager","AppChatsManager","AppMessagesManager","AppPeersManager","PhonebookContactsService","ErrorService",function(e,t,n,i,a,o,r,s,c,l,d,u){function p(a){var r,s=e.search.messages&&e.search.query.length>0,l=++b;return i.cancel(k),s?(k=a?n.when():i(angular.noop,500),r=k.then(function(){return c.getSearch({_:"inputPeerEmpty"},e.search.query,{_:"inputMessagesFilterEmpty"},y)})):r=c.getDialogs(e.search.query,y),r.then(function(e){if(l!=b)return n.reject();if(s){var t=[];angular.forEach(e.history,function(e){var n=c.getMessage(e),i=c.getMessagePeer(n);t.push({peerID:i,top_message:e,unread_count:-1})}),e={count:e.count,dialogs:t}}return e},function(e){return"NETWORK_BAD_REQUEST"==e.type&&"https:"==location.protocol&&(u.confirm({type:"HTTPS_MIXED_FAIL"}).then(function(){location=location.toString().replace(/^https:/,"http:")}),e.handled=!0),401==e.code&&(o.logOut()["finally"](function(){t.url("/login")}),e.handled=!0),n.reject()})}function m(t){_=0,y=0,v=!1,w={},g=!1,p(t).then(function(t){e.dialogs=[],e.contacts=[],e.foundUsers=[],t.dialogs.length&&(_+=t.dialogs.length,y=t.dialogs[t.dialogs.length-1].top_message,v=null===t.count||_=5&&i(function(){t==b&&o.invokeApi("contacts.search",{q:e.search.query,limit:10}).then(function(n){console.log(e.search.query,n),r.saveApiUsers(n.users),t==b&&(e.foundUsers=[],angular.forEach(n.results,function(t){var n=t.user_id;void 0===w[n]&&e.foundUsers.push({userID:n,user:r.getUser(n),peerString:r.getUserString(n)})}))},function(e){400==e.code&&(e.handled=!0)})},500)}function f(){return!g||v&&_?v||e.search.messages||!e.search.query&&e.dialogs.length?void p().then(function(t){t.dialogs.length&&(_+=t.dialogs.length,y=t.dialogs[t.dialogs.length-1].top_message,v=null===t.count||_-1?(i=e.peerHistories[o],o&&(e.peerHistories.splice(o,1),e.peerHistories.unshift(i)),i):(i={peerID:t,messages:[]},e.peerHistories.unshift(i),a=e.peerHistories.length-r,a>0&&e.peerHistories.splice(r-1,a),i)}function g(t){var n;for(n=0;n=0;o--)r=i.history[o],r>O&&P.messages.push(s.wrapForHistory(r));i.history.length?(O=i.history.length>=a?i.history[0]:0,s.regroupWrappedHistory(P.messages,-a)&&e.$broadcast("messages_regroup"),delete e.state.empty,e.$broadcast("ui_history_append")):O=0,e.skippedHistory=L=O>0,j&&b()}})}}function b(){if(N){if(V)return void(j=!0);j=!1,H=!0;var t=R,n=q,i=e.historyFilter.mediaType&&{_:B[e.historyFilter.mediaType]},a=Config.Mobile?20:0,o=i?s.getSearch(e.curDialog.inputPeer,"",i,U,a):s.getHistory(e.curDialog.inputPeer,U,a);o.then(function(i){H=!1,t==R&&n==q&&(angular.forEach(i.history,function(e){P.messages.unshift(s.wrapForHistory(e))}),N=null===i.count||i.history.length&&P.messages.length=i-1?t.history[0]:0,U=t.history[t.history.length-1],e.skippedHistory=L=O>0,N=null===t.count||n&&nt;for(o=0;o0){var t=[];angular.forEach(e.selectedMsgs,function(e,n){t.push(n)}),s.deleteMessages(t).then(function(){S()})}}function A(){if(e.selectedCount>0){var t=[];angular.forEach(e.selectedMsgs,function(e,n){t.push(n)}),d.selectPeer({confirm_type:"FORWARD_PEER"}).then(function(e){var n=c.getPeerID(e);s.forwardMessages(n,t).then(function(){S(),i.$broadcast("history_focus",{peerString:e})})})}}function T(){e.historyState.selectActions?S():(e.historyState.selectActions=!0,e.$broadcast("ui_panel_update"))}function E(t){e.historyFilter.mediaType=t||!1,P.messages=[],e.state.empty=!0,w()}function I(){e.historyFilter.mediaType?E():e.curDialog.messageID?i.$broadcast("history_focus",{peerString:e.curDialog.peer}):w(!0)}e.$watch("curDialog",h),l.attach(),u.start(),p.start(),e.peerHistories=[],e.skippedHistory=!1,e.selectedMsgs={},e.selectedCount=0,e.historyState.selectActions=!1,e.missedCount=0,e.state={},e.toggleMessage=C,e.selectedDelete=x,e.selectedForward=A,e.selectedCancel=S,e.selectedFlush=M,e.toggleEdit=T,e.toggleMedia=E,e.returnToRecent=I,e.$on("history_edit_toggle",T),e.$on("history_edit_flush",M),e.$on("history_media_toggle",function(e,t){E(t)}),e.$on("history_return_recent",I);var D,P=!1,N=!1,L=!1,U=0,O=0,F=!1,B={photos:"inputMessagesFilterPhotos",video:"inputMessagesFilterVideo",documents:"inputMessagesFilterDocument",audio:"inputMessagesFilterAudio"},R=0,q=0,H=!1,j=!1,z=0,V=!1,W=!1;e.$on("history_update",angular.noop);var G={};e.$on("history_append",function(t,a){var o=g(a.peerID);if(o){var r=a.peerID==e.curDialog.peerID;if(r){if(e.historyFilter.mediaType||e.skippedHistory)return void(a.my?I():e.missedCount++);delete e.state.empty}o.messages.push(s.wrapForHistory(a.messageID)),s.regroupWrappedHistory(o.messages,-3)&&e.$broadcast("messages_regroup"),r&&(e.historyState.typing.splice(0,e.historyState.typing.length),e.$broadcast("ui_history_append_new",{my:a.my}),a.my&&e.historyUnreadAfter&&(delete e.historyUnreadAfter,e.$broadcast("messages_unread_after")),i.idle.isIDLE||n(function(){s.readHistory(e.curDialog.inputPeer)}))}}),e.$on("history_delete",function(t,n){var i=g(n.peerID);if(i){var a,o=[];for(a=0;a=0?i+n:0,s=++v,c=r>=g.length?d():e.when();c.then(function(){s==v&&(t.messageID=g[r],t.photoID=o.getMessage(t.messageID).media.photo.id,t.photo=a.wrapForFull(t.photoID),u())})}function d(){return b?b:b=o.getSearch(m,h,f,_).then(function(e){e.history.length?(_=e.history[e.history.length-1],g=g.concat(e.history),y=g.length0,t.nav.hasPrev=y||e0}if(t.photo=a.wrapForFull(t.photoID),t.nav={},t.download=function(){a.downloadPhoto(t.photoID)},(!t.messageID||Config.Mobile)&&(t.nav.next=function(){i.close()}),t.messageID){if(t.forward=function(){var e=t.messageID;s.selectPeer({confirm_type:"FORWARD_PEER"}).then(function(t){var i=r.getPeerID(t);o.forwardMessages(i,[e]).then(function(){n.$broadcast("history_focus",{peerString:t})})})},Config.Mobile)return t.canForward=!0,void(t.canDelete=!0);t["delete"]=function(){var e=t.messageID;c.confirm({type:"MESSAGE_DELETE"}).then(function(){o.deleteMessages([e])})};var p=o.getMessagePeer(o.getMessage(t.messageID)),m=r.getInputPeerByID(p),h="",f={_:"inputMessagesFilterPhotos"},g=[t.messageID],_=t.messageID,y=!0;u(),o.getSearch(m,h,f,0,1e3).then(function(e){e.history.indexOf(t.messageID)>=0&&(g=e.history,_=g[g.length-1],u())});var v=0,b=!1;t.nav.next=function(){return t.nav.hasNext?void l(-1):!1},t.nav.prev=function(){return t.nav.hasPrev?void l(1):!1},t.$on("history_delete",function(e,n){if(n.peerID==p){if(n.msgs[t.messageID])if(t.nav.hasNext)t.nav.next();else{if(!t.nav.hasPrev)return i.dismiss();t.nav.prev()}for(var a=[],o=0;o=0?i+n:0,r=++_,s=o>=h.length?u():e.when();s.then(function(){r==_&&(t.photoID=h[o],t.photo=a.wrapForFull(t.photoID),p())})}function u(){return y?y:y=a.getUserPhotos(m,f).then(function(e){f=e.photos[e.photos.length-1],h=h.concat(e.photos),g=h.length0,t.nav.hasPrev=g||e=0&&(h=e.photos,f=h[h.length-1],g=h.length0&&Math.ceil(10*i[3])||0:5,t.notify.canVibrate=l.getVibrateSupport(),t.notify.vibrate=!i[4],t.notify.volumeOf4=function(){return 1+Math.ceil((t.notify.volume-1)/3.3)},t.toggleSound=function(){t.notify.volume=t.notify.volume?0:5};var a;t.$watch("notify.volume",function(e,t){if(e!==t){var i=e/10;c.set({notify_volume:i}),c.remove("notify_nosound"),l.clear(),a&&n.cancel(a),a=n(function(){l.testSound(i)},500)}}),t.toggleDesktop=function(){t.notify.desktop=!t.notify.desktop,t.notify.desktop?c.remove("notify_nodesktop"):c.set({notify_nodesktop:!0})},t.toggleVibrate=function(){t.notify.vibrate=!t.notify.vibrate,t.notify.vibrate?c.remove("notify_novibrate"):c.set({notify_novibrate:!0})},t.toggleCtrlEnter=function(n){t.send.enter=n,t.send.enter?c.remove("send_ctrlenter"):c.set({send_ctrlenter:!0}),e.$broadcast("settings_changed")}}),t.openChangelog=function(){p.showChangelog(!1)}}]).controller("ChangelogModalController",["$scope","$modal",function(e,t){e.changeUsername=function(){t.open({templateUrl:templateUrl("username_edit_modal"),controller:"UsernameEditModalController",windowClass:"username_edit_modal_window mobile_modal"})}}]).controller("ProfileEditModalController",["$scope","$modalInstance","AppUsersManager","MtpApiManager",function(e,t,n,i){e.profile={},e.error={},i.getUserID().then(function(t){e.profile=n.getUser(t)}),e.updateProfile=function(){e.profile.updating=!0,i.invokeApi("account.updateProfile",{first_name:e.profile.first_name||"",last_name:e.profile.last_name||""}).then(function(i){e.error={},n.saveApiUser(i),t.close()},function(n){switch(n.type){case"FIRSTNAME_INVALID":e.error={field:"first_name"},n.handled=!0;break;case"LASTNAME_INVALID":e.error={field:"last_name"},n.handled=!0;break;case"NAME_NOT_MODIFIED":n.handled=!0,t.close()}})["finally"](function(){delete e.profile.updating})}}]).controller("UsernameEditModalController",["$scope","$modalInstance","AppUsersManager","MtpApiManager",function(e,t,n,i){e.profile={},e.error={},i.getUserID().then(function(t){e.profile=angular.copy(n.getUser(t))}),e.updateUsername=function(){e.profile.updating=!0,i.invokeApi("account.updateUsername",{username:e.profile.username||""}).then(function(i){e.checked={},n.saveApiUser(i),t.close()},function(e){"USERNAME_NOT_MODIFIED"==e.type&&(e.handled=!0,t.close())})["finally"](function(){delete e.profile.updating})},e.$watch("profile.username",function(t){return t.length?void i.invokeApi("account.checkUsername",{username:t||""}).then(function(n){e.profile.username==t&&(e.checked=n?{success:!0}:{error:!0})},function(n){if(e.profile.username==t)switch(n.type){case"USERNAME_INVALID":e.checked={error:!0},n.handled=!0}}):void(e.checked={})})}]).controller("ContactsModalController",["$scope","$modal","$modalInstance","AppUsersManager","ErrorService",function(e,t,n,i){function a(){e.selectedContacts={},e.selectedCount=0}function o(t){i.getContacts(t).then(function(n){e.contacts=[],e.slice.limit=20,angular.forEach(n,function(t){var n={userID:t,user:i.getUser(t),userPhoto:i.getUserPhoto(t,"User")};e.contacts.push(n)}),e.contactsEmpty=t?!1:!e.contacts.length,e.$broadcast("contacts_change")})}if(e.contacts=[],e.search={},e.slice={limit:20,limitDelta:20},a(),e.disabledContacts={},e.disabled)for(var r=0;r0){var t=[];return angular.forEach(e.selectedContacts,function(e,n){t.push(n)}),n.close(t)}},e.deleteSelected=function(){if(e.selectedCount>0){var t=[];angular.forEach(e.selectedContacts,function(e,n){t.push(n)}),i.deleteContacts(t).then(function(){e.toggleEdit(!1)})}},e.importContact=function(){i.openImportContact()}}]).controller("PeerSelectController",["$scope","$modalInstance","$q","AppPeersManager","ErrorService",function(e,t,n,i,a){e.dialogSelect=function(o){var r;if(e.confirm_type){var s=i.getPeerID(o),c=i.getPeer(s);r=a.confirm({type:e.confirm_type,peer_id:s,peer_data:c})}else r=n.when();r.then(function(){t.close(o)})},e.toggleSearch=function(){e.$broadcast("dialogs_search_toggle")}}]).controller("ChatCreateModalController",["$scope","$modalInstance","$rootScope","MtpApiManager","AppUsersManager","AppChatsManager","ApiUpdatesManager",function(e,t,n,i,a,o,r){e.group={name:""},e.createGroup=function(){if(e.group.name){e.group.creating=!0;var t=[];return angular.forEach(e.userIDs,function(e){t.push({_:"inputUserContact",user_id:e})}),i.invokeApi("messages.createChat",{title:e.group.name,users:t}).then(function(e){r.processUpdateMessage({_:"updates",seq:e.seq,users:e.users,chats:e.chats,updates:[{_:"updateNewMessage",message:e.message,pts:e.pts}]});var t=o.getChatString(e.message.to_id.chat_id);n.$broadcast("history_focus",{peerString:t})})["finally"](function(){delete e.group.creating})}}}]).controller("ChatEditModalController",["$scope","$modalInstance","$rootScope","MtpApiManager","AppUsersManager","AppChatsManager","ApiUpdatesManager",function(e,t,n,i,a,o,r){var s=o.getChat(e.chatID);e.group={name:s.title},e.updateGroup=function(){return e.group.name?e.group.name==s.title?t.close():(e.group.updating=!0,i.invokeApi("messages.editChatTitle",{chat_id:e.chatID,title:e.group.name}).then(function(t){r.processUpdateMessage({_:"updates",seq:t.seq,users:t.users,chats:t.chats,updates:[{_:"updateNewMessage",message:t.message,pts:t.pts}]});var i=o.getChatString(e.chatID);n.$broadcast("history_focus",{peerString:i})})["finally"](function(){delete e.group.updating})):void 0}}]).controller("ImportContactModalController",["$scope","$modalInstance","$rootScope","AppUsersManager","ErrorService","PhonebookContactsService",function(e,t,n,i,a,o){void 0===e.importContact&&(e.importContact={}),e.phonebookAvailable=o.isAvailable(),e.doImport=function(){e.importContact&&e.importContact.phone&&(e.progress={enabled:!0},i.importContact(e.importContact.phone,e.importContact.first_name||"",e.importContact.last_name||"").then(function(e){e||a.show({error:{code:404,type:"USER_NOT_USING_TELEGRAM"}}),t.close(e)})["finally"](function(){delete e.progress.enabled}))},e.importPhonebook=function(){o.openPhonebookImport().result.then(function(e){e?t.close(e[0]):t.dismiss()})}}]).controller("CountrySelectModalController",["$scope","$modalInstance","$rootScope","SearchIndexManager","_",function(e,t,n,i,a){e.search={},e.slice={limit:20,limitDelta:20};for(var o=i.createIndex(),r=0;r5184e5?o="shortDate":a>432e5&&(o="EEE"),t[e]=n(i,o)}}]).filter("time",["$filter",function(e){var t={},n=e("date"),i=Config.Mobile?"shortTime":"mediumTime";return function(e){return t[e]?t[e]:t[e]=n(1e3*e,i)}}]).filter("myDate",["$filter",function(e){var t={},n=e("date");return function(e){return t[e]?t[e]:t[e]=n(1e3*e,"fullDate")}}]).filter("duration",[function(){return function(e){e=parseInt(e),isNaN(e)&&(e=0);var t=e%60,n=Math.floor((e-t)/60);return 10>t&&(t="0"+t),n+":"+t}}]).filter("phoneNumber",[function(){return function(e){var t=" ";return e=(e||"").replace(/\D/g,""),"7"==e.charAt(0)&&11==e.length?"+"+e.charAt(0)+t+"("+e.substr(1,3)+")"+t+e.substr(4,3)+"-"+e.substr(7,2)+"-"+e.substr(9,2):"+"+e}}]).filter("formatSize",[function(){return function(e){return e?1024>e?e+" b":1048576>e?Math.round(e/1024*10)/10+" Kb":Math.round(e/1048576*100)/100+" Mb":"0"}}]).filter("formatSizeProgress",["$filter","_",function(e,t){return function(n){var i=e("formatSize")(n.done),a=i.split(" "),o=e("formatSize")(n.total),r=o.split(" ");return r[1]===a[1]?t("format_size_progress_mulitple",{done:a[0],total:r[0],parts:a[1]||""}):t("format_size_progress",{done:i,total:o})}}]).filter("nl2br",[function(){return function(e){return e.replace(/\n/g,"
")}}]).filter("richText",["$filter",function(e){return function(t){return e("linky")(t,"_blank").replace(/\n| /g,"
")}}]).filter("relativeTime",["$filter","_",function(e,t){var n=t.pluralize("relative_time_pluralize_minutes_ago"),i=t.pluralize("relative_time_pluralize_hours_ago");return function(a){var o=1e3*a,r=Math.abs(tsNow()-o);if(6e4>r)return t("relative_time_just_now");if(3e6>r){var s=Math.ceil(r/6e4);return n(s)}if(1e7>r){var c=Math.ceil(r/36e5);return i(c)}return e("dateOrTime")(a)}}]),angular.module("myApp.i18n",["izhukov.utils"]).factory("_",["$rootScope","$locale",function(e,t){function n(e,t){return e.replace(l,function(i,a,o){var r=t[a];return void 0===r?(console.warn("[i18n] missing param "+a+' for message "'+e+'"'),""):(void 0!==o&&(r=n(r,o.split("|"))),r.toString().trim())})}function i(e){return e.replace(/&/g,"&").replace(/([^\#-~| |!\n\*])/g,function(e){return"&#"+e.charCodeAt(0)+";"}).replace(//g,">")}function a(e){return e=e.replace(/\*\*(.+?)\*\*/g,"$1").replace(/\n/g,"
")}function o(e,t){var o=!1,l=e;if("_raw"===e.substr(-4)&&(o=!0,e=e.substr(0,e.length-4)),s.hasOwnProperty(e))l=s[e];else{if(!c.hasOwnProperty(e))return console.warn("[i18n] missing key "+e),e;l=c[e],console.warn("[i18n] missing locale key "+r+" / "+e)}return o||(l=i(l)),"_md"==e.substr(-3)&&(l=a(l)),arguments.length>1&&("string"==typeof t?(Array.prototype.shift.apply(arguments),l=n(l,arguments)):l=n(l,t)),l}var r=Config.I18n.locale,s=Config.I18n.messages,c=Config.I18n.fallback_messages,l=/\{\s*([a-zA-Z\d\-_]+)(?:\s*:\s*(.*?))?\s*\}/g;return o.locale=function(){return r},o.pluralize=function(n){var i=e.$eval(o(n+"_raw"));return function(e){return(i[t.pluralCat(e)]||"").replace("{}",e)}},o}]).filter("i18n",["_",function(e){return function(t,n){return e(t+"_raw",n)}}]).directive("ngPluralize",["_",function(e){return{restrict:"EA",priority:1,compile:function(t){var n=t.attr("when"),i=e(n+"_raw");t.attr("when",i)}}}]).directive("myI18n",["_",function(e){return{restrict:"EA",compile:function(t){var n=t.children('my-i18n-param:not([name]), [my-i18n-param=""]:not([name])').map(function(e,t){return t.outerHTML}).toArray();t.children('my-i18n-param[name], [my-i18n-param]:not([my-i18n-param=""]), [my-i18n-param][name]').each(function(e,t){n[angular.element(t).attr("my-i18n-param")||angular.element(t).attr("name")]=t.outerHTML}),t.children("my-i18n-param").remove();var i=t.attr("my-i18n")||t.attr("msgid")?t:t.children("my-i18n-format, [my-i18n-format]");i.each(function(t,i){var a=angular.element(i),o=a.attr("my-i18n")||a.attr("msgid")||a.attr("my-i18n-format")||a.html().replace(/\s+/g," ").trim(),r=e(o,n);a.html(r)})}}}]),angular.module("myApp.templates",[]).run(["$templateCache",function(e){e.put("partials/desktop/audio_player.html",'
\n \n
\n \n \n \n \n
\n \n \n \n
\n
\n
\n \n \n
\n
\n
\n
\n
\n
\n
\n
\n
\n \n
'),e.put("partials/desktop/changelog_modal.html",'
\n\n \n\n \n\n
\n'),e.put("partials/desktop/chat_create_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/desktop/chat_edit_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/desktop/chat_modal.html",'
\n\n \n\n \n\n
\n'),e.put("partials/desktop/confirm_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/desktop/contacts_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/desktop/country_select_modal.html",'
\n\n \n\n \n\n
\n'),e.put("partials/desktop/dialog.html",'\n\n
\n
\n \n \n
\n\n
\n \n
\n\n
\n\n
\n \n \n \n \n
\n\n
\n
\n \n
\n
\n \n {{((dialogMessage.out || dialogMessage.peerID < 0) && (dialogMessage.message.length || dialogMessage.media && dialogMessage.media._ != \'messageMediaEmpty\')) ? \':\' : \'\'}}\n \n\n \n \n \n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n \n\n \n \n \n \n \n \n \n\n \n
\n
\n\n
\n
\n'),e.put("partials/desktop/edit_contact_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/desktop/error_modal.html",'
\n\n \n\n \n\n
\n'),e.put("partials/desktop/full_gif.html",'\n\n
\n\n \n \n\n
\n\n
\n\n
\n
\n
\n
\n
\n\n
\n
GIF
\n
\n
\n\n
\n\n
'),e.put("partials/desktop/full_photo.html",'
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n \n \n \n
\n
\n
\n
\n
\n
'),e.put("partials/desktop/full_video.html",'
\n
\n
\n
\n
\n
\n
\n
\n
\n \n
\n
\n \n \n
\n
\n
\n
\n
\n
'),e.put("partials/desktop/head.html",'
\n \n
\n'),e.put("partials/desktop/im.html",'
\n\n
\n\n
\n\n
\n
\n \n \n\n
\n
\n \n \n
\n
\n
\n\n
\n
\n
\n\n
\n

\n

\n \n \n
\n\n
\n \n \n
\n\n
\n
\n \n
\n\n \n\n
\n
\n
\n
\n\n
\n\n
\n
\n

\n

\n \n
\n
\n
\n\n
\n \n
\n\n
\n
\n\n
\n\n
\n
\n\n \n \n\n \n \n \n \n \n \n\n
\n

\n

\n

\n

\n\n

\n
\n \n \n
\n
\n \n \n \n \n \n
\n

\n
\n\n
\n\n
\n\n
\n\n
\n\n
\n\n
\n
\n
\n \n \n \n \n
\n\n
\n
\n
\n
\n
\n\n
\n\n
\n\n
\n \n \n \n \n \n {{historyState.typing.length - 2}}\n \n
\n
\n\n
\n\n
\n\n
\n\n
\n\n
\n
\n \n \n \n \n \n
\n \n \n \n
\n
\n\n
\n\n
\n\n
\n
\n \n \n
\n
\n \n
\n
\n\n
\n
\n \n
\n\n
\n \n \n
\n\n
\n \n \n
\n\n
\n \n
\n\n \n
\n
\n\n
\n\n
\n\n
\n\n
\n
\n\n
\n\n
\n\n
\n\n
'),e.put("partials/desktop/import_contact_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/desktop/lang_footer.html",''),e.put("partials/desktop/login.html",'
\n\n\n\n\n'),e.put("partials/desktop/message.html",'
\n\n\n
\n\n
\n
\n \n \n
\n\n \n \n \n\n
\n\n
\n
\n \n
\n\n \n \n \n\n \n\n \n\n
\n \n \n
\n\n
\n\n \n\n
\n \n
\n \n
\n
\n\n
\n\n
\n
\n
\n
\n
\n
\n
\n\n
\n\n
\n
\n\n
\n
\n\n
\n\n'),e.put("partials/desktop/message_attach_audio.html",'
\n
\n
\n'),e.put("partials/desktop/message_attach_contact.html",'
\n \n
\n \n \n
\n
\n
'),e.put("partials/desktop/message_attach_document.html",'
\n\n
\n\n
\n
\n
\n\n
\n\n \n \n
\n \n
\n
\n\n
\n
\n \n \n \n
\n
\n \n \n
\n
\n \n
\n
\n
\n
\n
\n
\n
\n\n
\n
\n'),e.put("partials/desktop/message_attach_map.html",'\n \n'),e.put("partials/desktop/message_attach_pending.html",'
\n \n
\n
\n \n \n
\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n'),e.put("partials/desktop/message_attach_photo.html",'\n \n'),e.put("partials/desktop/message_attach_video.html",'
\n \n \n \n \n \n\n
\n
\n \n \n \n
\n
\n \n \n
\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n'),e.put("partials/desktop/message_service.html",'\n \n \n \n «»\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n \n\n'),e.put("partials/desktop/peer_select.html",'
\n\n \n\n \n\n
\n'),e.put("partials/desktop/photo_modal.html",'
\n\n \n\n
\n'),e.put("partials/desktop/profile_edit_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/desktop/settings_modal.html",'\n'),e.put("partials/desktop/user_modal.html",'
\n\n \n\n \n\n
\n'),e.put("partials/desktop/username_edit_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/desktop/video_modal.html",'
\n\n \n\n
\n'),e.put("partials/desktop/welcome.html",'
\n\n
\n\n
\n \n\n

\n\n
\n

\n
\n
\n \n
\n
\n\n \n\n\n\n
\n'),e.put("partials/mobile/audio_player.html",'
\n \n
\n \n \n \n \n
\n \n \n \n
\n
\n
\n \n \n
\n
\n
\n
\n
\n
\n
\n
\n
\n \n
'),e.put("partials/mobile/changelog_modal.html",'
\n\n \n\n \n\n
\n'),e.put("partials/mobile/chat_create_modal.html",'
\n\n
\n \n
\n\n \n\n
'),e.put("partials/mobile/chat_edit_modal.html",'
\n\n
\n \n
\n\n \n\n
'),e.put("partials/mobile/chat_modal.html",'
\n\n
\n \n
\n\n \n\n
\n'),e.put("partials/mobile/confirm_modal.html",'
\n\n \n\n \n\n \n\n
\n'),e.put("partials/mobile/contacts_modal.html",'
\n\n
\n \n
\n\n \n\n
\n'),e.put("partials/mobile/country_select_modal.html",'
\n\n
\n \n
\n\n \n\n
\n'),e.put("partials/mobile/dialog.html",'\n\n
\n
\n \n \n
\n\n
\n \n
\n\n
\n\n
\n \n \n \n \n
\n\n
\n
\n \n
\n
\n \n {{((dialogMessage.out || dialogMessage.peerID < 0) && (dialogMessage.message.length || dialogMessage.media && dialogMessage.media._ != \'messageMediaEmpty\')) ? \':\' : \'\'}}\n \n\n \n \n \n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n \n\n \n \n \n \n \n \n \n\n \n
\n
\n\n
\n
\n'),e.put("partials/mobile/edit_contact_modal.html",'
\n\n
\n \n
\n\n \n\n
'),e.put("partials/mobile/error_modal.html",'
\n\n \n\n \n\n
\n'),e.put("partials/mobile/full_gif.html",'\n\n
\n\n \n \n\n
\n\n
\n\n
\n
\n
\n
\n
\n\n
\n
GIF
\n
\n
\n\n
\n\n
'),e.put("partials/mobile/full_photo.html",'
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n \n \n \n
\n
\n
\n
\n
\n
'),e.put("partials/mobile/full_video.html",'
\n
\n
\n
\n
\n
\n
\n
\n
\n \n
\n
\n \n \n
\n
\n
\n
\n
\n
'),e.put("partials/mobile/head.html",'
\n \n
\n'),e.put("partials/mobile/im.html",'
\n\n
\n\n
\n\n
\n
\n \n\n
\n
\n \n \n
\n
\n
\n\n
\n\n
\n

\n

\n \n \n
\n\n
\n \n \n
\n\n
\n
\n \n
\n\n \n\n
\n
\n\n
\n
\n \n
\n\n
\n
\n\n
\n\n
\n
\n
\n \n \n \n \n
\n\n
\n
\n
\n
\n
\n\n
\n\n
\n\n
\n\n
\n\n
\n
\n \n \n
\n
\n\n
\n\n
\n\n
\n
\n\n
\n
\n \n
\n\n
\n \n \n
\n\n
\n \n
\n\n \n
\n
\n\n
\n\n
\n\n
\n\n
\n
\n\n
\n\n
\n\n
'),e.put("partials/mobile/import_contact_modal.html",'
\n\n
\n \n
\n\n \n\n \n\n
'),e.put("partials/mobile/login.html",'
\n\n\n\n\n'),e.put("partials/mobile/message.html",'
\n\n\n
\n\n
\n
\n \n \n
\n\n \n \n \n\n
\n\n
\n \n\n \n\n
\n \n \n
\n\n
\n\n \n\n
\n \n \n
\n\n
\n\n
\n
\n
\n
\n
\n
\n
\n\n
\n\n
\n
\n\n
\n
\n\n
\n\n'),e.put("partials/mobile/message_attach_audio.html",'
\n
\n
\n'),e.put("partials/mobile/message_attach_contact.html",'
\n \n
\n \n \n
\n
\n
'),e.put("partials/mobile/message_attach_document.html",'
\n\n
\n\n
\n
\n
\n\n
\n\n \n \n
\n \n
\n
\n\n
\n
\n \n \n \n
\n
\n \n \n
\n
\n \n
\n
\n
\n
\n
\n
\n
\n\n
\n
\n'),e.put("partials/mobile/message_attach_map.html",'\n \n'),e.put("partials/mobile/message_attach_pending.html",'
\n \n
\n
\n \n \n
\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n'),e.put("partials/mobile/message_attach_photo.html",'\n \n'),e.put("partials/mobile/message_attach_video.html",''),e.put("partials/mobile/message_service.html",'\n \n \n \n «»\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n \n\n'),e.put("partials/mobile/peer_select.html",'
\n\n
\n \n
\n\n \n\n
\n'),e.put("partials/mobile/phonebook_modal.html",'
\n\n
\n \n
\n\n \n\n \n\n
\n'),e.put("partials/mobile/photo_modal.html",'
\n\n \n\n
\n'),e.put("partials/mobile/profile_edit_modal.html",'
\n\n
\n \n
\n\n \n\n
'),e.put("partials/mobile/settings_modal.html",'\n'),e.put("partials/mobile/user_modal.html",'
\n\n
\n \n
\n\n \n\n
\n'),e.put("partials/mobile/username_edit_modal.html",'
\n\n
\n \n
\n\n \n\n
'),e.put("partials/mobile/video_modal.html",'
\n\n \n\n
\n'),e.put("partials/mobile/welcome.html",'
\n\n
\n\n
\n \n\n

\n\n
\n

\n
\n
\n \n
\n
\n\n \n\n\n\n
\n') }]),angular.module("myApp.directives",["myApp.filters"]).directive("myHead",function(){return{restrict:"AE",templateUrl:templateUrl("head")}}).directive("myLangFooter",function(){return{restrict:"AE",templateUrl:templateUrl("lang_footer")}}).directive("myDialog",function(){return{restrict:"AE",templateUrl:templateUrl("dialog")}}).directive("myMessage",["$filter","_",function(e,t){function n(e,t){var n,u,p=!1,m=!1,h=!1,f=!1,g=!1,_=!1,y=!1,v=function(){p!=(e.selectedMsgs[e.historyMessage.id]||!1)&&(p=!p,t.toggleClass(r,p))},b=function(){m!=e.historyMessage.grouped&&(m&&t.removeClass(m),m=e.historyMessage.grouped,m&&t.addClass(m)),_!=(e.historyMessage.needDate||!1)&&(_=!_,_?n?n.show():(n=$(a),$(n[0].firstChild).text(i(e.historyMessage.date)),u?n.insertBefore(u):n.prependTo(t)):n.hide())};v(),b(),e.$on("messages_select",v),e.$on("messages_regroup",b),e.$on("messages_focus",function(n,i){i==e.historyMessage.id!=h&&(h=!h,t.toggleClass(s,h))});var w;if(!e.historyMessage.out&&(e.historyMessage.unread||e.historyMessage.unreadAfter)){var k=function(){e.peerHistory.peerID==e.historyPeer.id&&y!=(e.historyUnreadAfter==e.historyMessage.id)&&(y=!y,y?u?u.show():u=$(o).prependTo(t):(u.hide(),w&&w()))};k(),w=e.$on("messages_unread_after",k)}if(e.historyMessage.unread){t.addClass(c);var C=e.$on("messages_read",function(){e.historyMessage.unread||(t.removeClass(c),C(),w&&!y&&w())})}if(e.historyMessage.error||e.historyMessage.pending){var S=function(){g!=(e.historyMessage.pending||!1)&&(g=!g,t.toggleClass(d,g)),f!=(e.historyMessage.error||!1)&&(f=!f,t.toggleClass(l,f)),f||g||M()},M=e.$on("messages_pending",S);S()}}var i=e("myDate"),a='
',o='
'+t("unread_messages_split")+"
",r="im_message_selected",s="im_message_focus",c="im_message_unread",l="im_message_error",d="im_message_pending";return{templateUrl:templateUrl("message"),link:n}}]).directive("myServiceMessage",function(){return{templateUrl:templateUrl("message_service")}}).directive("myMessagePhoto",function(){return{templateUrl:templateUrl("message_attach_photo")}}).directive("myMessageVideo",function(){return{templateUrl:templateUrl("message_attach_video")}}).directive("myMessageDocument",function(){return{templateUrl:templateUrl("message_attach_document")}}).directive("myMessageAudio",function(){return{templateUrl:templateUrl("message_attach_audio")}}).directive("myMessageMap",function(){return{templateUrl:templateUrl("message_attach_map")}}).directive("myMessageContact",function(){return{templateUrl:templateUrl("message_attach_contact")}}).directive("myMessagePending",function(){return{templateUrl:templateUrl("message_attach_pending")}}).directive("myDialogs",["$modalStack","$transition","$window","$timeout",function(e,t,n,i){function a(t,a,o){function r(t){if(!m&&e.getTop())return!0;if(36==t.keyCode&&!t.shiftKey&&!t.ctrlKey&&t.altKey){var n=$(c).find(".im_dialog_wrap a");return n.length&&($(n[0]).trigger("mousedown"),c.scrollTop=0,$(s).nanoScroller({flash:!0})),cancelEvent(t)}if(27==t.keyCode||9==t.keyCode&&t.shiftKey&&!t.ctrlKey&&!t.metaKey)return m?l.value&&$(u).trigger("click"):(l.focus(),l.value&&l.select()),cancelEvent(t);if(m&&13==t.keyCode){var n=$(c).find(".im_dialog_selected")[0]||$(c).find(".im_dialog_wrap a")[0];return n&&$(n).trigger("mousedown"),cancelEvent(t)}var i,a,o,r=Config.Modes.packed;if(40==t.keyCode||38==t.keyCode?(i=40==t.keyCode,a=!i,o=!t.shiftKey&&t.altKey):r&&9==t.keyCode&&t.ctrlKey&&!t.metaKey&&(i=!t.shiftKey,a=!i,o=!0),i||a){if(!o&&(!m||t.metaKey))return!0;var d,n=!o&&$(c).find(".im_dialog_selected")[0]||$(c).find(".active a.im_dialog")[0],p=n&&n.parentNode;if(p){var d=n[i?"nextSibling":"previousSibling"];if(!d||!d.className||-1==d.className.indexOf("im_dialog_wrap")){var h=$(c).find(".im_dialog_wrap"),f=h.index(n.parentNode),g=f+(i?1:-1);d=h[g]}}else{var h=$(c).find(".im_dialog_wrap");d=i?h[0]:h[h.length-1]}if(o?d&&$(d).find("a").trigger("mousedown"):(p&&d&&$(p).find("a").removeClass("im_dialog_selected"),d&&$(d).find("a").addClass("im_dialog_selected")),d){var _=d.offsetTop,y=d.offsetHeight,v=c.scrollTop,b=c.clientHeight;v>_?(c.scrollTop=_,$(s).nanoScroller({flash:!0})):_+y-b>v&&(c.scrollTop=_+y-b,$(s).nanoScroller({flash:!0}))}return cancelEvent(t)}}var s=$(".im_dialogs_wrap",a)[0],c=$(".im_dialogs_scrollable_wrap",a)[0],l=$(".im_dialogs_search_field",a)[0],d=$(".im_dialogs_panel",a)[0],u=$(".im_dialogs_search_clear",a)[0],p=$(".im_dialogs_tabs_wrap",a)[0],m=!1;$(l).on("focus blur",function(e){m="focus"==e.type,m||($(c).find(".im_dialog_selected").removeClass("im_dialog_selected"),l.value||t.$emit("ui_dialogs_search_clear"))}),t.$on("dialogs_search_toggle",function(){$(d).addClass("im_dialogs_panel_search"),t.$broadcast("ui_dialogs_search"),$(n).scrollTop(0),i(function(){l.focus()})}),t.$on("search_clear",function(){$(d).removeClass("im_dialogs_panel_search"),t.$broadcast("ui_dialogs_search")}),o.$observe("hasTabs",function(e){e="true"==e,$(p).toggle(e),t.$broadcast("ui_dialogs_tabs",e)}),$(document).on("keydown",r),t.$on("$destroy",function(){$(document).off("keydown",r)})}return{link:a}}]).directive("myDialogsList",["$window","$timeout",function(e,t){function n(n,i,a){function o(){return u&&u.offsetHeight||(u=$(d)[0]),a.modal?($(i).css({height:$(e).height()-(u?u.offsetHeight:58)-(Config.Mobile?46:200)}),void f()):(l&&l.offsetHeight||(l=$(".tg_page_head")[0]),p&&p.offsetHeight||(p=$(".footer_wrap")[0]),s&&s.offsetHeight||(s=$(".im_dialogs_col_wrap")[0]),$(i).css({height:$(e).height()-(p?p.offsetHeight:0)-(l?l.offsetHeight:44)-(u?u.offsetHeight:58)-parseInt($(s).css("paddingBottom")||0)}),void f())}var r=$(".im_dialogs_wrap",i)[0],s=$(".im_dialogs_col_wrap")[0],c=$(".im_dialogs_scrollable_wrap",i)[0],l=$(".tg_page_head")[0],d=Config.Mobile&&a.modal?".mobile_modal_body .im_dialogs_panel":".im_dialogs_panel",u=$(d)[0],p=$(".footer_wrap")[0],m=!1,h=!1;onContentLoaded(function(){$(r).nanoScroller({preventPageScrolling:!0,tabIndex:-1,iOSNativeScrolling:!0})});var f=function(){onContentLoaded(function(){$(r).nanoScroller()})};n.$on("ui_dialogs_prepend",f),n.$on("ui_dialogs_tabs",function(e,t){m=t,o()}),n.$on("ui_dialogs_search",o),n.$on("ui_dialogs_update",o),n.$on("ui_dialogs_append",function(){onContentLoaded(function(){f(),h=!1,t(function(){$(c).trigger("scroll")})})}),n.$on("ui_dialogs_change",function(){onContentLoaded(function(){f(),h=!1,t(function(){$(c).trigger("scroll")})})}),$(c).on("scroll",function(){i.is(":visible")&&!h&&c.scrollTop>=c.scrollHeight-c.clientHeight-300&&(n.$emit("dialogs_need_more"),h=!0)}),$(e).on("resize",o),o(),setTimeout(o,1e3)}return{link:n}}]).directive("myContactsList",["$window","$timeout",function(e){function t(t,n){function i(){$(n).css({height:$(e).height()-(o&&o.offsetHeight||0)-(a&&a.offsetHeight||0)-(Config.Mobile?64:200)}),$(r).nanoScroller()}var a=$(".contacts_modal_search")[0],o=$(".contacts_modal_panel")[0],r=$(".contacts_wrap",n)[0];onContentLoaded(function(){$(r).nanoScroller({preventPageScrolling:!0,tabIndex:-1,iOSNativeScrolling:!0}),i()}),$(e).on("resize",i),t.$on("contacts_change",function(){onContentLoaded(i)})}return{link:t}}]).directive("myCountriesList",["$window","$timeout",function(e){function t(t,n){function i(){$(n).css({height:$(e).height()-(o&&o.offsetHeight||0)-(a&&a.offsetHeight||0)-(Config.Mobile?64:200)}),$(r).nanoScroller()}var a=$(".countries_modal_search")[0],o=$(".countries_modal_panel")[0],r=$(".countries_wrap",n)[0];onContentLoaded(function(){$(r).nanoScroller({preventPageScrolling:!0,tabIndex:-1,iOSNativeScrolling:!0}),i()}),$(e).on("resize",i),t.$on("contacts_change",function(){onContentLoaded(i)})}return{link:t}}]).directive("myHistory",["$window","$timeout","$rootScope","$transition",function(e,t,n,i){function a(a,o){function r(){var e,n;if(n=$(".im_message_focus:visible",u)[0]){var i=u.clientHeight,a=u.scrollTop,o=n.offsetTop,r=n.clientHeight;(!a||o>a+i||a>o+r)&&(u.scrollTop=Math.max(0,o-Math.floor(i/2)+26)),A=!1}else(e=$(".im_message_unread_split:visible",u)[0])?(u.scrollTop=Math.max(0,e.offsetTop-52),A=!1):(u.scrollTop=u.scrollHeight,A=!0);k(),t(function(){$(u).trigger("scroll"),T=u.scrollTop})}function s(t){if(o.is(":visible")||$(o[0].parentNode.parentNode).is(":visible")){$(f).is(":visible")&&$(f).css({height:$(y).height()}),g&&g.offsetHeight||(g=$(".tg_page_head")[0]),_&&_.offsetHeight||(_=$(".footer_wrap")[0]);var n=$(e).height()-m.offsetHeight-h.offsetHeight-(g?g.offsetHeight:44)-(_?_.offsetHeight:0);$(l).css({height:n}),c(),t!==!0&&(A&&onContentLoaded(function(){u.scrollTop=u.scrollHeight,k()}),k(100))}}function c(){$(d).css({marginTop:0});var e=u.offsetHeight-d.offsetHeight-20-(Config.Mobile?0:49);d.offsetHeight>0&&e>0&&$(d).css({marginTop:e}),$(l).nanoScroller()}var l=$(".im_history_wrap",o)[0],d=$(".im_history_messages",o)[0],u=($(".im_history",o)[0],$(".im_history_scrollable_wrap",o)[0]),p=$(".im_history_scrollable",o)[0],m=$(".im_history_panel_wrap",o)[0],h=$(".im_bottom_panel_wrap",o)[0],f=$(".im_send_form_wrap",o)[0],g=$(".tg_page_head")[0],_=$(".footer_wrap")[0],y=$(".im_send_form",o)[0],v=!1,b=!1;onContentLoaded(function(){u.scrollTop=u.scrollHeight}),$(l).nanoScroller({preventPageScrolling:!0,tabIndex:-1,iOSNativeScrolling:!0});var w,k=function(e){t(function(){$(u).hasClass("im_history_to_bottom")||$(l).nanoScroller()},e||0)},C=!1,S=["transform","webkitTransform","MozTransform","msTransform","OTransform"];for(w=0;w0;o?a=u.scrollHeight:($(p).css({bottom:0}),$(u).addClass("im_history_to_bottom")),onContentLoaded(function(){if(o){x=!0,$(d).removeClass("im_history_appending"),u.scrollTop=u.scrollHeight,$(d).css(C,"translate(0px, "+(u.scrollHeight-a)+"px)"),$(l).nanoScroller();var e={};e[C]="translate(0px, 0px)",$(d).addClass("im_history_appending"),i($(d),e).then(function(){x=!1,$(d).removeClass("im_history_appending"),c()})}else $(u).removeClass("im_history_to_bottom"),$(p).css({bottom:""}),u.scrollTop=u.scrollHeight,c()})}}),a.$on("ui_history_change",function(){var e=parseInt($(u).css("paddingRight"));$(u).addClass("im_history_to_bottom"),u.scrollHeight,$(p).css({bottom:0,marginLeft:-Math.ceil(e/2)}),onContentLoaded(function(){$(u).removeClass("im_history_to_bottom"),$(p).css({bottom:"",marginLeft:""}),s(!0),v=!1,b=!1,r()})}),a.$on("ui_history_change_scroll",function(){onContentLoaded(r)}),a.$on("ui_history_focus",function(){A||(u.scrollTop=u.scrollHeight,k(),A=!0)}),a.$on("ui_history_prepend",function(){var e=u.scrollHeight,n=u.scrollTop,i=parseInt($(u).css("paddingRight")),o=u.clientHeight;$(u).addClass("im_history_to_bottom"),u.scrollHeight,$(p).css({bottom:-(e-n-o),marginLeft:-Math.ceil(i/2)});var s=function(){$(u).removeClass("im_history_to_bottom"),$(p).css({bottom:"",marginLeft:""}),T>=0?r():u.scrollTop=n+u.scrollHeight-e,c(),v=!1,t(function(){u.scrollHeight!=e&&$(u).trigger("scroll")}),clearTimeout(l),d()},l=setTimeout(s,0),d=a.$on("$viewContentLoaded",s)}),a.$on("ui_history_append",function(){var e=u.scrollHeight;onContentLoaded(function(){A=!1,c(),b=!1,T>=0&&r(),t(function(){u.scrollHeight!=e&&$(u).trigger("scroll")})})}),a.$on("ui_panel_update",function(){onContentLoaded(function(){s(),a.$broadcast("ui_message_send"),t(function(){$(u).trigger("scroll")})})}),a.$on("ui_selection_clear",function(){window.getSelection?window.getSelection().empty?window.getSelection().empty():window.getSelection().removeAllRanges&&window.getSelection().removeAllRanges():document.selection&&document.selection.empty()}),a.$on("ui_editor_resize",s),a.$on("ui_height",function(){onContentLoaded(s)});var A=!0,T=-1;$(u).on("scroll",function(){if(o.is(":visible")&&!$(u).hasClass("im_history_to_bottom")&&!x){var e=u.scrollTop;A=e>=u.scrollHeight-u.clientHeight,T>=0&&T!=e&&(T=-1),!v&&300>=e?(v=!0,a.$emit("history_need_more")):!b&&e>=u.scrollHeight-u.clientHeight-300&&(b=!0,a.$emit("history_need_less"))}}),$(e).on("resize",s),s(),onContentLoaded(s)}return{link:a}}]).directive("mySendForm",["$timeout","$modalStack","Storage","ErrorService","$interpolate",function(e,t,n,i,a){function o(o,r){function s(){E=0,T=0}function c(){if(S){e.cancel(M);var t=$("
").text(o.draftMessage.text||"").html();t=t.replace(/\n/g,"
"),$(S).html(t),d()}}function l(){S&&($(S).trigger("change"),d())}function d(){var e=S.offsetHeight;I!=e&&(I=e,o.$emit("ui_editor_resize"))}function u(e){return 9!=e.keyCode||e.shiftKey||e.ctrlKey||e.metaKey||t.getTop()?void 0:(k.focus(),cancelEvent(e))}function p(){onContentLoaded(function(){k.focus()})}function m(e){var t,n=e&&e.target;if(n&&(t=n.src)&&0===t.indexOf("data")){n.parentNode.removeChild(n),t=t.substr(5).split(";");for(var a=t[0],r=atob(t[1].split(",")[1]),s=new Uint8Array(r.length),c=0;c0&&i.confirm({type:"FILES_CLIPBOARD_PASTE",files:r}).then(function(){o.draftMessage.files=r,o.draftMessage.isMedia=!0})}function f(e){var t=!1;return g&&1!=g||(g=checkDragEvent(e)?2:1,t=!0),2==g&&(_&&setTimeout(function(){clearTimeout(_),_=!1},0),"dragenter"==e.type||"dragover"==e.type?t&&$(b).css({height:$(k).height()+12,width:$(k).width()+12}).show():("drop"==e.type&&o.$apply(function(){o.draftMessage.files=Array.prototype.slice.call(e.originalEvent.dataTransfer.files),o.draftMessage.isMedia=!0}),_=setTimeout(function(){$(b).hide(),g=!1,_=!1},300))),cancelEvent(e)}var g,_,y=$("textarea",r)[0],v=$("input",r),b=$(".im_send_dropbox_wrap",r)[0],w=$(".im_emoji_btn",r)[0],k=y,C=($(y).emojiarea({button:w,norealTime:!0}),$(".emoji-menu",r)[0],$(".im_submit",r)[0]),S=$(".emoji-wysiwyg-editor",r)[0];if(S){k=S,$(S).addClass("form-control"),$(S).attr("placeholder",a($(y).attr("placeholder"))(o));var M;$(S).on("DOMNodeInserted",m).on("keyup",function(){d(),o.$apply(function(){o.draftMessage.text=S.textContent}),e.cancel(M),M=e(l,1e3)})}e(function(){v.on("change",function(){var e=this;o.$apply(function(){o.draftMessage.files=Array.prototype.slice.call(e.files),o.draftMessage.isMedia=$(e).hasClass("im_media_attach_input")||Config.Mobile,setTimeout(function(){try{e.value=""}catch(t){}},1e3)})})},1e3);var x=!0,A=function(){n.get("send_ctrlenter").then(function(e){x=!e})};o.$on("settings_changed",A),A(),$(k).on("keydown",function(t){if(S&&d(),13==t.keyCode){var n=!1;if(x&&!t.shiftKey?n=!0:x||!t.ctrlKey&&!t.metaKey||(n=!0),n)return e.cancel(M),l(),$(r).trigger("submit"),$(r).trigger("message_send"),s(),cancelEvent(t)}}),$(C).on("mousedown touchstart",function(t){return e.cancel(M),l(),$(r).trigger("submit"),$(r).trigger("message_send"),s(),cancelEvent(t)});var T,E=0;$(k).on("keyup",function(){var e=tsNow(),t=k[S?"textContent":"value"].length;e-E>5e3&&t!=T&&(E=e,T=t,o.$emit("ui_typing"))});var I=S.offsetHeight;$(document).on("keydown",u),$("body").on("dragenter dragleave dragover drop",f),$(document).on("paste",h),Config.Navigator.touch||(o.$on("ui_peer_change",p),o.$on("ui_history_focus",p),o.$on("ui_history_change",p)),o.$on("ui_message_send",p),o.$on("ui_peer_draft",c),o.$on("ui_message_before_send",l),o.$on("$destroy",function(){$("body").off("dragenter dragleave dragover drop",f),$(document).off("paste",h),$(document).off("keydown",u),$(C).off("mousedown"),v.off("change"),S&&$(S).off("DOMNodeInserted keyup",m),$(k).off("keydown")}),Config.Navigator.touch||p()}return{link:o,scope:{draftMessage:"="}}}]).directive("myLoadThumb",["MtpApiFileManager",function(e){function t(t,n,i){var a=0,o=e.getCachedFile(t.thumb&&t.thumb.location&&!t.thumb.location.empty&&t.thumb.location);o&&n.attr("src",o),t.thumb&&t.thumb.width&&t.thumb.height&&(n.attr("width",t.thumb.width),n.attr("height",t.thumb.height));var r=t.$watchCollection("thumb.location",function(i){t.thumb&&t.thumb.width&&t.thumb.height&&(n.attr("width",t.thumb.width),n.attr("height",t.thumb.height),t.$emit("ui_height"));var o=++a;if(!i||i.empty)return n.attr("src",t.thumb&&t.thumb.placeholder||"img/blank.gif"),void s();var r=e.getCachedFile(i);return r?(n.attr("src",r),void s()):(n.attr("src")||n.attr("src",t.thumb.placeholder||"img/blank.gif"),void e.downloadSmallFile(t.thumb.location).then(function(e){o==a&&(n.attr("src",e),s())},function(e){console.log("Download image failed",e,t.thumb.location,n[0]),o==a&&(n.attr("src",t.thumb.placeholder||"img/blank.gif"),s())}))}),s=i.watch?angular.noop:function(){setTimeout(function(){t.$destroy(),r()},0)}}return{link:t,scope:{thumb:"="}}}]).directive("myLoadFullPhoto",["MtpApiFileManager","_",function(e,t){function n(n,i){var a=$("img",i)[0],o=$(".img_fullsize_with_progress_wrap",i).add(".img_fullsize_progress_wrap",i).add($(a)),r=function(){o.css({width:n.fullPhoto.width,height:n.fullPhoto.height}),n.$emit("ui_height")},s=0;n.$watchCollection("fullPhoto.location",function(){var i=e.getCachedFile(n.thumbLocation),o=++s;if(i?(a.src=i,r()):a.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",n.fullPhoto.location){var c;if(n.fullPhoto.size){var l={_:"inputFileLocation",volume_id:n.fullPhoto.location.volume_id,local_id:n.fullPhoto.location.local_id,secret:n.fullPhoto.location.secret};c=e.downloadFile(n.fullPhoto.location.dc_id,l,n.fullPhoto.size)}else c=e.downloadSmallFile(n.fullPhoto.location);n.progress={enabled:!0,percent:0},c.then(function(e){o==s&&(n.progress.enabled=!1,a.src=e,r())},function(e){console.log("Download image failed",e,n.fullPhoto.location),n.progress.enabled=!1,n.error=e&&"FS_BROWSER_UNSUPPORTED"==e.type?{html:t("error_browser_no_local_file_system_image_md",{"moz-link":'{1}',"chrome-link":'{1}',"telegram-link":'{1}'})}:{text:t("error_image_download_failed"),error:e}},function(e){n.progress.percent=Math.max(1,Math.floor(100*e.done/e.total))})}}),r()}return{link:n,transclude:!0,templateUrl:templateUrl("full_photo"),scope:{fullPhoto:"=",thumbLocation:"="}}}]).directive("myLoadVideo",["$sce","MtpApiFileManager","_",function(e,t,n){function i(i){i.progress={enabled:!0,percent:1},i.player={};var a,o={_:"inputVideoFileLocation",id:i.video.id,access_hash:i.video.access_hash},r=!1;if(navigator.plugins)for(a=0;a=0&&(r=!0);var s=t.downloadFile(i.video.dc_id,o,i.video.size,{mime:"video/mp4"});s.then(function(t){i.progress.enabled=!1,i.player.hasQuicktime=r,i.player.quicktime=!1,i.player.src=e.trustAsResourceUrl(t),i.$emit("ui_height")},function(e){console.log("Download video failed",e,i.video),i.progress.enabled=!1,i.player.src="",i.error=e&&"FS_BROWSER_UNSUPPORTED"==e.type?{html:n("error_browser_no_local_file_system_video_md",{"moz-link":'{1}',"chrome-link":'{1}',"telegram-link":'{1}'})}:{text:n("error_video_download_failed"),error:e}},function(e){i.progress.percent=Math.max(1,Math.floor(100*e.done/e.total))}),i.$emit("ui_height"),i.$on("$destroy",function(){s.cancel()})}return{link:i,transclude:!0,templateUrl:templateUrl("full_video"),scope:{video:"="}}}]).directive("myLoadGif",["$rootScope","MtpApiFileManager",function(e,t){function n(n){var i=!1,a={_:"inputDocumentFileLocation",id:n.document.id,access_hash:n.document.access_hash};n.isActive=!1,n.document.url=t.getCachedFile(a),n.toggle=function(o){return checkClick(o,!0)?(e.downloadDoc(n.document.id),!1):n.document.url?(n.isActive=!n.isActive,void n.$emit("ui_height")):i?(i.cancel(),void(i=!1)):(n.document.progress={enabled:!0,percent:1,total:n.document.size},i=t.downloadFile(n.document.dc_id,a,n.document.size,null,{mime:n.document.mime_type}),void i.then(function(e){n.document.url=e,n.isActive=!0,delete n.document.progress,console.log("file save done"),n.$emit("ui_height")},function(){n.document.progress.enabled=!1},function(e){console.log("dl progress",e),n.document.progress.done=e.done,n.document.progress.percent=Math.max(1,Math.floor(100*e.done/e.total))}))}}return{link:n,templateUrl:templateUrl("full_gif"),scope:{document:"="}}}]).directive("myMapPoint",["ExternalResourcesManager",function(e){function t(t,n){var i="AIzaSyC32ij28dCa0YzEV_HqbWfIwTZQql-RNS0",a="https://maps.googleapis.com/maps/api/staticmap?sensor=false¢er="+t.point.lat+","+t.point["long"]+"&zoom=13&size=200x100&scale=2&key="+i;e.downloadImage(a).then(function(e){n.append('')}),n.attr("href","https://maps.google.com/?q="+t.point.lat+","+t.point["long"]),n.attr("target","_blank")}return{link:t,scope:{point:"="}}}]).directive("myLoadingDots",["$interval",function(){function e(e,n){n.html(t(n[0])?'
':"...")}function t(e){if(void 0===n&&(n=void 0!==e.style.animationName,n===!1)){var t,i="Webkit Moz O ms Khtml".split(" ");for(t=0;t=n.scrollHeight-n.clientHeight-300&&(i=!0,e.$apply(function(){e.slice.limit+=e.slice.limitDelta||20}),onContentLoaded(function(){i=!1,$(t).nanoScroller()}))})}return{link:e,scope:!0}}).directive("myModalPosition",["$window","$timeout",function(e,t){function n(n,i,a){var o=function(){if(!Config.Mobile||!$(i[0].parentNode.parentNode.parentNode).hasClass("mobile_modal")){var e=i[0].parentNode.offsetHeight,n=i[0].parentNode.parentNode.parentNode.offsetHeight;n>e?$(i[0].parentNode).css("marginTop",(n-e)/2):$(i[0].parentNode).css("marginTop",""),"no"!=a.animation&&t(function(){$(i[0].parentNode).addClass("modal-content-animated")},300)}};onContentLoaded(o),$(e).on("resize",o),n.$on("ui_height",function(){onContentLoaded(o)})}return{link:n}}]).directive("myVerticalPosition",["$window","$timeout",function(e){function t(t,n,i){var a="true"===i.padding,o=0,r=function(){var r=n[0].offsetHeight,s=r-(r&&a?2*o:0),c=$(e).height(),l=i.myVerticalPosition&&parseFloat(i.myVerticalPosition)||.5,d=c>s?parseInt((c-s)*l):"",u=a?{paddingTop:d,paddingBottom:d}:{marginTop:d,marginBottom:d};n.css(u),n.addClass("vertical-aligned"),o!==d&&t.$emit("ui_height"),o=d};onContentLoaded(r),$(e).on("resize",r),t.$on("ui_height",function(){onContentLoaded(r)})}return{link:t}}]).directive("myUserLink",["$timeout","$rootScope","AppUsersManager",function(e,t,n){function i(e,i,a){var o=e.$eval(a.myUserLink),r=n.getUser(o);i.html((r[a.short&&e.$eval(a.short)?"rFirstName":"rFullName"]||"").valueOf()),"A"==i[0].tagName&&i.on("click",function(){t.openUser(o)}),a.color&&e.$eval(a.color)&&i.addClass("user_color_"+r.num)}return{link:i}}]).directive("myUserStatus",["$filter","$rootScope","AppUsersManager",function(e,t,n){function i(){angular.forEach(s,function(e){e()})}function a(e,i,a){var c,l=r++,d=function(){var e=n.getUser(c);i.html(o(e)).toggleClass("status_online",e.status&&"userStatusOnline"==e.status._)};e.$watch(a.myUserStatus,function(e){c=e,d()}),t.$on("user_update",function(e,t){c==t&&d()}),s[l]=d,e.$on("$destroy",function(){delete s[l]})}var o=e("userStatus"),r=0,s={};return setInterval(i,9e4),{link:a}}]).directive("myUserPhotolink",["$rootScope","AppUsersManager",function(e,t){function n(n,i,a){n.photo=t.getUserPhoto(n.userID,"User"),(n.showStatus=a.status&&n.$eval(a.status))&&(n.user=t.getUser(n.userID)),"A"==i[0].tagName&&i.on("click",function(){e.openUser(n.userID)}),a.imgClass&&$(i[0].firstChild).addClass(a.imgClass)}return{link:n,scope:{userID:"=myUserPhotolink"},template:''}}]).directive("myAudioPlayer",["$sce","$timeout","$q","FileManager","MtpApiFileManager",function(e,t,n,i,a){function o(t){var n={_:"document"==t._?"inputDocumentFileLocation":"inputAudioFileLocation",id:t.id,access_hash:t.access_hash};t.progress={enabled:!0,percent:1,total:t.size};var i=a.downloadFile(t.dc_id,n,t.size,{mime:"audio/ogg"});return t.progress.cancel=i.cancel,i.then(function(n){delete t.progress,t.rawUrl=n,t.url=e.trustAsResourceUrl(n)},function(e){console.log("audio download failed",e),t.progress.enabled=!1},function(e){console.log("audio dl progress",e),t.progress.done=e.done,t.progress.percent=Math.max(1,Math.floor(100*e.done/e.total))})}function r(e){return e===c?!1:(c&&c.pause(),void(c=e))}function s(e){e.mediaPlayer={},e.download=function(){(e.audio.rawUrl?n.when():o(e.audio)).then(function(){i.download(e.audio.rawUrl,e.audio.mime_type||"audio/ogg",e.audio.file_name||"audio.ogg")})},e.togglePlay=function(){e.audio.url?(r(e.mediaPlayer.player),e.mediaPlayer.player.playPause()):e.audio.progress&&e.audio.progress.enabled?e.audio.progress.cancel():o(e.audio).then(function(){onContentLoaded(function(){r(e.mediaPlayer.player),e.mediaPlayer.player.play()})})}}var c=!1;return{link:s,scope:{audio:"="},templateUrl:templateUrl("audio_player")}}]),angular.module("myApp.directives").directive("myDialogsListMobile",["$window","$timeout",function(e,t){function n(n,i,a){function o(){return d&&d.offsetHeight||(d=$(l)[0]),a.modal?void $(i).css({height:$(e).height()-(d?d.offsetHeight:58)-46}):(c&&c.offsetHeight||(c=$(".tg_page_head")[0]),r&&r.offsetHeight||(r=$(".im_dialogs_col_wrap")[0]),void $(i).css({height:$(e).height()-(c?c.offsetHeight:46)-(d?d.offsetHeight:58)-parseInt($(r).css("paddingBottom")||0)}))}var r=$(".im_dialogs_col_wrap")[0],s=i[0],c=$(".tg_page_head")[0],l=a.modal?".mobile_modal_body .im_dialogs_panel":".im_dialogs_panel",d=$(l)[0],u=!1,p=!1;n.$on("ui_dialogs_tabs",function(e,t){u=t,o()}),n.$on("ui_dialogs_search",o),n.$on("ui_dialogs_update",o),n.$on("ui_dialogs_append",function(){onContentLoaded(function(){p=!1,t(function(){$(s).trigger("scroll")})})}),n.$on("ui_dialogs_change",function(){onContentLoaded(function(){p=!1,t(function(){$(s).trigger("scroll")})})}),$(s).on("scroll",function(){i.is(":visible")&&!p&&s.scrollTop>=s.scrollHeight-s.clientHeight-300&&(n.$emit("dialogs_need_more"),p=!0)}),$(e).on("resize",o),o(),setTimeout(o,1e3)}return{link:n}}]).directive("myHistoryMobile",["$window","$timeout","$rootScope","$transition",function(e,t){function n(n,i){function a(){var e,n;if(n=$(".im_message_focus:visible",c)[0]){var i=c.clientHeight,a=c.scrollTop,o=n.offsetTop,r=n.clientHeight;(!a||o>a+i||a>o+r)&&(c.scrollTop=Math.max(0,o-Math.floor(i/2)+26)),g=!1}else(e=$(".im_message_unread_split:visible",c)[0])?(c.scrollTop=Math.max(0,e.offsetTop-52),g=!1):(c.scrollTop=c.scrollHeight,g=!0);t(function(){$(c).trigger("scroll"),_=c.scrollTop})}function o(t){if(i.is(":visible")||$(i[0].parentNode.parentNode).is(":visible")){$(u).is(":visible")&&$(u).css({height:$(m).height()}),p&&p.offsetHeight||(p=$(".tg_page_head")[0]);var n=$(e).height()-d.offsetHeight-(p?p.offsetHeight:46);$(s).css({height:n}),r(),t!==!0&&g&&onContentLoaded(function(){c.scrollTop=c.scrollHeight})}}function r(){return}var s=$(".im_history_wrap",i)[0],c=($(".im_history_messages",i)[0],$(".im_history_scrollable_wrap",i)[0]),l=$(".im_history_scrollable",i)[0],d=$(".im_bottom_panel_wrap",i)[0],u=$(".im_send_form_wrap",i)[0],p=$(".tg_page_head")[0],m=$(".im_send_form",i)[0],h=!1,f=!1;onContentLoaded(function(){c.scrollTop=c.scrollHeight}),n.$on("ui_history_append_new",function(e,t){if(g||t.my){var n=parseInt($(c).css("paddingRight"));$(c).addClass("im_history_to_bottom"),$(l).css({bottom:0,marginLeft:-Math.ceil(n/2)}),onContentLoaded(function(){$(c).removeClass("im_history_to_bottom"),$(l).css({bottom:"",marginLeft:""}),c.scrollTop=c.scrollHeight,r()})}}),n.$on("ui_history_change",function(){var e=parseInt($(c).css("paddingRight"));$(c).addClass("im_history_to_bottom"),$(l).css({bottom:0,marginLeft:-Math.ceil(e/2)}),onContentLoaded(function(){$(c).removeClass("im_history_to_bottom"),$(l).css({bottom:"",marginLeft:""}),o(!0),h=!1,f=!1,a()})}),n.$on("ui_history_change_scroll",function(){onContentLoaded(a)}),n.$on("ui_history_focus",function(){g||(c.scrollTop=c.scrollHeight,g=!0)}),n.$on("ui_history_prepend",function(){var e=c.scrollHeight,i=c.scrollTop,o=parseInt($(c).css("paddingRight")),s=c.clientHeight;$(c).addClass("im_history_to_bottom"),c.scrollHeight,$(l).css({bottom:-(e-i-s),marginLeft:-Math.ceil(o/2)});var d=function(){$(c).removeClass("im_history_to_bottom"),$(l).css({bottom:"",marginLeft:""}),_>=0?a():c.scrollTop=i+c.scrollHeight-e,r(),h=!1,t(function(){c.scrollHeight!=e&&$(c).trigger("scroll")}),clearTimeout(u),p()},u=setTimeout(d,0),p=n.$on("$viewContentLoaded",d)}),n.$on("ui_history_append",function(){var e=c.scrollHeight;onContentLoaded(function(){g=!1,r(),f=!1,_>=0&&a(),t(function(){c.scrollHeight!=e&&$(c).trigger("scroll")})})}),n.$on("ui_panel_update",function(){onContentLoaded(function(){o(),n.$broadcast("ui_message_send"),t(function(){$(c).trigger("scroll")})})}),n.$on("ui_selection_clear",function(){window.getSelection?window.getSelection().empty?window.getSelection().empty():window.getSelection().removeAllRanges&&window.getSelection().removeAllRanges():document.selection&&document.selection.empty()}),n.$on("ui_editor_resize",o),n.$on("ui_height",function(){onContentLoaded(o)});var g=!0,_=-1;$(c).on("scroll",function(){if(i.is(":visible")&&!$(c).hasClass("im_history_to_bottom")){var e=c.scrollTop;g=e>=c.scrollHeight-c.clientHeight,_>=0&&_!=e&&(_=-1),!h&&300>=e?(h=!0,n.$emit("history_need_more")):!f&&e>=c.scrollHeight-c.clientHeight-300&&(f=!0,n.$emit("history_need_less"))}}),$(e).on("resize",o),o(),onContentLoaded(o)}return{link:n}}]).directive("myContactsListMobile",["$window","$timeout",function(e){function t(t,n){function i(){$(n).css({height:$(e).height()-(o&&o.offsetHeight||0)-(a&&a.offsetHeight||0)-64})}var a=$(".contacts_modal_search")[0],o=$(".contacts_modal_panel")[0];$(e).on("resize",i),t.$on("contacts_change",function(){onContentLoaded(i)}),onContentLoaded(i)}return{link:t}}]).directive("myCountriesListMobile",["$window","$timeout",function(e){function t(t,n){function i(){$(n).css({height:$(e).height()-(o&&o.offsetHeight||0)-(a&&a.offsetHeight||0)-64})}var a=$(".countries_modal_search")[0],o=$(".countries_modal_panel")[0];$(e).on("resize",i),onContentLoaded(i)}return{link:t}}]).directive("myInfiniteScrollerMobile",function(){function e(e,t){var n=t[0],i=!1;$(n).on("scroll",function(){t.is(":visible")&&!i&&n.scrollTop>=n.scrollHeight-n.clientHeight-300&&(i=!0,e.$apply(function(){e.slice.limit+=e.slice.limitDelta||20 }),onContentLoaded(function(){i=!1}))})}return{link:e,scope:!0}}); \ No newline at end of file diff --git a/js/locales/en-us.json b/js/locales/en-us.json index 25d311b8..64c0ca8d 100644 --- a/js/locales/en-us.json +++ b/js/locales/en-us.json @@ -341,8 +341,7 @@ "phonebook_modal_submit": "Import contacts", "welcome_header_md": "**Telegram** Web", - "welcome_text_1_md": "This is an unofficial web-client for the **Telegram Messenger**.", - "welcome_text_2_md": "It's still an **alpha-version** and may not be 200% reliable", + "welcome_text_1_md": "The official **web client** for Telegram.", "welcome_start_messaging": "Start Messaging", "welcome_fast_messaging_header": "Fast messaging", "welcome_fast_messaging_text": "Send messages with rich emoji support right from your desktop or laptop computer", diff --git a/webogram.appcache b/webogram.appcache index e53eb609..54375d2c 100644 --- a/webogram.appcache +++ b/webogram.appcache @@ -1,5 +1,5 @@ CACHE MANIFEST -# Time: Wed Oct 15 2014 22:22:13 GMT+0400 (MSK) +# Time: Wed Oct 15 2014 23:29:16 GMT+0400 (MSK) CACHE: