diff --git a/js/app.js b/js/app.js index 0f7e2bbf..de79d6a7 100644 --- a/js/app.js +++ b/js/app.js @@ -24,11 +24,11 @@ g=p.constructors[u];break}if(!g)throw new Error("Constructor not found for predi function u(){if(!f&&!Config.Navigator.mobile&&!Config.Modes.packed){f=!0,l.start(),t.$watch("idle.isIDLE",g),i(g,5e3),g();try{$($window).on("beforeunload",p)}catch(e){}}}function p(){s.remove(_?"xt_instance":"xt_idle_instance")}function m(){if(_||y)return!1;console.log(dT(),"deactivate"),v=!1,y=!0,p(),o.dismissAll(),document.title=e("inactive_tab_title_raw");var a=n(""),i=t.$new(!0);i.close=function(){r.close()},i.reload=function(){r.reload()},a(i,function(e){$(".page_wrap").hide(),$(e).appendTo($("body"))}),t.idle.deactivated=!0}function g(){if(y)return!1;var e=tsNow(),n=t.idle&&t.idle.isIDLE,i={id:h,idle:n,time:e};s.get("xt_instance","xt_idle_instance").then(function(t){var o=t[0],r=t[1];!n||!o||o.id==h||o.time=1e3?void o.resolve(s):void this["continue"]()},t.onerror=function(e){console.log("phonebook error",e,e.type,e.message),o.reject(e)},o.promise}return{isAvailable:i,openPhonebookImport:o,getPhonebookContacts:s}}]).service("AppChatsManager",["$q","$rootScope","$modal","_","MtpApiManager","AppUsersManager","AppPhotosManager","RichTextProcessor",function(e,t,n,a,i,o,s,r){function l(e){angular.forEach(e,c)}function c(e){if(angular.isObject(e)){e.rTitle=r.wrapRichText(e.title,{noLinks:!0,noLinebreaks:!0})||a("chat_title_deleted");var n=C[e.id],i=SearchIndexManager.cleanSearchText(e.title||"").split(" "),o=i.shift(),s=i.pop();if(e.initials=o.charAt(0)+(s?s.charAt(0):o.charAt(1)),e.num=Math.abs(e.id>>1)%8+1,void 0===e.pFlags&&(e.pFlags={}),!e.pFlags.min||void 0===n){if(e.username){var l=SearchIndexManager.cleanUsername(e.username);S[l]=e.id}void 0===n?n=C[e.id]=e:(safeReplaceObject(n,e),t.$broadcast("chat_update",e.id)),void 0!==I[e.id]&&safeReplaceObject(I[e.id],e&&e.photo&&e.photo.photo_small||{empty:!0})}}}function d(e){return C[e]||{id:e,deleted:!0,access_hash:M[e]}}function u(e,t){if(void 0===C[e])return!1;var n=d(e);if("chatForbidden"==n._||"channelForbidden"==n._||n.pFlags.kicked||n.pFlags.left)return!1;if(n.pFlags.creator)return!0;switch(t){case"send":if("channel"==n._&&!n.pFlags.megagroup&&!n.pFlags.editor)return!1;break;case"edit_title":case"edit_photo":case"invite":if("channel"==n._){if(!n.pFlags.megagroup)return!1;if(!(n.pFlags.editor||"invite"==t&&n.pFlags.democracy))return!1}else if(n.pFlags.admins_enabled&&!n.pFlags.admin)return!1}return!0}function p(e){return S[e]||0}function m(e,t){M[e]=t}function g(e){x[e]=!0}function h(e){var t=C[e];return!((!t||"channel"!=t._&&"channelForbidden"!=t._)&&!M[e])}function f(e){if(x[e])return!0;var t=C[e];return!(!t||"channel"!=t._||!t.pFlags.megagroup)}function _(e){return e||0}function v(e){return e?{_:"inputChannel",channel_id:e,access_hash:d(e).access_hash||M[e]||0}:{_:"inputChannelEmpty"}}function y(e,t){var n=C[e];return angular.isObject(n)&&(t||!n.pFlags.min)}function b(e){var t=d(e);return void 0===I[e]&&(I[e]=t&&t.photo&&t.photo.photo_small||{empty:!0}),{placeholder:"img/placeholders/GroupAvatar"+Math.ceil(t.num/2)+"@2x.png",location:I[e]}}function w(e){var t=d(e);return h(e)?(f(e)?"s":"c")+e+"_"+t.access_hash:"g"+e}function k(e,t){var n=angular.copy(t),a=d(e);if(n.participants&&"chatParticipants"==n.participants._&&i.getUserID().then(function(e){var t=a.pFlags.creator||a.pFlags.admins_enabled&&a.pFlags.admin;angular.forEach(n.participants.participants,function(n){n.canLeave=e==n.user_id,n.canKick=!n.canLeave&&(a.pFlags.creator||"chatParticipant"==n._&&(t||e==n.inviter_id)),n.user=o.getUser(n.user_id)})}),n.participants&&"channelParticipants"==n.participants._){var s=a.pFlags.creator||a.pFlags.editor||a.pFlags.moderator;angular.forEach(n.participants.participants,function(e){e.canLeave=!a.pFlags.creator&&"channelParticipantSelf"==e._,e.canKick=s&&"channelParticipant"==e._,e.user=o.getUser(e.user_id)})}return n.about&&(n.rAbout=r.wrapRichText(n.about,{noLinebreaks:!0})),n.peerString=w(e),n.chat=a,n}function $(e,a){var i=t.$new();if(i.chatID=e,h(e)){n.open({templateUrl:templateUrl("channel_modal"),controller:"ChannelModalController",scope:i,windowClass:"chat_modal_window channel_modal_window mobile_modal"})}else{n.open({templateUrl:templateUrl("chat_modal"),controller:"ChatModalController",scope:i,windowClass:"chat_modal_window mobile_modal"})}}var C={},S={},M={},x={},I={};return t.$on("apiUpdate",function(e,n){switch(n._){case"updateChannel":var a=n.channel_id;t.$broadcast("channel_settings",{channelID:a})}}),{saveApiChats:l,saveApiChat:c,getChat:d,isChannel:h,isMegagroup:f,hasRights:u,saveChannelAccess:m,saveIsMegagroup:g,getChatInput:_,getChannelInput:v,getChatPhoto:b,getChatString:w,resolveUsername:p,hasChat:y,wrapForFull:k,openChat:$}}]).service("AppPeersManager",["$q","qSync","AppUsersManager","AppChatsManager","MtpApiManager",function(e,t,n,a,i){function o(e){var t=e.charAt(0),i=e.substr(1).split("_");return"u"==t?(n.saveUserAccess(i[0],i[1]),{_:"inputPeerUser",user_id:i[0],access_hash:i[1]}):"c"==t||"s"==t?(a.saveChannelAccess(i[0],i[1]),"s"==t&&a.saveIsMegagroup(i[0]),{_:"inputPeerChannel",channel_id:i[0],access_hash:i[1]||0}):{_:"inputPeerChat",chat_id:i[0]}}function s(e){if(!e)return{_:"inputPeerEmpty"};if(e<0){var t=-e;return a.isChannel(t)?{_:"inputPeerChannel",channel_id:t,access_hash:a.getChat(t).access_hash||0}:{_:"inputPeerChat",chat_id:t}}return{_:"inputPeerUser",user_id:e,access_hash:n.getUser(e).access_hash||0}}function r(e){var t;if(e>0)t="%pu "+n.getUserSearchText(e);else if(e<0){var i=a.getChat(-e);t="%pg "+(i.title||"")}return t}function l(e){return e>0?n.getUserString(e):a.getChatString(-e)}function c(e){if(e>0)return{_:"peerUser",user_id:e};var t=-e;return a.isChannel(t)?{_:"peerChannel",channel_id:t}:{_:"peerChat",chat_id:t}}function d(e){var o=SearchIndexManager.cleanUsername(e);if(o.match(/^\d+$/))return t.when(!1);var s,r,l;return(s=n.resolveUsername(o))&&(l=n.getUser(s).username,SearchIndexManager.cleanUsername(l)==o)?t.when(s):(r=a.resolveUsername(o))&&(l=a.getChat(r).username,SearchIndexManager.cleanUsername(l)==o)?t.when(-r):i.invokeApi("contacts.resolveUsername",{username:e}).then(function(e){return n.saveApiUsers(e.users),a.saveApiChats(e.chats),u(e.peer)})}function u(e){if(angular.isObject(e))return e.user_id?e.user_id:-(e.channel_id||e.chat_id);var t="u"==e.charAt(0),n=e.substr(1).split("_");return t?n[0]:-n[0]||0}function p(e){return e>0?n.getUser(e):a.getChat(-e)}function m(e){return e>0?n.getUserPhoto(e):a.getChatPhoto(-e)}function g(e){return e<0&&a.isChannel(-e)}function h(e){return e<0&&a.isMegagroup(-e)}function f(e){return e>0&&n.isBot(e)}return{getInputPeer:o,getInputPeerByID:s,getPeerSearchText:r,getPeerString:l,getOutputPeer:c,getPeerID:u,getPeer:p,getPeerPhoto:m,resolveUsername:d,isChannel:g,isMegagroup:h,isBot:f}}]).service("AppProfileManager",["$q","$rootScope","AppUsersManager","AppChatsManager","AppPeersManager","AppPhotosManager","NotificationsManager","MtpApiManager","ApiUpdatesManager","RichTextProcessor",function(e,t,n,a,i,o,s,r,l,c){function d(e){var t=e&&e.user_id;if(!t)return!1;var n={};return angular.forEach(e.commands,function(e){n[e.command]=e.description}),_[t]={id:t,version:e.version,shareText:e.share_text,description:e.description,commands:n}}function u(e,t){return r.invokeApi("users.getFullUser",{id:n.getUserInput(e)}).then(function(a){return t&&t.phone_number?(a.user.phone=t.phone_number,(t.first_name||t.last_name)&&(a.user.first_name=t.first_name,a.user.last_name=t.last_name),n.saveApiUser(a.user)):n.saveApiUser(a.user,!0),a.profile_photo&&o.savePhoto(a.profile_photo,{user_id:e}),void 0!==a.about&&(a.rAbout=c.wrapRichText(a.about,{noLinebreaks:!0})),s.savePeerSettings(e,a.notify_settings),a.bot_info&&(a.bot_info=d(a.bot_info)),a})}function p(t){var a=[];return t>=0&&!n.isBot(t)||i.isChannel(t)&&!i.isMegagroup(t)?e.when(a):t>=0?u(t).then(function(e){var t=e.bot_info;return t&&"botInfoEmpty"!=t._&&a.push(t),a}):m(-t).then(function(e){return angular.forEach(e.bot_info,function(e){a.push(d(e))}),a})}function m(i){if(a.isChannel(i))return f(i);if(void 0!==v[i]){var l=a.getChat(i);if(l.version==v[i].participants.version||l.pFlags.left)return e.when(v[i])}return void 0!==y[i]?y[i]:(console.trace(dT(),"Get chat full",i,a.getChat(i)),y[i]=r.invokeApi("messages.getFullChat",{chat_id:a.getChatInput(i)}).then(function(e){a.saveApiChats(e.chats),n.saveApiUsers(e.users);var r=e.full_chat;return r&&r.chat_photo.id&&o.savePhoto(r.chat_photo),s.savePeerSettings(-i,r.notify_settings),delete y[i],v[i]=r,t.$broadcast("chat_full_update",i),r}))}function g(e,t){return m(e).then(function(n){if(!t&&n.exported_invite&&"chatInviteExported"==n.exported_invite._)return n.exported_invite.link;var i;return i=a.isChannel(e)?r.invokeApi("channels.exportInvite",{channel:a.getChannelInput(e)}):r.invokeApi("messages.exportChatInvite",{chat_id:a.getChatInput(e)}),i.then(function(t){return void 0!==v[e]&&(v[e].exported_invite=t),t.link})})}function h(e){return r.invokeApi("channels.getParticipants",{channel:a.getChannelInput(e),filter:{_:"channelParticipantsRecent"},offset:0,limit:a.isMegagroup(e)?50:200}).then(function(t){n.saveApiUsers(t.users);var i=t.participants,o=a.getChat(e);if(!o.pFlags.kicked&&!o.pFlags.left){for(var s,r=n.getSelf().id,l=!1,c=0,d=i.length;c800&&(a-=208);var s=l(n,a,o);s&&!s.preloaded&&(s.preloaded=!0,s.size?i.downloadFile(s.location.dc_id,{_:"inputFileLocation",volume_id:s.location.volume_id,local_id:s.location.local_id,secret:s.location.secret},s.size):i.downloadSmallFile(s.location))}}function u(e){return f[e]||{_:"photoEmpty"}}function p(e,t){t=t||{};var n=angular.copy(f[e])||{_:"photoEmpty"},a=t.website?64:Math.min(_-80,Config.Mobile?210:260),i=t.website?64:Math.min(v-100,Config.Mobile?210:260),o=l(n,a,i),s={placeholder:"img/placeholders/PhotoThumbConversation.gif",width:a,height:i};if(t.website&&Config.Mobile&&(a=50,i=50),o&&"photoSizeEmpty"!=o._){var r=calcImageInBox(o.w,o.h,a,i);s.width=r.w,s.height=r.h,s.location=o.location,s.size=o.size}else s.width=100,s.height=100;return n.thumb=s,n}function m(e){var n=p(e),a=$(window).width()-(Config.Mobile?0:32),i=$(t).height()-(Config.Mobile?0:116);!Config.Mobile&&a>800&&(a-=208);var o=l(n,a,i),s={placeholder:"img/placeholders/PhotoThumbModal.gif"};if(s.width=a,s.height=i,o&&"photoSizeEmpty"!=o._){var r=calcImageInBox(o.w,o.h,a,i,!0);s.width=r.w,s.height=r.h,s.modalWidth=Math.max(s.width,Math.min(400,a)),s.location=o.location,s.size=o.size}return n.full=s,n}function g(t,a){if(!t||"0"===t)return!1;var i=n.$new(!0);i.photoID=t;var o="PhotoModalController";a&&a.p>0?(o="UserpicModalController",i.userID=a.p):a&&a.p<0?(o="ChatpicModalController",i.chatID=-a.p):a&&a.m>0&&(i.messageID=a.m,a.w&&(i.webpageID=a.w));e.open({templateUrl:templateUrl("photo_modal"),windowTemplateUrl:templateUrl("media_modal_layout"),controller:o,scope:i,windowClass:"photo_modal_window"})}function h(e){var n=f[e],a="jpg",o="image/jpeg",r="photo"+e+"."+a,c=Math.max(screen.width||0,$(window).width()-36,800),d=Math.max(screen.height||0,$(t).height()-150,800),u=l(n,c,d),p={_:"inputFileLocation",volume_id:u.location.volume_id,local_id:u.location.local_id,secret:u.location.secret};s.chooseSave(r,a,o).then(function(e){e&&i.downloadFile(u.location.dc_id,p,u.size,{mime:o,toFileEntry:e}).then(function(){},function(e){console.log("photo download failed",e)})},function(){var e=i.getCachedFile(p);return e?s.download(e,o,r):void i.downloadFile(u.location.dc_id,p,u.size,{mime:o}).then(function(e){s.download(e,o,r)},function(e){console.log("photo download failed",e)})})}var f={},_=$(window).width(),v=$(window).height();return n.preloadPhoto=d,n.openPhoto=g,{savePhoto:r,preloadPhoto:d,getUserPhotos:c,getPhoto:u,choosePhotoSize:l,wrapForHistory:p,wrapForFull:m,openPhoto:g,downloadPhoto:h}}]).service("AppWebPagesManager",["$modal","$sce","$window","$rootScope","MtpApiManager","AppPhotosManager","AppDocsManager","RichTextProcessor",function(e,t,n,a,i,o,s,r){function l(e,t,n){e.photo&&"photo"===e.photo._?o.savePhoto(e.photo,n):delete e.photo,e.document&&"document"===e.document._?s.saveDoc(e.document,n):("document"==e.type&&delete e.type,delete e.document);var i=e.site_name,l=e.title||e.author||i||"";i&&l==i&&delete e.site_name,l.length>100&&(l=l.substr(0,80)+"..."),e.rTitle=r.wrapRichText(l,{noLinks:!0,noLinebreaks:!0});var c="";if("GitHub"==i){var d=e.url.match(/(https?:\/\/github\.com\/[^\/]+\/[^\/]+)/);d&&(c=d[0]+"/issues/{1}")}var u=e.description||"";if(u.length>180&&(u=u.substr(0,150).replace(/(\n|\s)+$/,"")+"..."),e.rDescription=r.wrapRichText(u,{contextSite:i||"external",contextHashtag:c}),"photo"!=e.type&&"video"!=e.type&&"gif"!=e.type&&"document"!=e.type&&!e.description&&e.photo&&(e.type="photo"),t&&(void 0===m[e.id]&&(m[e.id]={}),m[e.id][t]=!0,p[e.id]=e),void 0===p[e.id]?p[e.id]=e:safeReplaceObject(p[e.id],e),!t&&void 0!==m[e.id]){var g=[];angular.forEach(m[e.id],function(e,t){g.push(t)}),a.$broadcast("webpage_updated",{id:e.id,msgs:g})}}function c(t,n){var i=a.$new(!0);i.webpageID=t,i.messageID=n,e.open({templateUrl:templateUrl("embed_modal"),windowTemplateUrl:templateUrl("media_modal_layout"),controller:"EmbedModalController",scope:i,windowClass:"photo_modal_window"})}function d(e){var t=angular.copy(p[e])||{_:"webPageEmpty"};return t.photo&&t.photo.id&&(t.photo=o.wrapForHistory(t.photo.id,{website:"photo"!=t.type&&"video"!=t.type})),t.document&&t.document.id&&(t.document=s.wrapForHistory(t.document.id)),t}function u(e){var a=d(e);if(!a.embed_url)return a;var i=$(window).width()-(Config.Mobile?0:10),o=$(n).height()-(Config.Mobile?92:150);!Config.Mobile&&i>800&&(i-=208);var s={width:i,height:o};if(a.embed_width&&a.embed_height){var r=calcImageInBox(a.embed_width,a.embed_height,i,o);s.width=r.w,s.height=r.h}else s.height=s.width=Math.min(i,o);var l=Config.Modes.chrome_packed?"webview":"iframe",c="iframe"!=a.embed_type?a.embed_type||"text/html":"text/html",u="<"+l+' src="'+encodeEntities(a.embed_url)+'" type="'+encodeEntities(c)+'" frameborder="0" border="0" webkitallowfullscreen mozallowfullscreen allowfullscreen width="'+s.width+'" height="'+s.height+'" style="width: '+s.width+"px; height: "+s.height+'px;">";return s.html=t.trustAs("html",u),a.full=s,a}var p={},m={};return a.$on("apiUpdate",function(e,t){switch(t._){case"updateWebPage":l(t.webpage)}}),{saveWebPage:l,openEmbed:c,wrapForFull:u,wrapForHistory:d}}]).service("AppDocsManager",["$sce","$rootScope","$modal","$window","$q","$timeout","RichTextProcessor","MtpApiFileManager","FileManager","qSync",function(e,t,n,a,i,o,s,r,l,c){function d(e,t){if(w[e.id]=e,t&&angular.extend(e,t),e.thumb&&"photoCachedSize"==e.thumb._&&(r.saveSmallFile(e.thumb.location,e.thumb.bytes),e.thumb.size=e.thumb.bytes.length,delete e.thumb.bytes,e.thumb._="photoSize"),e.thumb&&"photoSizeEmpty"==e.thumb._&&delete e.thumb,angular.forEach(e.attributes,function(t){switch(t._){case"documentAttributeFilename":e.file_name=t.file_name;break;case"documentAttributeAudio":e.duration=t.duration,e.audioTitle=t.title,e.audioPerformer=t.performer,e.type=t.pFlags.voice?"voice":"audio";break;case"documentAttributeVideo":e.duration=t.duration,e.w=t.w,e.h=t.h,e.thumb&&(e.type="video");break;case"documentAttributeSticker":e.sticker=!0,void 0!==t.alt&&(e.stickerEmojiRaw=t.alt,e.stickerEmoji=s.wrapRichText(e.stickerEmojiRaw,{noLinks:!0,noLinebreaks:!0})),t.stickerset&&("inputStickerSetEmpty"==t.stickerset._?delete t.stickerset:"inputStickerSetID"==t.stickerset._&&(e.stickerSetInput=t.stickerset)),e.thumb&&"image/webp"==e.mime_type&&(e.type="sticker");break;case"documentAttributeImageSize":e.w=t.w,e.h=t.h;break;case"documentAttributeAnimated":"image/gif"!=e.mime_type&&"video/mp4"!=e.mime_type||!e.thumb||(e.type="gif"),e.animated=!0}}),!e.mime_type)switch(e.type){case"gif":e.mime_type="video/mp4";break;case"video":e.mime_type="video/mp4";break;case"sticker":e.mime_type="image/webp";break;case"audio":e.mime_type="audio/mpeg";break;case"voice":e.mime_type="audio/ogg";break;default:e.mime_type="application/octet-stream"}e.file_name||(e.file_name=""),"documentEmpty"==e._&&(e.size=0)}function u(e){return w[e]||{_:"documentEmpty"}}function p(e){return void 0!==w[e]}function m(e){if(e.file_name)return e.file_name;var t="."+e.mime_type.split("/")[1];return".octet-stream"==t&&(t=""),"t_"+(e.type||"file")+e.id+t}function g(e){if(void 0!==k[e])return k[e];var t,n,a,i,o=angular.copy(w[e]),s=o.thumb,r=!1;switch(o.type){case"video":t=Math.min(C-80,Config.Mobile?210:150),n=Math.min(S-100,Config.Mobile?210:150);break;case"sticker":r=!0,t=Math.min(C-80,Config.Mobile?128:192),n=Math.min(S-100,Config.Mobile?128:192);break;case"gif":r=!0,t=Math.min(C-80,Config.Mobile?210:260),n=Math.min(S-100,Config.Mobile?210:260);break;default:t=n=100}return r&&o.w&&o.h?i=calcImageInBox(o.w,o.h,t,n):s&&(i=calcImageInBox(s.w,s.h,t,n)),i?(a={width:i.w,height:i.h},s&&(a.location=s.location,a.size=s.size)):a=!1,o.thumb=a,o.withPreview=!Config.Mobile&&o.mime_type.match(/^image\/(gif|png|jpeg|jpg|bmp|tiff)/)?1:0,k[e]=o}function h(e){var t=w[e],n=k[e]||t||{},a={_:"inputDocumentFileLocation",id:e,access_hash:t.access_hash,file_name:m(t)};void 0===n.downloaded&&r.getDownloadedFile(a,t.size).then(function(){n.downloaded=!0},function(){n.downloaded=!1})}function f(n,a){var s=w[n],d=k[n]||s||{},u={_:"inputDocumentFileLocation",id:n,access_hash:s.access_hash,file_name:m(s)};if("documentEmpty"==s._)return i.reject();if(d.downloaded&&!a){var p=r.getCachedFile(u);if(p)return c.when(p)}d.progress={enabled:!d.downloaded,percent:1,total:s.size};var g=r.downloadFile(s.dc_id,u,s.size,{mime:s.mime_type||"application/octet-stream",toFileEntry:a});return g.then(function(t){t&&(l.getFileCorrectUrl(t,s.mime_type).then(function(t){var n=e.trustAsResourceUrl(t);d.url=n,s.url=n}),d.downloaded=!0),d.progress.percent=100,o(function(){delete d.progress})},function(e){console.log("document download failed",e),d.progress.enabled=!1},function(e){console.log("dl progress",e),d.progress.enabled=!0,d.progress.done=e.done,d.progress.percent=Math.max(1,Math.floor(100*e.done/e.total)),t.$broadcast("history_update")}),d.progress.cancel=g.cancel,g}function _(e,a){var i=t.$new(!0);i.docID=e,i.messageID=a;n.open({templateUrl:templateUrl("document_modal"),windowTemplateUrl:templateUrl("media_modal_layout"),controller:"DocumentModalController",scope:i,windowClass:"document_modal_window"})}function v(e){var t=w[e],n=(k[e]||t||{},t.mime_type,m(t)),a=(n.split(".",2)||[])[1]||"";l.chooseSave(m(t),a,t.mime_type).then(function(t){t&&f(e,t)},function(){f(e).then(function(e){l.download(e,t.mime_type,n)})})}function y(e){var t=g(e),n=Math.min($(window).width()-(Config.Mobile?0:60),542),a=$(window).height()-(Config.Mobile?92:150),i={placeholder:"img/placeholders/docThumbModal.gif",width:n,height:a};if(t.w&&t.h){var o=calcImageInBox(t.w,t.h,n,a);i.width=o.w,i.height=o.h}else i.height=i.width=Math.min(n,a);return t.full=i,t.fullThumb=angular.copy(t.thumb),t.fullThumb.width=i.width,t.fullThumb.height=i.height,t}function b(e,a){var i=t.$new(!0);return i.docID=e,i.messageID=a,n.open({templateUrl:templateUrl("video_modal"),windowTemplateUrl:templateUrl("media_modal_layout"),controller:"VideoModalController",scope:i,windowClass:"video_modal_window"})}var w={},k={},C=$(window).width(),S=$(window).height();return{saveDoc:d,getDoc:u,hasDoc:p,wrapForHistory:g,wrapVideoForFull:y,updateDocDownloaded:h,downloadDoc:f,openDoc:_,openVideo:b,saveDocFile:v}}]).service("AppStickersManager",["$q","$rootScope","$modal","_","FileManager","MtpApiManager","AppDocsManager","Storage","ApiUpdatesManager",function(e,t,n,a,i,o,s,r,l){function c(){b||(b=!0,setTimeout(d,1e3))}function d(e){return r.get("all_stickers").then(function(t){var n=Config.Schema.API.layer;return t.layer!=n&&(t=!1),t&&t.date>tsNow(!0)&&!e?u(t):o.invokeApi("messages.getAllStickers",{hash:t&&t.hash||""}).then(function(e){var a="messages.allStickersNotModified"==e._;return a&&(e=t),e.date=tsNow(!0)+3600,e.layer=n,delete e._,a?(r.set({ all_stickers:e}),u(e)):p(e,t&&t.fullSets).then(function(){return r.set({all_stickers:e}),u(e)})})})}function u(e){if(w!==e.hash){w=e.hash;var t,n,i,o,r,l,c,d;for(k=[],i=e.sets.length,t=0;t15&&(i=i.slice(0,15)),i.push([e,1])),ConfigStorage.set({stickers_popular:i})})}function h(e){return o.invokeApi("messages.getStickerSet",{stickerset:e}).then(function(e){for(var t=0;t1209600||(a=e[t][0],p.hasUser(a)||p.saveApiUser(e[t][1]),i.push({id:a,rate:e[t][2],date:e[t][3]}))}return i})}function _(e){f().then(function(t){for(var a=!1,i=t.length,o=[],s=0;s15&&(o=o.slice(0,15)),o.push([e,p.getUser(e),1,tsNow(!0)])),ConfigStorage.set({inline_bots_popular:o}),n.$broadcast("inline_bots_popular")})}function v(n){return m.resolveUsername(n).then(function(a){if(a>0){var i=p.getUser(a);if(i.pFlags.bot&&void 0!==i.bot_inline_placeholder){var o={username:n,id:a,placeholder:i.bot_inline_placeholder};return i.pFlags.bot_inline_geo&&h.isAvailable()?x(a).then(function(){return h.getPosition().then(function(t){return o.geo=t,e.when(o)})})["catch"](function(){return e.when(o)}):e.when(o)}}return t.reject()},function(e){return e.handled=!0,t.reject(e)})}function y(e,t,n,a,i){return s.invokeApi("messages.getInlineBotResults",{flags:0|(a?1:0),bot:p.getUserInput(t),peer:m.getInputPeerByID(e),query:n,geo_point:a&&{_:"inputGeoPoint",lat:a.lat,"long":a["long"]},offset:i},{timeout:1,stopTime:-1,noErrorBox:!0}).then(function(e){var n=e.query_id;return delete e._,delete e.flags,delete e.query_id,e.switch_pm&&(e.switch_pm.rText=u.wrapRichText(e.switch_pm.text,{noLinebreaks:!0,noLinks:!0})),angular.forEach(e.results,function(e){var a=n+"_"+e.id;e.qID=a,e.botID=t,e.rTitle=u.wrapRichText(e.title,{noLinebreaks:!0,noLinks:!0}),e.rDescription=u.wrapRichText(e.description,{noLinebreaks:!0,noLinks:!0}),e.initials=(e.url||e.title||e.type||"").substr(0,1),e.document&&c.saveDoc(e.document),e.photo&&d.savePhoto(e.photo),I[a]=e}),e})}function b(e,t,n){if(e&&e[0]&&("photo"==e[0].type||"gif"==e[0].type||"sticker"==e[0].type)){var a=[];angular.forEach(e,function(e){var t,n,i,o;if("botInlineMediaResult"==e._){if(i=e.document)t=e.document.w,n=e.document.h;else if(o=e.photo){var s=(o.sizes||[])[0];t=s&&s.w,n=s&&s.h}}else t=e.w,n=e.h;t&&n||(t=n=1),a.push(t/n)});var i=[],o=0,s=0;angular.forEach(a,function(e){var a=e*n;s+=a,!o||o<4&&s<1.1*t?o++:(i.push(o),o=1,s=a)}),o&&i.push(o);var r=0,l=i.length-1;angular.forEach(i,function(i,o){var s=o==l,c=a.slice(r,r+i),d=0;angular.forEach(c,function(e){d+=e}),angular.forEach(c,function(a,i){var o=n,l=t*a/d,c=o*a;s&&l>c&&(l=c);var u=e[r+i];u.thumbW=Math.floor(l)-2,u.thumbH=Math.floor(o)-2}),r+=i})}}function w(e,t,a){var o=m.getPeerString(e),s={};s["inline_switch_pm"+t]={peer:o,time:tsNow()},i.set(s),n.$broadcast("history_focus",{peerString:m.getPeerString(t)}),r.startBot(t,0,a)}function k(t){var n=p.getUser(t);if(!n||!n.pFlags.bot||!n.bot_inline_placeholder)return e.when(!1);var a="inline_switch_pm"+t;return i.get(a).then(function(e){return!!(e&&(i.remove(a),tsNow()-e.time<36e5))&&e.peer})}function $(e,t,a){n.$broadcast("history_focus",{peerString:t,attachment:{_:"inline_query",mention:"@"+p.getUser(e).username,query:a}})}function C(e,t){var n=r.getMessage(e),a=n.viaBotID||n.fromID;return k(a).then(function(e){return e?$(a,e,t.query):void g.selectPeer({canSend:!0}).then(function(e){return $(a,e,t.query)})})}function S(e,t){var n=r.getMessage(e),i=(n.fromID,r.getMessagePeer(n));return s.invokeApi("messages.getBotCallbackAnswer",{peer:m.getInputPeerByID(i),msg_id:l.getMessageLocalID(e),data:t.data},{timeout:1,stopTime:-1,noErrorBox:!0}).then(function(e){if("string"==typeof e.message&&e.message.length){var t=u.wrapRichText(e.message,{noLinks:!0,noLinebreaks:!0});e.pFlags.alert?o.show({title_html:t,alert:!0}):a.pop({type:"info",body:t.valueOf(),bodyOutputType:"trustedHtml",showCloseButton:!1})}})}function M(e,t,n){var a=I[t];if(void 0===a)return!1;_(a.botID);var i=t.split("_"),o=i.shift(),s=i.join("_");if(n=n||{},n.viaBotID=a.botID,n.queryID=o,n.resultID=s,a.send_message.reply_markup&&(n.reply_markup=a.send_message.reply_markup),"botInlineMessageText"==a.send_message._)n.entities=a.send_message.entities,r.sendText(e,a.send_message.message,n);else{var l="",c=!1;switch(a.send_message._){case"botInlineMessageMediaAuto":if(l=a.send_message.caption,"botInlineMediaResult"==a._){var d=a.document,u=a.photo;c=d?{_:"inputMediaDocument",id:{_:"inputDocument",id:d.id,access_hash:d.access_hash},caption:l}:{_:"inputMediaPhoto",id:{_:"inputPhoto",id:u.id,access_hash:u.access_hash},caption:l}}break;case"botInlineMessageMediaGeo":c={_:"inputMediaGeoPoint",geo_point:{_:"inputGeoPoint",lat:a.send_message.geo.lat,"long":a.send_message.geo["long"]}};break;case"botInlineMessageMediaVenue":c={_:"inputMediaVenue",geo_point:{_:"inputGeoPoint",lat:a.send_message.geo.lat,"long":a.send_message.geo["long"]},title:a.send_message.title,address:a.send_message.address,provider:a.send_message.provider,venue_id:a.send_message.venue_id};break;case"botInlineMessageMediaContact":c={_:"inputMediaContact",phone_number:a.send_message.phone_number,first_name:a.send_message.first_name,last_name:a.send_message.last_name}}c||(c={_:"messageMediaPending",type:a.type,file_name:a.title||a.content_url||a.url,size:0,progress:{percent:30,total:0}}),r.sendOther(e,c,n)}}function x(e){var n="bot_access_geo"+e;return i.get(n).then(function(e){return!(!e||!e.granted)||o.confirm({type:"BOT_ACCESS_GEO_INLINE"}).then(function(){var e={};return e[n]={granted:!0,time:tsNow()},i.set(e),!0},function(){var e={};return e[n]={denied:!0,time:tsNow()},i.set(e),t.reject()})})}var I={};return{resolveInlineMention:v,getPopularBots:f,sendInlineResult:M,getInlineResults:y,regroupWrappedResults:b,switchToPM:w,checkSwitchReturn:k,switchInlineButtonClick:C,callbackButtonClick:S}}]).service("ApiUpdatesManager",["$rootScope","MtpNetworkerFactory","AppUsersManager","AppChatsManager","AppPeersManager","MtpApiManager",function(e,t,n,a,i,o){function s(){var e=_.seq+1,t=_.pendingSeqUpdates[e];if(!t)return!1;for(var n,a,i=t.updates,n=0,a=i.length;n=_.syncPending.seqAwaiting&&(_.syncPending.ptsAwaiting?delete _.syncPending.seqAwaiting:(clearTimeout(_.syncPending.timeout),_.syncPending=!1)),!0}function r(e){var t=e?m(e):_;if(!t.pendingPtsUpdates.length)return!1;t.pendingPtsUpdates.sort(function(e,t){return e.pts-t.pts});for(var n,a=t.pts,i=!1,o=!1,s=0,r=t.pendingPtsUpdates.length;s=n.pts&&(i=n.pts,o=s);if(!i)return!1;for(console.log(dT(),"pop pending pts updates",i,t.pendingPtsUpdates.slice(0,o+1)),t.pts=i,s=0;s<=o;s++)n=t.pendingPtsUpdates[s],h(n);return t.pendingPtsUpdates.splice(0,o+1),!t.pendingPtsUpdates.length&&t.syncPending&&(t.syncPending.seqAwaiting?delete t.syncPending.ptsAwaiting:(clearTimeout(t.syncPending.timeout),t.syncPending=!1)),!0}function l(){_.syncLoading||d()}function c(e){var t={date:e.date,seq:e.seq,seqStart:e.seq_start};switch(e._){case"updatesTooLong":case"new_session_created":l();break;case"updateShort":g(e.update,t);break;case"updateShortMessage":case"updateShortChatMessage":var o=2&e.flags,s=e.from_id||(o?y:e.user_id),r=e.chat_id?-e.chat_id:o?e.user_id:y;g({_:"updateNewMessage",message:{_:"message",flags:e.flags,pFlags:e.pFlags,id:e.id,from_id:s,to_id:i.getOutputPeer(r),date:e.date,message:e.message,fwd_from:e.fwd_from,reply_to_msg_id:e.reply_to_msg_id,entities:e.entities},pts:e.pts,pts_count:e.pts_count},t);break;case"updatesCombined":case"updates":n.saveApiUsers(e.users),a.saveApiChats(e.chats),angular.forEach(e.updates,function(e){g(e,t)});break;default:console.warn(dT(),"Unknown update message",e)}}function d(){_.syncLoading||(_.syncLoading=!0,_.pendingSeqUpdates={},_.pendingPtsUpdates=[]),_.syncPending&&(clearTimeout(_.syncPending.timeout),_.syncPending=!1),o.invokeApi("updates.getDifference",{pts:_.pts,date:_.date,qts:-1}).then(function(t){if("updates.differenceEmpty"==t._)return console.log(dT(),"apply empty diff",t.seq),_.date=t.date,_.seq=t.seq,_.syncLoading=!1,e.$broadcast("stateSynchronized"),!1;n.saveApiUsers(t.users),a.saveApiChats(t.chats);angular.forEach(t.other_updates,function(e){switch(e._){case"updateChannelTooLong":case"updateNewChannelMessage":case"updateEditChannelMessage":return void g(e)}h(e)}),angular.forEach(t.new_messages,function(e){h({_:"updateNewMessage",message:e,pts:_.pts,pts_count:0})});var i=t.intermediate_state||t.state;_.seq=i.seq,_.pts=i.pts,_.date=i.date,"updates.differenceSlice"==t._?d():(e.$broadcast("stateSynchronized"),_.syncLoading=!1)})}function u(t){var i=m(t);i.syncLoading||(i.syncLoading=!0,i.pendingPtsUpdates=[]),i.syncPending&&(clearTimeout(i.syncPending.timeout),i.syncPending=!1),o.invokeApi("updates.getChannelDifference",{channel:a.getChannelInput(t),filter:{_:"channelMessagesFilterEmpty"},pts:i.pts,limit:30}).then(function(o){return i.pts=o.pts,"updates.channelDifferenceEmpty"==o._?(console.log(dT(),"apply channel empty diff",o),i.syncLoading=!1,e.$broadcast("stateSynchronized"),!1):"updates.channelDifferenceTooLong"==o._?(console.log(dT(),"channel diff too long",o),i.syncLoading=!1,delete v[t],h({_:"updateChannelReload",channel_id:t}),!1):(n.saveApiUsers(o.users),a.saveApiChats(o.chats),console.log(dT(),"applying",o.other_updates.length,"channel other updates"),angular.forEach(o.other_updates,function(e){h(e)}),console.log(dT(),"applying",o.new_messages.length,"channel new messages"),angular.forEach(o.new_messages,function(e){h({_:"updateNewChannelMessage",message:e,pts:i.pts,pts_count:0})}),console.log(dT(),"apply channel diff",i.pts),void("updates.channelDifference"!=o._||o.pFlags["final"]?(console.log(dT(),"finished channel get diff"),e.$broadcast("stateSynchronized"),i.syncLoading=!1):u(t)))})}function p(e,t){if(!t)throw new Error("Add channel state without pts "+e);return void 0===v[e]&&(v[e]={pts:t,pendingPtsUpdates:[],syncPending:!1,syncLoading:!1},!0)}function m(e,t){return void 0===v[e]&&p(e,t),v[e]}function g(e,t){t=t||{};var o=!1;switch(e._){case"updateNewChannelMessage":case"updateEditChannelMessage":o=-i.getPeerID(e.message.to_id);break;case"updateDeleteChannelMessages":o=e.channel_id;break;case"updateChannelTooLong":if(o=e.channel_id,void 0===v[o])return!1}var c=o?m(o,e.pts):_;if(c.syncLoading)return!1;if("updateChannelTooLong"==e._)return u(o),!1;if("updateNewMessage"==e._||"updateEditMessage"==e._||"updateNewChannelMessage"==e._||"updateEditChannelMessage"==e._){var p=e.message,g=i.getPeerID(p.to_id),f=p.fwd_from||{};if(p.from_id&&!n.hasUser(p.from_id,p.pFlags.post)||f.from_id&&!n.hasUser(f.from_id,!!f.channel_id)||f.channel_id&&!a.hasChat(f.channel_id)||g>0&&!n.hasUser(g)||g<0&&!a.hasChat(-g))return console.warn(dT(),"Not enough data for message update",p),o&&a.hasChat(o)?u(o):l(),!1}else if(o&&!a.hasChat(o))return!1;var y,b;if(e.pts){var w=c.pts+(e.pts_count||0);if(wc.pts)c.pts=e.pts,y=!0;else if(e.pts_count)return!1;o&&t.date&&_.date0){var k=t.seq,$=t.seqStart||k;if($!=c.seq+1&&$>c.seq)return console.warn(dT(),"Seq hole",c,c.syncPending&&c.syncPending.seqAwaiting),void 0===c.pendingSeqUpdates[$]&&(c.pendingSeqUpdates[$]={seq:k,date:t.date,updates:[]}),c.pendingSeqUpdates[$].updates.push(e),c.syncPending||(c.syncPending={timeout:setTimeout(function(){d()},5e3)}),(!c.syncPending.seqAwaiting||c.syncPending.seqAwaiting<$)&&(c.syncPending.seqAwaiting=$),!1;c.seq!=k&&(c.seq=k,t.date&&c.datem)||(m=!1,!1))}var c,d=0,u=!1,p=0,m=!1;return n.getUserID().then(function(e){p=e}),t.$on("apiUpdate",function(e,t){"updateUserStatus"==t._&&t.user_id==p&&(m=tsNow()+("userStatusOnline"==t.status._?3e5:0))}),{start:o,isOtherDeviceActive:l}}]).service("NotificationsManager",["$rootScope","$window","$interval","$q","_","MtpApiManager","AppPeersManager","IdleManager","Storage","AppRuntimeManager","FileManager",function(e,t,n,a,i,o,s,r,l,c,d){function u(){l.get("notify_nodesktop","notify_volume","notify_novibrate","notify_nopreview").then(function(e){K.nodesktop=e[0],K.volume=e[1]===!1?.5:e[1],K.novibrate=e[2],K.nopreview=e[3]})}function p(){return K}function m(e){return void 0!==H[e]?H[e]:H[e]=o.invokeApi("account.getNotifySettings",{peer:{_:"inputNotifyPeer",peer:s.getInputPeerByID(e)}})}function g(e){if(e=e||"favicon.ico",P!==e){var t=document.createElement("link");t.rel="shortcut icon",t.type="image/x-icon",t.href=e,q.parentNode.replaceChild(t,q),q=t,P=e}}function h(t,n){H[t]=a.when(n),e.$broadcast("notify_settings",{peerID:t})}function f(e,t){h(e,t);var n=angular.copy(t);return n._="inputPeerNotifySettings",o.invokeApi("account.updateNotifySettings",{peer:{_:"inputNotifyPeer",peer:s.getInputPeerByID(e)},settings:n})}function _(e){return m(e).then(function(e){return"peerNotifySettings"==e._&&1e3*e.mute_until>tsNow()})}function v(){if(u(),e.$on("settings_changed",u),I(),!F)return!1;"Notification"in window&&"granted"!==Notification.permission&&"denied"!==Notification.permission&&$(t).on("click",b);try{"onbeforeunload"in window&&$(t).on("beforeunload",x)}catch(n){}}function y(){x(),n.cancel(D),g(),G=!0}function b(){Notification.requestPermission(),$(t).off("click",b)}function w(e){if(!G){if(Config.Navigator.ffos&&!Config.Navigator.ffos2p)e.image="https://telegram.org/img/t_logo.png";else if(e.image&&!angular.isString(e.image)){if(Config.Navigator.ffos2p)return d.getDataUrl(e.image,"image/jpeg").then(function(t){e.image=t,w(e)}),!1;e.image=d.getUrl(e.image,"image/jpeg")}else e.image||(e.image="img/icons/icon60.png");O++;var t=tsNow();if(K.volume>0&&(!e.tag||!U[e.tag]||t>U[e.tag]+6e4)&&(k(K.volume),U[e.tag]=t),!F||"Notification"in window&&"granted"!==Notification.permission)return!1;if(K.nodesktop){if(L&&!K.novibrate)return void navigator.vibrate([200,100,200])}else{var n,a=++R,i=e.key||"k"+a;if("Notification"in window)n=new Notification(e.title,{icon:e.image||"",body:e.message||"",tag:e.tag||""});else if("mozNotification"in navigator)n=navigator.mozNotification.createNotification(e.title,e.message||"",e.image||"");else{if(!E)return;window.external.msSiteModeClearIconOverlay(),window.external.msSiteModeSetIconOverlay("img/icons/icon16.png",e.title),window.external.msSiteModeActivate(),n={index:a}}n.onclick=function(){n.close(),c.focus(),x(),e.onclick&&e.onclick()},n.onclose=function(){n.hidden||(delete N[i],x())},n.show&&n.show(),N[i]=n,Config.Navigator.mobile||setTimeout(function(){S(i)},8e3)}}}function k(e){var t=tsNow();if(!(B&&t');a.find("audio")[0].volume=e}}function C(e){var t=N[e];if(t){O>0&&O--;try{t.close?t.close():E&&t.index==R&&window.external.msSiteModeClearIconOverlay()}catch(n){}delete O[e]}}function S(e){var t=N[e];if(t){try{t.close&&(t.hidden=!0,t.close())}catch(n){}delete O[e]}}function M(e){delete U[e]}function x(){E?window.external.msSiteModeClearIconOverlay():angular.forEach(N,function(e){try{e.close&&e.close()}catch(t){}}),N={},O=0}function I(){if(Y)return!1;if(navigator.push&&Config.Navigator.ffos&&Config.Modes.packed){var e=navigator.push.register();e.onsuccess=function(t){clearTimeout(X),console.log(dT(),"Push registered",e.result),Y=e.result,o.invokeApi("account.registerDevice",{token_type:4,token:Y})},e.onerror=function(e){console.error("Push register error",e,e.toString()),X=setTimeout(I,Z),Z=Math.min(3e4,1.5*Z)}}}function A(){return L}navigator.vibrate=navigator.vibrate||navigator.mozVibrate||navigator.webkitVibrate;var E=!1;try{window.external&&window.external.msIsSiteMode()&&(E=!0)}catch(T){}var D,P,F=E||"Notification"in window||"mozNotification"in navigator,N={},R=0,O=0,U={},L=!!navigator.vibrate,B=!1,j=!1,H={},q=$('link[rel="icon"]:first')[0],V=i.pluralize("page_title_pluralize_notifications"),z=document.title,W=!1,G=!1,K={};e.$watch("idle.deactivated",function(e){e&&y()}),e.$watch("idle.isIDLE",function(e){G||(e||x(),Config.Navigator.mobile||(n.cancel(D),e?(z=document.title,D=n(function(){W||!O?(W=!1,document.title=z,g()):(W=!0,document.title=V(O),g("favicon_unread.ico"))},1e3)):(W=!1,document.title=z,g())))}),e.$on("apiUpdate",function(e,t){switch(t._){case"updateNotifySettings":if("notifyPeer"==t.peer._){var n=s.getPeerID(t.peer.peer);h(n,t.notify_settings)}}});var Y=!1;return window.navigator.mozSetMessageHandler&&(window.navigator.mozSetMessageHandler("push",function(t){console.log(dT(),"received push",t),e.$broadcast("push_received")}),window.navigator.mozSetMessageHandler("push-register",function(e){console.log(dT(),"received push",e),Y=!1,I()})),{start:v,notify:w,cancel:C,clear:x,soundReset:M,getPeerSettings:m,getPeerMuted:_,savePeerSettings:h,updatePeerSettings:f,updateNotifySettings:u,getNotifySettings:p,getVibrateSupport:A,testSound:k};var Z,X}]).service("PasswordManager",["$timeout","$q","$rootScope","MtpApiManager","CryptoWorker","MtpSecureRandom",function(e,t,n,a,i,o){function s(e){return a.invokeApi("account.getPassword",{},e).then(function(e){return e})}function r(e,n){var i,s,r={new_settings:{_:"account.passwordInputSettings",flags:0,hint:n.hint||""}};if(i="string"==typeof n.cur_password&&n.cur_password.length>0?u(e.current_salt,n.cur_password):t.when([]),"string"==typeof n.new_password&&n.new_password.length>0){var l=new Array(8),c=bufferConcat(e.new_salt,l);o.nextBytes(l),s=u(c,n.new_password),r.new_settings.new_salt=c,r.new_settings.flags|=1}else"string"==typeof n.new_password&&(r.new_settings.flags|=1,r.new_settings.new_salt=[]),s=t.when([]);return"string"==typeof n.email&&(r.new_settings.flags|=2,r.new_settings.email=n.email||""),t.all([i,s]).then(function(e){return r.current_password_hash=e[0],r.new_settings.new_password_hash=e[1],a.invokeApi("account.updatePasswordSettings",r)})}function l(e,t,n){return u(e.current_salt,t).then(function(e){return a.invokeApi("auth.checkPassword",{password_hash:e},n)})}function c(e,t){return a.invokeApi("auth.requestPasswordRecovery",{},t)}function d(e,t){return a.invokeApi("auth.recoverPassword",{code:e},t)}function u(e,t){for(var n=unescape(encodeURIComponent(t)),a=new ArrayBuffer(n.length),o=new Uint8Array(a),s=0,r=n.length;s=1)return console.log("Skip error box, too many open",s,n,a),!1;a=a||{};var i=e.$new();angular.extend(i,n),s++;var o=t.open({templateUrl:templateUrl("error_modal"),scope:i,windowClass:a.windowClass||"error_modal_window"});return o.result["finally"](function(){s--}),o}function i(e,t){return a({title:e,description:t})}function o(n,a){a=a||{};var i=e.$new();angular.extend(i,n);var o=t.open({templateUrl:templateUrl("confirm_modal"),scope:i,windowClass:a.windowClass||"confirm_modal_window"});return o.result}var s=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:a,alert:i,confirm:o}}]).service("PeersSelectService",["$rootScope","$modal",function(e,t){function n(n){var a=e.$new();return a.multiSelect=!1,a.noMessages=!0,n&&angular.extend(a,n),t.open({templateUrl:templateUrl("peer_select"),controller:"PeerSelectController",scope:a,windowClass:"peer_select_window mobile_modal",backdrop:"single"}).result}function a(a){if(Config.Mobile)return n(a).then(function(e){return[e]});var i=e.$new();return i.multiSelect=!0,i.noMessages=!0,a&&angular.extend(i,a),t.open({templateUrl:templateUrl("peer_select"),controller:"PeerSelectController",scope:i,windowClass:"peer_select_window mobile_modal",backdrop:"single"}).result}return{selectPeer:n,selectPeers:a}}]).service("ContactsSelectService",["$rootScope","$modal",function(e,t){function n(n,a){a=a||{};var i=e.$new();return i.multiSelect=n,angular.extend(i,a),!i.action&&n&&(i.action="select"),t.open({templateUrl:templateUrl("contacts_modal"),controller:"ContactsModalController",scope:i,windowClass:"contacts_modal_window mobile_modal",backdrop:"single"}).result}return{selectContacts:function(e){return n(!0,e)},selectContact:function(e){return n(!1,e)}}}]).service("ChangelogNotifyService",["Storage","$rootScope","$modal",function(e,t,n){function a(){e.get("last_version").then(function(t){t!=Config.App.version&&(t&&i(t),e.set({last_version:Config.App.version}))})}function i(e){var a=t.$new();a.lastVersion=e,n.open({controller:"ChangelogModalController",templateUrl:templateUrl("changelog_modal"),scope:a,windowClass:"changelog_modal_window mobile_modal"})}return{checkUpdate:a,showChangelog:i}}]).service("HttpsMigrateService",["ErrorService","Storage",function(e,t){function n(){t.get("https_dismiss").then(function(n){(!n||tsNow()>n+432e5)&&e.confirm({type:"MIGRATE_TO_HTTPS"}).then(function(){var e;try{e=window.open("https://web.telegram.org","_blank")}catch(t){}e||(location.href="https://web.telegram.org")},function(){t.set({https_dismiss:tsNow()})})})}function a(){i||"http:"!=location.protocol||Config.Modes.http||Config.App.domains.indexOf(location.hostname)==-1||(i=!0,setTimeout(n,12e4))}var i=!1;return{start:a,check:n}}]).service("LayoutSwitchService",["ErrorService","Storage","AppRuntimeManager","$window",function(e,t,n,a){function i(e){ConfigStorage.noPrefix(),t.set({layout_selected:e?"mobile":"desktop",layout_width:$(window).width()}).then(function(){n.reload()})}function o(n){if(!l){var a=$(window).width(),o=a<600;!a||!n&&(Config.Navigator.mobile?a<=800:o)||o!=Config.Mobile&&(ConfigStorage.noPrefix(),t.get("layout_width").then(function(n){return a!=n&&(l=!0,void e.confirm({type:o?"SWITCH_MOBILE_VERSION":"SWITCH_DESKTOP_VERSION"}).then(function(){i(o)},function(){ConfigStorage.noPrefix(),t.set({layout_width:a}),l=!1}))}))}}function s(){r||Config.Navigator.mobile||(r=!0,o(),$(a).on("resize",o))}var r=!1,l=!1;return{start:s,switchLayout:i}}]).service("TelegramMeWebService",["Storage",function(e){function t(t){return!n&&void e.get("tgme_sync").then(function(n){var a=tsNow(!0);if(t&&n&&n.canRedirect==t&&n.ts+86400>a)return!1;e.set({tgme_sync:{canRedirect:t,ts:a}});var i=$("