|
|
@ -2285,26 +2285,22 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
var currentStickerSets = []; |
|
|
|
var currentStickerSets = []; |
|
|
|
|
|
|
|
|
|
|
|
$rootScope.$on('apiUpdate', function (e, update) { |
|
|
|
$rootScope.$on('apiUpdate', function (e, update) { |
|
|
|
var rewriteCached = false; |
|
|
|
if (update._ != 'updateStickerSets' && |
|
|
|
if (update._ == 'updateStickerSets') { |
|
|
|
update._ != 'updateNewStickerSet' && |
|
|
|
getStickers(true); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (update._ != 'updateNewStickerSet' && |
|
|
|
|
|
|
|
update._ != 'updateDelStickerSet' && |
|
|
|
update._ != 'updateDelStickerSet' && |
|
|
|
update._ != 'updateStickerSetsOrder') { |
|
|
|
update._ != 'updateStickerSetsOrder') { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return Storage.get('all_stickers').then(function (stickers) { |
|
|
|
return Storage.get('all_stickers').then(function (stickers) { |
|
|
|
if (stickers && |
|
|
|
if (!stickers || |
|
|
|
stickers.layer == Config.Schema.API.layer) { |
|
|
|
stickers.layer != Config.Schema.API.layer) { |
|
|
|
|
|
|
|
$rootScope.$broadcast('stickers_changed'); |
|
|
|
|
|
|
|
} |
|
|
|
switch (update._) { |
|
|
|
switch (update._) { |
|
|
|
case 'updateNewStickerSet': |
|
|
|
case 'updateNewStickerSet': |
|
|
|
var fullSet = update.stickerset; |
|
|
|
var fullSet = update.stickerset; |
|
|
|
var set = fullSet.set; |
|
|
|
var set = fullSet.set; |
|
|
|
set.pFlags.installed = true; |
|
|
|
|
|
|
|
stickers.fullSets[set.id] = fullSet; |
|
|
|
|
|
|
|
var pos = false; |
|
|
|
var pos = false; |
|
|
|
for (var i = 0, len = stickers.sets.length; i < len; i++) { |
|
|
|
for (var i = 0, len = stickers.sets.length; i < len; i++) { |
|
|
|
if (stickers.sets[i].id == set.id) { |
|
|
|
if (stickers.sets[i].id == set.id) { |
|
|
@ -2315,12 +2311,17 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
if (pos !== false) { |
|
|
|
if (pos !== false) { |
|
|
|
stickers.sets.splice(pos, 1); |
|
|
|
stickers.sets.splice(pos, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
set.pFlags.installed = true; |
|
|
|
stickers.sets.unshift(set); |
|
|
|
stickers.sets.unshift(set); |
|
|
|
|
|
|
|
stickers.fullSets[set.id] = fullSet; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'updateDelStickerSet': |
|
|
|
case 'updateDelStickerSet': |
|
|
|
|
|
|
|
var set; |
|
|
|
for (var i = 0, len = stickers.sets.length; i < len; i++) { |
|
|
|
for (var i = 0, len = stickers.sets.length; i < len; i++) { |
|
|
|
if (stickers.sets[i].id == update.id) { |
|
|
|
set = stickers.sets[i]; |
|
|
|
|
|
|
|
if (set.id == update.id) { |
|
|
|
|
|
|
|
set.pFlags.installed = false; |
|
|
|
stickers.sets.splice(i, 1); |
|
|
|
stickers.sets.splice(i, 1); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -2335,21 +2336,22 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
}); |
|
|
|
}); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
stickers.hash = getStickerSetsHash(stickers.sets); |
|
|
|
|
|
|
|
stickers.date = 0; |
|
|
|
Storage.set({all_stickers: stickers}).then(function () { |
|
|
|
Storage.set({all_stickers: stickers}).then(function () { |
|
|
|
getStickers(true) |
|
|
|
$rootScope.$broadcast('stickers_changed'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
start: start, |
|
|
|
start: start, |
|
|
|
|
|
|
|
getStickers: getStickers, |
|
|
|
openStickersetLink: openStickersetLink, |
|
|
|
openStickersetLink: openStickersetLink, |
|
|
|
openStickerset: openStickerset, |
|
|
|
openStickerset: openStickerset, |
|
|
|
installStickerset: installStickerset, |
|
|
|
installStickerset: installStickerset, |
|
|
|
pushPopularSticker: pushPopularSticker, |
|
|
|
pushPopularSticker: pushPopularSticker, |
|
|
|
getStickers: getStickers, |
|
|
|
|
|
|
|
getStickerset: getStickerset |
|
|
|
getStickerset: getStickerset |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -2360,46 +2362,38 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getPopularStickers () { |
|
|
|
function getStickers (force) { |
|
|
|
return Storage.get('stickers_popular').then(function (popStickers) { |
|
|
|
return Storage.get('all_stickers').then(function (stickers) { |
|
|
|
var result = []; |
|
|
|
var layer = Config.Schema.API.layer; |
|
|
|
var i, len, docID; |
|
|
|
if (stickers.layer != layer) { |
|
|
|
if (popStickers && popStickers.length) { |
|
|
|
stickers = false; |
|
|
|
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]}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (stickers && stickers.date > tsNow(true) && !force) { |
|
|
|
|
|
|
|
return processRawStickers(stickers); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
return MtpApiManager.invokeApi('messages.getAllStickers', { |
|
|
|
return result; |
|
|
|
hash: stickers && stickers.hash || '' |
|
|
|
}); |
|
|
|
}).then(function (newStickers) { |
|
|
|
|
|
|
|
var notModified = newStickers._ == 'messages.allStickersNotModified'; |
|
|
|
|
|
|
|
if (notModified) { |
|
|
|
|
|
|
|
newStickers = stickers; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
newStickers.date = tsNow(true) + 3600; |
|
|
|
|
|
|
|
newStickers.layer = layer; |
|
|
|
|
|
|
|
delete newStickers._; |
|
|
|
|
|
|
|
|
|
|
|
function pushPopularSticker (id) { |
|
|
|
if (notModified) { |
|
|
|
getPopularStickers().then(function (popularStickers) { |
|
|
|
Storage.set({all_stickers: newStickers}); |
|
|
|
var exists = false; |
|
|
|
return processRawStickers(newStickers); |
|
|
|
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 getStickerSets(newStickers, stickers && stickers.fullSets).then(function () { |
|
|
|
return b[1] - a[1]; |
|
|
|
Storage.set({all_stickers: newStickers}); |
|
|
|
|
|
|
|
return processRawStickers(newStickers); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
|
|
|
|
if (result.length > 15) { |
|
|
|
|
|
|
|
result = result.slice(0, 15); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
result.push([id, 1]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ConfigStorage.set({stickers_popular: result}); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function processRawStickers(stickers) { |
|
|
|
function processRawStickers(stickers) { |
|
|
@ -2443,49 +2437,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
docIDs: docIDs |
|
|
|
docIDs: docIDs |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log('stickers', resultStickersets); |
|
|
|
|
|
|
|
return resultStickersets; |
|
|
|
return resultStickersets; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getStickers (force) { |
|
|
|
function getStickerSets (allStickers, prevCachedSets) { |
|
|
|
return Storage.get('all_stickers').then(function (stickers) { |
|
|
|
|
|
|
|
var layer = Config.Schema.API.layer; |
|
|
|
|
|
|
|
if (stickers.layer != layer) { |
|
|
|
|
|
|
|
stickers = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (stickers && stickers.date > tsNow(true) && !force) { |
|
|
|
|
|
|
|
return processRawStickers(stickers); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return MtpApiManager.invokeApi('messages.getAllStickers', { |
|
|
|
|
|
|
|
hash: stickers && stickers.hash || '' |
|
|
|
|
|
|
|
}).then(function (newStickers) { |
|
|
|
|
|
|
|
var notModified = newStickers._ == 'messages.allStickersNotModified'; |
|
|
|
|
|
|
|
if (notModified) { |
|
|
|
|
|
|
|
newStickers = stickers; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
newStickers.date = tsNow(true) + 3600; |
|
|
|
|
|
|
|
newStickers.layer = layer; |
|
|
|
|
|
|
|
delete newStickers._; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (notModified) { |
|
|
|
|
|
|
|
Storage.set({all_stickers: newStickers}); |
|
|
|
|
|
|
|
return processRawStickers(newStickers); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return getStickerSets(newStickers).then(function () { |
|
|
|
|
|
|
|
Storage.set({all_stickers: newStickers}); |
|
|
|
|
|
|
|
return processRawStickers(newStickers); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getStickerSets (allStickers) { |
|
|
|
|
|
|
|
var promises = []; |
|
|
|
var promises = []; |
|
|
|
var cachedSets = allStickers.fullSets || {}; |
|
|
|
var cachedSets = prevCachedSets || allStickers.fullSets || {}; |
|
|
|
allStickers.fullSets = {}; |
|
|
|
allStickers.fullSets = {}; |
|
|
|
angular.forEach(allStickers.sets, function (shortSet) { |
|
|
|
angular.forEach(allStickers.sets, function (shortSet) { |
|
|
|
var fullSet = cachedSets[shortSet.id]; |
|
|
|
var fullSet = cachedSets[shortSet.id]; |
|
|
@ -2507,6 +2465,48 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
return $q.all(promises); |
|
|
|
return $q.all(promises); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 getStickerset (inputStickerset) { |
|
|
|
function getStickerset (inputStickerset) { |
|
|
|
return MtpApiManager.invokeApi('messages.getStickerSet', { |
|
|
|
return MtpApiManager.invokeApi('messages.getStickerSet', { |
|
|
|
stickerset: inputStickerset |
|
|
|
stickerset: inputStickerset |
|
|
@ -2561,6 +2561,18 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
windowClass: 'stickerset_modal_window mobile_modal' |
|
|
|
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('ApiUpdatesManager', function ($rootScope, MtpNetworkerFactory, AppUsersManager, AppChatsManager, AppPeersManager, MtpApiManager) { |
|
|
|
.service('ApiUpdatesManager', function ($rootScope, MtpNetworkerFactory, AppUsersManager, AppChatsManager, AppPeersManager, MtpApiManager) { |
|
|
|