@ -11,7 +11,7 @@
@@ -11,7 +11,7 @@
angular . module ( 'myApp.services' , [ 'myApp.i18n' , 'izhukov.utils' ] )
. service ( 'AppUsersManager' , function ( $rootScope , $modal , $modalStack , $filter , $q , qSync , MtpApiFileManager , MtpApi Manager , RichTextProcessor , ErrorService , Storage , _ ) {
. service ( 'AppUsersManager' , function ( $rootScope , $modal , $modalStack , $filter , $q , qSync , MtpApiManager , RichTextProcessor , ErrorService , Storage , _ ) {
var users = { } ,
usernames = { } ,
userAccess = { } ,
@ -575,7 +575,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -575,7 +575,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} )
. service ( 'AppChatsManager' , function ( $q , $rootScope , $modal , _ , MtpApiFileManager , MtpApi Manager , AppUsersManager , AppPhotosManager , RichTextProcessor ) {
. service ( 'AppChatsManager' , function ( $q , $rootScope , $modal , _ , MtpApiManager , AppUsersManager , AppPhotosManager , RichTextProcessor ) {
var chats = { } ,
usernames = { } ,
channelAccess = { } ,
@ -833,7 +833,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -833,7 +833,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
} )
. service ( 'AppPeersManager' , function ( qSync , AppUsersManager , AppChatsManager , MtpApiManager ) {
. service ( 'AppPeersManager' , function ( $q , qSync , AppUsersManager , AppChatsManager , MtpApiManager ) {
function getInputPeer ( peerString ) {
var firstChar = peerString . charAt ( 0 ) ,
@ -944,6 +944,24 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -944,6 +944,24 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} ) ;
}
function resolveInlineMention ( username ) {
return resolveUsername ( username ) . then ( function ( peerID ) {
if ( peerID > 0 ) {
var bot = AppUsersManager . getUser ( peerID ) ;
if ( bot . pFlags . bot && bot . bot _inline _placeholder !== undefined ) {
return qSync . when ( {
id : peerID ,
placeholder : bot . bot _inline _placeholder
} ) ;
}
}
return $q . reject ( ) ;
} , function ( error ) {
error . handled = true ;
return $q . reject ( error ) ;
} ) ;
}
function getPeerID ( peerString ) {
if ( angular . isObject ( peerString ) ) {
return peerString . user _id
@ -990,6 +1008,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -990,6 +1008,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
getPeer : getPeer ,
getPeerPhoto : getPeerPhoto ,
resolveUsername : resolveUsername ,
resolveInlineMention : resolveInlineMention ,
isChannel : isChannel ,
isMegagroup : isMegagroup ,
isBot : isBot
@ -1222,6 +1241,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -1222,6 +1241,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} ) ;
break ;
}
return $q . reject ( error ) ;
} ) ;
}
@ -1907,7 +1927,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -1907,7 +1927,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
} )
. service ( 'AppDocsManager' , function ( $sce , $rootScope , $modal , $window , $q , RichTextProcessor , MtpApiFileManager , FileManager , qSync ) {
. service ( 'AppDocsManager' , function ( $sce , $rootScope , $modal , $window , $q , $timeout , RichTextProcessor , MtpApiFileManager , FileManager , qSync ) {
var docs = { } ,
docsForHistory = { } ,
windowW = $ ( window ) . width ( ) ,
@ -2096,13 +2116,18 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -2096,13 +2116,18 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} ) ;
downloadPromise . then ( function ( blob ) {
delete historyDoc . progress ;
if ( blob ) {
FileManager . getFileCorrectUrl ( blob , doc . mime _type ) . then ( function ( url ) {
historyDoc . url = $sce . trustAsResourceUrl ( url ) ;
var trustedUrl = $sce . trustAsResourceUrl ( url ) ;
historyDoc . url = trustedUrl ;
doc . url = trustedUrl ;
} )
historyDoc . downloaded = true ;
}
historyDoc . progress . percent = 100 ;
$timeout ( function ( ) {
delete historyDoc . progress ;
} ) ;
console . log ( 'file save done' ) ;
} , function ( e ) {
console . log ( 'document download failed' , e ) ;
@ -2274,24 +2299,81 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -2274,24 +2299,81 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
} )
. service ( 'AppStickersManager' , function ( $q , $rootScope , $modal , _ , FileManager , MtpApiManager , MtpApiFileManager , AppDocsManager , Storage ) {
. service ( 'AppStickersManager' , function ( $q , $rootScope , $modal , _ , FileManager , MtpApiManager , AppDocsManager , Storage , ApiUpdatesManager ) {
var currentStickers = [ ] ;
var currentStickersets = [ ] ;
var installedStickersets = { } ;
var stickersetItems = { } ;
var applied = false ;
var started = false ;
var applied = false ;
var currentStickerSets = [ ] ;
$rootScope . $on ( 'apiUpdate' , function ( e , update ) {
if ( update . _ != 'updateStickerSets' &&
update . _ != 'updateNewStickerSet' &&
update . _ != 'updateDelStickerSet' &&
update . _ != 'updateStickerSetsOrder' ) {
return false ;
}
return Storage . get ( 'all_stickers' ) . then ( function ( stickers ) {
if ( ! stickers ||
stickers . layer != Config . Schema . API . layer ) {
$rootScope . $broadcast ( 'stickers_changed' ) ;
}
switch ( update . _ ) {
case 'updateNewStickerSet' :
var fullSet = update . stickerset ;
var set = fullSet . set ;
var pos = false ;
for ( var i = 0 , len = stickers . sets . length ; i < len ; i ++ ) {
if ( stickers . sets [ i ] . id == set . id ) {
pos = i ;
break ;
}
}
if ( pos !== false ) {
stickers . sets . splice ( pos , 1 ) ;
}
set . pFlags . installed = true ;
stickers . sets . unshift ( set ) ;
stickers . fullSets [ set . id ] = fullSet ;
break ;
case 'updateDelStickerSet' :
var set ;
for ( var i = 0 , len = stickers . sets . length ; i < len ; i ++ ) {
set = stickers . sets [ i ] ;
if ( set . id == update . id ) {
set . pFlags . installed = false ;
stickers . sets . splice ( i , 1 ) ;
break ;
}
}
delete stickers . fullSets [ update . id ] ;
break ;
case 'updateStickerSetsOrder' :
var order = update . order ;
stickers . sets . sort ( function ( a , b ) {
return order . indexOf ( a . id ) - order . indexOf ( b . id ) ;
} ) ;
break ;
}
stickers . hash = getStickerSetsHash ( stickers . sets ) ;
stickers . date = 0 ;
Storage . set ( { all _stickers : stickers } ) . then ( function ( ) {
$rootScope . $broadcast ( 'stickers_changed' ) ;
} ) ;
} ) ;
} ) ;
return {
start : start ,
getStickers : getStickers ,
openStickersetLink : openStickersetLink ,
openStickerset : openStickerset ,
installStickerset : installStickerset ,
pushPopularSticker : pushPopularSticker ,
getStickers : getStickers ,
getStickerset : getStickerset ,
getStickersImages : getStickersImages
getStickerset : getStickerset
} ;
function start ( ) {
@ -2301,104 +2383,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -2301,104 +2383,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
}
function getPopularStickers ( ) {
return Storage . get ( 'stickers_popular' ) . then ( function ( popStickers ) {
var result = [ ] ;
var i , len , docID ;
if ( popStickers && popStickers . length ) {
for ( i = 0 , len = popStickers . length ; i < len ; i ++ ) {
docID = popStickers [ i ] [ 0 ] ;
if ( AppDocsManager . hasDoc ( docID ) ) {
result . push ( { id : docID , rate : popStickers [ i ] [ 1 ] } ) ;
}
}
} ;
return result ;
} ) ;
}
function pushPopularSticker ( id ) {
getPopularStickers ( ) . then ( function ( popularStickers ) {
var exists = false ;
var count = popularStickers . length ;
var result = [ ] ;
for ( var i = 0 ; i < count ; i ++ ) {
if ( popularStickers [ i ] . id == id ) {
exists = true ;
popularStickers [ i ] . rate ++ ;
}
result . push ( [ popularStickers [ i ] . id , popularStickers [ i ] . rate ] ) ;
}
if ( exists ) {
result . sort ( function ( a , b ) {
return b [ 1 ] - a [ 1 ] ;
} ) ;
} else {
if ( result . length > 15 ) {
result = result . slice ( 0 , 15 ) ;
}
result . push ( [ id , 1 ] ) ;
}
ConfigStorage . set ( { stickers _popular : result } ) ;
} ) ;
}
function processRawStickers ( stickers ) {
if ( applied !== stickers . hash ) {
applied = stickers . hash ;
var i , j , len1 , len2 , doc , set , setItems , fullSet ;
currentStickersets = [ ] ;
currentStickers = [ ] ;
len1 = stickers . sets . length ;
for ( i = 0 ; i < len1 ; i ++ ) {
set = stickers . sets [ i ] ;
fullSet = stickers . fullSets [ set . id ] ;
len2 = fullSet . documents . length ;
setItems = [ ] ;
for ( j = 0 ; j < len2 ; j ++ ) {
doc = fullSet . documents [ j ] ;
AppDocsManager . saveDoc ( doc ) ;
currentStickers . push ( doc . id ) ;
setItems . push ( doc . id ) ;
}
currentStickersets . push ( {
id : set . id ,
title : set . title ,
short _name : set . short _name ,
installed : ( set . flags & ( 1 << 0 ) ) > 0 ,
disabled : ( set . flags & ( 1 << 1 ) ) > 0 ,
official : ( set . flags & ( 1 << 2 ) ) > 0 ,
docIDs : setItems
} ) ;
installedStickersets [ set . id ] = true ;
}
}
return getPopularStickers ( ) . then ( function ( popularStickers ) {
var resultStickersets = currentStickersets ;
if ( popularStickers . length ) {
resultStickersets = currentStickersets . slice ( ) ;
var setItems = [ ] ;
var i , len ;
for ( i = 0 , len = popularStickers . length ; i < len ; i ++ ) {
setItems . push ( popularStickers [ i ] . id ) ;
}
resultStickersets . unshift ( {
id : 0 ,
title : _ ( 'im_stickers_tab_recent_raw' ) ,
short _name : '' ,
installed : true ,
disabled : false ,
official : false ,
docIDs : setItems
} )
}
return resultStickersets ;
} ) ;
}
function getStickers ( force ) {
return Storage . get ( 'all_stickers' ) . then ( function ( stickers ) {
var layer = Config . Schema . API . layer ;
@ -2424,7 +2408,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -2424,7 +2408,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return processRawStickers ( newStickers ) ;
}
return getStickerSets ( newStickers ) . then ( function ( ) {
return getStickerSets ( newStickers , stickers && stickers . fullSets ) . then ( function ( ) {
Storage . set ( { all _stickers : newStickers } ) ;
return processRawStickers ( newStickers ) ;
} ) ;
@ -2433,9 +2417,54 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -2433,9 +2417,54 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} )
}
function getStickerSets ( allStickers ) {
function processRawStickers ( stickers ) {
if ( applied !== stickers . hash ) {
applied = stickers . hash ;
var i , j , len1 , len2 , doc , set , docIDs , documents ;
currentStickerSets = [ ] ;
len1 = stickers . sets . length ;
for ( i = 0 ; i < len1 ; i ++ ) {
set = stickers . sets [ i ] ;
if ( set . pFlags . disabled ) {
continue ;
}
documents = stickers . fullSets [ set . id ] . documents ;
len2 = documents . length ;
docIDs = [ ] ;
for ( j = 0 ; j < len2 ; j ++ ) {
doc = documents [ j ] ;
AppDocsManager . saveDoc ( doc ) ;
docIDs . push ( doc . id ) ;
}
set . docIDs = docIDs ;
currentStickerSets . push ( set ) ;
}
}
return getPopularStickers ( ) . then ( function ( popularStickers ) {
var resultStickersets = currentStickerSets ;
if ( popularStickers . length ) {
resultStickersets = currentStickerSets . slice ( ) ;
var docIDs = [ ] ;
var i , len ;
for ( i = 0 , len = popularStickers . length ; i < len ; i ++ ) {
docIDs . push ( popularStickers [ i ] . id ) ;
}
resultStickersets . unshift ( {
id : 0 ,
title : _ ( 'im_stickers_tab_recent_raw' ) ,
short _name : '' ,
docIDs : docIDs
} ) ;
}
return resultStickersets ;
} ) ;
}
function getStickerSets ( allStickers , prevCachedSets ) {
var promises = [ ] ;
var cachedSets = allStickers . fullSets || { } ;
var cachedSets = prevCachedSets || allStickers . fullSets || { } ;
allStickers . fullSets = { } ;
angular . forEach ( allStickers . sets , function ( shortSet ) {
var fullSet = cachedSets [ shortSet . id ] ;
@ -2457,24 +2486,46 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -2457,24 +2486,46 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return $q . all ( promises ) ;
}
function downloadStickerThumb ( docID ) {
var doc = AppDocsManager . getDoc ( docID ) ;
var thumbLocation = angular . copy ( doc . thumb . location ) ;
thumbLocation . sticker = true ;
return MtpApiFileManager . downloadSmallFile ( thumbLocation ) . then ( function ( blob ) {
return {
id : doc . id ,
src : FileManager . getUrl ( blob , 'image/webp' )
function getPopularStickers ( ) {
return Storage . get ( 'stickers_popular' ) . then ( function ( popStickers ) {
var result = [ ] ;
var i , len , docID ;
if ( popStickers && popStickers . length ) {
for ( i = 0 , len = popStickers . length ; i < len ; i ++ ) {
docID = popStickers [ i ] [ 0 ] ;
if ( AppDocsManager . hasDoc ( docID ) ) {
result . push ( { id : docID , rate : popStickers [ i ] [ 1 ] } ) ;
}
}
} ;
return result ;
} ) ;
}
function getStickersImages ( ) {
var promises = [ ] ;
angular . forEach ( currentStickers , function ( docID ) {
promises . push ( downloadStickerThumb ( docID ) ) ;
function pushPopularSticker ( id ) {
getPopularStickers ( ) . then ( function ( popularStickers ) {
var exists = false ;
var count = popularStickers . length ;
var result = [ ] ;
for ( var i = 0 ; i < count ; i ++ ) {
if ( popularStickers [ i ] . id == id ) {
exists = true ;
popularStickers [ i ] . rate ++ ;
}
result . push ( [ popularStickers [ i ] . id , popularStickers [ i ] . rate ] ) ;
}
if ( exists ) {
result . sort ( function ( a , b ) {
return b [ 1 ] - a [ 1 ] ;
} ) ;
} else {
if ( result . length > 15 ) {
result = result . slice ( 0 , 15 ) ;
}
result . push ( [ id , 1 ] ) ;
}
ConfigStorage . set ( { stickers _popular : result } ) ;
} ) ;
return $q . all ( promises ) ;
}
function getStickerset ( inputStickerset ) {
@ -2484,31 +2535,32 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -2484,31 +2535,32 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
for ( var i = 0 ; i < result . documents . length ; i ++ ) {
AppDocsManager . saveDoc ( result . documents [ i ] ) ;
}
result . installed = installedStickersets [ result . set . id ] !== undefined ;
return result ;
} ) ;
}
function installStickerset ( s et, uninstall ) {
function installStickerset ( fullS et, uninstall ) {
var method = uninstall
? 'messages.uninstallStickerSet'
: 'messages.installStickerSet' ;
var inputStickerset = {
_ : 'inputStickerSetID' ,
id : set . id ,
access _hash : set . access _hash
id : fullSet . set . id ,
access _hash : fullSet . set . access _hash
} ;
return MtpApiManager . invokeApi ( method , {
stickerset : inputStickerset ,
disabled : false
} ) . then ( function ( result ) {
var update ;
if ( uninstall ) {
delete installedStickersets [ set . id ] ;
update = { _ : 'updateDelStickerSet' , id : fullSet . set . id } ;
} else {
installedStickersets [ set . id ] = true ;
update = { _ : 'updateNewStickerSet' , stickerset : fullSet } ;
}
Storage . remove ( 'all_stickers' ) . then ( function ( ) {
getStickers ( true ) ;
ApiUpdatesManager . processUpdateMessage ( {
_ : 'updateShort' ,
update : update
} ) ;
} ) ;
}
@ -2530,6 +2582,186 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -2530,6 +2582,186 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
windowClass : 'stickerset_modal_window mobile_modal'
} ) ;
}
function getStickerSetsHash ( stickerSets ) {
var acc = 0 , set ;
for ( var i = 0 ; i < stickerSets . length ; i ++ ) {
set = stickerSets [ i ] ;
if ( set . pFlags . disabled || ! set . pFlags . installed ) {
continue ;
}
acc = ( ( acc * 20261 ) + 0x80000000 + set . hash ) % 0x80000000 ;
}
return acc ;
}
} )
. service ( 'AppInlineBotsManager' , function ( MtpApiManager , AppMessagesManager , AppDocsManager , AppPhotosManager , RichTextProcessor , AppUsersManager ) {
var inlineResults = { } ;
return {
sendInlineResult : sendInlineResult ,
regroupWrappedResults : regroupWrappedResults ,
getInlineResults : getInlineResults
} ;
function getInlineResults ( botID , query , offset ) {
return MtpApiManager . invokeApi ( 'messages.getInlineBotResults' , {
bot : AppUsersManager . getUserInput ( botID ) ,
query : query ,
offset : offset
} , { timeout : 1 , stopTime : - 1 , noErrorBox : true } ) . then ( function ( botResults ) {
var queryID = botResults . query _id ;
delete botResults . _ ;
delete botResults . flags ;
delete botResults . query _id ;
angular . forEach ( botResults . results , function ( result ) {
var qID = queryID + '_' + result . id ;
result . qID = qID ;
result . botID = botID ;
result . rTitle = RichTextProcessor . wrapRichText ( result . title , { noLinebreaks : true , noLinks : true } ) ;
result . rDescription = RichTextProcessor . wrapRichText ( result . description , { noLinebreaks : true , noLinks : true } ) ;
result . initials = ( result . url || result . title || result . type || '' ) . substr ( 0 , 1 )
if ( result . document ) {
AppDocsManager . saveDoc ( result . document ) ;
}
if ( result . photo ) {
AppPhotosManager . savePhoto ( result . photo ) ;
}
inlineResults [ qID ] = result ;
} ) ;
return botResults ;
} ) ;
}
function regroupWrappedResults ( results , rowW , rowH ) {
if ( ! results ||
! results [ 0 ] ||
results [ 0 ] . type != 'photo' && results [ 0 ] . type != 'gif' ) {
return ;
}
var ratios = [ ] ;
angular . forEach ( results , function ( result ) {
var w , h ;
if ( result . _ == 'botInlineMediaResultDocument' ) {
w = result . document . w ;
h = result . document . h ;
}
else if ( result . _ == 'botInlineMediaResultPhoto' ) {
var photoSize = ( result . photo . sizes || [ ] ) [ 0 ] ;
w = photoSize && photoSize . w ;
h = photoSize && photoSize . h ;
}
else {
w = result . w ;
h = result . h ;
}
if ( ! w || ! h ) {
w = h = 1 ;
}
ratios . push ( w / h ) ;
} ) ;
var rows = [ ] ;
var curCnt = 0 ;
var curW = 0 ;
angular . forEach ( ratios , function ( ratio ) {
var w = ratio * rowH ;
curW += w ;
if ( ! curCnt || curCnt < 4 && curW < ( rowW * 1.1 ) ) {
curCnt ++ ;
} else {
rows . push ( curCnt ) ;
curCnt = 1 ;
curW = w ;
}
} ) ;
if ( curCnt ) {
rows . push ( curCnt ) ;
}
var i = 0 ;
var thumbs = [ ] ;
var lastRowI = rows . length - 1 ;
angular . forEach ( rows , function ( rowCnt , rowI ) {
var lastRow = rowI == lastRowI ;
var curRatios = ratios . slice ( i , i + rowCnt ) ;
var sumRatios = 0 ;
angular . forEach ( curRatios , function ( ratio ) {
sumRatios += ratio ;
} ) ;
angular . forEach ( curRatios , function ( ratio , j ) {
var thumbH = rowH ;
var thumbW = rowW * ratio / sumRatios ;
var realW = thumbH * ratio ;
if ( lastRow && thumbW > realW ) {
thumbW = realW ;
}
var result = results [ i + j ] ;
result . thumbW = Math . floor ( thumbW ) ;
result . thumbH = Math . floor ( thumbH ) ;
} ) ;
i += rowCnt ;
} ) ;
}
function sendInlineResult ( peerID , qID , options ) {
var inlineResult = inlineResults [ qID ] ;
if ( inlineResult === undefined ) {
return false ;
}
var splitted = qID . split ( '_' ) ;
var queryID = splitted . shift ( ) ;
var resultID = splitted . join ( '_' ) ;
options = options || { } ;
options . viaBotID = inlineResult . botID ;
options . queryID = queryID ;
options . resultID = resultID ;
if ( inlineResult . send _message . _ == 'botInlineMessageText' ) {
options . entities = inlineResult . send _message . entities ;
AppMessagesManager . sendText ( peerID , inlineResult . send _message . message , options ) ;
} else {
var caption = '' ;
if ( inlineResult . send _message . _ == 'botInlineMessageMediaAuto' ) {
caption = inlineResult . send _message . caption ;
}
var inputMedia = false ;
if ( inlineResult . _ == 'botInlineMediaResultDocument' ) {
var doc = inlineResult . document ;
inputMedia = {
_ : 'inputMediaDocument' ,
id : { _ : 'inputDocument' , id : doc . id , access _hash : doc . access _hash } ,
caption : caption
} ;
}
else if ( inlineResult . _ == 'botInlineMediaResultPhoto' ) {
var photo = inlineResult . photo ;
inputMedia = {
_ : 'inputMediaPhoto' ,
id : { _ : 'inputPhoto' , id : photo . id , access _hash : photo . access _hash } ,
caption : caption
} ;
}
if ( ! inputMedia ) {
inputMedia = {
_ : 'messageMediaPending' ,
type : inlineResult . type ,
file _name : inlineResult . title || inlineResult . content _url || inlineResult . url ,
size : 0 ,
progress : { percent : 30 , total : 0 }
} ;
}
AppMessagesManager . sendOther ( peerID , inputMedia , options ) ;
}
}
} )
. service ( 'ApiUpdatesManager' , function ( $rootScope , MtpNetworkerFactory , AppUsersManager , AppChatsManager , AppPeersManager , MtpApiManager ) {
@ -2828,6 +3060,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -2828,6 +3060,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
function addChannelState ( channelID , pts ) {
if ( ! pts ) {
throw new Error ( 'Add channel state without pts ' + channelID ) ;
}
if ( channelStates [ channelID ] === undefined ) {
channelStates [ channelID ] = {
pts : pts ,
@ -2842,9 +3077,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -2842,9 +3077,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
function getChannelState ( channelID , pts ) {
if ( channelStates [ channelID ] === undefined ) {
if ( ! pts ) {
throw new Error ( 'Get channel empty state without pts ' + channelID ) ;
}
addChannelState ( channelID , pts ) ;
}
return channelStates [ channelID ] ;
@ -3997,7 +4229,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
@@ -3997,7 +4229,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
type : 'JUMP_EXT_URL' ,
url : url
} ) . then ( function ( ) {
window . open ( url , '_blank' ) ;
var target = '_blank' ;
if ( url . search ( 'https://telegram.me/' ) === 0 ) {
target = '_self' ;
}
window . open ( url , target ) ;
} ) ;
return true ;
}