function BigInteger(e,t,n){null!=e&&("number"==typeof e?this.fromNumber(e,t,n):null==t&&"string"!=typeof e?this.fromString(e,256):this.fromString(e,t))}function nbi(){return new BigInteger(null)}function am1(e,t,n,i,r,o){for(;--o>=0;){var a=t*this[e++]+n[i]+r;r=Math.floor(a/67108864),n[i++]=67108863&a}return r}function am2(e,t,n,i,r,o){for(var a=32767&t,s=t>>15;--o>=0;){var c=32767&this[e],l=this[e++]>>15,u=s*c+l*a;c=a*c+((32767&u)<<15)+n[i]+(1073741823&r),r=(c>>>30)+(u>>>15)+s*l+(r>>>30),n[i++]=1073741823&c}return r}function am3(e,t,n,i,r,o){for(var a=16383&t,s=t>>14;--o>=0;){var c=16383&this[e],l=this[e++]>>14,u=s*c+l*a;c=a*c+((16383&u)<<14)+n[i]+r,r=(c>>28)+(u>>14)+s*l,n[i++]=268435455&c}return r}function int2char(e){return BI_RM.charAt(e)}function intAt(e,t){var n=BI_RC[e.charCodeAt(t)];return null==n?-1:n}function bnpCopyTo(e){for(var t=this.t-1;t>=0;--t)e[t]=this[t];e.t=this.t,e.s=this.s}function bnpFromInt(e){this.t=1,this.s=0>e?-1:0,e>0?this[0]=e:-1>e?this[0]=e+this.DV:this.t=0}function nbv(e){var t=nbi();return t.fromInt(e),t}function bnpFromString(e,t,n){var i;if(16==t)i=4;else if(8==t)i=3;else if(256==t)i=8;else if(2==t)i=1;else if(32==t)i=5;else{if(4!=t)return void this.fromRadix(e,t);i=2}this.t=0,this.s=0;for(var r=e.length,o=!1,a=0;--r>=0;){var s=8==i?255&e[r]:intAt(e,r);0>s?"-"==e.charAt(r)&&(o=!0):(o=!1,0==a?this[this.t++]=s:a+i>this.DB?(this[this.t-1]|=(s&(1<>this.DB-a):this[this.t-1]|=s<=this.DB&&(a-=this.DB))}8==i&&0!=(128&e[0])&&n&&(this.s=-1,a>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==e;)--this.t}function bnToString(e){if(this.s<0)return"-"+this.negate().toString(e);var t;if(16==e)t=4;else if(8==e)t=3;else if(2==e)t=1;else if(32==e)t=5;else{if(4!=e)return this.toRadix(e);t=2}var n,i=(1<0)for(s>s)>0&&(r=!0,o=int2char(n));a>=0;)t>s?(n=(this[a]&(1<>(s+=this.DB-t)):(n=this[a]>>(s-=t)&i,0>=s&&(s+=this.DB,--a)),n>0&&(r=!0),r&&(o+=int2char(n));return r?o:"0"}function bnNegate(){var e=nbi();return BigInteger.ZERO.subTo(this,e),e}function bnAbs(){return this.s<0?this.negate():this}function bnCompareTo(e){var t=this.s-e.s;if(0!=t)return t;var n=this.t;if(t=n-e.t,0!=t)return this.s<0?-t:t;for(;--n>=0;)if(0!=(t=this[n]-e[n]))return t;return 0}function nbits(e){var t,n=1;return 0!=(t=e>>>16)&&(e=t,n+=16),0!=(t=e>>8)&&(e=t,n+=8),0!=(t=e>>4)&&(e=t,n+=4),0!=(t=e>>2)&&(e=t,n+=2),0!=(t=e>>1)&&(e=t,n+=1),n}function bnBitLength(){return this.t<=0?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnpDLShiftTo(e,t){var n;for(n=this.t-1;n>=0;--n)t[n+e]=this[n];for(n=e-1;n>=0;--n)t[n]=0;t.t=this.t+e,t.s=this.s}function bnpDRShiftTo(e,t){for(var n=e;n=0;--n)t[n+a+1]=this[n]>>r|s,s=(this[n]&o)<=0;--n)t[n]=0;t[a]=s,t.t=this.t+a+1,t.s=this.s,t.clamp()}function bnpRShiftTo(e,t){t.s=this.s;var n=Math.floor(e/this.DB);if(n>=this.t)return void(t.t=0);var i=e%this.DB,r=this.DB-i,o=(1<>i;for(var a=n+1;a>i;i>0&&(t[this.t-n-1]|=(this.s&o)<n;)i+=this[n]-e[n],t[n++]=i&this.DM,i>>=this.DB;if(e.t>=this.DB;i+=this.s}else{for(i+=this.s;n>=this.DB;i-=e.s}t.s=0>i?-1:0,-1>i?t[n++]=this.DV+i:i>0&&(t[n++]=i),t.t=n,t.clamp()}function bnpMultiplyTo(e,t){var n=this.abs(),i=e.abs(),r=n.t;for(t.t=r+i.t;--r>=0;)t[r]=0;for(r=0;r=0;)e[n]=0;for(n=0;n=t.DV&&(e[n+t.t]-=t.DV,e[n+t.t+1]=1)}e.t>0&&(e[e.t-1]+=t.am(n,t[n],e,2*n,0,1)),e.s=0,e.clamp()}function bnpDivRemTo(e,t,n){var i=e.abs();if(!(i.t<=0)){var r=this.abs();if(r.t0?(i.lShiftTo(c,o),r.lShiftTo(c,n)):(i.copyTo(o),r.copyTo(n));var l=o.t,u=o[l-1];if(0!=u){var p=u*(1<1?o[l-2]>>this.F2:0),d=this.FV/p,f=(1<=0&&(n[n.t++]=1,n.subTo(y,n)),BigInteger.ONE.dlShiftTo(l,y),y.subTo(o,o);o.t=0;){var v=n[--g]==u?this.DM:Math.floor(n[g]*d+(n[g-1]+h)*f);if((n[g]+=o.am(0,v,n,m,0,l))0&&n.rShiftTo(c,n),0>a&&BigInteger.ZERO.subTo(n,n)}}}function bnMod(e){var t=nbi();return this.abs().divRemTo(e,null,t),this.s<0&&t.compareTo(BigInteger.ZERO)>0&&e.subTo(t,t),t}function Classic(e){this.m=e}function cConvert(e){return e.s<0||e.compareTo(this.m)>=0?e.mod(this.m):e}function cRevert(e){return e}function cReduce(e){e.divRemTo(this.m,null,e)}function cMulTo(e,t,n){e.multiplyTo(t,n),this.reduce(n)}function cSqrTo(e,t){e.squareTo(t),this.reduce(t)}function bnpInvDigit(){if(this.t<1)return 0;var e=this[0];if(0==(1&e))return 0;var t=3&e;return t=t*(2-(15&e)*t)&15,t=t*(2-(255&e)*t)&255,t=t*(2-((65535&e)*t&65535))&65535,t=t*(2-e*t%this.DV)%this.DV,t>0?this.DV-t:-t}function Montgomery(e){this.m=e,this.mp=e.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<0&&this.m.subTo(t,t),t}function montRevert(e){var t=nbi();return e.copyTo(t),this.reduce(t),t}function montReduce(e){for(;e.t<=this.mt2;)e[e.t++]=0;for(var t=0;t>15)*this.mpl&this.um)<<15)&e.DM;for(n=t+this.m.t,e[n]+=this.m.am(0,i,e,t,0,this.m.t);e[n]>=e.DV;)e[n]-=e.DV,e[++n]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)}function montSqrTo(e,t){e.squareTo(t),this.reduce(t)}function montMulTo(e,t,n){e.multiplyTo(t,n),this.reduce(n)}function bnpIsEven(){return 0==(this.t>0?1&this[0]:this.s)}function bnpExp(e,t){if(e>4294967295||1>e)return BigInteger.ONE;var n=nbi(),i=nbi(),r=t.convert(this),o=nbits(e)-1;for(r.copyTo(n);--o>=0;)if(t.sqrTo(n,i),(e&1<0)t.mulTo(i,r,n);else{var a=n;n=i,i=a}return t.revert(n)}function bnModPowInt(e,t){var n;return n=256>e||t.isEven()?new Classic(t):new Montgomery(t),this.exp(e,n)}function bnClone(){var e=nbi();return this.copyTo(e),e}function bnIntValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<>24}function bnShortValue(){return 0==this.t?this.s:this[0]<<16>>16}function bnpChunkSize(e){return Math.floor(Math.LN2*this.DB/Math.log(e))}function bnSigNum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function bnpToRadix(e){if(null==e&&(e=10),0==this.signum()||2>e||e>36)return"0";var t=this.chunkSize(e),n=Math.pow(e,t),i=nbv(n),r=nbi(),o=nbi(),a="";for(this.divRemTo(i,r,o);r.signum()>0;)a=(n+o.intValue()).toString(e).substr(1)+a,r.divRemTo(i,r,o);return o.intValue().toString(e)+a}function bnpFromRadix(e,t){this.fromInt(0),null==t&&(t=10);for(var n=this.chunkSize(t),i=Math.pow(t,n),r=!1,o=0,a=0,s=0;sc?"-"==e.charAt(s)&&0==this.signum()&&(r=!0):(a=t*a+c,++o>=n&&(this.dMultiply(i),this.dAddOffset(a,0),o=0,a=0))}o>0&&(this.dMultiply(Math.pow(t,o)),this.dAddOffset(a,0)),r&&BigInteger.ZERO.subTo(this,this)}function bnpFromNumber(e,t,n){if("number"==typeof t)if(2>e)this.fromInt(1);else for(this.fromNumber(e,n),this.testBit(e-1)||this.bitwiseTo(BigInteger.ONE.shiftLeft(e-1),op_or,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(t);)this.dAddOffset(2,0),this.bitLength()>e&&this.subTo(BigInteger.ONE.shiftLeft(e-1),this);else{var i=new Array,r=7&e;i.length=(e>>3)+1,t.nextBytes(i),r>0?i[0]&=(1<0)for(r>r)!=(this.s&this.DM)>>r&&(n[o++]=i|this.s<=0;)8>r?(i=(this[t]&(1<>(r+=this.DB-8)):(i=this[t]>>(r-=8)&255,0>=r&&(r+=this.DB,--t)),e&&0!=(128&i)&&(i|=-256),0==o&&(128&this.s)!=(128&i)&&++o,(o>0||i!=this.s)&&(n[o++]=i);return n}function bnEquals(e){return 0==this.compareTo(e)}function bnMin(e){return this.compareTo(e)<0?this:e}function bnMax(e){return this.compareTo(e)>0?this:e}function bnpBitwiseTo(e,t,n){var i,r,o=Math.min(e.t,this.t);for(i=0;o>i;++i)n[i]=t(this[i],e[i]);if(e.te?this.rShiftTo(-e,t):this.lShiftTo(e,t),t}function bnShiftRight(e){var t=nbi();return 0>e?this.lShiftTo(-e,t):this.rShiftTo(e,t),t}function lbit(e){if(0==e)return-1;var t=0;return 0==(65535&e)&&(e>>=16,t+=16),0==(255&e)&&(e>>=8,t+=8),0==(15&e)&&(e>>=4,t+=4),0==(3&e)&&(e>>=2,t+=2),0==(1&e)&&++t,t}function bnGetLowestSetBit(){for(var e=0;e=this.t?0!=this.s:0!=(this[t]&1<n;)i+=this[n]+e[n],t[n++]=i&this.DM,i>>=this.DB;if(e.t>=this.DB;i+=this.s}else{for(i+=this.s;n>=this.DB;i+=e.s}t.s=0>i?-1:0,i>0?t[n++]=i:-1>i&&(t[n++]=this.DV+i),t.t=n,t.clamp()}function bnAdd(e){var t=nbi();return this.addTo(e,t),t}function bnSubtract(e){var t=nbi();return this.subTo(e,t),t}function bnMultiply(e){var t=nbi();return this.multiplyTo(e,t),t}function bnSquare(){var e=nbi();return this.squareTo(e),e}function bnDivide(e){var t=nbi();return this.divRemTo(e,t,null),t}function bnRemainder(e){var t=nbi();return this.divRemTo(e,null,t),t}function bnDivideAndRemainder(e){var t=nbi(),n=nbi();return this.divRemTo(e,t,n),new Array(t,n)}function bnpDMultiply(e){this[this.t]=this.am(0,e-1,this,0,0,this.t),++this.t,this.clamp()}function bnpDAddOffset(e,t){if(0!=e){for(;this.t<=t;)this[this.t++]=0;for(this[t]+=e;this[t]>=this.DV;)this[t]-=this.DV,++t>=this.t&&(this[this.t++]=0),++this[t]}}function NullExp(){}function nNop(e){return e}function nMulTo(e,t,n){e.multiplyTo(t,n)}function nSqrTo(e,t){e.squareTo(t)}function bnPow(e){return this.exp(e,new NullExp)}function bnpMultiplyLowerTo(e,t,n){var i=Math.min(this.t+e.t,t);for(n.s=0,n.t=i;i>0;)n[--i]=0;var r;for(r=n.t-this.t;r>i;++i)n[i+this.t]=this.am(0,e[i],n,i,0,this.t);for(r=Math.min(e.t,t);r>i;++i)this.am(0,e[i],n,i,0,t-i);n.clamp()}function bnpMultiplyUpperTo(e,t,n){--t;var i=n.t=this.t+e.t-t;for(n.s=0;--i>=0;)n[i]=0;for(i=Math.max(t-this.t,0);i2*this.m.t)return e.mod(this.m);if(e.compareTo(this.m)<0)return e;var t=nbi();return e.copyTo(t),this.reduce(t),t}function barrettRevert(e){return e}function barrettReduce(e){for(e.drShiftTo(this.m.t-1,this.r2),e.t>this.m.t+1&&(e.t=this.m.t+1,e.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);e.compareTo(this.r2)<0;)e.dAddOffset(1,this.m.t+1);for(e.subTo(this.r2,e);e.compareTo(this.m)>=0;)e.subTo(this.m,e)}function barrettSqrTo(e,t){e.squareTo(t),this.reduce(t)}function barrettMulTo(e,t,n){e.multiplyTo(t,n),this.reduce(n)}function bnModPow(e,t){var n,i,r=e.bitLength(),o=nbv(1);if(0>=r)return o;n=18>r?1:48>r?3:144>r?4:768>r?5:6,i=8>r?new Classic(t):t.isEven()?new Barrett(t):new Montgomery(t);var a=new Array,s=3,c=n-1,l=(1<1){var u=nbi();for(i.sqrTo(a[1],u);l>=s;)a[s]=nbi(),i.mulTo(u,a[s-2],a[s]),s+=2}var p,d,f=e.t-1,h=!0,g=nbi();for(r=nbits(e[f])-1;f>=0;){for(r>=c?p=e[f]>>r-c&l:(p=(e[f]&(1<0&&(p|=e[f-1]>>this.DB+r-c)),s=n;0==(1&p);)p>>=1,--s;if((r-=s)<0&&(r+=this.DB,--f),h)a[p].copyTo(o),h=!1;else{for(;s>1;)i.sqrTo(o,g),i.sqrTo(g,o),s-=2;s>0?i.sqrTo(o,g):(d=o,o=g,g=d),i.mulTo(g,a[p],o)}for(;f>=0&&0==(e[f]&1<o)return t;for(o>r&&(o=r),o>0&&(t.rShiftTo(o,t),n.rShiftTo(o,n));t.signum()>0;)(r=t.getLowestSetBit())>0&&t.rShiftTo(r,t),(r=n.getLowestSetBit())>0&&n.rShiftTo(r,n),t.compareTo(n)>=0?(t.subTo(n,t),t.rShiftTo(1,t)):(n.subTo(t,n),n.rShiftTo(1,n));return o>0&&n.lShiftTo(o,n),n}function bnpModInt(e){if(0>=e)return 0;var t=this.DV%e,n=this.s<0?e-1:0;if(this.t>0)if(0==t)n=this[0]%e;else for(var i=this.t-1;i>=0;--i)n=(t*n+this[i])%e;return n}function bnModInverse(e){var t=e.isEven();if(this.isEven()&&t||0==e.signum())return BigInteger.ZERO;for(var n=e.clone(),i=this.clone(),r=nbv(1),o=nbv(0),a=nbv(0),s=nbv(1);0!=n.signum();){for(;n.isEven();)n.rShiftTo(1,n),t?(r.isEven()&&o.isEven()||(r.addTo(this,r),o.subTo(e,o)),r.rShiftTo(1,r)):o.isEven()||o.subTo(e,o),o.rShiftTo(1,o);for(;i.isEven();)i.rShiftTo(1,i),t?(a.isEven()&&s.isEven()||(a.addTo(this,a),s.subTo(e,s)),a.rShiftTo(1,a)):s.isEven()||s.subTo(e,s),s.rShiftTo(1,s);n.compareTo(i)>=0?(n.subTo(i,n),t&&r.subTo(a,r),o.subTo(s,o)):(i.subTo(n,i),t&&a.subTo(r,a),s.subTo(o,s))}return 0!=i.compareTo(BigInteger.ONE)?BigInteger.ZERO:s.compareTo(e)>=0?s.subtract(e):s.signum()<0?(s.addTo(e,s),s.signum()<0?s.add(e):s):s}function bnIsProbablePrime(e){var t,n=this.abs();if(1==n.t&&n[0]<=lowprimes[lowprimes.length-1]){for(t=0;ti;)i*=lowprimes[r++];for(i=n.modInt(i);r>t;)if(i%lowprimes[t++]==0)return!1}return n.millerRabin(e)}function bnpMillerRabin(e){var t=this.subtract(BigInteger.ONE),n=t.getLowestSetBit();if(0>=n)return!1;var i=t.shiftRight(n);e=e+1>>1,e>lowprimes.length&&(e=lowprimes.length);for(var r=nbi(),o=0;e>o;++o){r.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);var a=r.modPow(i,this);if(0!=a.compareTo(BigInteger.ONE)&&0!=a.compareTo(t)){for(var s=1;s++>8&255,rng_pool[rng_pptr++]^=e>>16&255,rng_pool[rng_pptr++]^=e>>24&255,rng_pptr>=rng_psize&&(rng_pptr-=rng_psize)}function rng_seed_time(){rng_seed_int((new Date).getTime())}function rng_get_byte(){if(null==rng_state){for(rng_seed_time(),rng_state=prng_newstate(),rng_state.init(rng_pool),rng_pptr=0;rng_pptrt;++t)this.S[t]=t;for(n=0,t=0;256>t;++t)n=n+this.S[t]+e[t%e.length]&255,i=this.S[t],this.S[t]=this.S[n],this.S[n]=i;this.i=0,this.j=0}function ARC4next(){var e;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,e=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=e,this.S[e+this.S[this.i]&255]}function prng_newstate(){return new Arcfour}function bigint(e){return new BigInteger(e.toString(16),16)}function bigStringInt(e){return new BigInteger(e,10)}function dHexDump(e){for(var t=[],n=0;nt;t+=2)i.push(parseInt(e.substr(t,2),16));return i}function bytesToBase64(e){for(var t,n="",i=e.length,r=0,o=0;i>o;o++)t=o%3,r|=e[o]<<(16>>>t&24),(2===t||i-o===1)&&(n+=String.fromCharCode(uint6ToBase64(r>>>18&63),uint6ToBase64(r>>>12&63),uint6ToBase64(r>>>6&63),uint6ToBase64(63&r)),r=0);return n.replace(/A(?=A$|$)/g,"=")}function uint6ToBase64(e){return 26>e?e+65:52>e?e+71:62>e?e-4:62===e?43:63===e?47:65}function bytesCmp(e,t){var n=e.length;if(n!=t.length)return!1;for(var i=0;n>i;i++)if(e[i]!=t[i])return!1;return!0}function bytesXor(e,t){for(var n=e.length,i=[],r=0;n>r;++r)i[r]=e[r]^t[r];return i}function bytesToWords(e){for(var t=e.length,n=[],i=0;t>i;i++)n[i>>>2]|=e[i]<<24-i%4*8;return new CryptoJS.lib.WordArray.init(n,t)}function bytesFromWords(e){for(var t=e.words,n=e.sigBytes,i=[],r=0;n>r;r++)i.push(t[r>>>2]>>>24-r%4*8&255);return i}function bytesFromBigInt(e,t){for(var n=e.toByteArray();!n[0]&&(!t||n.length>t);)n=n.slice(1);return n}function bytesToArrayBuffer(e){return new Uint8Array(e).buffer}function bytesFromArrayBuffer(e){for(var t=e.byteLength,n=new Uint8Array(e),i=[],r=0;t>r;++r)i[r]=n[r];return i}function longToInts(e){var t=bigStringInt(e).divideAndRemainder(bigint(4294967296));return[t[0].intValue(),t[1].intValue()]}function longToBytes(e){return bytesFromWords({words:longToInts(e),sigBytes:8}).reverse()}function longFromInts(e,t){return bigint(e).shiftLeft(32).add(bigint(t)).toString(10)}function intToUint(e){return e=parseInt(e),0>e&&(e+=4294967296),e}function uintToInt(e){return e>2147483647&&(e-=4294967296),e}function sha1Hash(e){var t=sha1.hash(e,!0);return t}function rsaEncrypt(e,t){var n=255-t.length;if(n>0){var i=new Array(n);(new SecureRandom).nextBytes(i),t=t.concat(i)}var r=new BigInteger(e.modulus,16),o=new BigInteger(e.exponent,16),a=new BigInteger(t),s=a.modPowInt(o,r),c=bytesFromBigInt(s,256);return c}function aesEncrypt(e,t,n){var i=16-e.length%16;if(i>0&&16>i){var r=new Array(i);(new SecureRandom).nextBytes(r),e=e.concat(r)}var o=CryptoJS.AES.encrypt(bytesToWords(e),bytesToWords(t),{iv:bytesToWords(n),padding:CryptoJS.pad.NoPadding,mode:CryptoJS.mode.IGE}).ciphertext,a=bytesFromWords(o);return a}function aesDecrypt(e,t,n){var i=CryptoJS.AES.decrypt({ciphertext:bytesToWords(e)},bytesToWords(t),{iv:bytesToWords(n),padding:CryptoJS.pad.NoPadding,mode:CryptoJS.mode.IGE}),r=bytesFromWords(i);return r}function gzipUncompress(e){var t=new Zlib.Gunzip(e).decompress();return t}function nextRandomInt(e){return Math.floor(Math.random()*e)}function pqPrimeFactorization(e){var t=new BigInteger(e),n=!1;if(console.log("PQ start",e,t.bitLength()),t.bitLength()<=64)try{n=pqPrimeLong(goog.math.Long.fromString(t.toString(16),16))}catch(i){console.error("Pq long Exception",i)}return n===!1&&(n=pqPrimeBigInteger(t)),console.log("PQ finish"),n}function pqPrimeBigInteger(e){for(var t,n=0,i=0;3>i;i++){for(var r=(15&nextRandomInt(128))+17,o=bigint(nextRandomInt(1e9)+1),a=o.clone(),s=1<c;c++){++n;for(var l=o.clone(),u=o.clone(),p=bigint(r);!u.equals(BigInteger.ZERO);)u.and(BigInteger.ONE).equals(BigInteger.ZERO)||(p=p.add(l),p.compareTo(e)>0&&(p=p.subtract(e))),l=l.add(l),l.compareTo(e)>0&&(l=l.subtract(e)),u=u.shiftRight(1);o=p.clone();var d=o.compareTo(a)<0?a.subtract(o):o.subtract(a);if(t=d.gcd(e),!t.equals(BigInteger.ONE))break;0==(c&c-1)&&(a=o.clone())}if(t.compareTo(BigInteger.ONE)>0)break}var f,h,g=e.divide(t);return t.compareTo(g)>0?(f=g,h=t):(f=t,h=g),[bytesFromBigInt(f),bytesFromBigInt(h)]}function gcdLong(e,t){for(;e.notEquals(goog.math.Long.ZERO)&&t.notEquals(goog.math.Long.ZERO);){for(;t.and(goog.math.Long.ONE).equals(goog.math.Long.ZERO);)t=t.shiftRight(1);for(;e.and(goog.math.Long.ONE).equals(goog.math.Long.ZERO);)e=e.shiftRight(1);e.compare(t)>0?e=e.subtract(t):t=t.subtract(e)}return t.equals(goog.math.Long.ZERO)?e:t}function pqPrimeLong(e){for(var t,n=0,i=0;3>i;i++){for(var r=goog.math.Long.fromInt((15&nextRandomInt(128))+17),o=goog.math.Long.fromInt(nextRandomInt(1e9)+1),a=o,s=1<c;c++){++n;for(var l=o,u=o,p=r;u.notEquals(goog.math.Long.ZERO);)u.and(goog.math.Long.ONE).notEquals(goog.math.Long.ZERO)&&(p=p.add(l),p.compare(e)>0&&(p=p.subtract(e))),l=l.add(l),l.compare(e)>0&&(l=l.subtract(e)),u=u.shiftRight(1);o=p;var d=o.compare(a)<0?a.subtract(o):o.subtract(a);if(t=gcdLong(d,e),t.notEquals(goog.math.Long.ONE))break;0==(c&c-1)&&(a=o)}if(t.compare(goog.math.Long.ONE)>0)break}var f,h,g=e.div(t);return t.compare(g)>0?(f=g,h=t):(f=t,h=g),[bytesFromHex(f.toString(16)),bytesFromHex(h.toString(16))]}function TLSerialization(e){return e=e||{},this.maxLength=e.startMaxLength||2048,this.offset=0,this.createBuffer(),this.mtproto=e.mtproto||!1,this}function TLDeserialization(e,t){return t=t||{},this.offset=0,this.override=t.override||{},this.buffer=e,this.intView=new Uint32Array(this.buffer),this.byteView=new Uint8Array(this.buffer),this.mtproto=t.mtproto||!1,this}function dT(){return"["+(((new Date).getTime()-_logTimer)/1e3).toFixed(3)+"]"}function checkClick(e,t){return 1==e.which&&(e.ctrlKey||e.metaKey)||2==e.which?!0:(t||e.preventDefault(),!1)}function checkDragEvent(e){if(!e||e.target&&("IMG"==e.target.tagName||"A"==e.target.tagName))return!1;if(!e.dataTransfer||!e.dataTransfer.types)return!0;for(var t=0;t0&&t-1 in e)}function i(e){var t=Mt[e]={};return ut.each(e.match(dt)||[],function(e,n){t[n]=!0}),t}function r(e,n,i,r){if(ut.acceptData(e)){var o,a,s=ut.expando,c=e.nodeType,l=c?ut.cache:e,u=c?e[s]:e[s]&&s;if(u&&l[u]&&(r||l[u].data)||i!==t||"string"!=typeof n)return u||(u=c?e[s]=tt.pop()||ut.guid++:s),l[u]||(l[u]=c?{}:{toJSON:ut.noop}),("object"==typeof n||"function"==typeof n)&&(r?l[u]=ut.extend(l[u],n):l[u].data=ut.extend(l[u].data,n)),a=l[u],r||(a.data||(a.data={}),a=a.data),i!==t&&(a[ut.camelCase(n)]=i),"string"==typeof n?(o=a[n],null==o&&(o=a[ut.camelCase(n)])):o=a,o}}function o(e,t,n){if(ut.acceptData(e)){var i,r,o=e.nodeType,a=o?ut.cache:e,c=o?e[ut.expando]:ut.expando;if(a[c]){if(t&&(i=n?a[c]:a[c].data)){ut.isArray(t)?t=t.concat(ut.map(t,ut.camelCase)):t in i?t=[t]:(t=ut.camelCase(t),t=t in i?[t]:t.split(" ")),r=t.length;for(;r--;)delete i[t[r]];if(n?!s(i):!ut.isEmptyObject(i))return}(n||(delete a[c].data,s(a[c])))&&(o?ut.cleanData([e],!0):ut.support.deleteExpando||a!=a.window?delete a[c]:a[c]=null)}}}function a(e,n,i){if(i===t&&1===e.nodeType){var r="data-"+n.replace(xt,"-$1").toLowerCase();if(i=e.getAttribute(r),"string"==typeof i){try{i="true"===i?!0:"false"===i?!1:"null"===i?null:+i+""===i?+i:kt.test(i)?ut.parseJSON(i):i}catch(o){}ut.data(e,n,i)}else i=t}return i}function s(e){var t;for(t in e)if(("data"!==t||!ut.isEmptyObject(e[t]))&&"toJSON"!==t)return!1;return!0}function c(){return!0}function l(){return!1}function u(){try{return X.activeElement}catch(e){}}function p(e,t){do e=e[t];while(e&&1!==e.nodeType);return e}function d(e,t,n){if(ut.isFunction(t))return ut.grep(e,function(e,i){return!!t.call(e,i,e)!==n});if(t.nodeType)return ut.grep(e,function(e){return e===t!==n});if("string"==typeof t){if(jt.test(t))return ut.filter(t,e,n);t=ut.filter(t,e)}return ut.grep(e,function(e){return ut.inArray(e,t)>=0!==n})}function f(e){var t=Wt.split("|"),n=e.createDocumentFragment();if(n.createElement)for(;t.length;)n.createElement(t.pop());return n}function h(e,t){return ut.nodeName(e,"table")&&ut.nodeName(1===t.nodeType?t:t.firstChild,"tr")?e.getElementsByTagName("tbody")[0]||e.appendChild(e.ownerDocument.createElement("tbody")):e}function g(e){return e.type=(null!==ut.find.attr(e,"type"))+"/"+e.type,e}function m(e){var t=on.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function y(e,t){for(var n,i=0;null!=(n=e[i]);i++)ut._data(n,"globalEval",!t||ut._data(t[i],"globalEval"))}function v(e,t){if(1===t.nodeType&&ut.hasData(e)){var n,i,r,o=ut._data(e),a=ut._data(t,o),s=o.events;if(s){delete a.handle,a.events={};for(n in s)for(i=0,r=s[n].length;r>i;i++)ut.event.add(t,n,s[n][i])}a.data&&(a.data=ut.extend({},a.data))}}function _(e,t){var n,i,r;if(1===t.nodeType){if(n=t.nodeName.toLowerCase(),!ut.support.noCloneEvent&&t[ut.expando]){r=ut._data(t);for(i in r.events)ut.removeEvent(t,i,r.handle);t.removeAttribute(ut.expando)}"script"===n&&t.text!==e.text?(g(t).text=e.text,m(t)):"object"===n?(t.parentNode&&(t.outerHTML=e.outerHTML),ut.support.html5Clone&&e.innerHTML&&!ut.trim(t.innerHTML)&&(t.innerHTML=e.innerHTML)):"input"===n&&tn.test(e.type)?(t.defaultChecked=t.checked=e.checked,t.value!==e.value&&(t.value=e.value)):"option"===n?t.defaultSelected=t.selected=e.defaultSelected:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}}function b(e,n){var i,r,o=0,a=typeof e.getElementsByTagName!==K?e.getElementsByTagName(n||"*"):typeof e.querySelectorAll!==K?e.querySelectorAll(n||"*"):t;if(!a)for(a=[],i=e.childNodes||e;null!=(r=i[o]);o++)!n||ut.nodeName(r,n)?a.push(r):ut.merge(a,b(r,n));return n===t||n&&ut.nodeName(e,n)?ut.merge([e],a):a}function w(e){tn.test(e.type)&&(e.defaultChecked=e.checked)}function $(e,t){if(t in e)return t;for(var n=t.charAt(0).toUpperCase()+t.slice(1),i=t,r=Mn.length;r--;)if(t=Mn[r]+n,t in e)return t;return i}function S(e,t){return e=t||e,"none"===ut.css(e,"display")||!ut.contains(e.ownerDocument,e)}function C(e,t){for(var n,i,r,o=[],a=0,s=e.length;s>a;a++)i=e[a],i.style&&(o[a]=ut._data(i,"olddisplay"),n=i.style.display,t?(o[a]||"none"!==n||(i.style.display=""),""===i.style.display&&S(i)&&(o[a]=ut._data(i,"olddisplay",T(i.nodeName)))):o[a]||(r=S(i),(n&&"none"!==n||!r)&&ut._data(i,"olddisplay",r?n:ut.css(i,"display"))));for(a=0;s>a;a++)i=e[a],i.style&&(t&&"none"!==i.style.display&&""!==i.style.display||(i.style.display=t?o[a]||"":"none"));return e}function M(e,t,n){var i=vn.exec(t);return i?Math.max(0,i[1]-(n||0))+(i[2]||"px"):t}function k(e,t,n,i,r){for(var o=n===(i?"border":"content")?4:"width"===t?1:0,a=0;4>o;o+=2)"margin"===n&&(a+=ut.css(e,n+Cn[o],!0,r)),i?("content"===n&&(a-=ut.css(e,"padding"+Cn[o],!0,r)),"margin"!==n&&(a-=ut.css(e,"border"+Cn[o]+"Width",!0,r))):(a+=ut.css(e,"padding"+Cn[o],!0,r),"padding"!==n&&(a+=ut.css(e,"border"+Cn[o]+"Width",!0,r)));return a}function x(e,t,n){var i=!0,r="width"===t?e.offsetWidth:e.offsetHeight,o=pn(e),a=ut.support.boxSizing&&"border-box"===ut.css(e,"boxSizing",!1,o);if(0>=r||null==r){if(r=dn(e,t,o),(0>r||null==r)&&(r=e.style[t]),_n.test(r))return r;i=a&&(ut.support.boxSizingReliable||r===e.style[t]),r=parseFloat(r)||0}return r+k(e,t,n||(a?"border":"content"),i,o)+"px"}function T(e){var t=X,n=wn[e];return n||(n=E(e,t),"none"!==n&&n||(un=(un||ut("')}return e.trustAs("html",r)}var o,a=[],s={},c=Config.Emoji,l=18;for(o in c)a.push(c[o][0]),s[c[o][0]]=o;var u=new RegExp("((?:(ftp|https?)://|(?:mailto:)?([A-Za-z0-9._%+-]+@))(\\S*\\.\\S*[^\\s.;,(){}<>\"']))|(\\n)|("+a.join("|")+")","i"),p=/(?:https?:\/\/)?(?:www\.)?youtu(?:|.be|be.com|.b)(?:\/v\/|\/watch\\?v=|e\/|\/watch(?:.+)v=)(.{11})(?:\&[^\s]*)?/;return{wrapRichText:r}}]).service("IdleManager",["$rootScope","$window","$timeout",function(e,t,n){function i(){a||(a=!0,$(t).on("blur focus keydown mousedown touchstart",r))}function r(i){"mousemove"==i.type&&$(t).off("mousemove",r);var a="blur"==i.type||"timeout"==i.type?!0:!1;n.cancel(o),a||(o=n(function(){r({type:"timeout"})},3e4)),e.idle.isIDLE!=a&&(e.$apply(function(){e.idle.isIDLE=a}),a&&"timeout"==i.type&&$(t).on("mousemove",r))}e.idle={isIDLE:!1};var o,a=!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 r(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(){a&&e.cancel(a),t.idle.isIDLE?a=e(function(){r(!0)},5e3):(r(!1),a=e(o,6e4))}var a,s=0,c=!1;return{start:i}}]).service("NotificationsManager",["$rootScope","$window","$timeout","$interval","$q","MtpApiManager","AppPeersManager","IdleManager","AppConfigManager",function(e,t,n,i,r,o,a,s,c){function l(e){return void 0!==M[e]?M[e]:M[e]=o.invokeApi("account.getNotifySettings",{peer:{_:"inputNotifyPeer",peer:a.getInputPeerByID(e)}})}function u(e,t){M[e]=r.when(t)}function p(e,t){u(e,t);var n=angular.copy(t);return n._="inputPeerNotifySettings",o.invokeApi("account.updateNotifySettings",{peer:{_:"inputNotifyPeer",peer:a.getInputPeerByID(e)},settings:n})}function d(e){return l(e).then(function(e){return"peerNotifySettings"==e._&&1e3*e.mute_until>tsNow()})}function f(){if(!b)return!1;"granted"!==Notification.permission&&"denied"!==Notification.permission&&$(t).on("click",h);try{$(t).on("beforeunload",v)}catch(e){}}function h(){Notification.requestPermission(),$(t).off("click",h)}function g(t){return e.idle.isIDLE?(C++,b&&"granted"===Notification.permission?(c.get("notify_nosound","notify_volume").then(function(e){(!e[0]&&e[1]===!1||e[1]>0)&&m(e[1]||.5)}),void c.get("notify_nodesktop").then(function(e){if(!e){var n=++S,i=t.key||"k"+n,r=new Notification(t.title,{icon:t.image||"",body:t.message||"",tag:t.tag||""});r.onclick=function(){r.close(),window.chrome&&chrome.app&&chrome.app.window&&chrome.app.window.current().focus(),window.focus(),v(),t.onclick&&t.onclick()},r.onclose=function(){delete w[i],v()},w[i]=r}})):!1):!1}function m(e){var t="img/sound_a.wav",n=$("#notify_sound").html('');n.find("audio")[0].volume=e}function y(e){var t=w[e];if(t)try{t.close&&t.close()}catch(n){}}function v(){angular.forEach(w,function(e){try{e.close&&e.close()}catch(t){}}),w={}}var _,b="Notification"in window,w={},S=0,C=0,M={},k=$('link[rel="icon"]'),x=$(''),T=document.title;return e.$watch("idle.isIDLE",function(e){i.cancel(_),e?(T=document.title,_=i(function(){var e=tsNow();!C||e%2e3>1e3?(document.title=T,$('link[rel="icon"]').replaceWith(k)):(document.title=C>1?C+" notifications":"1 notification",$('link[rel="icon"]').replaceWith(x))},1e3)):(C=0,document.title=T,$('link[rel="icon"]').replaceWith(k),v())}),e.$on("apiUpdate",function(e,t){switch(t._){case"updateNotifySettings":if("notifyPeer"==t.peer._){var n=a.getPeerID(t.peer.peer);u(n,t.notify_settings)}}}),{start:f,notify:g,cancel:y,clear:v,getPeerSettings:l,getPeerMuted:d,savePeerSettings:u,updatePeerSettings:p,testSound:m}}]).service("ErrorService",["$rootScope","$modal","$window",function(e,t,n){function i(n,i){if(a>=2)return console.log("Skip error box, too many open",a,n,i),!1;i=i||{};var r=e.$new();angular.extend(r,n),a++;var o=t.open({templateUrl:"partials/error_modal.html",scope:r,windowClass:i.windowClass||"error_modal_window"});return o.result["finally"](function(){a--}),o}function r(e,t){return i({title:e,description:t})}function o(n,i){i=i||{};var r=e.$new();angular.extend(r,n);var o=t.open({templateUrl:"partials/confirm_modal.html",scope:r,windowClass:i.windowClass||"confirm_modal_window"});return o.result}var a=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:r,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:"partials/peer_select.html",controller:"PeerSelectController",scope:i,windowClass:"peer_select_window"}).result}return{selectPeer:n}}]).service("ContactsSelectService",["$rootScope","$modal",function(e,t){function n(n,i){i=i||{};var r=e.$new();return r.multiSelect=n,angular.extend(r,i),t.open({templateUrl:"partials/contacts_modal.html",controller:"ContactsModalController",scope:r,windowClass:"contacts_modal_window"}).result}return{selectContacts:function(e){return n(!0,e)},selectContact:function(e){return n(!1,e)}}}]).service("ChangelogNotifyService",["AppConfigManager","$rootScope","$http","$modal",function(e,t,n,i){function r(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&&(a(t||"0"),e.set({last_version:Config.App.version}))})}function a(e){var n=t.$new();n.lastVersion=e,n.canShowVersion=function(t){return n.lastVersion===!1||void 0===n.lastVersion?!0:r(t,e)>0},i.open({templateUrl:"partials/changelog_modal.html",scope:n,windowClass:"changelog_modal_window"})}return{checkUpdate:o,showChangelog:a}}]),angular.module("myApp.controllers",[]).controller("AppWelcomeController",["$scope","$location","MtpApiManager","ErrorService",function(e,t,n){n.getUserID().then(function(n){n?t.url("/im"):e.showWelcome=!0})}]).controller("AppLoginController",["$scope","$location","$timeout","$modal","$modalStack","MtpApiManager","ErrorService",function(e,t,n,i,r,o,a){function s(){var t,n,i,r=((e.credentials.phone_country||"")+(e.credentials.phone_number||"")).replace(/\D+/g,""),o=0,a=!1;if(r.length)for(t=0;t=o&&!r.indexOf(i)&&(o=i.length,a=Config.CountryCodes[t][0]);e.credentials.phone_full=r,e.credentials.phone_country_name=a||"Unknown"}function c(e){o.setUserAuth(u.dcID,{expires:e.expires,id:e.user.id}),n.cancel(p),t.url("/im")}function l(){n.cancel(p),--e.callPending.remaining?p=n(l,1e3):(e.callPending.success=!1,o.invokeApi("auth.sendCall",{phone_number:e.credentials.phone_full,phone_code_hash:e.credentials.phone_code_hash},u).then(function(){e.callPending.success=!0}))}r.dismissAll(),o.getUserID().then(function(e){return e?void t.url("/im"):void 0});var u={dcID:1,createNetworker:!0};e.credentials={phone_country:"+1",phone_country_name:"USA",phone_number:"",phone_full:""},e.progress={},e.callPending={},e.selectCountry=function(){var t=i.open({templateUrl:"partials/country_select_modal.html",controller:"CountrySelectModalController",windowClass:"countries_modal_window"});t.result.then(function(t){e.credentials.phone_country=t,e.$broadcast("country_selected")})},e.$watch("credentials.phone_country",s),e.$watch("credentials.phone_number",s);var p;e.sendCode=function(){n.cancel(p),a.confirm({type:"LOGIN_PHONE_CORRECT",country_code:e.credentials.phone_country,phone_number:e.credentials.phone_number}).then(function(){e.progress.enabled=!0,o.invokeApi("auth.sendCode",{phone_number:e.credentials.phone_full,sms_type:0,api_id:Config.App.id,api_hash:Config.App.hash},u).then(function(t){e.progress.enabled=!1,e.credentials.phone_code_hash=t.phone_code_hash,e.credentials.phone_occupied=t.phone_registered,e.error={},e.callPending.remaining=t.send_call_timeout||60,l()},function(t){switch(e.progress.enabled=!1,console.log("sendCode error",t),t.type){case"NETWORK_BAD_REQUEST":"https:"==location.protocol&&(a.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}})})},e.editPhone=function(){n.cancel(p),delete e.credentials.phone_code_hash,delete e.credentials.phone_unoccupied,delete e.credentials.phone_code_valid,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,o.invokeApi(n,i,u).then(c,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}})}}]).controller("AppIMController",["$scope","$location","$routeParams","$modal","$rootScope","$modalStack","MtpApiManager","AppUsersManager","ContactsSelectService","ChangelogNotifyService","ErrorService",function(e,t,n,i,r,o,a,s,c,l,u){function p(){e.curDialog={peer:n.p||!1}}e.$on("$routeUpdate",p),e.$on("history_focus",function(n,i){o.dismissAll(),i.peerString==e.curDialog.peer?e.$broadcast("ui_history_focus"):t.url("/im?p="+i.peerString)}),e.isLoggedIn=!0,e.isEmpty={},e.openSettings=function(){i.open({templateUrl:"partials/settings_modal.html",controller:"SettingsModalController",windowClass:"settings_modal_window"})},e.openContacts=function(){c.selectContact().then(function(t){e.dialogSelect(s.getUserString(t))})},e.openGroup=function(){c.selectContacts().then(function(t){if(1==t.length)e.dialogSelect(s.getUserString(t[0]));else if(t.length>1){var n=r.$new();n.userIDs=t,i.open({templateUrl:"partials/chat_create_modal.html",controller:"ChatCreateModalController",scope:n,windowClass:"contacts_modal_window"})}})},e.dialogSelect=function(e){r.$broadcast("history_focus",{peerString:e})},e.logOut=function(){u.confirm({type:"LOGOUT"}).then(function(){a.logOut().then(function(){location.hash="/login",location.reload()})})},p(),l.checkUpdate()}]).controller("AppImDialogsController",["$scope","$location","MtpApiManager","AppUsersManager","AppChatsManager","AppMessagesManager","AppPeersManager","ErrorService",function(e,t,n,i,r,o,a,s){function c(){p=0,d=0,f=!1,h={},u=!1,o.getDialogs(e.search.query,d).then(function(t){e.dialogs=[],e.contacts=[],t.dialogs.length&&(p+=t.dialogs.length,d=t.dialogs[t.dialogs.length-1].top_message,f=null===t.count||p0?a=t:0>t&&(o=a+t),n=o;a>n;n++){if(i=e.history[n],r&&i.from_id==r.from_id&&!r.fwd_from_id==!i.fwd_from_id&&!r.action&&!i.action&&i.datet;for(o=0;o0){var t=[];angular.forEach(e.selectedMsgs,function(e,n){t.push(n)}),s.deleteMessages(t).then(function(){w()})}}function M(){if(e.selectedCount>0){var t=[];angular.forEach(e.selectedMsgs,function(e,n){t.push(n)}),u.selectPeer({confirm_type:"FORWARD_PEER"}).then(function(e){var n=c.getPeerID(e);s.forwardMessages(n,t).then(function(){w(),i.$broadcast("history_focus",{peerString:e})})})}}function k(){e.selectActions?w():(e.selectActions=!0,e.$broadcast("ui_panel_update"))}function x(t){t&&(e.missedCount=0),e.mediaType=t||!1,e.history=[],v()}function T(){e.curDialog.peerID>0?i.openUser(e.curDialog.peerID):e.curDialog.peerID<0&&i.openChat(-e.curDialog.peerID)}e.$watch("curDialog.peer",h),l.attach(),p.start(),d.start(),e.history=[],e.mediaType=!1,e.selectedMsgs={},e.selectedCount=0,e.selectActions=!1,e.missedCount=0,e.typing={},e.state={},e.toggleMessage=b,e.selectedDelete=C,e.selectedForward=M,e.selectedCancel=w,e.selectedFlush=S,e.toggleEdit=k,e.toggleMedia=x,e.showPeerInfo=T;var E,A=0,I=!1,D=0,P=!1,N={photos:"inputMessagesFilterPhotos",video:"inputMessagesFilterVideo",documents:"inputMessagesFilterDocument",audio:"inputMessagesFilterAudio"},L=0,B={};e.$on("history_update",angular.noop),e.$on("history_append",function(t,r){if(r.peerID==e.curDialog.peerID){if(e.mediaType)return void(r.my?x():e.missedCount++);e.history.push(s.wrapForHistory(r.messageID)),m(-3),e.typing={},e.$broadcast("ui_history_append",{my:r.my}),r.my&&(e.historyUnread={}),A++,i.idle.isIDLE||n(function(){s.readHistory(e.curDialog.inputPeer)})}}),e.$on("history_delete",function(t,n){if(n.peerID==e.curDialog.peerID){for(var i=[],r=0;r=0?i+n:0,s=++_,c=a>=m.length?u():e.when();c.then(function(){s==_&&(t.messageID=m[a],t.photoID=o.getMessage(t.messageID).media.photo.id,t.photo=r.wrapForFull(t.photoID),p())})}function u(){return b?b:b=o.getSearch(f,h,g,y).then(function(e){e.history.length?(y=e.history[e.history.length-1],m=m.concat(e.history),v=m.length0,t.nav.hasPrev=v||e0}if(t.photo=r.wrapForFull(t.photoID),t.nav={},!t.messageID)return void(t.nav.next=function(){i.close()});var d=o.getMessagePeer(o.getMessage(t.messageID)),f=a.getInputPeerByID(d),h="",g={_:"inputMessagesFilterPhotos"},m=[t.messageID],y=t.messageID,v=!0;p(),o.getSearch(f,h,g,0,1e3).then(function(e){e.history.indexOf(t.messageID)>=0&&(m=e.history,y=m[m.length-1],p())});var _=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.forward=function(){var e=t.messageID;s.selectPeer({confirm_type:"FORWARD_PEER"}).then(function(t){var i=a.getPeerID(t);o.forwardMessages(i,[e]).then(function(){n.$broadcast("history_focus",{peerString:t})})})},t.delete=function(){var e=t.messageID;c.confirm({type:"MESSAGE_DELETE"}).then(function(){o.deleteMessages([e])})},t.download=function(){r.downloadPhoto(t.photoID)},t.$on("history_delete",function(e,n){if(console.log(dT(),"delete",n),n.peerID==d){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 r=[],o=0;o=0?i+n:0,a=++y,s=o>=h.length?p():e.when();s.then(function(){a==y&&(t.photoID=h[o],t.photo=r.wrapForFull(t.photoID),d())})}function p(){return v?v:v=r.getUserPhotos(f,g).then(function(e){g=e.photos[e.photos.length-1],h=h.concat(e.photos),m=h.length0,t.nav.hasPrev=m||e=0&&(h=e.photos,g=h[h.length-1],m=h.length0&&Math.ceil(10*i[3])||0:5,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 r;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(),r&&n.cancel(r),r=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.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(){d.showChangelog(!1)}}]).controller("ProfileEditModalController",["$rootScope","$scope","$timeout","$modal","$modalInstance","AppUsersManager","AppChatsManager","MtpApiManager","AppConfigManager","NotificationsManager","MtpApiFileManager","ApiUpdatesManager",function(e,t,n,i,r,o,a,s){t.profile={},t.error={},s.getUserID().then(function(e){t.profile=o.getUser(e)}),t.updateProfile=function(){t.profile.updating=!0,s.invokeApi("account.updateProfile",{first_name:t.profile.first_name||"",last_name:t.profile.last_name||""}).then(function(e){t.error={},o.saveApiUser(e),r.close()},function(e){switch(e.type){case"FIRSTNAME_INVALID":t.error={field:"first_name"},e.handled=!0;break;case"LASTNAME_INVALID":t.error={field:"last_name"},e.handled=!0;break;case"NAME_NOT_MODIFIED":e.handled=!0,r.close()}})["finally"](function(){delete t.profile.updating})}}]).controller("ContactsModalController",["$scope","$modal","$modalInstance","AppUsersManager","ErrorService",function(e,t,n,i){function r(t){i.getContacts(t).then(function(t){e.contacts=[],e.slice.limit=20,angular.forEach(t,function(t){var n={userID:t,user:i.getUser(t),userPhoto:i.getUserPhoto(t,"User")};e.contacts.push(n)}),e.$broadcast("contacts_change")})}if(e.contacts=[],e.search={},e.slice={limit:20,limitDelta:20},e.selectedContacts={},e.disabledContacts={},e.selectedCount=0,e.disabled)for(var o=0;o0){var t=[];return angular.forEach(e.selectedContacts,function(e,n){t.push(n)}),n.close(t)}},e.importContact=function(){i.openImportContact().then(function(){r(e.search&&e.search.query||"")})}}]).controller("PeerSelectController",["$scope","$modalInstance","$q","AppPeersManager","ErrorService",function(e,t,n,i,r){e.dialogSelect=function(o){var a;if(e.confirm_type){var s=i.getPeerID(o),c=i.getPeer(s);a=r.confirm({type:e.confirm_type,peer_id:s,peer_data:c})}else a=n.when();a.then(function(){t.close(o)})}}]).controller("ChatCreateModalController",["$scope","$modalInstance","$rootScope","MtpApiManager","AppUsersManager","AppChatsManager","ApiUpdatesManager",function(e,t,n,i,r,o,a){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.saveApiUsers(e.users),o.saveApiChats(e.chats),a.saveSeq(e.seq)&&a.saveUpdate({_:"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,r,o,a){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.saveApiUsers(t.users),o.saveApiChats(t.chats),a.saveSeq(t.seq)&&a.saveUpdate({_:"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",function(e,t,n,i){void 0===e.importContact&&(e.importContact={}),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){t.close(e)})["finally"](function(){delete e.progress.enabled}))}}]).controller("CountrySelectModalController",["$scope","$modalInstance","$rootScope","SearchIndexManager",function(e,t,n,i){e.search={},e.slice={limit:20,limitDelta:20};for(var r=i.createIndex(),o=0;o5184e5?o="shortDate":r>432e5&&(o="EEE"),t[n]=e("date")(i,o)}}]).filter("duration",[function(){return function(e){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){return function(t){var n=e("formatSize")(t.done),i=n.split(" "),r=e("formatSize")(t.total),o=r.split(" ");return o[1]===i[1]?i[0]+" of "+o[0]+" "+(i[1]||""):n+" of "+r}}]).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){return function(t){var n=1e3*t,i=Math.abs(tsNow()-n);return 6e4>i?"just now":3e6>i?Math.ceil(i/6e4)+" minutes ago":1e7>i?Math.ceil(i/36e5)+" hours ago":e("dateOrTime")(t)}}]),angular.module("myApp.templates",[]).run(["$templateCache",function(e){e.put("partials/changelog_modal.html",'
\n\n \n\n \n\n
'),e.put("partials/chat_create_modal.html",'
\n\n \n\n \n\n \n\n
'),e.put("partials/chat_edit_modal.html",'
\n\n \n\n \n\n \n\n
'),e.put("partials/chat_modal.html",'
\n\n \n\n \n\n
'),e.put("partials/confirm_modal.html",'
\n\n \n\n \n\n \n\n
'),e.put("partials/contacts_modal.html",'
\n\n \n\n \n\n
'),e.put("partials/country_select_modal.html",'
\n\n \n\n \n\n
'),e.put("partials/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 You{{((dialogMessage.out || dialogMessage.peerID < 0) && (dialogMessage.message.length || dialogMessage.media && dialogMessage.media._ != \'messageMediaEmpty\')) ? \':\' : \'\'}}\n \n\n \n Photo\n Video\n Document\n Audio\n Location\n Contact\n \n\n \n created the group \n changed group name\n changed group photo\n removed group photo\n\n \n \n returned to group\n \n \n invited \n \n \n\n \n \n left group\n \n \n kicked \n \n \n \n\n \n
\n\n
\n
\n'),e.put("partials/edit_contact_modal.html",'
\n\n \n\n \n\n \n\n
'),e.put("partials/error_modal.html",'
\n\n \n\n \n\n
'),e.put("partials/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/full_photo.html",'
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n \n \n \n
\n
\n
\n
\n
\n
'),e.put("partials/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/head.html",'
\n \n
'),e.put("partials/im.html",'
\n\n
\n\n
\n\n
\n
\n \n \n
\n
\n
\n
\n\n
\n

No contacts yet

\n

Get started by adding a contact to chat with

\n \n
\n\n \n\n
\n
Contacts
\n \n
\n\n
\n
\n
\n
\n\n
\n
\n
\n

Get started

\n

Welcome to Telegram Web. You can always set your profile photo and change your name in Settings.

\n \n
\n
\n Please select a chat to start messaging\n
\n
\n
\n Loading history\n
\n\n
\n
\n\n
\n\n
\n
\n\n Info\n Edit\n\n \n \n Show all messages\n \n \n\n
\n

Photos

\n

Videos

\n

Documents

\n

Voice messages

\n\n

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

\n
\n\n
\n\n
\n\n
\n\n
\n\n
\n\n
\n
\n
\n
\n Loading history\n
\n
\n No messages here yet...\n
\n
\n\n
\n
\n
\n
\n\n
\n
\n is typing\n
\n
\n\n
\n\n
\n\n
\n\n
\n\n \n\n
\n\n
\n\n
\n
\n \n \n
\n
\n \n
\n
\n
Drop photos here to send
\n \n\n
\n \n \n
\n\n
\n \n \n
\n\n
\n \n
\n\n \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/import_contact_modal.html",'
\n\n \n\n \n\n \n\n
'),e.put("partials/login.html",'
\n\n\n\n'),e.put("partials/message.html",'
\n \n \n
\n\n
\n\n\n
\n\n
\n
\n\n \n\n \n \n created the group «»\n \n \n changed group name to «»\n \n \n changed group photo\n \n \n removed group photo\n \n \n \n invited \n \n \n returned to group\n \n \n \n \n kicked \n \n \n left group\n \n \n\n \n \n\n
\n\n \n \n \n\n
\n\n
\n
\n \n
\n\n \n \n \n\n \n\n \n \n \n
\n \n
\n\n
\n\n \n \n\n
\n Forwarded message from , \n
\n\n
\n\n \n \n \n\n
\n \n \n \n \n \n\n
\n
\n Video\n \n \n
\n \n
\n Cancel\n
\n
\n
\n
\n
\n
\n
\n
\n\n
\n\n
\n\n
\n \n \n
\n \n
\n
\n\n
\n
\n \n \n \n
\n
\n Download\n Open\n
\n
\n Cancel\n
\n
\n
\n
\n
\n
\n
\n\n
\n
\n\n\n
\n \n \n \n \n\n
\n
\n \n Voice message\n \n \n \n
\n
\n Play\n
\n
\n Cancel\n
\n
\n
\n
\n
\n
\n
\n \n
\n
\n
\n\n \n \n \n\n
\n \n \n \n
\n \n \n
\n
\n
\n\n
\n \n
\n
\n \n \n
\n
\n Cancel\n
\n
\n
\n
\n
\n
\n
\n
\n\n\n
\n\n
\n
\n\n
\n
\n\n
\n\n'),e.put("partials/peer_select.html",'
\n\n \n\n
'),e.put("partials/photo_modal.html",'
\n\n \n\n
'),e.put("partials/profile_edit_modal.html",'
\n\n \n\n \n\n \n\n
'),e.put("partials/settings_modal.html",'\n'),e.put("partials/user_modal.html",'
\n\n \n\n \n\n
'),e.put("partials/video_modal.html",'
\n\n \n\n
'),e.put("partials/welcome.html",'
\n\n\n
\n\n
\n \n\n

Telegram Web

\n\n
\n

This is an unofficial web-client for the Telegram Messenger.

\n

It\'s still an alpha-version and may not be 200% reliable

\n
\n \n
\n\n \n\n\n\n
\n') }]),angular.module("myApp.directives",["myApp.filters"]).directive("myDialog",function(){return{restrict:"AE",scope:!0,translude:!1,templateUrl:"partials/dialog.html"}}).directive("myMessage",function(){return{restrict:"AE",scope:!0,translude:!1,templateUrl:"partials/message.html"}}).directive("myDialogs",["$modalStack",function(e){function t(t,n){function i(t){if(!s&&e.getTop())return!0;if(36==t.keyCode&&!t.shiftKey&&!t.ctrlKey&&t.altKey){var n=$(o).find(".im_dialog_wrap a")[0];return n&&(n.click(),o.scrollTop=0,$(r).nanoScroller({flash:!0})),cancelEvent(t)}if(27==t.keyCode||9==t.keyCode&&t.shiftKey&&!t.ctrlKey&&!t.metaKey)return s||(a.focus(),a.value&&a.select()),cancelEvent(t);if(s&&13==t.keyCode){var n=$(o).find(".im_dialog_selected")[0]||$(o).find(".im_dialog_wrap a")[0];return n&&n.click(),cancelEvent(t)}if(38==t.keyCode||40==t.keyCode){var i=!t.shiftKey&&t.altKey;if(!i&&(!s||t.metaKey))return!0;var c,l=40==t.keyCode,n=!i&&$(o).find(".im_dialog_selected")[0]||$(o).find(".active a.im_dialog")[0],u=n&&n.parentNode;if(u){var c=n[l?"nextSibling":"previousSibling"];if(!c||!c.className||-1==c.className.indexOf("im_dialog_wrap")){var p=$(o).find(".im_dialog_wrap"),d=p.index(n.parentNode),f=d+(l?1:-1);c=p[f]}}else{var p=$(o).find(".im_dialog_wrap");c=l?p[0]:p[p.length-1]}if(i?c&&$(c).find("a")[0].click():(u&&c&&$(u).find("a").removeClass("im_dialog_selected"),c&&$(c).find("a").addClass("im_dialog_selected")),c){var h=c.offsetTop,g=c.offsetHeight,m=o.scrollTop,y=o.clientHeight;m>h?(o.scrollTop=h,$(r).nanoScroller({flash:!0})):h+g-y>m&&(o.scrollTop=h+g-y,$(r).nanoScroller({flash:!0}))}return cancelEvent(t)}}var r=$(".im_dialogs_wrap",n)[0],o=$(".im_dialogs_scrollable_wrap",n)[0],a=$(".im_dialogs_search_field",n)[0],s=!1;$(a).on("focus blur",function(e){s="focus"==e.type,s||$(o).find(".im_dialog_selected").removeClass("im_dialog_selected")}),$(document).on("keydown",i),t.$on("$destroy",function(){$(document).off("keydown",i)})}return{link:t}}]).directive("myDialogsList",["$window","$timeout",function(e,t){function n(n,i,r){function o(){return r.modal?($(i).css({height:$(e).height()-200}),void p()):(c&&c.offsetHeight||(c=$(".tg_page_head")[0]),l&&l.offsetHeight||(l=$(".im_page_footer")[0]),$(i).css({height:$(e).height()-l.offsetHeight-(c?c.offsetHeight:44)-72}),void p())}var a=$(".im_dialogs_wrap",i)[0],s=$(".im_dialogs_scrollable_wrap",i)[0],c=$(".tg_page_head")[0],l=$(".im_page_footer")[0],u=!1;onContentLoaded(function(){$(a).nanoScroller({preventPageScrolling:!0,tabIndex:-1,iOSNativeScrolling:!0})});var p=function(){onContentLoaded(function(){$(a).nanoScroller()})};n.$on("ui_dialogs_prepend",p),n.$on("ui_dialogs_append",function(){onContentLoaded(function(){p(),u=!1,t(function(){$(s).trigger("scroll")})})}),n.$on("ui_dialogs_change",function(){onContentLoaded(function(){p(),u=!1,t(function(){$(s).trigger("scroll")})})}),$(s).on("scroll",function(){!u&&s.scrollTop>=s.scrollHeight-s.clientHeight-300&&(n.$emit("dialogs_need_more"),u=!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)-(r&&r.offsetHeight||0)-200}),$(a).nanoScroller()}var r=$(".contacts_modal_search")[0],o=$(".contacts_modal_panel")[0],a=$(".contacts_wrap",n)[0];onContentLoaded(function(){$(a).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)-(r&&r.offsetHeight||0)-200}),$(a).nanoScroller()}var r=$(".countries_modal_search")[0],o=$(".countries_modal_panel")[0],a=$(".countries_wrap",n)[0];onContentLoaded(function(){$(a).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","$transition",function(e,t,n){function i(i,r){function o(t){if(r.is(":visible")&&$(r[0].parentNode).is(":visible")){$(h).is(":visible")&&$(h).css({height:$(y).height()}),g&&g.offsetHeight||(g=$(".tg_page_head")[0]),m&&m.offsetHeight||(m=$(".im_page_footer")[0]);var n=$(e).height()-d.offsetHeight-f.offsetHeight-(g?g.offsetHeight:44)-m.offsetHeight;$(s).css({height:n}),$(l).css({minHeight:n-44}),a(),t!==!0&&(k&&onContentLoaded(function(){u.scrollTop=u.scrollHeight,b()}),b(100))}}function a(){$(c).css({marginTop:0}),c.offsetHeight>0&&c.offsetHeight<=u.offsetHeight&&$(c).css({marginTop:u.offsetHeight-c.offsetHeight-20-44+"px"}),$(s).nanoScroller()}var s=$(".im_history_wrap",r)[0],c=$(".im_history_messages",r)[0],l=$(".im_history",r)[0],u=$(".im_history_scrollable_wrap",r)[0],p=$(".im_history_scrollable",r)[0],d=$(".im_history_panel_wrap",r)[0],f=$(".im_bottom_panel_wrap",r)[0],h=$(".im_send_form_wrap",r)[0],g=$(".tg_page_head")[0],m=$(".im_page_footer")[0],y=$(".im_send_form",r)[0],v=!1;onContentLoaded(function(){u.scrollTop=u.scrollHeight,$(s).nanoScroller({preventPageScrolling:!0,tabIndex:-1,iOSNativeScrolling:!0})});var _,b=function(e){t(function(){$(u).hasClass("im_history_to_bottom")||$(s).nanoScroller()},e||0)},w=!1,S=["transform","webkitTransform","MozTransform","msTransform","OTransform"];for(_=0;_=u.scrollHeight-u.clientHeight,!v&&u.scrollTop<=300&&(v=!0,i.$emit("history_need_more"))))}),$(e).on("resize",o),o(),onContentLoaded(o)}return{link:i}}]).directive("mySendForm",["$timeout","$modalStack","AppConfigManager","ErrorService",function(e,t,n,i){function r(r,o){function a(){if(w){e.cancel(S);var t=$("
").text(r.draftMessage.text||"").html();t=t.replace(/\n/g,"
"),$(w).html(t),c()}}function s(){w&&($(w).trigger("change"),c())}function c(){var e=w.offsetHeight;x!=e&&(x=e,r.$emit("ui_editor_resize"))}function l(e){return 9!=e.keyCode||e.shiftKey||e.ctrlKey||e.metaKey||t.getTop()?void 0:(b.focus(),cancelEvent(e))}function u(){onContentLoaded(function(){b.focus()})}function p(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 o=t[0],a=atob(t[1].split(",")[1]),s=new Uint8Array(a.length),c=0;c0&&i.confirm({type:"FILES_CLIPBOARD_PASTE",files:a}).then(function(){r.draftMessage.files=a,r.draftMessage.isMedia=!0})}function f(e){var t=!1;return h&&1!=h||(h=checkDragEvent(e)?2:1,t=!0),2==h&&(g&&setTimeout(function(){clearTimeout(g),g=!1},0),"dragenter"==e.type||"dragover"==e.type?t&&$(v).css({height:$(b).height()+12,width:$(b).width()+12}).show():("drop"==e.type&&r.$apply(function(){r.draftMessage.files=Array.prototype.slice.call(e.originalEvent.dataTransfer.files),r.draftMessage.isMedia=!0}),g=setTimeout(function(){$(v).hide(),h=!1,g=!1},300))),cancelEvent(e)}var h,g,m=$("textarea",o)[0],y=$("input",o),v=$(".im_send_dropbox_wrap",o)[0],_=$(".im_emoji_btn",o)[0],b=m,w=($(m).emojiarea({button:_,norealTime:!0}),$(".emoji-menu",o)[0],$(".emoji-wysiwyg-editor",o)[0]);if(w){b=w,$(w).addClass("form-control"),$(w).attr("placeholder",$(m).attr("placeholder"));var S;$(w).on("keyup",function(){c(),r.draftMessage.text=w.innerText,e.cancel(S),S=e(s,1e3)})}y.on("change",function(){var e=this;r.$apply(function(){r.draftMessage.files=Array.prototype.slice.call(e.files),r.draftMessage.isMedia=$(e).hasClass("im_media_attach_input"),setTimeout(function(){try{e.value=""}catch(t){}},1e3)})});var C=!0,M=function(){n.get("send_ctrlenter").then(function(e){C=!e})};r.$on("settings_changed",M),M(),$(b).on("keydown",function(e){if(w&&c(),13==e.keyCode){var t=!1;if(C&&!e.shiftKey?t=!0:C||!e.ctrlKey&&!e.metaKey||(t=!0),t)return $(o).trigger("submit"),$(o).trigger("message_send"),cancelEvent(e)}}),$(".im_submit",o).on("mousedown",function(e){return $(o).trigger("submit"),$(o).trigger("message_send"),cancelEvent(e)});var k=0;$(b).on("keyup",function(){var e=tsNow();5e3>e-k||(k=e,r.$emit("ui_typing"))});var x=w.offsetHeight;$(document).on("keydown",l),$("body").on("dragenter dragleave dragover drop",f),$(document).on("paste",d),w&&$(w).on("DOMNodeInserted",p),Config.Navigator.mobile||(r.$on("ui_peer_change",u),r.$on("ui_history_focus",u),r.$on("ui_history_change",u)),r.$on("ui_message_send",u),r.$on("ui_peer_draft",a),r.$on("ui_message_before_send",s),r.$on("$destroy",function(){$("body").off("dragenter dragleave dragover drop",f),$(document).off("paste",d),$(document).off("keydown",l),w&&$(w).off("DOMNodeInserted",p)}),Config.Navigator.mobile||u()}return{link:r,scope:{draftMessage:"="}}}]).directive("myLoadThumb",["MtpApiFileManager",function(e){function t(t,n){var i=0,r=e.getCachedFile(t.thumb&&t.thumb.location&&!t.thumb.location.empty&&t.thumb.location);r&&n.attr("src",r),t.thumb&&t.thumb.width&&t.thumb.height&&(n.attr("width",t.thumb.width),n.attr("height",t.thumb.height));var o=(t.$watchCollection("thumb.location",function(r){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 a=++i;if(!r||r.empty)return n.attr("src",t.thumb&&t.thumb.placeholder||"img/blank.gif"),void o();var s=e.getCachedFile(r);return s?(n.attr("src",s),void o()):(n.attr("src")||n.attr("src",t.thumb.placeholder||"img/blank.gif"),void e.downloadSmallFile(t.thumb.location).then(function(e){a==i&&(n.attr("src",e),o())},function(e){console.log("Download image failed",e,t.thumb.location,n[0]),a==i&&(n.attr("src",t.thumb.placeholder||"img/blank.gif"),o())}))}),angular.noop)}return{link:t,scope:{thumb:"="}}}]).directive("myLoadFullPhoto",["MtpApiFileManager",function(e){function t(t,n){var i=$("img",n)[0],r=$(".img_fullsize_with_progress_wrap",n).add(".img_fullsize_progress_wrap",n).add($(i)),o=function(){r.css({width:t.fullPhoto.width,height:t.fullPhoto.height}),t.$emit("ui_height")},a=0;t.$watchCollection("fullPhoto.location",function(){var n=e.getCachedFile(t.thumbLocation),r=++a;if(n?(i.src=n,o()):i.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",t.fullPhoto.location){var s;if(t.fullPhoto.size){var c={_:"inputFileLocation",volume_id:t.fullPhoto.location.volume_id,local_id:t.fullPhoto.location.local_id,secret:t.fullPhoto.location.secret};s=e.downloadFile(t.fullPhoto.location.dc_id,c,t.fullPhoto.size)}else s=e.downloadSmallFile(t.fullPhoto.location);t.progress={enabled:!0,percent:0},s.then(function(e){r==a&&(t.progress.enabled=!1,i.src=e,o())},function(e){console.log("Download image failed",e,t.fullPhoto.location),t.progress.enabled=!1,t.error=e&&"FS_BROWSER_UNSUPPORTED"==e.type?{html:'Your browser doesn\'t support LocalFileSystem feature which is needed to display this image.
Please, install Google Chrome or use mobile app instead.'}:{text:"Download failed",error:e}},function(e){t.progress.percent=Math.max(1,Math.floor(100*e.done/e.total))})}}),o()}return{link:t,transclude:!0,templateUrl:"partials/full_photo.html",scope:{fullPhoto:"=",thumbLocation:"="}}}]).directive("myLoadVideo",["$sce","MtpApiFileManager",function(e,t){function n(n){n.progress={enabled:!0,percent:1},n.player={};var i,r={_:"inputVideoFileLocation",id:n.video.id,access_hash:n.video.access_hash},o=!1;if(navigator.plugins)for(i=0;i=0&&(o=!0);var a=t.downloadFile(n.video.dc_id,r,n.video.size,{mime:"video/mp4"});a.then(function(t){n.progress.enabled=!1,n.player.hasQuicktime=o,n.player.quicktime=!1,n.player.src=e.trustAsResourceUrl(t),n.$emit("ui_height")},function(e){console.log("Download video failed",e,n.video),n.progress.enabled=!1,n.player.src="",n.error=e&&"FS_BROWSER_UNSUPPORTED"==e.type?{html:'Your browser doesn\'t support LocalFileSystem feature which is needed to play this video.
Please, install Google Chrome or use mobile app instead.'}:{text:"Video download failed",error:e}},function(e){n.progress.percent=Math.max(1,Math.floor(100*e.done/e.total))}),n.$emit("ui_height"),n.$on("$destroy",function(){a.cancel()})}return{link:n,transclude:!0,templateUrl:"partials/full_video.html",scope:{video:"="}}}]).directive("myLoadGif",["MtpApiFileManager",function(e){function t(t){var n=!1,i={_:"inputDocumentFileLocation",id:t.document.id,access_hash:t.document.access_hash};t.isActive=!1,t.document.url=e.getCachedFile(i),t.toggle=function(){return t.document.url?(t.isActive=!t.isActive,void t.$emit("ui_height")):n?(n.cancel(),void(n=!1)):(t.document.progress={enabled:!0,percent:1,total:t.document.size},n=e.downloadFile(t.document.dc_id,i,t.document.size,null,{mime:t.document.mime_type}),void n.then(function(e){t.document.url=e,t.isActive=!0,delete t.document.progress,console.log("file save done"),t.$emit("ui_height")},function(){t.document.progress.enabled=!1},function(e){console.log("dl progress",e),t.document.progress.done=e.done,t.document.progress.percent=Math.max(1,Math.floor(100*e.done/e.total))}))}}return{link:t,templateUrl:"partials/full_gif.html",scope:{document:"="}}}]).directive("myMapPoint",["ExternalResourcesManager",function(e){function t(t,n){var i="AIzaSyC32ij28dCa0YzEV_HqbWfIwTZQql-RNS0",r="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(r).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,r){var o=function(){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"!=r.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 r=!1,o=function(){var o=n[0].offsetHeight,a=$(e).height(),s=i.myVerticalPosition&&parseFloat(i.myVerticalPosition)||.5,c=a>o?parseInt((a-o)*s):"";n.css({marginTop:c,marginBottom:c}),r!==c&&t.$emit("ui_height"),r=c};onContentLoaded(o),$(e).on("resize",o),t.$on("ui_height",function(){onContentLoaded(o)})}return{link:t}}]);