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,a){for(;--a>=0;){var o=t*this[e++]+n[i]+r;r=Math.floor(o/67108864),n[i++]=67108863&o}return r}function am2(e,t,n,i,r,a){for(var o=32767&t,s=t>>15;--a>=0;){var c=32767&this[e],l=this[e++]>>15,p=s*c+l*o;c=o*c+((32767&p)<<15)+n[i]+(1073741823&r),r=(c>>>30)+(p>>>15)+s*l+(r>>>30),n[i++]=1073741823&c}return r}function am3(e,t,n,i,r,a){for(var o=16383&t,s=t>>14;--a>=0;){var c=16383&this[e],l=this[e++]>>14,p=s*c+l*o;c=o*c+((16383&p)<<14)+n[i]+r,r=(c>>28)+(p>>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,a=!1,o=0;--r>=0;){var s=8==i?255&e[r]:intAt(e,r);0>s?"-"==e.charAt(r)&&(a=!0):(a=!1,0==o?this[this.t++]=s:o+i>this.DB?(this[this.t-1]|=(s&(1<>this.DB-o):this[this.t-1]|=s<=this.DB&&(o-=this.DB))}8==i&&0!=(128&e[0])&&n&&(this.s=-1,o>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,a=int2char(n));o>=0;)t>s?(n=(this[o]&(1<>(s+=this.DB-t)):(n=this[o]>>(s-=t)&i,0>=s&&(s+=this.DB,--o)),n>0&&(r=!0),r&&(a+=int2char(n));return r?a:"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+o+1]=this[n]>>r|s,s=(this[n]&a)<=0;--n)t[n]=0;t[o]=s,t.t=this.t+o+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,a=(1<>i;for(var o=n+1;o>i;i>0&&(t[this.t-n-1]|=(this.s&a)<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,a),r.lShiftTo(c,n)):(i.copyTo(a),r.copyTo(n));var l=a.t,p=a[l-1];if(0!=p){var u=p*(1<1?a[l-2]>>this.F2:0),d=this.FV/u,f=(1<=0&&(n[n.t++]=1,n.subTo(y,n)),BigInteger.ONE.dlShiftTo(l,y),y.subTo(a,a);a.t=0;){var v=n[--m]==p?this.DM:Math.floor(n[m]*d+(n[m-1]+h)*f);if((n[m]+=a.am(0,v,n,g,0,l))0&&n.rShiftTo(c,n),0>o&&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),a=nbits(e)-1;for(r.copyTo(n);--a>=0;)if(t.sqrTo(n,i),(e&1<0)t.mulTo(i,r,n);else{var o=n;n=i,i=o}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(),a=nbi(),o="";for(this.divRemTo(i,r,a);r.signum()>0;)o=(n+a.intValue()).toString(e).substr(1)+o,r.divRemTo(i,r,a);return a.intValue().toString(e)+o}function bnpFromRadix(e,t){this.fromInt(0),null==t&&(t=10);for(var n=this.chunkSize(t),i=Math.pow(t,n),r=!1,a=0,o=0,s=0;sc?"-"==e.charAt(s)&&0==this.signum()&&(r=!0):(o=t*o+c,++a>=n&&(this.dMultiply(i),this.dAddOffset(o,0),a=0,o=0))}a>0&&(this.dMultiply(Math.pow(t,a)),this.dAddOffset(o,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[a++]=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==a&&(128&this.s)!=(128&i)&&++a,(a>0||i!=this.s)&&(n[a++]=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,a=Math.min(e.t,this.t);for(i=0;a>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(),a=nbv(1);if(0>=r)return a;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 o=new Array,s=3,c=n-1,l=(1<1){var p=nbi();for(i.sqrTo(o[1],p);l>=s;)o[s]=nbi(),i.mulTo(p,o[s-2],o[s]),s+=2}var u,d,f=e.t-1,h=!0,m=nbi();for(r=nbits(e[f])-1;f>=0;){for(r>=c?u=e[f]>>r-c&l:(u=(e[f]&(1<0&&(u|=e[f-1]>>this.DB+r-c)),s=n;0==(1&u);)u>>=1,--s;if((r-=s)<0&&(r+=this.DB,--f),h)o[u].copyTo(a),h=!1;else{for(;s>1;)i.sqrTo(a,m),i.sqrTo(m,a),s-=2;s>0?i.sqrTo(a,m):(d=a,a=m,m=d),i.mulTo(m,o[u],a)}for(;f>=0&&0==(e[f]&1<a)return t;for(a>r&&(a=r),a>0&&(t.rShiftTo(a,t),n.rShiftTo(a,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 a>0&&n.lShiftTo(a,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),a=nbv(0),o=nbv(0),s=nbv(1);0!=n.signum();){for(;n.isEven();)n.rShiftTo(1,n),t?(r.isEven()&&a.isEven()||(r.addTo(this,r),a.subTo(e,a)),r.rShiftTo(1,r)):a.isEven()||a.subTo(e,a),a.rShiftTo(1,a);for(;i.isEven();)i.rShiftTo(1,i),t?(o.isEven()&&s.isEven()||(o.addTo(this,o),s.subTo(e,s)),o.rShiftTo(1,o)):s.isEven()||s.subTo(e,s),s.rShiftTo(1,s);n.compareTo(i)>=0?(n.subTo(i,n),t&&r.subTo(o,r),a.subTo(s,a)):(i.subTo(n,i),t&&o.subTo(r,o),s.subTo(a,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(),a=0;e>a;++a){r.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);var o=r.modPow(i,this);if(0!=o.compareTo(BigInteger.ONE)&&0!=o.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,a=0;i>a;a++)t=a%3,r|=e[a]<<(16>>>t&24),(2===t||i-a===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),a=new BigInteger(e.exponent,16),o=new BigInteger(t),s=o.modPowInt(a,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 a=CryptoJS.AES.encrypt(bytesToWords(e),bytesToWords(t),{iv:bytesToWords(n),padding:CryptoJS.pad.NoPadding,mode:CryptoJS.mode.IGE}).ciphertext,o=bytesFromWords(a);return o}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,a=bigint(nextRandomInt(1e9)+1),o=a.clone(),s=1<c;c++){++n;for(var l=a.clone(),p=a.clone(),u=bigint(r);!p.equals(BigInteger.ZERO);)p.and(BigInteger.ONE).equals(BigInteger.ZERO)||(u=u.add(l),u.compareTo(e)>0&&(u=u.subtract(e))),l=l.add(l),l.compareTo(e)>0&&(l=l.subtract(e)),p=p.shiftRight(1);a=u.clone();var d=a.compareTo(o)<0?o.subtract(a):a.subtract(o);if(t=d.gcd(e),!t.equals(BigInteger.ONE))break;0==(c&c-1)&&(o=a.clone())}if(t.compareTo(BigInteger.ONE)>0)break}var f,h,m=e.divide(t);return t.compareTo(m)>0?(f=m,h=t):(f=t,h=m),[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),a=goog.math.Long.fromInt(nextRandomInt(1e9)+1),o=a,s=1<c;c++){++n;for(var l=a,p=a,u=r;p.notEquals(goog.math.Long.ZERO);)p.and(goog.math.Long.ONE).notEquals(goog.math.Long.ZERO)&&(u=u.add(l),u.compare(e)>0&&(u=u.subtract(e))),l=l.add(l),l.compare(e)>0&&(l=l.subtract(e)),p=p.shiftRight(1);a=u;var d=a.compare(o)<0?o.subtract(a):a.subtract(o);if(t=gcdLong(d,e),t.notEquals(goog.math.Long.ONE))break;0==(c&c-1)&&(o=a)}if(t.compare(goog.math.Long.ONE)>0)break}var f,h,m=e.div(t);return t.compare(m)>0?(f=m,h=t):(f=t,h=m),[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 pt.each(e.match(dt)||[],function(e,n){t[n]=!0}),t}function r(e,n,i,r){if(pt.acceptData(e)){var a,o,s=pt.expando,c=e.nodeType,l=c?pt.cache:e,p=c?e[s]:e[s]&&s;if(p&&l[p]&&(r||l[p].data)||i!==t||"string"!=typeof n)return p||(p=c?e[s]=tt.pop()||pt.guid++:s),l[p]||(l[p]=c?{}:{toJSON:pt.noop}),("object"==typeof n||"function"==typeof n)&&(r?l[p]=pt.extend(l[p],n):l[p].data=pt.extend(l[p].data,n)),o=l[p],r||(o.data||(o.data={}),o=o.data),i!==t&&(o[pt.camelCase(n)]=i),"string"==typeof n?(a=o[n],null==a&&(a=o[pt.camelCase(n)])):a=o,a}}function a(e,t,n){if(pt.acceptData(e)){var i,r,a=e.nodeType,o=a?pt.cache:e,c=a?e[pt.expando]:pt.expando;if(o[c]){if(t&&(i=n?o[c]:o[c].data)){pt.isArray(t)?t=t.concat(pt.map(t,pt.camelCase)):t in i?t=[t]:(t=pt.camelCase(t),t=t in i?[t]:t.split(" ")),r=t.length;for(;r--;)delete i[t[r]];if(n?!s(i):!pt.isEmptyObject(i))return}(n||(delete o[c].data,s(o[c])))&&(a?pt.cleanData([e],!0):pt.support.deleteExpando||o!=o.window?delete o[c]:o[c]=null)}}}function o(e,n,i){if(i===t&&1===e.nodeType){var r="data-"+n.replace(kt,"-$1").toLowerCase();if(i=e.getAttribute(r),"string"==typeof i){try{i="true"===i?!0:"false"===i?!1:"null"===i?null:+i+""===i?+i:Ct.test(i)?pt.parseJSON(i):i}catch(a){}pt.data(e,n,i)}else i=t}return i}function s(e){var t;for(t in e)if(("data"!==t||!pt.isEmptyObject(e[t]))&&"toJSON"!==t)return!1;return!0}function c(){return!0}function l(){return!1}function p(){try{return K.activeElement}catch(e){}}function u(e,t){do e=e[t];while(e&&1!==e.nodeType);return e}function d(e,t,n){if(pt.isFunction(t))return pt.grep(e,function(e,i){return!!t.call(e,i,e)!==n});if(t.nodeType)return pt.grep(e,function(e){return e===t!==n});if("string"==typeof t){if(jt.test(t))return pt.filter(t,e,n);t=pt.filter(t,e)}return pt.grep(e,function(e){return pt.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 pt.nodeName(e,"table")&&pt.nodeName(1===t.nodeType?t:t.firstChild,"tr")?e.getElementsByTagName("tbody")[0]||e.appendChild(e.ownerDocument.createElement("tbody")):e}function m(e){return e.type=(null!==pt.find.attr(e,"type"))+"/"+e.type,e}function g(e){var t=an.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++)pt._data(n,"globalEval",!t||pt._data(t[i],"globalEval"))}function v(e,t){if(1===t.nodeType&&pt.hasData(e)){var n,i,r,a=pt._data(e),o=pt._data(t,a),s=a.events;if(s){delete o.handle,o.events={};for(n in s)for(i=0,r=s[n].length;r>i;i++)pt.event.add(t,n,s[n][i])}o.data&&(o.data=pt.extend({},o.data))}}function _(e,t){var n,i,r;if(1===t.nodeType){if(n=t.nodeName.toLowerCase(),!pt.support.noCloneEvent&&t[pt.expando]){r=pt._data(t);for(i in r.events)pt.removeEvent(t,i,r.handle);t.removeAttribute(pt.expando)}"script"===n&&t.text!==e.text?(m(t).text=e.text,g(t)):"object"===n?(t.parentNode&&(t.outerHTML=e.outerHTML),pt.support.html5Clone&&e.innerHTML&&!pt.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,a=0,o=typeof e.getElementsByTagName!==X?e.getElementsByTagName(n||"*"):typeof e.querySelectorAll!==X?e.querySelectorAll(n||"*"):t;if(!o)for(o=[],i=e.childNodes||e;null!=(r=i[a]);a++)!n||pt.nodeName(r,n)?o.push(r):pt.merge(o,b(r,n));return n===t||n&&pt.nodeName(e,n)?pt.merge([e],o):o}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"===pt.css(e,"display")||!pt.contains(e.ownerDocument,e)}function x(e,t){for(var n,i,r,a=[],o=0,s=e.length;s>o;o++)i=e[o],i.style&&(a[o]=pt._data(i,"olddisplay"),n=i.style.display,t?(a[o]||"none"!==n||(i.style.display=""),""===i.style.display&&S(i)&&(a[o]=pt._data(i,"olddisplay",T(i.nodeName)))):a[o]||(r=S(i),(n&&"none"!==n||!r)&&pt._data(i,"olddisplay",r?n:pt.css(i,"display"))));for(o=0;s>o;o++)i=e[o],i.style&&(t&&"none"!==i.style.display&&""!==i.style.display||(i.style.display=t?a[o]||"":"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 C(e,t,n,i,r){for(var a=n===(i?"border":"content")?4:"width"===t?1:0,o=0;4>a;a+=2)"margin"===n&&(o+=pt.css(e,n+xn[a],!0,r)),i?("content"===n&&(o-=pt.css(e,"padding"+xn[a],!0,r)),"margin"!==n&&(o-=pt.css(e,"border"+xn[a]+"Width",!0,r))):(o+=pt.css(e,"padding"+xn[a],!0,r),"padding"!==n&&(o+=pt.css(e,"border"+xn[a]+"Width",!0,r)));return o}function k(e,t,n){var i=!0,r="width"===t?e.offsetWidth:e.offsetHeight,a=un(e),o=pt.support.boxSizing&&"border-box"===pt.css(e,"boxSizing",!1,a);if(0>=r||null==r){if(r=dn(e,t,a),(0>r||null==r)&&(r=e.style[t]),_n.test(r))return r;i=o&&(pt.support.boxSizingReliable||r===e.style[t]),r=parseFloat(r)||0}return r+C(e,t,n||(o?"border":"content"),i,a)+"px"}function T(e){var t=K,n=wn[e];return n||(n=A(e,t),"none"!==n&&n||(pn=(pn||pt("')}return e.trustAs("html",r)}var a,o=[],s={},c=Config.Emoji,l=18;for(a in c)o.push(c[a][0]),s[c[a][0]]=a;var p=new RegExp("((?:(ftp|https?)://|(?:mailto:)?([A-Za-z0-9._%+-]+@))(\\S*\\.\\S*[^\\s.;,(){}<>\"']))|(\\n)|("+o.join("|")+")","i"),u=/(?: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(){o||(o=!0,$(t).on("blur focus keydown mousedown touchstart",r))}function r(i){"mousemove"==i.type&&$(t).off("mousemove",r);var o="blur"==i.type||"timeout"==i.type?!0:!1;n.cancel(a),o||(a=n(function(){r({type:"timeout"})},3e4)),e.idle.isIDLE!=o&&(e.$apply(function(){e.idle.isIDLE=o}),o&&"timeout"==i.type&&$(t).on("mousemove",r))}e.idle={isIDLE:!1};var a,o=!1;return{start:i}}]).service("StatusManager",["$timeout","$rootScope","MtpApiManager","IdleManager",function(e,t,n){function i(){c||(c=!0,t.$watch("idle.isIDLE",a),t.$watch("offline",a))}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 a(){o&&e.cancel(o),t.idle.isIDLE?o=e(function(){r(!0)},5e3):(r(!1),o=e(a,6e4))}var o,s=0,c=!1;return{start:i}}]).service("NotificationsManager",["$rootScope","$window","$timeout","$interval","$q","MtpApiManager","AppPeersManager","IdleManager","AppConfigManager",function(e,t,n,i,r,a,o,s,c){function l(e){return void 0!==M[e]?M[e]:M[e]=a.invokeApi("account.getNotifySettings",{peer:{_:"inputNotifyPeer",peer:o.getInputPeerByID(e)}})}function p(e,t){M[e]=r.when(t)}function u(e,t){p(e,t);var n=angular.copy(t);return n._="inputPeerNotifySettings",a.invokeApi("account.updateNotifySettings",{peer:{_:"inputNotifyPeer",peer:o.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 m(t){return e.idle.isIDLE?(x++,b&&"granted"===Notification.permission?(c.get("notify_nosound").then(function(e){e||g()}),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 g(){var e="img/sound_a.wav";$("#notify_sound").html('')}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,x=0,M={},C=$('link[rel="icon"]'),k=$(''),T=document.title;return e.$watch("idle.isIDLE",function(e){i.cancel(_),e?(T=document.title,_=i(function(){var e=tsNow();!x||e%2e3>1e3?(document.title=T,$('link[rel="icon"]').replaceWith(C)):(document.title=x>1?x+" notifications":"1 notification",$('link[rel="icon"]').replaceWith(k))},1e3)):(x=0,document.title=T,$('link[rel="icon"]').replaceWith(C),v())}),e.$on("apiUpdate",function(e,t){switch(t._){case"updateNotifySettings":if("notifyPeer"==t.peer._){var n=o.getPeerID(t.peer.peer);p(n,t.notify_settings)}}}),{start:f,notify:m,cancel:y,clear:v,getPeerSettings:l,getPeerMuted:d,savePeerSettings:p,updatePeerSettings:u}}]).service("ErrorService",["$rootScope","$modal","$window",function(e,t,n){function i(n,i){if(o>=2)return console.log("Skip error box, too many open",o,n,i),!1;i=i||{};var r=e.$new();angular.extend(r,n),o++;var a=t.open({templateUrl:"partials/error_modal.html",scope:r,windowClass:i.windowClass||"error_modal_window"});return a.result["finally"](function(){o--}),a}function r(e,t){return i({title:e,description:t})}function a(n,i){i=i||{};var r=e.$new();angular.extend(r,n);var a=t.open({templateUrl:"partials/confirm_modal.html",scope:r,windowClass:i.windowClass||"confirm_modal_window"});return a.result}var o=0;return n.safeConfirm=function(e,t){"string"==typeof e&&(e={message:e}),a(e).then(function(e){t(e||!0)},function(){t(!1)})},{show:i,alert:r,confirm:a}}]).service("PeersSelectService",["$rootScope","$modal",function(e,t){function n(){var n=e.$new();return t.open({templateUrl:"partials/peer_select.html",controller:"PeerSelectController",scope:n,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)}}}]),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","MtpApiManager","ErrorService",function(e,t,n,i,r){function a(e){i.setUserAuth(s.dcID,{expires:e.expires,id:e.user.id}),n.cancel(c),t.url("/im")}function o(){n.cancel(c),--e.callPending.remaining?c=n(o,1e3):(e.callPending.success=!1,i.invokeApi("auth.sendCall",{phone_number:e.credentials.phone_number,phone_code_hash:e.credentials.phone_code_hash},s).then(function(){e.callPending.success=!0}))}i.getUserID().then(function(e){return e?void t.url("/im"):void 0});var s={dcID:1,createNetworker:!0};e.credentials={},e.progress={},e.callPending={};var c;e.sendCode=function(){n.cancel(c),e.progress.enabled=!0,i.invokeApi("auth.checkPhone",{phone_number:e.credentials.phone_number},s).then(function(t){return e.progress.enabled=!1,t.phone_registered?(e.progress.enabled=!0,void i.invokeApi("auth.sendCode",{phone_number:e.credentials.phone_number,sms_type:0,api_id:2496,api_hash:"8da85b0d5bfe62527e5b244c209159c3"},s).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,o()},function(t){switch(e.progress.enabled=!1,console.log("sendCode error",t),t.type){case"PHONE_NUMBER_INVALID":e.error={field:"phone"},t.handled=!0}})):(r.show({error:{code:400,type:"ACCOUNT_REQUIRED"},phone:e.credentials.phone_number}),!1)},function(t){switch(e.progress.enabled=!1,t.type){case"PHONE_NUMBER_INVALID":e.error={field:"phone"},t.handled=!0}})},e.logIn=function(t){var n="auth.signIn",r={phone_number:e.credentials.phone_number,phone_code_hash:e.credentials.phone_code_hash,phone_code:e.credentials.phone_code};t&&(n="auth.signUp",angular.extend(r,{first_name:e.credentials.first_name,last_name:e.credentials.last_name})),e.progress.enabled=!0,i.invokeApi(n,r,s).then(a,function(t){if(e.progress.enabled=!1,400==t.code&&"PHONE_NUMBER_UNOCCUPIED"==t.type)return t.handled=!0,e.logIn(!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"},t.handled=!0}})}}]).controller("AppIMController",["$scope","$location","$routeParams","$modal","$rootScope","$modalStack","MtpApiManager","AppUsersManager","ContactsSelectService","ErrorService",function(e,t,n,i,r,a,o,s,c,l){function p(){e.curDialog={peer:n.p||!1}}e.$on("$routeUpdate",p),e.$on("history_focus",function(n,i){a.dismissAll(),i.peerString==e.curDialog.peer?e.$broadcast("ui_history_focus"):t.url("/im?p="+i.peerString)}),e.isLoggedIn=!0,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(){l.confirm({type:"LOGOUT"}).then(function(){o.logOut().then(function(){location.hash="/login",location.reload()})})},p()}]).controller("AppImDialogsController",["$scope","$location","MtpApiManager","AppUsersManager","AppChatsManager","AppMessagesManager","AppPeersManager",function(e,t,n,i,r,a){function o(){l=0,p=0,u=!1,d={},c=!1,a.getDialogs(e.search.query,p).then(function(t){e.dialogs=[],e.contacts=[],t.dialogs.length&&(l+=t.dialogs.length,p=t.dialogs[t.dialogs.length-1].top_message,u=null===t.count||l0?o=t:0>t&&(a=o+t),n=a;o>n;n++)i=e.history[n],r&&i.from_id==r.from_id&&i.date0){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)}),p.selectPeer().then(function(e){var n=c.getPeerID(e);s.forwardMessages(n,t).then(function(){w(),i.$broadcast("history_focus",{peerString:e})})})}}function C(){e.selectActions?w():(e.selectActions=!0,e.$broadcast("ui_panel_update"))}function k(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(),u.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=x,e.selectedForward=M,e.selectedCancel=w,e.selectedFlush=S,e.toggleEdit=C,e.toggleMedia=k,e.showPeerInfo=T;var A,E=0,D=!1,I=0,P={photos:"inputMessagesFilterPhotos",video:"inputMessagesFilterVideo",documents:"inputMessagesFilterDocument"},N=0,L={};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?k():e.missedCount++);e.history.push(s.wrapForHistory(r.messageID)),g(-3),e.typing={},e.$broadcast("ui_history_append",{my:r.my}),r.my&&(e.historyUnread={}),E++,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=o>=g.length?p():e.when();c.then(function(){s==_&&(t.messageID=g[o],t.photoID=a.getMessage(t.messageID).media.photo.id,t.photo=r.wrapForFull(t.photoID),u())})}function p(){return b?b:b=a.getSearch(f,h,m,y).then(function(e){y=e.history[e.history.length-1],g=g.concat(e.history),v=e.history.length||g.length0}if(t.photo=r.wrapForFull(t.photoID),t.nav={},!t.messageID)return void(t.nav.next=function(){i.close()});var d=a.getMessagePeer(a.getMessage(t.messageID)),f=o.getInputPeerByID(d),h="",m={_:"inputMessagesFilterPhotos"},g=[t.messageID],y=t.messageID,v=!0;u(),a.getSearch(f,h,m,0,1e3).then(function(e){e.history.indexOf(t.messageID)>=0&&(g=e.history,y=g[g.length-1],u())});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().then(function(t){var i=o.getPeerID(t);a.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(){a.deleteMessages([e])})},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=[],a=0;a0){var t=[];return angular.forEach(e.selectedContacts,function(e,n){t.push(n)}),n.close(t)}},e.importContact=function(){t.open({templateUrl:"partials/import_contact_modal.html",controller:"ImportContactModalController",windowClass:"import_contact_modal_window"}).result.then(function(t){t&&r(e.search&&e.search.query||"")})}}]).controller("PeerSelectController",["$scope","$modalInstance",function(e,t){e.dialogSelect=function(e){t.close(e)}}]).controller("ChatCreateModalController",["$scope","$modalInstance","$rootScope","MtpApiManager","AppUsersManager","AppChatsManager","ApiUpdatesManager",function(e,t,n,i,r,a,o){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),a.saveApiChats(e.chats),o.saveSeq(e.seq)&&o.saveUpdate({_:"updateNewMessage",message:e.message,pts:e.pts});var t=a.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,a,o){var s=a.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),a.saveApiChats(t.chats),o.saveSeq(t.seq)&&o.saveUpdate({_:"updateNewMessage",message:t.message,pts:t.pts});var i=a.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}))}}]),angular.module("myApp.filters",[]).filter("userName",[function(){return function(e){return e&&(e.first_name||e.last_name)?e.first_name+" "+e.last_name:"DELETED"}}]).filter("userFirstName",[function(){return function(e){return e&&(e.first_name||e.last_name)?e.first_name||e.last_name:"DELETED"}}]).filter("userStatus",["$filter",function(e){return function(t){return t&&t.status&&"userStatusEmpty"!=t.status._?"userStatusOnline"==t.status._?"online":"last seen "+e("relativeTime")(t.status.was_online):"offline"}}]).filter("chatTitle",[function(){return function(e){return e&&e.title?e.title:"DELETED"}}]).filter("dateOrTime",["$filter",function(e){var t={};return function(n){if(t[n])return t[n];var i=1e3*n,r=Math.abs(tsNow()-i),a="HH:mm";return r>5184e5?a="shortDate":r>432e5&&(a="EEE"),t[n]=e("date")(i,a)}}]).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),a=r.split(" ");return a[1]===i[1]?i[0]+" of "+a[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/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/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 \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
\n
\n
\n
\n\n
\n
\n Please select a chat to start messaging\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 +{{missedCount}}\n \n\n
\n

Photos

\n

Videos

\n

Documents

\n\n

\n
\n \n {{historyPeer.data | userStatus}}\n
\n
\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 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 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
\n
\n

Welcome to an unofficial web-client of mobile Telegram messenger.

\n

It is an alpha, which means it is still not 200% secure and functional.

\n

Visit telegram.org to learn more.

\n
\n Start Messaging\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("myDialogsList",["$window","$timeout",function(e,t){function n(n,i,r){function a(){return r.modal?($(i).css({height:$(e).height()-200}),void u()):(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 u())}var o=$(".im_dialogs_wrap",i)[0],s=$(".im_dialogs_scrollable_wrap",i)[0],c=$(".tg_page_head")[0],l=$(".im_page_footer")[0],p=!1;onContentLoaded(function(){$(o).nanoScroller({preventPageScrolling:!0,tabIndex:-1,iOSNativeScrolling:!0})});var u=function(){onContentLoaded(function(){$(o).nanoScroller()})};n.$on("ui_dialogs_prepend",u),n.$on("ui_dialogs_append",function(){onContentLoaded(function(){u(),p=!1,t(function(){$(s).trigger("scroll")})})}),n.$on("ui_dialogs_change",function(){onContentLoaded(function(){u(),p=!1,t(function(){$(s).trigger("scroll")})})}),$(s).on("scroll",function(){!p&&s.scrollTop>=s.scrollHeight-s.clientHeight-300&&(n.$emit("dialogs_need_more"),p=!0)}),$(e).on("resize",a),a(),setTimeout(a,1e3)}return{link:n}}]).directive("myContactsList",["$window","$timeout",function(e){function t(t,n){function i(){$(n).css({height:$(e).height()-(a&&a.offsetHeight||0)-(r&&r.offsetHeight||0)-200}),$(o).nanoScroller()}var r=$(".contacts_modal_search")[0],a=$(".contacts_modal_panel")[0],o=$(".contacts_wrap",n)[0];onContentLoaded(function(){$(o).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 a(t){if(r.is(":visible")&&$(r[0].parentNode).is(":visible")){$(h).is(":visible")&&$(h).css({height:$(y).height()}),m&&m.offsetHeight||(m=$(".tg_page_head")[0]),g&&g.offsetHeight||(g=$(".im_page_footer")[0]);var n=$(e).height()-d.offsetHeight-f.offsetHeight-(m?m.offsetHeight:44)-g.offsetHeight;$(s).css({height:n}),$(l).css({minHeight:n-44}),o(),t!==!0&&(C&&onContentLoaded(function(){p.scrollTop=p.scrollHeight,b()}),b(100))}}function o(){$(c).css({marginTop:0}),c.offsetHeight>0&&c.offsetHeight<=p.offsetHeight&&$(c).css({marginTop:p.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],p=$(".im_history_scrollable_wrap",r)[0],u=$(".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],m=$(".tg_page_head")[0],g=$(".im_page_footer")[0],y=$(".im_send_form",r)[0],v=!1;onContentLoaded(function(){p.scrollTop=p.scrollHeight,$(s).nanoScroller({preventPageScrolling:!0,tabIndex:-1,iOSNativeScrolling:!0})});var _,b=function(e){t(function(){$(p).hasClass("im_history_to_bottom")||$(s).nanoScroller()},e||0)},w=!1,S=["transform","webkitTransform","MozTransform","msTransform","OTransform"];for(_=0;_=p.scrollHeight-p.clientHeight,!v&&p.scrollTop<=300&&(v=!0,i.$emit("history_need_more"))))}),$(e).on("resize",a),a(),onContentLoaded(a)}return{link:i}}]).directive("mySendForm",["$timeout","AppConfigManager","ErrorService",function(e,t,n){function i(i,r){function a(){if(_){e.cancel(b);var t=$("
").text(i.draftMessage.text||"").html();t=t.replace(/\n/g,"
"),$(_).html(t),s()}}function o(){_&&($(_).trigger("change"),s())}function s(){var e=_.offsetHeight;M!=e&&(M=e,i.$emit("ui_editor_resize"))}function c(){onContentLoaded(function(){v.focus()})}function l(e){var t,r=e&&e.target;if(r&&(t=r.src)&&0===t.indexOf("data")){r.parentNode.removeChild(r),t=t.substr(5).split(";");for(var a=t[0],o=atob(t[1].split(",")[1]),s=new Uint8Array(o.length),c=0;c0&&n.confirm({type:"FILES_CLIPBOARD_PASTE",files:o}).then(function(){i.draftMessage.files=o,i.draftMessage.isMedia=!0})}function u(e){var t=!1;return d&&1!=d||(d=checkDragEvent(e)?2:1,t=!0),2==d&&(f&&setTimeout(function(){clearTimeout(f),f=!1},0),"dragenter"==e.type||"dragover"==e.type?t&&$(g).css({height:$(v).height()+12,width:$(v).width()+12}).show():("drop"==e.type&&i.$apply(function(){i.draftMessage.files=Array.prototype.slice.call(e.originalEvent.dataTransfer.files),i.draftMessage.isMedia=!0}),f=setTimeout(function(){$(g).hide(),d=!1,f=!1},300))),cancelEvent(e)}var d,f,h=$("textarea",r)[0],m=$("input",r),g=$(".im_send_dropbox_wrap",r)[0],y=$(".im_emoji_btn",r)[0],v=h,_=($(h).emojiarea({button:y,norealTime:!0}),$(".emoji-menu",r)[0],$(".emoji-wysiwyg-editor",r)[0]);if(_){v=_,$(_).addClass("form-control"),$(_).attr("placeholder",$(h).attr("placeholder"));var b;$(_).on("keyup",function(){s(),i.draftMessage.text=_.innerText,e.cancel(b),b=e(o,1e3)})}m.on("change",function(){var e=this;i.$apply(function(){i.draftMessage.files=Array.prototype.slice.call(e.files),i.draftMessage.isMedia=$(e).hasClass("im_media_attach_input"),setTimeout(function(){try{e.value=""}catch(t){}},1e3)})});var w=!0,S=function(){t.get("send_ctrlenter").then(function(e){w=!e})};i.$on("settings_changed",S),S(),$(v).on("keydown",function(e){if(_&&s(),13==e.keyCode){var t=!1;if(w&&!e.shiftKey?t=!0:w||!e.ctrlKey&&!e.metaKey||(t=!0),t)return $(r).trigger("submit"),cancelEvent(e)}});var x=0;$(v).on("keyup",function(){var e=tsNow();5e3>e-x||(x=e,i.$emit("ui_typing"))});var M=_.offsetHeight;$("body").on("dragenter dragleave dragover drop",u),$(document).on("paste",p),_&&$(_).on("DOMNodeInserted",l),i.$on("ui_peer_change",c),i.$on("ui_history_focus",c),i.$on("ui_history_change",c),i.$on("ui_message_send",c),i.$on("ui_peer_draft",a),i.$on("ui_message_before_send",o),i.$on("$destroy",function(){$("body").off("dragenter dragleave dragover drop",u),$(document).off("paste",p),_&&$(_).off("DOMNodeInserted",l)}),c()}return{link:i,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 a=(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));var o=++i;if(!r||r.empty)return n.attr("src",t.thumb&&t.thumb.placeholder||"img/blank.gif"),void a();var s=e.getCachedFile(r);return s?(n.attr("src",s),void a()):(n.attr("src")||n.attr("src",t.thumb.placeholder||"img/blank.gif"),void e.downloadSmallFile(t.thumb.location).then(function(e){o==i&&(n.attr("src",e),a())},function(e){console.log("Download image failed",e,t.thumb.location,n[0]),o==i&&(n.attr("src",t.thumb.placeholder||"img/blank.gif"),a())}))}),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)),a=function(){r.css({width:t.fullPhoto.width,height:t.fullPhoto.height}),t.$emit("ui_height")},o=0;t.$watchCollection("fullPhoto.location",function(){var n=e.getCachedFile(t.thumbLocation),r=++o;if(n?(i.src=n,a()):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==o&&(t.progress.enabled=!1,i.src=e,a())},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))})}}),a()}return{link:t,transclude:!0,template:'
{{error.text}}
',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},a=!1;if(navigator.plugins)for(i=0;i=0&&(a=!0);var o=t.downloadFile(n.video.dc_id,r,n.video.size,null,{mime:"video/mp4"});o.then(function(t){n.progress.enabled=!1,n.player.hasQuicktime=a,n.player.quicktime=!1,n.player.src=e.trustAsResourceUrl(t)},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.$on("$destroy",function(){o.cancel()})}return{link:n,transclude:!0,template:'
',scope:{video:"="}}}]).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;te?$(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(a),$(e).on("resize",a),n.$on("ui_height",function(){onContentLoaded(a)})}return{link:n}}]).directive("myVerticalPosition",["$window","$timeout",function(e){function t(t,n,i){var r=!1,a=function(){var a=n[0].offsetHeight,o=$(e).height(),s=i.myVerticalPosition&&parseFloat(i.myVerticalPosition)||.5,c=o>a?parseInt((o-a)*s):"";n.css({marginTop:c,marginBottom:c}),r!==c&&t.$emit("ui_height"),r=c};onContentLoaded(a),$(e).on("resize",a),t.$on("ui_height",function(){onContentLoaded(a)})}return{link:t}}]);