From 3eb529224034ec735880499c70b0235f9cb28efb Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Mon, 23 Nov 2015 13:23:55 +0300 Subject: [PATCH] Improved megagroups support --- app/js/controllers.js | 12 ++++++-- app/js/lib/utils.js | 3 +- app/js/locales/en-us.json | 3 ++ app/js/messages_manager.js | 2 +- app/js/services.js | 24 +++++++++++++++- app/partials/desktop/channel_modal.html | 14 +++++++--- app/partials/desktop/confirm_modal.html | 1 + app/partials/desktop/dialog.html | 2 +- .../desktop/megagroup_edit_modal.html | 28 +++++++++++++++++++ app/partials/mobile/dialog.html | 2 +- 10 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 app/partials/desktop/megagroup_edit_modal.html diff --git a/app/js/controllers.js b/app/js/controllers.js index fcade6b3..95b14850 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -1204,6 +1204,9 @@ angular.module('myApp.controllers', ['myApp.i18n']) $scope.$broadcast('ui_peer_change'); $scope.$broadcast('ui_history_change'); safeReplaceObject($scope.state, {loaded: true, empty: !peerHistory.messages.length}); + + updateBotActions(); + updateChannelActions(); } } @@ -3341,6 +3344,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) $scope.chatFull = AppChatsManager.wrapForFull($scope.chatID, {}); $scope.settings = {notifications: true}; + $scope.isMegagroup = AppChatsManager.isMegagroup($scope.chatID); AppProfileManager.getChannelFull($scope.chatID, true).then(function (chatFull) { $scope.chatFull = AppChatsManager.wrapForFull($scope.chatID, chatFull); @@ -3389,7 +3393,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) }; $scope.deleteChannel = function () { - return ErrorService.confirm({type: 'CHANNEL_DELETE'}).then(function () { + return ErrorService.confirm({type: $scope.isMegagroup ? 'MEGAGROUP_DELETE' : 'CHANNEL_DELETE'}).then(function () { MtpApiManager.invokeApi('channels.deleteChannel', { channel: AppChatsManager.getChannelInput($scope.chatID) }).then(onChatUpdated); @@ -3481,7 +3485,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) scope.chatID = $scope.chatID; $modal.open({ - templateUrl: templateUrl('channel_edit_modal'), + templateUrl: templateUrl($scope.isMegagroup ? 'megagroup_edit_modal' : 'channel_edit_modal'), controller: 'ChannelEditModalController', scope: scope, windowClass: 'md_simple_modal_window mobile_modal' @@ -4384,6 +4388,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) promises.push(editAbout()); } + $scope.channel.updating = true; return $q.all(promises).then(function () { var peerString = AppChatsManager.getChatString($scope.chatID); $rootScope.$broadcast('history_focus', {peerString: peerString}); @@ -4414,6 +4419,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) $scope.exportedInvite = {link: _('group_invite_link_loading_raw')}; var isChannel = AppChatsManager.isChannel($scope.chatID); + var isMegagroup = AppChatsManager.isMegagroup($scope.chatID); function selectLink () { $timeout(function () { @@ -4442,7 +4448,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) $scope.revokeLink = function () { ErrorService.confirm({ - type: isChannel ? 'REVOKE_CHANNEL_INVITE_LINK' : 'REVOKE_GROUP_INVITE_LINK' + type: isChannel && !isMegagroup ? 'REVOKE_CHANNEL_INVITE_LINK' : 'REVOKE_GROUP_INVITE_LINK' }).then(function () { updateLink(true); }) diff --git a/app/js/lib/utils.js b/app/js/lib/utils.js index 21ac7e93..c1640d68 100644 --- a/app/js/lib/utils.js +++ b/app/js/lib/utils.js @@ -352,7 +352,8 @@ function templateUrl (tplName) { chat_invite_link_modal: 'desktop', reply_markup: 'desktop', dialog_service: 'desktop', - channel_edit_modal: 'desktop' + channel_edit_modal: 'desktop', + megagroup_edit_modal: 'desktop' }; var layout = forceLayout[tplName] || (Config.Mobile ? 'mobile' : 'desktop'); return 'partials/' + layout + '/' + tplName + '.html'; diff --git a/app/js/locales/en-us.json b/app/js/locales/en-us.json index 7d258844..2b8313ce 100644 --- a/app/js/locales/en-us.json +++ b/app/js/locales/en-us.json @@ -33,6 +33,7 @@ "group_modal_migrate_item2": "New members see the entire chat history", "group_modal_migrate_item3": "Admins delete messages for everyone", "group_modal_migrate_item4": "Notifications are muted by default", + "group_modal_delete_group": "Delete group", "channel_modal_info": "Channel info", "channel_modal_description": "Description", @@ -186,6 +187,7 @@ "group_edit_modal_title": "Edit group", "group_edit_name": "Group name", + "group_edit_about": "Group description", "group_edit_submit": "Save", "group_edit_submit_active": "Saving...", @@ -229,6 +231,7 @@ "confirm_modal_revoke_group_link": "Are you sure you want to revoke this link? Once you do, no one will be able to join the group using it.", "confirm_modal_revoke_channel_link": "Are you sure you want to revoke this link? Once you do, no one will be able to join the channel using it.", "confirm_modal_delete_channel_md": "Are you sure you want to delete this channel?\n\nAll members will be removed and all messages will be lost.", + "confirm_modal_delete_group_md": "Are you sure you want to delete this group?\n\nAll members will be removed and all messages will be lost.", "confirm_modal_jump_ext_url_md": "Open this link?\n\n{url}", "confirm_modal_migrate_supergroup_md": "Please note that group members will need to update their Telegram apps to the latest version to see your supergroup.\n\nAre you sure you want to upgrade this group?", diff --git a/app/js/messages_manager.js b/app/js/messages_manager.js index 7ae4f700..d6ad8397 100644 --- a/app/js/messages_manager.js +++ b/app/js/messages_manager.js @@ -1897,7 +1897,7 @@ angular.module('myApp.services') chatTitle = chatInvite.title; } ErrorService.confirm({ - type: chatInvite.flags & 1 ? 'JOIN_CHANNEL_BY_LINK' : 'JOIN_GROUP_BY_LINK', + type: (chatInvite.pFlags.channel && !chatInvite.pFlags.megagroup) ? 'JOIN_CHANNEL_BY_LINK' : 'JOIN_GROUP_BY_LINK', title: chatTitle }).then(function () { return MtpApiManager.invokeApi('messages.importChatInvite', { diff --git a/app/js/services.js b/app/js/services.js index 081e8010..d1e3a5b0 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -1116,7 +1116,29 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) limit: AppChatsManager.isMegagroup(id) ? 50 : 200 }).then(function (result) { AppUsersManager.saveApiUsers(result.users); - return result.participants; + var participants = result.participants; + + var chat = AppChatsManager.getChat(id); + if (!chat.pFlags.kicked && !chat.pFlags.left) { + var myID = AppUsersManager.getSelf().id; + var myIndex = false; + var myParticipant; + for (var i = 0, len = participants.length; i < len; i++) { + if (participants[i].user_id == myID) { + myIndex = i; + break; + } + } + if (myIndex !== false) { + myParticipant = participants[i]; + participants.splice(i, 1); + } else { + myParticipant = {_: 'channelParticipantSelf', user_id: myID}; + } + participants.unshift(myParticipant); + } + + return participants; }); } diff --git a/app/partials/desktop/channel_modal.html b/app/partials/desktop/channel_modal.html index 1654c78c..f45924b4 100644 --- a/app/partials/desktop/channel_modal.html +++ b/app/partials/desktop/channel_modal.html @@ -6,7 +6,10 @@ -
+
+ + +
@@ -91,15 +94,18 @@
-