Browse Source

Improved megagroups support

master
Igor Zhukov 9 years ago
parent
commit
3eb5292240
  1. 12
      app/js/controllers.js
  2. 3
      app/js/lib/utils.js
  3. 3
      app/js/locales/en-us.json
  4. 2
      app/js/messages_manager.js
  5. 24
      app/js/services.js
  6. 14
      app/partials/desktop/channel_modal.html
  7. 1
      app/partials/desktop/confirm_modal.html
  8. 2
      app/partials/desktop/dialog.html
  9. 28
      app/partials/desktop/megagroup_edit_modal.html
  10. 2
      app/partials/mobile/dialog.html

12
app/js/controllers.js

@ -1204,6 +1204,9 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.$broadcast('ui_peer_change'); $scope.$broadcast('ui_peer_change');
$scope.$broadcast('ui_history_change'); $scope.$broadcast('ui_history_change');
safeReplaceObject($scope.state, {loaded: true, empty: !peerHistory.messages.length}); 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.chatFull = AppChatsManager.wrapForFull($scope.chatID, {});
$scope.settings = {notifications: true}; $scope.settings = {notifications: true};
$scope.isMegagroup = AppChatsManager.isMegagroup($scope.chatID);
AppProfileManager.getChannelFull($scope.chatID, true).then(function (chatFull) { AppProfileManager.getChannelFull($scope.chatID, true).then(function (chatFull) {
$scope.chatFull = AppChatsManager.wrapForFull($scope.chatID, chatFull); $scope.chatFull = AppChatsManager.wrapForFull($scope.chatID, chatFull);
@ -3389,7 +3393,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}; };
$scope.deleteChannel = function () { $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', { MtpApiManager.invokeApi('channels.deleteChannel', {
channel: AppChatsManager.getChannelInput($scope.chatID) channel: AppChatsManager.getChannelInput($scope.chatID)
}).then(onChatUpdated); }).then(onChatUpdated);
@ -3481,7 +3485,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
scope.chatID = $scope.chatID; scope.chatID = $scope.chatID;
$modal.open({ $modal.open({
templateUrl: templateUrl('channel_edit_modal'), templateUrl: templateUrl($scope.isMegagroup ? 'megagroup_edit_modal' : 'channel_edit_modal'),
controller: 'ChannelEditModalController', controller: 'ChannelEditModalController',
scope: scope, scope: scope,
windowClass: 'md_simple_modal_window mobile_modal' windowClass: 'md_simple_modal_window mobile_modal'
@ -4384,6 +4388,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
promises.push(editAbout()); promises.push(editAbout());
} }
$scope.channel.updating = true;
return $q.all(promises).then(function () { return $q.all(promises).then(function () {
var peerString = AppChatsManager.getChatString($scope.chatID); var peerString = AppChatsManager.getChatString($scope.chatID);
$rootScope.$broadcast('history_focus', {peerString: peerString}); $rootScope.$broadcast('history_focus', {peerString: peerString});
@ -4414,6 +4419,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.exportedInvite = {link: _('group_invite_link_loading_raw')}; $scope.exportedInvite = {link: _('group_invite_link_loading_raw')};
var isChannel = AppChatsManager.isChannel($scope.chatID); var isChannel = AppChatsManager.isChannel($scope.chatID);
var isMegagroup = AppChatsManager.isMegagroup($scope.chatID);
function selectLink () { function selectLink () {
$timeout(function () { $timeout(function () {
@ -4442,7 +4448,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.revokeLink = function () { $scope.revokeLink = function () {
ErrorService.confirm({ 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 () { }).then(function () {
updateLink(true); updateLink(true);
}) })

3
app/js/lib/utils.js

@ -352,7 +352,8 @@ function templateUrl (tplName) {
chat_invite_link_modal: 'desktop', chat_invite_link_modal: 'desktop',
reply_markup: 'desktop', reply_markup: 'desktop',
dialog_service: 'desktop', dialog_service: 'desktop',
channel_edit_modal: 'desktop' channel_edit_modal: 'desktop',
megagroup_edit_modal: 'desktop'
}; };
var layout = forceLayout[tplName] || (Config.Mobile ? 'mobile' : 'desktop'); var layout = forceLayout[tplName] || (Config.Mobile ? 'mobile' : 'desktop');
return 'partials/' + layout + '/' + tplName + '.html'; return 'partials/' + layout + '/' + tplName + '.html';

3
app/js/locales/en-us.json

@ -33,6 +33,7 @@
"group_modal_migrate_item2": "New members see the entire chat history", "group_modal_migrate_item2": "New members see the entire chat history",
"group_modal_migrate_item3": "Admins delete messages for everyone", "group_modal_migrate_item3": "Admins delete messages for everyone",
"group_modal_migrate_item4": "Notifications are muted by default", "group_modal_migrate_item4": "Notifications are muted by default",
"group_modal_delete_group": "Delete group",
"channel_modal_info": "Channel info", "channel_modal_info": "Channel info",
"channel_modal_description": "Description", "channel_modal_description": "Description",
@ -186,6 +187,7 @@
"group_edit_modal_title": "Edit group", "group_edit_modal_title": "Edit group",
"group_edit_name": "Group name", "group_edit_name": "Group name",
"group_edit_about": "Group description",
"group_edit_submit": "Save", "group_edit_submit": "Save",
"group_edit_submit_active": "Saving...", "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_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_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_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_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?", "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?",

2
app/js/messages_manager.js

@ -1897,7 +1897,7 @@ angular.module('myApp.services')
chatTitle = chatInvite.title; chatTitle = chatInvite.title;
} }
ErrorService.confirm({ 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 title: chatTitle
}).then(function () { }).then(function () {
return MtpApiManager.invokeApi('messages.importChatInvite', { return MtpApiManager.invokeApi('messages.importChatInvite', {

24
app/js/services.js

@ -1116,7 +1116,29 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
limit: AppChatsManager.isMegagroup(id) ? 50 : 200 limit: AppChatsManager.isMegagroup(id) ? 50 : 200
}).then(function (result) { }).then(function (result) {
AppUsersManager.saveApiUsers(result.users); 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;
}); });
} }

14
app/partials/desktop/channel_modal.html

@ -6,7 +6,10 @@
<a class="md_modal_action md_modal_action_close" ng-click="$close()" my-i18n="modal_close"></a> <a class="md_modal_action md_modal_action_close" ng-click="$close()" my-i18n="modal_close"></a>
<a class="md_modal_action" ng-if="hasRights('edit_title')" ng-click="editChannel()" my-i18n="modal_edit"></a> <a class="md_modal_action" ng-if="hasRights('edit_title')" ng-click="editChannel()" my-i18n="modal_edit"></a>
</div> </div>
<div class="md_modal_title" my-i18n="channel_modal_info"></div> <div class="md_modal_title" ng-switch="isMegagroup">
<span ng-switch-when="true" my-i18n="group_modal_info"></span>
<span ng-switch-default my-i18n="channel_modal_info"></span>
</div>
</div> </div>
<div class="peer_modal_profile_wrap clearfix"> <div class="peer_modal_profile_wrap clearfix">
@ -91,15 +94,18 @@
</div> </div>
<div class="md_modal_iconed_section_wrap md_modal_iconed_section_link" ng-if="chatFull.chat.pFlags.creator || !chatFull.chat.pFlags.left && !chatFull.chat.pFlags.kicked"> <div class="md_modal_iconed_section_wrap md_modal_iconed_section_link" ng-if="chatFull.chat.pFlags.creator || !chatFull.chat.pFlags.left && !chatFull.chat.pFlags.kicked && !isMegagroup">
<i class="md_modal_section_icon md_modal_section_icon_more"></i> <i class="md_modal_section_icon md_modal_section_icon_more"></i>
<div class="md_modal_section_link_wrap" ng-if="!chatFull.chat.pFlags.creator && !chatFull.chat.pFlags.left && !chatFull.chat.pFlags.kicked"> <div class="md_modal_section_link_wrap" ng-if="!chatFull.chat.pFlags.creator && !chatFull.chat.pFlags.left && !chatFull.chat.pFlags.kicked && !isMegagroup">
<a class="md_modal_section_link" ng-click="leaveChannel()" my-i18n="channel_modal_leave_channel"></a> <a class="md_modal_section_link" ng-click="leaveChannel()" my-i18n="channel_modal_leave_channel"></a>
</div> </div>
<div class="md_modal_section_link_wrap" ng-if="chatFull.chat.pFlags.creator"> <div class="md_modal_section_link_wrap" ng-if="chatFull.chat.pFlags.creator">
<a class="md_modal_section_link md_modal_section_link_danger" ng-click="deleteChannel()" my-i18n="channel_modal_delete_channel"></a> <a class="md_modal_section_link md_modal_section_link_danger" ng-click="deleteChannel()" ng-switch="isMegagroup">
<span ng-switch-when="true" my-i18n="group_modal_delete_group"></span>
<span ng-switch-default my-i18n="channel_modal_delete_channel"></span>
</a>
</div> </div>
</div> </div>

1
app/partials/desktop/confirm_modal.html

@ -55,6 +55,7 @@
<div ng-switch-when="REVOKE_GROUP_INVITE_LINK" my-i18n="confirm_modal_revoke_group_link"></div> <div ng-switch-when="REVOKE_GROUP_INVITE_LINK" my-i18n="confirm_modal_revoke_group_link"></div>
<div ng-switch-when="REVOKE_CHANNEL_INVITE_LINK" my-i18n="confirm_modal_revoke_channel_link"></div> <div ng-switch-when="REVOKE_CHANNEL_INVITE_LINK" my-i18n="confirm_modal_revoke_channel_link"></div>
<div ng-switch-when="CHANNEL_DELETE" my-i18n="confirm_modal_delete_channel_md"></div> <div ng-switch-when="CHANNEL_DELETE" my-i18n="confirm_modal_delete_channel_md"></div>
<div ng-switch-when="MEGAGROUP_DELETE" my-i18n="confirm_modal_delete_group_md"></div>
<div ng-switch-when="JUMP_EXT_URL" my-i18n="confirm_modal_jump_ext_url_md" class="confirm_modal_extlink_jump"> <div ng-switch-when="JUMP_EXT_URL" my-i18n="confirm_modal_jump_ext_url_md" class="confirm_modal_extlink_jump">
<my-i18n-param name="url"><strong ng-bind="url"></strong></my-i18n-param> <my-i18n-param name="url"><strong ng-bind="url"></strong></my-i18n-param>
</div> </div>

2
app/partials/desktop/dialog.html

@ -34,7 +34,7 @@
<div ng-switch-default class="im_dialog_message"> <div ng-switch-default class="im_dialog_message">
<span ng-switch="dialogMessage.peerID > 0 || dialogMessage.fromID < 0"> <span ng-switch="dialogMessage.peerID > 0 || dialogMessage.fromID < 0">
<span ng-switch-when="true"> <span ng-switch-when="true">
<span class="im_dialog_chat_from_wrap" ng-if="dialogMessage.pFlags.out"> <span class="im_dialog_chat_from_wrap" ng-if="dialogMessage.pFlags.out && dialogMessage.fromID > 0">
<span <span
class="im_dialog_chat_from" class="im_dialog_chat_from"
my-i18n="conversation_you" my-i18n="conversation_you"

28
app/partials/desktop/megagroup_edit_modal.html

@ -0,0 +1,28 @@
<div class="md_simple_modal_wrap" my-modal-position>
<div class="md_simple_modal_body">
<form class="modal_simple_form" ng-submit="updateChannel()">
<h4 my-i18n="channel_edit_modal_title"></h4>
<div class="md-input-group" my-labeled-input>
<label class="md-input-label" my-i18n="group_edit_name"></label>
<input class="md-input" my-focused type="text" ng-model="channel.title" />
</div>
<div class="md-input-group" my-labeled-input>
<label class="md-input-label" my-i18n="group_edit_about"></label>
<input class="md-input" type="text" ng-model="channel.about" />
</div>
</form>
</div>
<div class="md_simple_modal_footer">
<button class="btn btn-md" ng-click="$dismiss()" my-i18n="modal_cancel"></button>
<button class="btn btn-md btn-md-primary" ng-class="{disabled: channel.updating}" ng-click="updateChannel()" ng-bind="channel.updating ? 'group_edit_submit_active' : 'group_edit_submit' | i18n" ng-disabled="channel.updating"></button>
</div>
</div>

2
app/partials/mobile/dialog.html

@ -34,7 +34,7 @@
<div ng-switch-default class="im_dialog_message"> <div ng-switch-default class="im_dialog_message">
<span ng-switch="dialogMessage.peerID > 0 || dialogMessage.fromID < 0"> <span ng-switch="dialogMessage.peerID > 0 || dialogMessage.fromID < 0">
<span ng-switch-when="true"> <span ng-switch-when="true">
<span class="im_dialog_chat_from_wrap" ng-if="dialogMessage.pFlags.out"> <span class="im_dialog_chat_from_wrap" ng-if="dialogMessage.pFlags.out && dialogMessage.fromID > 0">
<span <span
class="im_dialog_chat_from" class="im_dialog_chat_from"
my-i18n="conversation_you" my-i18n="conversation_you"

Loading…
Cancel
Save