diff --git a/js/app.js b/js/app.js index 711bb145..b9ac3896 100644 --- a/js/app.js +++ b/js/app.js @@ -61,20 +61,19 @@ this.updateSession(),this.lastServerMessages=[],this.checkConnectionPeriod=0,thi controller:"UserModalController",scope:a,windowClass:"user_modal_window mobile_modal",backdrop:"single"})}function I(e,t,n){return o.invokeApi("contacts.importContacts",{contacts:[{_:"inputPhoneContact",client_id:"1",phone:e,first_name:t,last_name:n}],replace:!1}).then(function(e){h(e.users);var t=!1;return angular.forEach(e.imported,function(e){D(t=e.user_id,!0)}),t||!1})}function x(e){var t,n,i=[];for(t=0;t=1e3?void r.resolve(o):void this["continue"]()},t.onerror=function(e){console.log("phonebook error",e,e.type,e.message),r.reject(e)},r.promise}return{isAvailable:a,openPhonebookImport:r,getPhonebookContacts:o}}]).service("AppChatsManager",["$q","$rootScope","$modal","_","MtpApiManager","AppUsersManager","AppPhotosManager","RichTextProcessor",function(e,t,n,i,a,r,o,s){function l(e){angular.forEach(e,c)}function c(e){if(angular.isObject(e)){e.rTitle=s.wrapRichText(e.title,{noLinks:!0,noLinebreaks:!0})||i("chat_title_deleted");var n=C[e.id],a=SearchIndexManager.cleanSearchText(e.title||"").split(" "),r=a.shift(),o=a.pop();if(e.initials=r.charAt(0)+(o?o.charAt(0):r.charAt(1)),e.num=Math.abs(e.id>>1)%8+1,void 0===e.pFlags&&(e.pFlags={}),!e.pFlags.min||void 0===n){if("channel"==e._&&void 0===e.participants_count&&void 0!==n&&n.participants_count&&(e.participants_count=n.participants_count),e.username){var l=SearchIndexManager.cleanUsername(e.username);T[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:E[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 T[e]||0}function f(e,t){E[e]=t}function m(e){$[e]=!0}function h(e){var t=C[e];return!((!t||"channel"!=t._&&"channelForbidden"!=t._)&&!E[e])}function g(e){if($[e])return!0;var t=C[e];return!(!t||"channel"!=t._||!t.pFlags.megagroup)}function _(e){return h(e)&&!g(e)}function v(e){return e||0}function y(e){return e?{_:"inputChannel",channel_id:e,access_hash:d(e).access_hash||E[e]||0}:{_:"inputChannelEmpty"}}function b(e,t){var n=C[e];return angular.isObject(n)&&(t||!n.pFlags.min)}function w(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 k(e){var t=d(e);return h(e)?(g(e)?"s":"c")+e+"_"+t.access_hash:"g"+e}function M(e,t){var n=angular.copy(t),i=d(e);return n.participants_count||(n.participants_count=i.participants_count),n.participants&&"chatParticipants"==n.participants._&&(n.participants.participants=S(e,n.participants.participants)),n.about&&(n.rAbout=s.wrapRichText(n.about,{noLinebreaks:!0})),n.peerString=k(e),n.chat=i,n}function S(e,t){var n=d(e);if(h(e)){var i=n.pFlags.creator||n.pFlags.editor||n.pFlags.moderator;angular.forEach(t,function(e){e.canLeave="channelParticipantSelf"==e._,e.canKick=i&&"channelParticipant"==e._,e.user=r.getUser(e.user_id)})}else{var a=r.getSelf().id,i=n.pFlags.creator||n.pFlags.admins_enabled&&n.pFlags.admin;angular.forEach(t,function(e){e.canLeave=a==e.user_id,e.canKick=!e.canLeave&&(n.pFlags.creator||"chatParticipant"==e._&&(i||a==e.inviter_id)),e.user=r.getUser(e.user_id)})}return t}function A(e,i){var a=t.$new();if(a.chatID=e,h(e)){n.open({templateUrl:templateUrl("channel_modal"),controller:"ChannelModalController",scope:a,windowClass:"chat_modal_window channel_modal_window mobile_modal"})}else{n.open({templateUrl:templateUrl("chat_modal"),controller:"ChatModalController",scope:a,windowClass:"chat_modal_window mobile_modal"})}}var C={},T={},E={},$={},I={};return t.$on("apiUpdate",function(e,n){switch(n._){case"updateChannel":var i=n.channel_id;t.$broadcast("channel_settings",{channelID:i})}}),{saveApiChats:l,saveApiChat:c,getChat:d,isChannel:h,isMegagroup:g,isBroadcast:_,hasRights:u,saveChannelAccess:f,saveIsMegagroup:m,getChatInput:v,getChannelInput:y,getChatPhoto:w,getChatString:k,resolveUsername:p,hasChat:b,wrapForFull:M,wrapParticipants:S,openChat:A}}]).service("AppPeersManager",["$q","qSync","AppUsersManager","AppChatsManager","MtpApiManager",function(e,t,n,i,a){function r(e){var t=e.charAt(0),a=e.substr(1).split("_");return"u"==t?(n.saveUserAccess(a[0],a[1]),{_:"inputPeerUser",user_id:a[0],access_hash:a[1]}):"c"==t||"s"==t?(i.saveChannelAccess(a[0],a[1]),"s"==t&&i.saveIsMegagroup(a[0]),{_:"inputPeerChannel",channel_id:a[0],access_hash:a[1]||0}):{_:"inputPeerChat",chat_id:a[0]}}function o(e){if(!e)return{_:"inputPeerEmpty"};if(e<0){var t=-e;return i.isChannel(t)?{_:"inputPeerChannel",channel_id:t,access_hash:i.getChat(t).access_hash||0}:{_:"inputPeerChat",chat_id:t}}return{_:"inputPeerUser",user_id:e,access_hash:n.getUser(e).access_hash||0}}function s(e){var t;if(e>0)t="%pu "+n.getUserSearchText(e);else if(e<0){var a=i.getChat(-e);t="%pg "+(a.title||"")}return t}function l(e){return e>0?n.getUserString(e):i.getChatString(-e)}function c(e){if(e>0)return{_:"peerUser",user_id:e};var t=-e;return i.isChannel(t)?{_:"peerChannel",channel_id:t}:{_:"peerChat",chat_id:t}}function d(e){var r=SearchIndexManager.cleanUsername(e);if(r.match(/^\d+$/))return t.when(!1);var o,s,l;return(o=n.resolveUsername(r))&&(l=n.getUser(o).username,SearchIndexManager.cleanUsername(l)==r)?t.when(o):(s=i.resolveUsername(r))&&(l=i.getChat(s).username,SearchIndexManager.cleanUsername(l)==r)?t.when(-s):a.invokeApi("contacts.resolveUsername",{username:e}).then(function(e){return n.saveApiUsers(e.users),i.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):i.getChat(-e)}function f(e){return e>0?n.getUserPhoto(e):i.getChatPhoto(-e)}function m(e){return e<0&&i.isChannel(-e)}function h(e){return e<0&&i.isMegagroup(-e)}function g(e){return e<0&&!i.isBroadcast(-e)}function _(e){return m(e)&&!h(e)}function v(e){return e>0&&n.isBot(e)}return{getInputPeer:r,getInputPeerByID:o,getPeerSearchText:s,getPeerString:l,getOutputPeer:c,getPeerID:u,getPeer:p,getPeerPhoto:f,resolveUsername:d,isChannel:m,isAnyGroup:g,isMegagroup:h,isBroadcast:_,isBot:v}}]).service("AppProfileManager",["$q","$rootScope","AppUsersManager","AppChatsManager","AppMessagesIDsManager","AppPeersManager","AppPhotosManager","NotificationsManager","MtpApiManager","ApiUpdatesManager","RichTextProcessor","Storage",function(e,t,n,i,a,r,o,s,l,c,d,u){function p(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}),w[t]={id:t,version:e.version,shareText:e.share_text,description:e.description,commands:n}}function f(e,t){return l.invokeApi("users.getFullUser",{id:n.getUserInput(e)}).then(function(i){return t&&t.phone_number?(i.user.phone=t.phone_number,(t.first_name||t.last_name)&&(i.user.first_name=t.first_name,i.user.last_name=t.last_name),n.saveApiUser(i.user)):n.saveApiUser(i.user,!0),i.profile_photo&&o.savePhoto(i.profile_photo,{user_id:e}),void 0!==i.about&&(i.rAbout=d.wrapRichText(i.about,{noLinebreaks:!0})),s.savePeerSettings(e,i.notify_settings),i.bot_info&&(i.bot_info=p(i.bot_info)),i})}function m(t){var i=[];return t>=0&&!n.isBot(t)||r.isChannel(t)&&!r.isMegagroup(t)?e.when(i):t>=0?f(t).then(function(e){var t=e.bot_info;return t&&"botInfoEmpty"!=t._&&i.push(t),i}):h(-t).then(function(e){return angular.forEach(e.bot_info,function(e){i.push(p(e))}),i})}function h(a){if(i.isChannel(a))return v(a);if(void 0!==k[a]){var r=i.getChat(a);if(r.version==k[a].participants.version||r.pFlags.left)return e.when(k[a])}return void 0!==M[a]?M[a]:M[a]=l.invokeApi("messages.getFullChat",{chat_id:i.getChatInput(a)}).then(function(e){i.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(-a,r.notify_settings),delete M[a],k[a]=r,t.$broadcast("chat_full_update",a),r})}function g(e,t){return h(e).then(function(n){if(!t&&n.exported_invite&&"chatInviteExported"==n.exported_invite._)return n.exported_invite.link;var a;return a=i.isChannel(e)?l.invokeApi("channels.exportInvite",{channel:i.getChannelInput(e)}):l.invokeApi("messages.exportChatInvite",{chat_id:i.getChatInput(e)}),a.then(function(t){return void 0!==k[e]&&(k[e].exported_invite=t),t.link})})}function _(t,a,r,o){a=a||{_:"channelParticipantsRecent"},r=r||200,o=o||0;var s=[t,a._,o,r].join("_"),c=S[s];if("channelParticipantsRecent"==a._){var d=i.getChat(t);if(d&&d.pFlags&&(d.pFlags.kicked||d.pFlags.broadcast&&!d.pFlags.creator&&!d.admin_rights))return e.reject()}var u=function(e){var s=0;if(e){var c=[];angular.forEach(e,function(e){c.push(e.user_id)}),c.sort(),angular.forEach(c,function(e){s=(20261*s+2147483648+e)%2147483648})}return l.invokeApi("channels.getParticipants",{channel:i.getChannelInput(t),filter:a,offset:o,limit:r,hash:s}).then(function(t){return"channels.channelParticipantsNotModified"==t._?e:(n.saveApiUsers(t.users),t.participants)})},p=function(e){var r=i.getChat(t),s="channelParticipantsRecent"==a._&&!o&&!r.pFlags.kicked&&!r.pFlags.left;if(s){e=angular.copy(e);for(var l,c=n.getSelf().id,d=!1,u=0,p=e.length;uf-6e4)return m;var h=m.then(function(e){return u(e).then(p)});return S[s]=[f,h],h}var h=u().then(p);return S[s]=[f,h],h}function v(r,d){return void 0===k[r]||d?void 0!==M[r]?M[r]:M[r]=l.invokeApi("channels.getFullChannel",{channel:i.getChannelInput(r)}).then(function(e){i.saveApiChats(e.chats),n.saveApiUsers(e.users);var l=e.full_chat;return l&&l.chat_photo.id&&o.savePhoto(l.chat_photo),s.savePeerSettings(-r,l.notify_settings),l.pinned_msg_id&&(l.pinned_msg_id=a.getFullMessageID(l.pinned_msg_id,r)),delete M[r],k[r]=l,t.$broadcast("chat_full_update",r),l},function(t){switch(t.type){case"CHANNEL_PRIVATE":var n=i.getChat(r);n={_:"channelForbidden",access_hash:n.access_hash,title:n.title},c.processUpdateMessage({_:"updates",updates:[{_:"updateChannel",channel_id:r}],chats:[n],users:[]})}return e.reject(t)}):e.when(k[r])}function y(e){return v(e).then(function(t){var n=t&&t.pinned_msg_id;return!!n&&u.get("pinned_hidden"+e).then(function(e){return a.getMessageLocalID(n)!=e&&n})})}function b(e,n){var i={};i["pinned_hidden"+e]=a.getMessageLocalID(n),u.set(i),t.$broadcast("peer_pinned_message",-e)}var w={},k={},M={},S={};return t.$on("apiUpdate",function(e,n){switch(n._){case"updateChatParticipants":var i=n.participants,r=k[i.id];void 0!==r&&(r.participants=n.participants,t.$broadcast("chat_full_update",chatID));break;case"updateChatParticipantAdd":var r=k[n.chat_id];if(void 0!==r){for(var i=r.participants.participants||[],o=0,s=i.length;o800&&(i-=208);var o=l(n,i,r);o&&!o.preloaded&&(o.preloaded=!0,o.size?a.downloadFile(o.location.dc_id,{_:"inputFileLocation",volume_id:o.location.volume_id,local_id:o.location.local_id,secret:o.location.secret},o.size):a.downloadSmallFile(o.location))}}function u(e){return g[e]||{_:"photoEmpty"}}function p(e,t){t=t||{};var n=angular.copy(g[e])||{_:"photoEmpty"},i=t.website?64:Math.min(_-80,Config.Mobile?210:260),a=t.website?64:Math.min(v-100,Config.Mobile?210:260),r=l(n,i,a),o={placeholder:"img/placeholders/PhotoThumbConversation.gif",width:i,height:a};if(t.website&&Config.Mobile&&(i=50,a=50),r&&"photoSizeEmpty"!=r._){var s=calcImageInBox(r.w,r.h,i,a);o.width=s.w,o.height=s.h,o.location=r.location,o.size=r.size}else o.width=100,o.height=100;return n.thumb=o,n}function f(e){var n=p(e),i=$(window).width()-(Config.Mobile?0:32),a=$(t).height()-(Config.Mobile?0:116);!Config.Mobile&&i>800&&(i-=208);var r=l(n,i,a),o={placeholder:"img/placeholders/PhotoThumbModal.gif"};if(o.width=i,o.height=a,r&&"photoSizeEmpty"!=r._){var s=calcImageInBox(r.w,r.h,i,a,!0);o.width=s.w,o.height=s.h,o.modalWidth=Math.max(o.width,Math.min(400,i)),o.location=r.location,o.size=r.size}return n.full=o,n}function m(t,i){if(!t||"0"===t)return!1;var a=n.$new(!0);a.photoID=t;var r="PhotoModalController";i&&i.p>0?(r="UserpicModalController",a.userID=i.p):i&&i.p<0?(r="ChatpicModalController",a.chatID=-i.p):i&&i.m>0&&(a.messageID=i.m,i.w&&(a.webpageID=i.w));e.open({templateUrl:templateUrl("photo_modal"),windowTemplateUrl:templateUrl("media_modal_layout"),controller:r,scope:a,windowClass:"photo_modal_window"})}function h(e){var n=g[e],i="jpg",r="image/jpeg",s="photo"+e+"."+i,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};o.chooseSave(s,i,r).then(function(e){e&&a.downloadFile(u.location.dc_id,p,u.size,{mime:r,toFileEntry:e}).then(function(){},function(e){console.log("photo download failed",e)})},function(){var e=a.getCachedFile(p);return e?o.download(e,r,s):void a.downloadFile(u.location.dc_id,p,u.size,{mime:r}).then(function(e){o.download(e,r,s)},function(e){console.log("photo download failed",e)})})}var g={},_=$(window).width(),v=$(window).height();return n.preloadPhoto=d,n.openPhoto=m,{savePhoto:s,preloadPhoto:d,getUserPhotos:c,getPhoto:u,choosePhotoSize:l,wrapForHistory:p,wrapForFull:f,openPhoto:m,downloadPhoto:h}}]).service("AppWebPagesManager",["$modal","$sce","$window","$rootScope","MtpApiManager","AppPhotosManager","AppDocsManager","RichTextProcessor",function(e,t,n,i,a,r,o,s){function l(e,t,n){e.photo&&"photo"===e.photo._?r.savePhoto(e.photo,n):delete e.photo,e.document&&"document"===e.document._?o.saveDoc(e.document,n):("document"==e.type&&delete e.type,delete e.document);var a=e.site_name,l=e.title||e.author||a||"";a&&l==a&&delete e.site_name,l.length>100&&(l=l.substr(0,80)+"..."),e.rTitle=s.wrapRichText(l,{noLinks:!0,noLinebreaks:!0});var c="";if("GitHub"==a){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=s.wrapRichText(u,{contextSite:a||"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===f[e.id]&&(f[e.id]={}),f[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!==f[e.id]){var m=[];angular.forEach(f[e.id],function(e,t){m.push(t)}),i.$broadcast("webpage_updated",{id:e.id,msgs:m})}}function c(t,n){var a=i.$new(!0);a.webpageID=t,a.messageID=n,e.open({templateUrl:templateUrl("embed_modal"),windowTemplateUrl:templateUrl("media_modal_layout"),controller:"EmbedModalController",scope:a,windowClass:"photo_modal_window"})}function d(e){var t=angular.copy(p[e])||{_:"webPageEmpty"};return t.photo&&t.photo.id&&(t.photo=r.wrapForHistory(t.photo.id,{website:"photo"!=t.type&&"video"!=t.type})),t.document&&t.document.id&&(t.document=o.wrapForHistory(t.document.id)),t}function u(e){var i=d(e);if(!i.embed_url)return i;var a=$(window).width()-(Config.Mobile?0:10),r=$(n).height()-(Config.Mobile?92:150);!Config.Mobile&&a>800&&(a-=208);var o={width:a,height:r};if(i.embed_width&&i.embed_height){var s=calcImageInBox(i.embed_width,i.embed_height,a,r);o.width=s.w,o.height=s.h}else o.height=o.width=Math.min(a,r);var l=Config.Modes.chrome_packed?"webview":"iframe",c="iframe"!=i.embed_type?i.embed_type||"text/html":"text/html",u="<"+l+' src="'+encodeEntities(i.embed_url)+'" type="'+encodeEntities(c)+'" frameborder="0" border="0" webkitallowfullscreen mozallowfullscreen allowfullscreen width="'+o.width+'" height="'+o.height+'" style="width: '+o.width+"px; height: "+o.height+'px;">";return o.html=t.trustAs("html",u),i.full=o,i}var p={},f={};return i.$on("apiUpdate",function(e,t){switch(t._){case"updateWebPage":l(t.webpage)}}),{saveWebPage:l,openEmbed:c,wrapForFull:u,wrapForHistory:d}}]).service("AppGamesManager",["$modal","$sce","$window","$rootScope","MtpApiManager","AppPhotosManager","AppDocsManager","RichTextProcessor",function(e,t,n,i,a,r,o,s){function l(e,t,n){e.photo&&"photo"===e.photo._?r.savePhoto(e.photo,n):delete e.photo,e.document&&"document"===e.document._?o.saveDoc(e.document,n):delete e.document,e.rTitle=s.wrapRichText(e.title,{noLinks:!0,noLinebreaks:!0}),e.rDescription=s.wrapRichText(e.description||"",{}),void 0===p[e.id]?p[e.id]=e:safeReplaceObject(p[e.id],e)}function c(t,n,a){var r=i.$new(!0);r.gameID=t,r.messageID=n,r.embedUrl=a,e.open({templateUrl:templateUrl("game_modal"),windowTemplateUrl:templateUrl("media_modal_layout"),controller:"GameModalController",scope:r,windowClass:"photo_modal_window mobile_modal"})}function d(e){var t=angular.copy(p[e])||{_:"gameEmpty"};return t.photo&&t.photo.id&&(t.photo=r.wrapForHistory(t.photo.id)),t.document&&t.document.id&&(t.document=o.wrapForHistory(t.document.id)),t}function u(e,i,a){var r=d(e),o=$(window).width()-(Config.Mobile?0:10),s=$(n).height()-(Config.Mobile?51:150);!Config.Mobile&&o>800&&(o-=208);var l={width:o,height:s},c=Config.Modes.chrome_packed?"webview":"iframe",u="text/html",p="<"+c+' src="'+encodeEntities(a)+'" type="'+encodeEntities(u)+'" frameborder="0" border="0" webkitallowfullscreen mozallowfullscreen allowfullscreen width="'+l.width+'" height="'+l.height+'" style="width: '+l.width+"px; height: "+l.height+'px;" sandbox="allow-scripts allow-same-origin">";return l.html=t.trustAs("html",p),r.full=l,r}var p={};return{saveGame:l,openGame:c,wrapForFull:u,wrapForHistory:d}}]).service("AppDocsManager",["$sce","$rootScope","$modal","$window","$q","$timeout","RichTextProcessor","MtpApiFileManager","FileManager","qSync",function(e,t,n,i,a,r,o,s,l,c){function d(e,t){if(w[e.id]=e,t&&angular.extend(e,t),e.thumb&&"photoCachedSize"==e.thumb._&&(s.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&&t.pFlags.round_message?e.type="round":e.thumb&&(e.type="video");break;case"documentAttributeSticker":e.sticker=!0,void 0!==t.alt&&(e.stickerEmojiRaw=t.alt,e.stickerEmoji=o.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":case"round":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 f(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 m(e){if(void 0!==k[e])return k[e];var t,n,i,a,r=angular.copy(w[e]),o=r.thumb,s=!1;switch(r.type){case"video":t=Math.min(M-80,Config.Mobile?210:150),n=Math.min(S-100,Config.Mobile?210:150);break;case"sticker":s=!0,t=Math.min(M-80,Config.Mobile?128:192),n=Math.min(S-100,Config.Mobile?128:192);break;case"gif":s=!0,t=Math.min(M-80,Config.Mobile?210:260),n=Math.min(S-100,Config.Mobile?210:260);break;case"round":s=!0,t=Math.min(M-80,200),n=Math.min(S-100,200);break;default:t=n=100}return s&&r.w&&r.h?a=calcImageInBox(r.w,r.h,t,n):o&&(a=calcImageInBox(o.w,o.h,t,n)),a?(i={width:a.w,height:a.h},o&&(i.location=o.location,i.size=o.size)):i=!1,r.thumb=i,r.withPreview=!Config.Mobile&&r.mime_type.match(/^image\/(gif|png|jpeg|jpg|bmp|tiff)/)?1:0,k[e]=r}function h(e){var t=w[e],n=k[e]||t||{},i={_:"inputDocumentFileLocation",id:e,access_hash:t.access_hash,version:t.version,file_name:f(t)};void 0===n.downloaded&&s.getDownloadedFile(i,t.size).then(function(){n.downloaded=!0},function(){n.downloaded=!1})}function g(n,i){var o=w[n],d=k[n]||o||{},u={_:"inputDocumentFileLocation",id:n,access_hash:o.access_hash,version:o.version,file_name:f(o)};if("documentEmpty"==o._)return a.reject();if(d.downloaded&&!i){var p=s.getCachedFile(u);if(p)return c.when(p)}d.progress={enabled:!d.downloaded,percent:1,total:o.size};var m=s.downloadFile(o.dc_id,u,o.size,{mime:o.mime_type||"application/octet-stream",toFileEntry:i});return m.then(function(t){t&&(l.getFileCorrectUrl(t,o.mime_type).then(function(t){var n=e.trustAsResourceUrl(t);d.url=n,o.url=n}),d.downloaded=!0),d.progress.percent=100,r(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=m.cancel,m}function _(e,i){var a=t.$new(!0);a.docID=e,a.messageID=i;n.open({templateUrl:templateUrl("document_modal"),windowTemplateUrl:templateUrl("media_modal_layout"),controller:"DocumentModalController",scope:a,windowClass:"document_modal_window"})}function v(e){var t=w[e],n=(k[e]||t||{},t.mime_type,f(t)),i=(n.split(".",2)||[])[1]||"";l.chooseSave(f(t),i,t.mime_type).then(function(t){t&&g(e,t)},function(){g(e).then(function(e){l.download(e,t.mime_type,n)})})}function y(e){var t=m(e),n=Math.min($(window).width()-(Config.Mobile?0:60),542),i=$(window).height()-(Config.Mobile?92:150),a={placeholder:"img/placeholders/docThumbModal.gif",width:n,height:i};if(t.w&&t.h){var r=calcImageInBox(t.w,t.h,n,i);a.width=r.w,a.height=r.h}else a.height=a.width=Math.min(n,i);return t.full=a,t.fullThumb=angular.copy(t.thumb),t.fullThumb.width=a.width,t.fullThumb.height=a.height,t}function b(e,i){var a=t.$new(!0);return a.docID=e,a.messageID=i,n.open({templateUrl:templateUrl("video_modal"),windowTemplateUrl:templateUrl("media_modal_layout"),controller:"VideoModalController",scope:a,windowClass:"video_modal_window"})}var w={},k={},M=$(window).width(),S=$(window).height();return{saveDoc:d,getDoc:u,hasDoc:p,wrapForHistory:m,wrapVideoForFull:y,updateDocDownloaded:h,downloadDoc:g,openDoc:_,openVideo:b,saveDocFile:v}}]).service("AppStickersManager",["$q","$rootScope","$modal","_","FileManager","MtpApiManager","AppDocsManager","Storage","ApiUpdatesManager",function(e,t,n,i,a,r,o,s,l){function c(){k||(k=!0,setTimeout(d,1e3))}function d(e){return s.get("all_stickers").then(function(t){var n=Config.Schema.API.layer;return t.layer==n&&void 0!==t.emojiIndex||(t=!1),t&&t.date>tsNow(!0)&&!e?(A=t.emojiIndex,u(t)):r.invokeApi("messages.getAllStickers",{hash:t&&t.hash||""}).then(function(e){var i="messages.allStickersNotModified"==e._;return i&&(e=t),e.date=tsNow(!0)+3600,e.layer=n,delete e._,i?(s.set({all_stickers:e}),A=e.emojiIndex,u(e)):m(e,t&&t.fullSets).then(function(){return s.set({all_stickers:e}),u(e)})})})}function u(e){if(M!==e.hash){M=e.hash;var t,n,a,r,s,l,c,d;for(S=[],a=e.sets.length,t=0;t15&&(a=a.slice(0,15)),a.push([e,1])),ConfigStorage.set({stickers_popular:a})})}function _(e){return r.invokeApi("messages.getStickerSet",{stickerset:e}).then(function(e){for(var t=0;t1209600||(i=e[t][0],f.hasUser(i)||f.saveApiUser(e[t][1]),a.push({id:i,rate:e[t][2],date:e[t][3]}))}return a})}function y(e){v().then(function(t){for(var i=!1,a=t.length,r=[],o=0;o15&&(r=r.slice(0,15)),r.push([e,f.getUser(e),1,tsNow(!0)])),ConfigStorage.set({inline_bots_popular:r}),n.$broadcast("inline_bots_popular")})}function b(n){return m.resolveUsername(n).then(function(i){if(i>0){var a=f.getUser(i);if(a.pFlags.bot&&void 0!==a.bot_inline_placeholder){var r={username:n,id:i,placeholder:a.bot_inline_placeholder};return a.pFlags.bot_inline_geo&&_.isAvailable()?x(i).then(function(){return _.getPosition().then(function(t){return r.geo=t,e.when(r)})})["catch"](function(){return e.when(r)}):e.when(r)}}return t.reject()},function(e){return e.handled=!0,t.reject(e)})}function w(e,t,n,i,a){return o.invokeApi("messages.getInlineBotResults",{flags:0|(i?1:0),bot:f.getUserInput(t),peer:m.getInputPeerByID(e),query:n,geo_point:i&&{_:"inputGeoPoint",lat:i.lat,"long":i["long"]},offset:a},{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=p.wrapRichText(e.switch_pm.text,{noLinebreaks:!0,noLinks:!0})),angular.forEach(e.results,function(e){var i=n+"_"+e.id;e.qID=i,e.botID=t,e.rTitle=p.wrapRichText(e.title,{noLinebreaks:!0,noLinks:!0}),e.rDescription=p.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),P[i]=e}),e})}function k(e,t,n){if(e&&e[0]&&["photo","gif","sticker"].indexOf(e[0].type)!=-1){var i=[];angular.forEach(e,function(e){var t,n,a,r;if("botInlineMediaResult"==e._){if(a=e.document)t=e.document.w,n=e.document.h;else if(r=e.photo){var o=(r.sizes||[])[0];t=o&&o.w,n=o&&o.h}}else t=e.w,n=e.h;t&&n||(t=n=1),i.push(t/n)});var a=[],r=0,o=0;angular.forEach(i,function(e){var i=e*n;o+=i,!r||r<4&&o<1.1*t?r++:(a.push(r),r=1,o=i)}),r&&a.push(r);var s=0,l=a.length-1;angular.forEach(a,function(a,r){var o=r==l,c=i.slice(s,s+a),d=0;angular.forEach(c,function(e){d+=e}),angular.forEach(c,function(i,a){var r=n,l=t*i/d,c=r*i;o&&l>c&&(l=c);var u=e[s+a];u.thumbW=Math.floor(l)-2,u.thumbH=Math.floor(r)-2}),s+=a})}}function M(e,t,i){var r=m.getPeerString(e),o={};o["inline_switch_pm"+t]={peer:r,time:tsNow()},a.set(o),n.$broadcast("history_focus",{peerString:m.getPeerString(t)}),s.startBot(t,0,i)}function S(t){var n=f.getUser(t);if(!n||!n.pFlags.bot||!n.bot_inline_placeholder)return e.when(!1);var i="inline_switch_pm"+t;return a.get(i).then(function(e){return!!(e&&(a.remove(i),tsNow()-e.time<36e5))&&e.peer})}function A(e,t,i){n.$broadcast("history_focus",{peerString:t,attachment:{_:"inline_query",mention:"@"+f.getUser(e).username,query:i}})}function C(e,t){var n=s.getMessage(e),i=n.viaBotID||n.fromID;if(t.pFlags&&t.pFlags.same_peer){var a=s.getMessagePeer(n),r=m.getPeerString(a);return void A(i,r,t.query)}return S(i).then(function(e){return e?A(i,e,t.query):void g.selectPeer({canSend:!0}).then(function(e){return A(i,e,t.query)})})}function T(e,t){var n=s.getMessage(e),i=(n.fromID,s.getMessagePeer(n));return o.invokeApi("messages.getBotCallbackAnswer",{flags:1,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)$(e.message,e.pFlags.alert);else if("string"==typeof e.url){var t=p.wrapUrl(e.url,!0);h.openUrl(t)}})}function E(e){var t=s.getMessage(e),n=s.getMessagePeer(t);return o.invokeApi("messages.getBotCallbackAnswer",{flags:2,peer:m.getInputPeerByID(n),msg_id:l.getMessageLocalID(e)},{timeout:1,stopTime:-1,noErrorBox:!0}).then(function(n){"string"==typeof n.message&&n.message.length?$(n.message,n.pFlags.alert):"string"==typeof n.url&&u.openGame(t.media.game.id,e,n.url)})}function $(e,t){if("string"==typeof e&&e.length){var n=p.wrapRichText(e,{noLinks:!0,noLinebreaks:!0});t?r.show({title_html:n,alert:!0}):i.pop({type:"info",body:n.valueOf(),bodyOutputType:"trustedHtml",showCloseButton:!1})}}function I(e,t,n){var i=P[t];if(void 0===i)return!1;y(i.botID);var a=t.split("_"),r=a.shift(),o=a.join("_");if(n=n||{},n.viaBotID=i.botID,n.queryID=r,n.resultID=o,i.send_message.reply_markup&&(n.reply_markup=i.send_message.reply_markup),"botInlineMessageText"==i.send_message._)n.entities=i.send_message.entities,s.sendText(e,i.send_message.message,n);else{var l="",c=!1;switch(i.send_message._){case"botInlineMessageMediaAuto":if(l=i.send_message.caption,"botInlineMediaResult"==i._){var d=i.document,u=i.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:i.send_message.geo.lat,"long":i.send_message.geo["long"]}};break;case"botInlineMessageMediaVenue":c={_:"inputMediaVenue",geo_point:{_:"inputGeoPoint",lat:i.send_message.geo.lat,"long":i.send_message.geo["long"]},title:i.send_message.title,address:i.send_message.address,provider:i.send_message.provider,venue_id:i.send_message.venue_id};break;case"botInlineMessageMediaContact":c={_:"inputMediaContact",phone_number:i.send_message.phone_number,first_name:i.send_message.first_name,last_name:i.send_message.last_name}}c||(c={_:"messageMediaPending",type:i.type,file_name:i.title||i.content_url||i.url,size:0,progress:{percent:30,total:0}}),s.sendOther(e,c,n)}}function x(e){var n="bot_access_geo"+e;return a.get(n).then(function(e){return!(!e||!e.granted)||r.confirm({type:"BOT_ACCESS_GEO_INLINE"}).then(function(){var e={};return e[n]={granted:!0,time:tsNow()},a.set(e),!0},function(){var e={};return e[n]={denied:!0,time:tsNow()},a.set(e),t.reject()})})}var P={};return{resolveInlineMention:b,getPopularBots:v,sendInlineResult:I,getInlineResults:w,regroupWrappedResults:k,switchToPM:M,checkSwitchReturn:S,switchInlineButtonClick:C,callbackButtonClick:T,gameButtonClick:E}}]).service("ApiUpdatesManager",["$rootScope","MtpNetworkerFactory","AppUsersManager","AppChatsManager","AppPeersManager","MtpApiManager",function(e,t,n,i,a,r){function o(){var e=_.seq+1,t=_.pendingSeqUpdates[e];if(!t)return!1;for(var n,i,a=t.updates,n=0,i=a.length;n=_.syncPending.seqAwaiting&&(_.syncPending.ptsAwaiting?delete _.syncPending.seqAwaiting:(clearTimeout(_.syncPending.timeout),_.syncPending=!1)),!0}function s(e){var t=e?f(e):_;if(!t.pendingPtsUpdates.length)return!1;t.pendingPtsUpdates.sort(function(e,t){return e.pts-t.pts});for(var n,i=t.pts,a=!1,r=!1,o=0,s=t.pendingPtsUpdates.length;o=n.pts&&(a=n.pts,r=o);if(!a)return!1;for(console.log(dT(),"pop pending pts updates",a,t.pendingPtsUpdates.slice(0,r+1)),t.pts=a,o=0;o<=r;o++)n=t.pendingPtsUpdates[o],h(n);return t.pendingPtsUpdates.splice(0,r+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,t){var r={date:e.date,seq:e.seq,seqStart:e.seq_start};switch(e._){case"updatesTooLong":case"new_session_created":l();break;case"updateShort":m(e.update,r);break;case"updateShortMessage":case"updateShortChatMessage":var o=2&e.flags,s=e.from_id||(o?y:e.user_id),c=e.chat_id?-e.chat_id:o?e.user_id:y;m({_:"updateNewMessage",message:{_:"message",flags:e.flags,pFlags:e.pFlags,id:e.id,from_id:s,to_id:a.getOutputPeer(c),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},r);break;case"updatesCombined":case"updates":n.saveApiUsers(e.users),i.saveApiChats(e.chats),angular.forEach(e.updates,function(e){m(e,r)});break;default:console.warn(dT(),"Unknown update message",e)}}function d(){_.syncLoading||(_.syncLoading=!0,_.pendingSeqUpdates={},_.pendingPtsUpdates=[]),_.syncPending&&(clearTimeout(_.syncPending.timeout),_.syncPending=!1),r.invokeApi("updates.getDifference",{pts:_.pts,date:_.date,qts:-1},{timeout:2147483647}).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),i.saveApiChats(t.chats);angular.forEach(t.other_updates,function(e){switch(e._){case"updateChannelTooLong":case"updateNewChannelMessage":case"updateEditChannelMessage":return void m(e)}h(e)}),angular.forEach(t.new_messages,function(e){h({_:"updateNewMessage",message:e,pts:_.pts,pts_count:0})});var a=t.intermediate_state||t.state;_.seq=a.seq,_.pts=a.pts,_.date=a.date,"updates.differenceSlice"==t._?d():(e.$broadcast("stateSynchronized"),_.syncLoading=!1)})}function u(t){var a=f(t);a.syncLoading||(a.syncLoading=!0,a.pendingPtsUpdates=[]),a.syncPending&&(clearTimeout(a.syncPending.timeout),a.syncPending=!1),r.invokeApi("updates.getChannelDifference",{channel:i.getChannelInput(t),filter:{_:"channelMessagesFilterEmpty"},pts:a.pts,limit:30}).then(function(r){return a.pts=r.pts,"updates.channelDifferenceEmpty"==r._?(console.log(dT(),"apply channel empty diff",r),a.syncLoading=!1,e.$broadcast("stateSynchronized"),!1):"updates.channelDifferenceTooLong"==r._?(console.log(dT(),"channel diff too long",r),a.syncLoading=!1,delete v[t],h({_:"updateChannelReload",channel_id:t}),!1):(n.saveApiUsers(r.users),i.saveApiChats(r.chats),console.log(dT(),"applying",r.other_updates.length,"channel other updates"),angular.forEach(r.other_updates,function(e){h(e)}),console.log(dT(),"applying",r.new_messages.length,"channel new messages"),angular.forEach(r.new_messages,function(e){h({_:"updateNewChannelMessage",message:e,pts:a.pts,pts_count:0})}),console.log(dT(),"apply channel diff",a.pts),void("updates.channelDifference"!=r._||r.pFlags["final"]?(console.log(dT(),"finished channel get diff"),e.$broadcast("stateSynchronized"),a.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 f(e,t){return void 0===v[e]&&p(e,t),v[e]}function m(e,t){t=t||{};var r=!1;switch(e._){case"updateNewChannelMessage":case"updateEditChannelMessage":r=-a.getPeerID(e.message.to_id);break;case"updateDeleteChannelMessages":r=e.channel_id;break;case"updateChannelTooLong":if(r=e.channel_id,void 0===v[r])return!1}var c=r?f(r,e.pts):_;if(c.syncLoading)return!1;if("updateChannelTooLong"==e._)return(!c.lastPtsUpdateTime||c.lastPtsUpdateTime0&&!n.hasUser(m)&&(y="toPeer User")||m<0&&!i.hasChat(-m)&&(y="toPeer Chat"))return console.warn(dT(),"Not enough data for message update",m,y,p),r&&i.hasChat(r)?u(r):l(),!1}else if(r&&!i.hasChat(r))return!1;var b,w;if(e.pts){var k=c.pts+(e.pts_count||0);if(kc.pts)c.pts=e.pts,b=!0,c.lastPtsUpdateTime=tsNow();else if(e.pts_count)return!1;r&&t.date&&_.date0){var M=t.seq,S=t.seqStart||M;if(S!=c.seq+1&&S>c.seq)return console.warn(dT(),"Seq hole",c,c.syncPending&&c.syncPending.seqAwaiting),void 0===c.pendingSeqUpdates[S]&&(c.pendingSeqUpdates[S]={seq:M,date:t.date,updates:[]}),c.pendingSeqUpdates[S].updates.push(e),c.syncPending||(c.syncPending={timeout:setTimeout(function(){d()},5e3)}),(!c.syncPending.seqAwaiting||c.syncPending.seqAwaitingf)||(f=!1,!1))}var c,d=0,u=!1,p=0,f=!1;return n.getUserID().then(function(e){p=e}),t.$on("apiUpdate",function(e,t){"updateUserStatus"==t._&&t.user_id==p&&(f=tsNow()+("userStatusOnline"==t.status._?3e5:0))}),{start:r,isOtherDeviceActive:l}}]).service("NotificationsManager",["$rootScope","$window","$interval","$q","$modal","_","toaster","MtpApiManager","AppPeersManager","AppChatsManager","AppUsersManager","IdleManager","Storage","AppRuntimeManager","FileManager","WebPushApiManager",function(e,t,n,i,a,r,o,s,l,c,d,u,p,f,m,h){function g(){p.get("notify_nodesktop","notify_volume","notify_novibrate","notify_nopreview","notify_nopush").then(function(e){if(ee.nodesktop=e[0],ee.volume=e[1]===!1?.5:e[1],ee.novibrate=e[2],ee.nopreview=e[3],ee.nopush=e[4],ne){var t=!ee.nopush&&!ee.nodesktop&&h.isAvailable||!1,n=te!==!1;t!=n&&(t?h.subscribe():h.unsubscribe())}h.setSettings(ee)})}function _(){return ee}function v(e){return void 0!==K[e]?K[e]:K[e]=s.invokeApi("account.getNotifySettings",{peer:{_:"inputNotifyPeer",peer:l.getInputPeerByID(e)}})}function y(e){if(e=e||"favicon.ico",U!==e){var t=document.createElement("link");t.rel="shortcut icon",t.type="image/x-icon",t.href=e,Y.parentNode.replaceChild(t,Y),Y=t,U=e}}function b(t,n){K[t]=i.when(n),e.$broadcast("notify_settings",{peerID:t})}function w(e,t){b(e,t);var n=angular.copy(t);return n._="inputPeerNotifySettings",s.invokeApi("account.updateNotifySettings",{peer:{_:"inputNotifyPeer",peer:l.getInputPeerByID(e)},settings:n})}function k(e){return v(e).then(function(e){return"peerNotifySettings"==e._&&1e3*e.mute_until>tsNow()})}function M(){if(g(),e.$on("settings_changed",g),h.start(),!B)return!1;"Notification"in window&&"granted"!==Notification.permission&&"denied"!==Notification.permission&&$(t).on("click",A);try{"onbeforeunload"in window&&$(t).on("beforeunload",P)}catch(n){}}function S(){P(),n.cancel(F),y(),Q=!0}function A(){Notification.requestPermission(),$(t).off("click",A)}function C(t){if(console.log("notify",t,e.idle.isIDLE,B,Q),!Q){if(Config.Navigator.ffos&&!Config.Navigator.ffos2p)t.image="https://telegram.org/img/t_logo.png";else if(t.image&&!angular.isString(t.image)){if(Config.Navigator.ffos2p)return m.getDataUrl(t.image,"image/jpeg").then(function(e){t.image=e,C(t)}),!1;t.image=m.getUrl(t.image,"image/jpeg")}else t.image||(t.image="img/icons/icon60.png");V++;var n=tsNow();if(ee.volume>0&&(!t.tag||!q[t.tag]||n>q[t.tag]+6e4)&&(T(ee.volume),q[t.tag]=n),!B||"Notification"in window&&"granted"!==Notification.permission)return!1;if(ee.nodesktop){if(z&&!ee.novibrate)return void navigator.vibrate([200,100,200])}else{var i,a=++j,r=t.key||"k"+a;if("Notification"in window)try{i=new Notification(t.title,{icon:t.image||"",body:t.message||"",tag:t.tag||"",silent:t.silent||!1})}catch(o){return B=!1,void h.setLocalNotificationsDisabled()}else if("mozNotification"in navigator)i=navigator.mozNotification.createNotification(t.title,t.message||"",t.image||"");else{if(!N)return;window.external.msSiteModeClearIconOverlay(),window.external.msSiteModeSetIconOverlay("img/icons/icon16.png",t.title),window.external.msSiteModeActivate(),i={index:a}}i.onclick=function(){i.close(),f.focus(),P(),t.onclick&&t.onclick()},i.onclose=function(){i.hidden||(delete H[r],P())},i.show&&i.show(),H[r]=i,Config.Navigator.mobile||setTimeout(function(){I(r)},8e3)}}}function T(e){var t=tsNow();if(!(W&&t');i.find("audio")[0].volume=e}}function E(e){var t=H[e];if(t){V>0&&V--;try{t.close?t.close():N&&t.index==j&&window.external.msSiteModeClearIconOverlay()}catch(n){}delete V[e]}}function I(e){var t=H[e];if(t){try{t.close&&(t.hidden=!0,t.close())}catch(n){}delete V[e]}}function x(e){delete q[e]}function P(){N?window.external.msSiteModeClearIconOverlay():angular.forEach(H,function(e){try{e.close&&e.close()}catch(t){}}),H={},V=0,h.hidePushNotifications()}function D(e){return(!te||!angular.equals(te,e))&&void s.invokeApi("account.registerDevice",{token_type:e.tokenType,token:e.tokenValue,other_uids:[]}).then(function(){te=e},function(e){e.handled=!0})}function R(e){return!!te&&void s.invokeApi("account.unregisterDevice",{token_type:e.tokenType,token:e.tokenValue,other_uids:[]}).then(function(){te=!1},function(e){e.handled=!0})}function O(){return z}navigator.vibrate=navigator.vibrate||navigator.mozVibrate||navigator.webkitVibrate;var N=!1;try{window.external&&window.external.msIsSiteMode()&&(N=!0)}catch(L){}var F,U,B=N||"Notification"in window||"mozNotification"in navigator,H={},j=0,V=0,q={},z=!!navigator.vibrate,W=!1,G=!1,K={},Y=$('link[rel="icon"]:first')[0],X=r.pluralize("page_title_pluralize_notifications"),J=document.title,Z=!1,Q=!1,ee={};e.$watch("idle.deactivated",function(e){e&&S()}),e.$watch("idle.isIDLE",function(e){Q||(e||P(),Config.Navigator.mobile||(n.cancel(F),e?(J=document.title,F=n(function(){Z||!V?(Z=!1,document.title=J,y()):(Z=!0,document.title=X(V),y("favicon_unread.ico"))},1e3)):(Z=!1,document.title=J,y())))}),e.$on("apiUpdate",function(e,t){switch(t._){case"updateNotifySettings":if("notifyPeer"==t.peer._){var n=l.getPeerID(t.peer.peer);b(n,t.notify_settings)}}});var te=!1,ne=!1;e.$on("push_init",function(e,t){ne=!0,ee.nodesktop||ee.nopush?R(t):t?D(t):h.subscribe()}),e.$on("push_subscribe",function(e,t){D(t)}),e.$on("push_unsubscribe",function(e,t){R(t)});var ie=i.defer(),ae=e.$on("dialogs_multiupdate",function(){ae(),ie.resolve()}),re=ie.promise;return e.$on("push_notification_click",function(t,n){if("push_settings"==n.action)return void re.then(function(){a.open({templateUrl:templateUrl("settings_modal"),controller:"SettingsModalController",windowClass:"settings_modal_window mobile_modal",backdrop:"single"})});if("mute1d"==n.action)return void s.invokeApi("account.updateDeviceLocked",function(){}).then(function(){var e=o.pop({type:"info",body:r("push_action_mute1d_success"),bodyOutputType:"trustedHtml",clickHandler:function(){o.clear(e)},showCloseButton:!1})});var i=n.custom&&n.custom.peerID;console.log("click",n,i),i&&re.then(function(){n.custom.channel_id&&!c.hasChat(n.custom.channel_id)||i>0&&!d.hasUser(i)||e.$broadcast("history_focus",{peerString:l.getPeerString(i)})})}),{start:M,notify:C,cancel:E,clear:P,soundReset:x,getPeerSettings:v,getPeerMuted:k,savePeerSettings:b,updatePeerSettings:w,updateNotifySettings:g,getNotifySettings:_,getVibrateSupport:O,testSound:T}}]).service("PasswordManager",["$timeout","$q","$rootScope","MtpApiManager","CryptoWorker","MtpSecureRandom",function(e,t,n,i,a,r){function o(e){return i.invokeApi("account.getPassword",{},e).then(function(e){return e})}function s(e,n){var a,o,s={new_settings:{_:"account.passwordInputSettings",flags:0,hint:n.hint||""}};if(a="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);r.nextBytes(l),o=u(c,n.new_password),s.new_settings.new_salt=c,s.new_settings.flags|=1}else"string"==typeof n.new_password&&(s.new_settings.flags|=1,s.new_settings.new_salt=[]),o=t.when([]);return"string"==typeof n.email&&(s.new_settings.flags|=2,s.new_settings.email=n.email||""),t.all([a,o]).then(function(e){return s.current_password_hash=e[0],s.new_settings.new_password_hash=e[1],i.invokeApi("account.updatePasswordSettings",s)})}function l(e,t,n){return u(e.current_salt,t).then(function(e){return i.invokeApi("auth.checkPassword",{password_hash:e},n)})}function c(e,t){return i.invokeApi("auth.requestPasswordRecovery",{},t)}function d(e,t){return i.invokeApi("auth.recoverPassword",{code:e},t)}function u(e,t){for(var n=unescape(encodeURIComponent(t)),i=new ArrayBuffer(n.length),r=new Uint8Array(i),o=0,s=n.length;o=1)return console.log("Skip error box, too many open",o,n,i),!1;i=i||{};var a=e.$new();angular.extend(a,n),o++;var r=t.open({templateUrl:templateUrl("error_modal"),scope:a,windowClass:i.windowClass||"error_modal_window"});return r.result["finally"](function(){o--}),r}function a(e,t){return i({title:e,description:t})}function r(n,i,a){i=i||{},a=a||{};var r=e.$new();angular.extend(r,n),angular.extend(r,{data:a});var o=t.open({templateUrl:templateUrl("confirm_modal"),scope:r,windowClass:i.windowClass||"confirm_modal_window"});return o.result}var o=0;return n.safeConfirm=function(e,t){"string"==typeof e&&(e={message:e}),r(e).then(function(e){t(e||!0)},function(){t(!1)})},{show:i,alert:a,confirm:r}}]).service("PeersSelectService",["$rootScope","$modal",function(e,t){function n(n){var i=e.$new();return i.multiSelect=!1,i.noMessages=!0,i.forPeerSelect=!0,n&&angular.extend(i,n),t.open({templateUrl:templateUrl("peer_select"),controller:"PeerSelectController",scope:i,windowClass:"peer_select_window mobile_modal",backdrop:"single"}).result}function i(i){if(Config.Mobile)return n(i).then(function(e){return[e]});var a=e.$new();return a.multiSelect=!0,a.noMessages=!0,a.forPeerSelect=!0,i&&angular.extend(a,i),t.open({templateUrl:templateUrl("peer_select"),controller:"PeerSelectController",scope:a,windowClass:"peer_select_window mobile_modal",backdrop:"single"}).result}return{selectPeer:n,selectPeers:i}}]).service("ContactsSelectService",["$rootScope","$modal",function(e,t){function n(n,i){i=i||{};var a=e.$new();return a.multiSelect=n,angular.extend(a,i),!a.action&&n&&(a.action="select"),t.open({templateUrl:templateUrl("contacts_modal"),controller:"ContactsModalController",scope:a,windowClass:"contacts_modal_window mobile_modal",backdrop:"single"}).result}return{selectContacts:function(e){return n(!0,e)},selectContact:function(e){return n(!1,e)}}}]).service("ChangelogNotifyService",["Storage","$rootScope","$modal","$timeout","MtpApiManager","ApiUpdatesManager",function(e,t,n,i,a,r){function o(){l||(l=!0,a.getUserID().then(function(t){t&&i(function(){e.get("last_version").then(function(t){t!=Config.App.version&&(t?a.invokeApi("help.getAppChangelog",{prev_app_version:t},{noErrorBox:!0}).then(function(t){return!("updates"==t._&&!t.updates.length)&&(r.processUpdateMessage(t),void e.set({last_version:Config.App.version}))}):e.set({last_version:Config.App.version}))})},5e3)}))}function s(e){var i=t.$new();i.lastVersion=e,n.open({controller:"ChangelogModalController",templateUrl:templateUrl("changelog_modal"),scope:i,windowClass:"changelog_modal_window mobile_modal"})}var l=!1;return{checkUpdate:o,showChangelog:s}}]).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 i(){a||"http:"!=location.protocol||Config.Modes.http||Config.App.domains.indexOf(location.hostname)==-1||(a=!0,setTimeout(n,12e4))}var a=!1;return{start:i,check:n}}]).service("LayoutSwitchService",["ErrorService","Storage","AppRuntimeManager","$window",function(e,t,n,i){function a(e){ConfigStorage.noPrefix(),t.set({layout_selected:e?"mobile":"desktop",layout_width:$(window).width()}).then(function(){n.reload()})}function r(n){if(!l){var i=$(window).width(),r=i<600;!i||!n&&(Config.Navigator.mobile?i<=800:r)||r!=Config.Mobile&&(ConfigStorage.noPrefix(),t.get("layout_width").then(function(n){return i!=n&&(l=!0,void e.confirm({type:r?"SWITCH_MOBILE_VERSION":"SWITCH_DESKTOP_VERSION"}).then(function(){a(r)},function(){ConfigStorage.noPrefix(),t.set({layout_width:i}),l=!1}))}))}}function o(){s||Config.Navigator.mobile||(s=!0,r(),$(i).on("resize",r))}var s=!1,l=!1;return{start:o,switchLayout:a}}]).service("TelegramMeWebService",["Storage",function(e){function t(t){return!n&&void e.get("tgme_sync").then(function(n){var i=tsNow(!0);if(t&&n&&n.canRedirect==t&&n.ts+86400>i)return!1;e.set({tgme_sync:{canRedirect:t,ts:i}});var a=$("