Browse Source

stickers wip

master
Igor Zhukov 8 years ago
parent
commit
d0a2f7b587
  1. 2
      app/js/controllers.js
  2. 91
      app/js/services.js

2
app/js/controllers.js

@ -4661,7 +4661,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.$broadcast('ui_height'); $scope.$broadcast('ui_height');
$scope.stickersetLoaded = true; $scope.stickersetLoaded = true;
$scope.stickerset = result.set; $scope.stickerset = result.set;
$scope.stickersetInstalled = result.installed; $scope.stickersetInstalled = result.set.pFlags.installed;
$scope.documents = result.documents; $scope.documents = result.documents;
$scope.stickerEmojis = {}; $scope.stickerEmojis = {};

91
app/js/services.js

@ -2281,15 +2281,17 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
var currentStickers = []; var currentStickers = [];
var currentStickersets = []; var currentStickersets = [];
var installedStickersets = {};
var stickersetItems = {}; var stickersetItems = {};
var applied = false; var applied = false;
var started = false; var started = false;
// $rootScope.$on('apiUpdate', function (e, update) { $rootScope.$on('apiUpdate', function (e, update) {
// if (update._ == 'updateStickerSets') { if (update._ == 'updateStickerSets') {
// } // Storage.remove('all_stickers').then(function () {
// }); // getStickers(true);
// });
}
});
return { return {
start: start, start: start,
@ -2298,8 +2300,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
installStickerset: installStickerset, installStickerset: installStickerset,
pushPopularSticker: pushPopularSticker, pushPopularSticker: pushPopularSticker,
getStickers: getStickers, getStickers: getStickers,
getStickerset: getStickerset, getStickerset: getStickerset
getStickersImages: getStickersImages
}; };
function start () { function start () {
@ -2354,32 +2355,24 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
function processRawStickers(stickers) { function processRawStickers(stickers) {
if (applied !== stickers.hash) { if (applied !== stickers.hash) {
applied = stickers.hash; applied = stickers.hash;
var i, j, len1, len2, doc, set, setItems, fullSet; var i, j, len1, len2, doc, set, docIDs, documents;
currentStickersets = []; currentStickersets = [];
currentStickers = [];
len1 = stickers.sets.length; len1 = stickers.sets.length;
for (i = 0; i < len1; i++) { for (i = 0; i < len1; i++) {
set = stickers.sets[i]; set = stickers.sets[i];
fullSet = stickers.fullSets[set.id]; if (set.pFlags.disabled) {
len2 = fullSet.documents.length; continue;
setItems = []; }
documents = stickers.fullSets[set.id].documents;
len2 = documents.length;
docIDs = [];
for (j = 0; j < len2; j++) { for (j = 0; j < len2; j++) {
doc = fullSet.documents[j]; doc = documents[j];
AppDocsManager.saveDoc(doc); AppDocsManager.saveDoc(doc);
currentStickers.push(doc.id); docIDs.push(doc.id);
setItems.push(doc.id);
} }
currentStickersets.push({ set.docIDs = docIDs;
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;
} }
} }
@ -2387,20 +2380,17 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
var resultStickersets = currentStickersets; var resultStickersets = currentStickersets;
if (popularStickers.length) { if (popularStickers.length) {
resultStickersets = currentStickersets.slice(); resultStickersets = currentStickersets.slice();
var setItems = []; var docIDs = [];
var i, len; var i, len;
for (i = 0, len = popularStickers.length; i < len; i++) { for (i = 0, len = popularStickers.length; i < len; i++) {
setItems.push(popularStickers[i].id); docIDs.push(popularStickers[i].id);
} }
resultStickersets.unshift({ resultStickersets.unshift({
id: 0, id: 0,
title: _('im_stickers_tab_recent_raw'), title: _('im_stickers_tab_recent_raw'),
short_name: '', short_name: '',
installed: true, docIDs: docIDs
disabled: false, });
official: false,
docIDs: setItems
})
} }
return resultStickersets; return resultStickersets;
@ -2465,26 +2455,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return $q.all(promises); 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 getStickersImages () {
var promises = [];
angular.forEach(currentStickers, function (docID) {
promises.push(downloadStickerThumb (docID));
});
return $q.all(promises);
}
function getStickerset (inputStickerset) { function getStickerset (inputStickerset) {
return MtpApiManager.invokeApi('messages.getStickerSet', { return MtpApiManager.invokeApi('messages.getStickerSet', {
stickerset: inputStickerset stickerset: inputStickerset
@ -2492,7 +2462,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
for (var i = 0; i < result.documents.length; i++) { for (var i = 0; i < result.documents.length; i++) {
AppDocsManager.saveDoc(result.documents[i]); AppDocsManager.saveDoc(result.documents[i]);
} }
result.installed = installedStickersets[result.set.id] !== undefined;
return result; return result;
}); });
} }
@ -2511,13 +2480,19 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
disabled: false disabled: false
}).then(function (result) { }).then(function (result) {
if (uninstall) { if (uninstall) {
delete installedStickersets[set.id];
} else { } else {
installedStickersets[set.id] = true; ApiUpdatesManager.processUpdateMessage({
_: 'updateShort',
update: {
_: 'updateNewStickerSet',
channel_id: channelID,
messages: msgIDs,
pts: affectedMessages.pts,
pts_count: affectedMessages.pts_count
}
});
} }
Storage.remove('all_stickers').then(function () {
getStickers(true);
});
}); });
} }

Loading…
Cancel
Save