From 6d9aa03695619787a31f238498c750c558923ced Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 1 Oct 2015 00:48:15 +0300 Subject: [PATCH] Improved channel updates --- app/js/controllers.js | 28 ++-- app/js/directives.js | 4 +- app/js/messages_manager.js | 19 ++- app/js/services.js | 198 ++++++++++++----------- app/less/app.less | 4 +- app/partials/desktop/channel_modal.html | 11 +- app/partials/desktop/chat_modal.html | 2 +- app/partials/desktop/dialog_service.html | 4 +- app/partials/desktop/settings_modal.html | 2 +- app/partials/desktop/user_modal.html | 2 +- 10 files changed, 147 insertions(+), 127 deletions(-) diff --git a/app/js/controllers.js b/app/js/controllers.js index e4d9160c..689593f5 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -616,7 +616,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) AppStickersManager.start(); }) - .controller('AppImDialogsController', function ($scope, $location, $q, $timeout, $routeParams, MtpApiManager, AppUsersManager, AppChatsManager, AppMessagesManager, AppPeersManager, PhonebookContactsService, ErrorService, AppRuntimeManager) { + .controller('AppImDialogsController', function ($scope, $location, $q, $timeout, $routeParams, MtpApiManager, AppUsersManager, AppChatsManager, AppMessagesManager, AppProfileManager, AppPeersManager, PhonebookContactsService, ErrorService, AppRuntimeManager) { $scope.dialogs = []; $scope.contacts = []; @@ -732,7 +732,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) case 'updateChatUserTyping': if (!AppUsersManager.hasUser(update.user_id)) { if (update.chat_id) { - AppChatsManager.getChatFull(update.chat_id); + AppProfileManager.getChatFull(update.chat_id); } return; } @@ -1724,9 +1724,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) $scope.$on('history_forbidden', function (e, updPeerID) { if (updPeerID == $scope.curDialog.peerID) { - $rootScope.$apply(function () { - $location.url('/im'); - }) + $location.url('/im'); } }); @@ -2075,7 +2073,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) $scope.$broadcast('mentions_update'); return; } - AppChatsManager.getChatFull(-peerID).then(function (chatFull) { + AppProfileManager.getChatFull(-peerID).then(function (chatFull) { var participantsVector = (chatFull.participants || {}).participants || []; var mentionUsers = []; @@ -3026,12 +3024,12 @@ angular.module('myApp.controllers', ['myApp.i18n']) }) - .controller('ChatModalController', function ($scope, $timeout, $rootScope, $modal, AppUsersManager, AppChatsManager, AppPhotosManager, MtpApiManager, MtpApiFileManager, NotificationsManager, AppMessagesManager, AppPeersManager, ApiUpdatesManager, ContactsSelectService, ErrorService) { + .controller('ChatModalController', function ($scope, $timeout, $rootScope, $modal, AppUsersManager, AppChatsManager, AppProfileManager, AppPhotosManager, MtpApiManager, MtpApiFileManager, NotificationsManager, AppMessagesManager, AppPeersManager, ApiUpdatesManager, ContactsSelectService, ErrorService) { $scope.chatFull = AppChatsManager.wrapForFull($scope.chatID, {}); $scope.settings = {notifications: true}; - AppChatsManager.getChatFull($scope.chatID).then(function (chatFull) { + AppProfileManager.getChatFull($scope.chatID).then(function (chatFull) { $scope.chatFull = AppChatsManager.wrapForFull($scope.chatID, chatFull); $scope.$broadcast('ui_height'); @@ -3176,12 +3174,12 @@ angular.module('myApp.controllers', ['myApp.i18n']) }) - .controller('ChannelModalController', function ($scope, $timeout, $rootScope, $modal, AppUsersManager, AppChatsManager, AppPhotosManager, MtpApiManager, MtpApiFileManager, NotificationsManager, AppMessagesManager, AppPeersManager, ApiUpdatesManager, ContactsSelectService, ErrorService) { + .controller('ChannelModalController', function ($scope, $timeout, $rootScope, $modal, AppUsersManager, AppChatsManager, AppProfileManager, AppPhotosManager, MtpApiManager, MtpApiFileManager, NotificationsManager, AppMessagesManager, AppPeersManager, ApiUpdatesManager, ContactsSelectService, ErrorService) { $scope.chatFull = AppChatsManager.wrapForFull($scope.chatID, {}); $scope.settings = {notifications: true}; - AppChatsManager.getChannelFull($scope.chatID, true).then(function (chatFull) { + AppProfileManager.getChannelFull($scope.chatID, true).then(function (chatFull) { $scope.chatFull = AppChatsManager.wrapForFull($scope.chatID, chatFull); $scope.$broadcast('ui_height'); @@ -3318,6 +3316,10 @@ angular.module('myApp.controllers', ['myApp.i18n']) }); } + $scope.goToHistory = function () { + $rootScope.$broadcast('history_focus', {peerString: $scope.chatFull.peerString}); + }; + }) .controller('SettingsModalController', function ($rootScope, $scope, $timeout, $modal, AppUsersManager, AppChatsManager, AppPhotosManager, MtpApiManager, Storage, NotificationsManager, MtpApiFileManager, PasswordManager, ApiUpdatesManager, ChangelogNotifyService, LayoutSwitchService, AppRuntimeManager, ErrorService, _) { @@ -3694,7 +3696,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) } $scope.$watch('profile.username', function (newVal) { - if (!newVal.length) { + if (!newVal || !newVal.length) { $scope.checked = {}; return; } @@ -4185,13 +4187,13 @@ angular.module('myApp.controllers', ['myApp.i18n']) }; }) - .controller('ChannelEditModalController', function ($q, $scope, $modalInstance, $rootScope, MtpApiManager, AppUsersManager, AppChatsManager, ApiUpdatesManager) { + .controller('ChannelEditModalController', function ($q, $scope, $modalInstance, $rootScope, MtpApiManager, AppUsersManager, AppChatsManager, AppProfileManager, ApiUpdatesManager) { var channel = AppChatsManager.getChat($scope.chatID); var initial = {title: channel.title}; $scope.channel = {title: channel.title}; - AppChatsManager.getChannelFull($scope.chatID).then(function (channelFull) { + AppProfileManager.getChannelFull($scope.chatID).then(function (channelFull) { initial.about = channelFull.about; $scope.channel.about = channelFull.about; }); diff --git a/app/js/directives.js b/app/js/directives.js index b2979174..e5c145e8 100755 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -2512,7 +2512,7 @@ angular.module('myApp.directives', ['myApp.filters']) } }) - .directive('myChatStatus', function ($rootScope, _, MtpApiManager, AppChatsManager, AppUsersManager) { + .directive('myChatStatus', function ($rootScope, _, MtpApiManager, AppChatsManager, AppUsersManager, AppProfileManager) { var ind = 0; var statuses = {}; @@ -2549,7 +2549,7 @@ angular.module('myApp.directives', ['myApp.filters']) if (!chatID) { return; } - AppChatsManager.getChatFull(chatID).then(function (chatFull) { + AppProfileManager.getChatFull(chatID).then(function (chatFull) { var participantsVector = (chatFull.participants || {}).participants || []; participantsCount = participantsVector.length; angular.forEach(participantsVector, function (participant) { diff --git a/app/js/messages_manager.js b/app/js/messages_manager.js index 102432d6..ff47da1c 100644 --- a/app/js/messages_manager.js +++ b/app/js/messages_manager.js @@ -1274,6 +1274,9 @@ angular.module('myApp.services') if (replyToMsgID) { flags |= 1; } + if (asChannel) { + flags |= 16; + } MtpApiManager.invokeApi('messages.sendMedia', { flags: flags, peer: inputPeer, @@ -1417,6 +1420,9 @@ angular.module('myApp.services') if (replyToMsgID) { flags |= 1; } + if (asChannel) { + flags |= 16; + } MtpApiManager.invokeApi('messages.sendMedia', { flags: flags, peer: inputPeer, @@ -1601,7 +1607,11 @@ angular.module('myApp.services') }).then(function (updates) { ApiUpdatesManager.processUpdateMessage(updates); - if (updates.updates && updates.updates.length) { + if (updates.chats && updates.chats.length == 1) { + $rootScope.$broadcast('history_focus', {peerString: AppChatsManager.getChatString(updates.chats[0].id) + }); + } + else if (updates.updates && updates.updates.length) { for (var i = 0, len = updates.updates.length, update; i < len; i++) { update = updates.updates[i]; if (update._ == 'updateNewMessage') { @@ -2457,7 +2467,7 @@ angular.module('myApp.services') var foundDialog = getDialogByPeerID(peerID); var hasDialog = foundDialog.length > 0; - var canViewHistory = channel._ == 'channel' && (channel.username || !channel.pFlags.left && !channel.pFlags.kicked); + var canViewHistory = channel._ == 'channel' && (channel.username || !channel.pFlags.left && !channel.pFlags.kicked) && true || false; var hasHistory = historiesStorage[peerID] !== undefined; if (canViewHistory != hasHistory) { @@ -2495,7 +2505,7 @@ angular.module('myApp.services') var peerID = -channelID; var inputPeer = AppPeersManager.getInputPeerByID(peerID); return $q.all([ - AppChatsManager.getChannelFull(channelID, true), + AppProfileManager.getChannelFull(channelID, true), getHistory(inputPeer, 0) ]).then(function (results) { var channelResult = results[0]; @@ -2508,7 +2518,8 @@ angular.module('myApp.services') top_important_message: topMsgID, read_inbox_max_id: channelResult.read_inbox_max_id, unread_count: channelResult.unread_count, - unread_important_count: channelResult.unread_important_count + unread_important_count: channelResult.unread_important_count, + notify_settings: channelResult.notify_settings }; saveChannelDialog(channelID, dialog); diff --git a/app/js/services.js b/app/js/services.js index 4757bceb..859b4460 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -551,8 +551,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) .service('AppChatsManager', function ($q, $rootScope, $modal, _, MtpApiFileManager, MtpApiManager, AppUsersManager, AppPhotosManager, RichTextProcessor) { var chats = {}, usernames = {}, - chatsFull = {}, - chatFullPromises = {}, channelAccess = {}, cachedPhotoLocations = {}; @@ -643,93 +641,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } } - function getChatFull(id) { - if (isChannel(id)) { - return getChannelFull(id); - } - if (chatsFull[id] !== undefined) { - if (chats[id].version == chatsFull[id].participants.version || - chats[id].left) { - return $q.when(chatsFull[id]); - } - } - if (chatFullPromises[id] !== undefined) { - return chatFullPromises[id]; - } - return chatFullPromises[id] = MtpApiManager.invokeApi('messages.getFullChat', { - chat_id: getChatInput(id) - }).then(function (result) { - saveApiChats(result.chats); - AppUsersManager.saveApiUsers(result.users); - var fullChat = result.full_chat; - if (fullChat && fullChat.chat_photo.id) { - AppPhotosManager.savePhoto(fullChat.chat_photo); - } - delete chatFullPromises[id]; - chatsFull[id] = fullChat; - $rootScope.$broadcast('chat_full_update', id); - - return fullChat; - }); - } - - function getChannelFull (id, force) { - if (chatsFull[id] !== undefined && !force) { - return $q.when(chatsFull[id]); - } - if (chatFullPromises[id] !== undefined) { - return chatFullPromises[id]; - } - - return chatFullPromises[id] = MtpApiManager.invokeApi('channels.getFullChannel', { - channel: getChannelInput(id) - }).then(function (result) { - saveApiChats(result.chats); - AppUsersManager.saveApiUsers(result.users); - var fullChannel = result.full_chat; - var chat = getChat(id); - if (fullChannel && fullChannel.chat_photo.id) { - AppPhotosManager.savePhoto(fullChannel.chat_photo); - } - var participantsPromise; - if ((fullChannel.flags & 8) || - chat.pFlags.creator || - chat.pFlags.editor || - chat.pFlags.moderator) { - participantsPromise = getChannelParticipants(id).then(function (participants) { - delete chatFullPromises[id]; - fullChannel.participants = { - _: 'channelParticipants', - participants: participants - }; - }, function (error) { - error.handled = true; - }); - } else { - participantsPromise = $q.when(); - } - return participantsPromise.then(function () { - delete chatFullPromises[id]; - chatsFull[id] = fullChannel; - $rootScope.$broadcast('chat_full_update', id); - - return fullChannel; - }); - }); - } - - function getChannelParticipants (id) { - return MtpApiManager.invokeApi('channels.getParticipants', { - channel: getChannelInput(id), - filter: {_: 'channelParticipantsRecent'}, - offset: 0, - limit: 200 - }).then(function (result) { - AppUsersManager.saveApiUsers(result.users); - return result.participants; - }); - } - function getChatInviteLink (id, force) { return getChatFull(id).then(function (chatFull) { if (!force && @@ -893,8 +804,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) saveChannelAccess: saveChannelAccess, getChatInput: getChatInput, getChannelInput: getChannelInput, - getChatFull: getChatFull, - getChannelFull: getChannelFull, getChatPhoto: getChatPhoto, getChatString: getChatString, getChatInviteLink: getChatInviteLink, @@ -1056,9 +965,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } }) -.service('AppProfileManager', function ($q, AppUsersManager, AppChatsManager, AppPhotosManager, NotificationsManager, MtpApiManager, RichTextProcessor) { +.service('AppProfileManager', function ($q, $rootScope, AppUsersManager, AppChatsManager, AppPeersManager, AppPhotosManager, NotificationsManager, MtpApiManager, RichTextProcessor) { var botInfos = {}; + var chatsFull = {}; + var chatFullPromises = {}; function saveBotInfo (botInfo) { var botID = botInfo && botInfo.user_id; @@ -1108,10 +1019,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) function getPeerBots (peerID) { var peerBots = []; + if (peerID >= 0 && !AppUsersManager.isBot(peerID) || + AppPeersManager.isChannel(peerID)) { + return $q.when(peerBots); + } if (peerID >= 0) { - if (!AppUsersManager.isBot(peerID)) { - return $q.when(peerBots); - } return getProfile(peerID).then(function (userFull) { var botInfo = userFull.bot_info; if (botInfo && botInfo._ != 'botInfoEmpty') { @@ -1121,7 +1033,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) }); } - return AppChatsManager.getChatFull(-peerID).then(function (chatFull) { + return getChatFull(-peerID).then(function (chatFull) { angular.forEach(chatFull.bot_info, function (botInfo) { peerBots.push(saveBotInfo(botInfo)); }); @@ -1130,9 +1042,101 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } + function getChatFull(id) { + if (AppChatsManager.isChannel(id)) { + return getChannelFull(id); + } + if (chatsFull[id] !== undefined) { + var chat = AppChatsManager.getChat(id); + if (chat.version == chatsFull[id].participants.version || + chat.left) { + return $q.when(chatsFull[id]); + } + } + if (chatFullPromises[id] !== undefined) { + return chatFullPromises[id]; + } + return chatFullPromises[id] = MtpApiManager.invokeApi('messages.getFullChat', { + chat_id: AppChatsManager.getChatInput(id) + }).then(function (result) { + AppChatsManager.saveApiChats(result.chats); + AppUsersManager.saveApiUsers(result.users); + var fullChat = result.full_chat; + if (fullChat && fullChat.chat_photo.id) { + AppPhotosManager.savePhoto(fullChat.chat_photo); + } + NotificationsManager.savePeerSettings(-id, fullChat.notify_settings); + delete chatFullPromises[id]; + chatsFull[id] = fullChat; + $rootScope.$broadcast('chat_full_update', id); + + return fullChat; + }); + } + + function getChannelParticipants (id) { + return MtpApiManager.invokeApi('channels.getParticipants', { + channel: AppChatsManager.getChannelInput(id), + filter: {_: 'channelParticipantsRecent'}, + offset: 0, + limit: 200 + }).then(function (result) { + AppUsersManager.saveApiUsers(result.users); + return result.participants; + }); + } + + function getChannelFull (id, force) { + if (chatsFull[id] !== undefined && !force) { + return $q.when(chatsFull[id]); + } + if (chatFullPromises[id] !== undefined) { + return chatFullPromises[id]; + } + + return chatFullPromises[id] = MtpApiManager.invokeApi('channels.getFullChannel', { + channel: AppChatsManager.getChannelInput(id) + }).then(function (result) { + AppChatsManager.saveApiChats(result.chats); + AppUsersManager.saveApiUsers(result.users); + var fullChannel = result.full_chat; + var chat = AppChatsManager.getChat(id); + if (fullChannel && fullChannel.chat_photo.id) { + AppPhotosManager.savePhoto(fullChannel.chat_photo); + } + NotificationsManager.savePeerSettings(-id, fullChannel.notify_settings); + var participantsPromise; + if ((fullChannel.flags & 8) || + chat.pFlags.creator || + chat.pFlags.editor || + chat.pFlags.moderator) { + participantsPromise = getChannelParticipants(id).then(function (participants) { + delete chatFullPromises[id]; + fullChannel.participants = { + _: 'channelParticipants', + participants: participants + }; + }, function (error) { + error.handled = true; + }); + } else { + participantsPromise = $q.when(); + } + return participantsPromise.then(function () { + delete chatFullPromises[id]; + chatsFull[id] = fullChannel; + $rootScope.$broadcast('chat_full_update', id); + + return fullChannel; + }); + }); + } + return { + getPeerBots: getPeerBots, getProfile: getProfile, - getPeerBots: getPeerBots + getChatFull: getChatFull, + getChannelFull: getChannelFull } }) diff --git a/app/less/app.less b/app/less/app.less index dd0d313f..fff9f99b 100644 --- a/app/less/app.less +++ b/app/less/app.less @@ -665,7 +665,7 @@ a.tg_checkbox { border-radius: 10px; overflow: hidden; float: left; - margin-left: -6px; + margin-left: -1px; margin-top: -3px; -webkit-transition: all ease 0.1s; transition: all ease 0.1s; @@ -3720,7 +3720,7 @@ a.countries_modal_search_clear { .md_modal_section { &s { - padding-top: 17px + padding-top: 17px; } &_icon { diff --git a/app/partials/desktop/channel_modal.html b/app/partials/desktop/channel_modal.html index be18859d..99c87a5b 100644 --- a/app/partials/desktop/channel_modal.html +++ b/app/partials/desktop/channel_modal.html @@ -27,18 +27,21 @@ -
-
-
+
+
+
+ + +
-
+
diff --git a/app/partials/desktop/chat_modal.html b/app/partials/desktop/chat_modal.html index 20591077..b06143e5 100644 --- a/app/partials/desktop/chat_modal.html +++ b/app/partials/desktop/chat_modal.html @@ -38,7 +38,7 @@
-
+