Browse Source

Improved supergroups support

Bots with commands
New has rights check
master
Igor Zhukov 9 years ago
parent
commit
e02b9fd2eb
  1. 10
      app/js/controllers.js
  2. 22
      app/js/directives.js
  3. 49
      app/js/services.js
  4. 8
      app/partials/desktop/channel_modal.html
  5. 5
      app/partials/desktop/chat_modal.html
  6. 13
      app/partials/mobile/channel_modal.html
  7. 8
      app/partials/mobile/chat_modal.html

10
app/js/controllers.js

@ -2179,7 +2179,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2179,7 +2179,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
return;
}
var needMentions = peerBots.length > 1;
var needMentions = peerID < 0;
var commandsList = [];
var commandsIndex = SearchIndexManager.createIndex();
@ -3304,6 +3304,10 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -3304,6 +3304,10 @@ angular.module('myApp.controllers', ['myApp.i18n'])
});
}
$scope.hasRights = function (action) {
return AppChatsManager.hasRights($scope.chatID, action);
}
})
.controller('ChannelModalController', function ($scope, $timeout, $rootScope, $modal, AppUsersManager, AppChatsManager, AppProfileManager, AppPhotosManager, MtpApiManager, MtpApiFileManager, NotificationsManager, AppMessagesManager, AppPeersManager, ApiUpdatesManager, ContactsSelectService, ErrorService) {
@ -3452,6 +3456,10 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -3452,6 +3456,10 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$rootScope.$broadcast('history_focus', {peerString: $scope.chatFull.peerString});
};
$scope.hasRights = function (action) {
return AppChatsManager.hasRights($scope.chatID, action);
}
})
.controller('SettingsModalController', function ($rootScope, $scope, $timeout, $modal, AppUsersManager, AppChatsManager, AppPhotosManager, MtpApiManager, Storage, NotificationsManager, MtpApiFileManager, PasswordManager, ApiUpdatesManager, ChangelogNotifyService, LayoutSwitchService, AppRuntimeManager, ErrorService, _) {

22
app/js/directives.js

@ -2621,18 +2621,20 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -2621,18 +2621,20 @@ angular.module('myApp.directives', ['myApp.filters'])
var update = function () {
var html = allPluralize(participantsCount);
var onlineCount = 0;
var wasMe = false;
angular.forEach(participants, function (t, userID) {
var user = AppUsersManager.getUser(userID);
if (user.status && user.status._ == 'userStatusOnline') {
if (user.id == myID) {
wasMe = true;
if (!AppChatsManager.isChannel(chatID)) {
var wasMe = false;
angular.forEach(participants, function (t, userID) {
var user = AppUsersManager.getUser(userID);
if (user.status && user.status._ == 'userStatusOnline') {
if (user.id == myID) {
wasMe = true;
}
onlineCount++;
}
onlineCount++;
});
if (onlineCount > 1 || onlineCount == 1 && !wasMe) {
html = _('group_modal_participants', {total: html, online: onlinePluralize(onlineCount)});
}
});
if (onlineCount > 1 || onlineCount == 1 && !wasMe) {
html = _('group_modal_participants', {total: html, online: onlinePluralize(onlineCount)});
}
if (!onlineCount && !participantsCount) {
html = '';

49
app/js/services.js

@ -613,12 +613,37 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -613,12 +613,37 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
chat.pFlags.left) {
return false;
}
if (isChannel(id) && action == 'send') {
if (!chat.pFlags.megagroup &&
!chat.pFlags.creator &&
!chat.pFlags.editor) {
return false;
}
if (chat.pFlags.creator) {
return true;
}
switch (action) {
case 'send':
if (chat._ == 'channel' &&
!chat.pFlags.megagroup &&
!chat.pFlags.editor) {
return false;
}
break;
case 'edit_title':
case 'edit_photo':
case 'invite':
if (chat._ == 'channel') {
if (chat.pFlags.megagroup) {
if (!chat.pFlags.editor) {
return false;
}
} else {
return false;
}
} else {
if (chat.pFlags.admins_enabled &&
!chat.pFlags.editor) {
return false;
}
}
break;
}
return true;
}
@ -1003,7 +1028,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1003,7 +1028,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
function getPeerBots (peerID) {
var peerBots = [];
if (peerID >= 0 && !AppUsersManager.isBot(peerID) ||
AppPeersManager.isChannel(peerID)) {
(AppPeersManager.isChannel(peerID) && !AppPeersManager.isMegagroup(peerID))) {
return $q.when(peerBots);
}
if (peerID >= 0) {
@ -1080,7 +1105,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1080,7 +1105,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
channel: AppChatsManager.getChannelInput(id),
filter: {_: 'channelParticipantsRecent'},
offset: 0,
limit: 200
limit: AppChatsManager.isMegagroup(id) ? 50 : 200
}).then(function (result) {
AppUsersManager.saveApiUsers(result.users);
return result.participants;
@ -1107,10 +1132,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1107,10 +1132,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
NotificationsManager.savePeerSettings(-id, fullChannel.notify_settings);
var participantsPromise;
if ((fullChannel.flags & 8) ||
chat.pFlags.creator ||
chat.pFlags.editor ||
chat.pFlags.moderator) {
if (fullChannel.flags & 8) {
participantsPromise = getChannelParticipants(id).then(function (participants) {
delete chatFullPromises[id];
fullChannel.participants = {
@ -2729,6 +2751,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2729,6 +2751,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
channelID = update.channel_id;
break;
}
if (channelID && !AppChatsManager.hasChat(channelID)) {
return false;
}
var curState = channelID ? getChannelState(channelID, update.pts) : updatesState;
// console.log('process', channelID, curState, update);

8
app/partials/desktop/channel_modal.html

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
<div class="md_modal_title_wrap">
<div class="md_modal_actions_wrap clearfix">
<a class="md_modal_action md_modal_action_close" ng-click="$close()" my-i18n="modal_close"></a>
<a class="md_modal_action" ng-if="chatFull.chat.pFlags.creator" 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 class="md_modal_title" my-i18n="channel_modal_info"></div>
</div>
@ -28,7 +28,7 @@ @@ -28,7 +28,7 @@
</div>
<div class="md_modal_split_actions_wrap">
<div class="md_modal_split_actions" ng-switch="chatFull.chat.pFlags.creator">
<div class="md_modal_split_actions" ng-switch="hasRights('edit_photo')">
<div ng-switch-when="true" class="md_modal_split_action">
<input my-file-upload type="file" multiple="false" class="im_attach_input" size="120" multiple="false" accept="image/x-png, image/png, image/gif, image/jpeg" title="{{'group_modal_update_photo' | i18n}}" />
<i class="md_modal_split_action_camera"></i>
@ -71,7 +71,7 @@ @@ -71,7 +71,7 @@
</div>
</div>
<div class="md_modal_iconed_section_wrap md_modal_iconed_section_link" ng-if="chatFull.chat.pFlags.creator || chatFull.chat.pFlags.left">
<div class="md_modal_iconed_section_wrap md_modal_iconed_section_link" ng-if="hasRights('invite') || chatFull.chat.pFlags.left">
<i class="md_modal_section_icon md_modal_section_icon_person"></i>
<div class="md_modal_section_link_wrap" ng-switch="chatFull.chat.pFlags.left">
@ -115,7 +115,7 @@ @@ -115,7 +115,7 @@
<div class="md_modal_section_peers_wrap">
<div class="md_modal_list_peer_wrap clearfix" ng-repeat="participant in chatFull.participants.participants | orderBy:'-user.sortStatus'">
<div class="md_modal_list_peer_wrap clearfix" ng-repeat="participant in chatFull.participants.participants">
<a ng-if="participant.canLeave" ng-click="leaveChannel()" class="md_modal_list_peer_action pull-right" my-i18n="group_modal_menu_leave"></a>
<a ng-if="participant.canKick" ng-click="kickFromChannel(participant.user_id)" class="md_modal_list_peer_action pull-right" my-i18n="group_modal_members_kick"></a>

5
app/partials/desktop/chat_modal.html

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
<div class="md_modal_title_wrap">
<div class="md_modal_actions_wrap clearfix">
<a class="md_modal_action md_modal_action_close" ng-click="$close()" my-i18n="modal_close"></a>
<a class="md_modal_action" ng-if="chatFull.chat._ != 'chatForbidden' &amp;&amp; !chatFull.chat.pFlags.left" ng-click="editTitle()" my-i18n="modal_edit"></a>
<a class="md_modal_action" ng-if="hasRights('edit_title')" ng-click="editTitle()" my-i18n="modal_edit"></a>
</div>
<div class="md_modal_title" my-i18n="group_modal_info"></div>
</div>
@ -40,7 +40,7 @@ @@ -40,7 +40,7 @@
<div class="md_modal_sections clearfix">
<div class="md_modal_iconed_section_wrap md_modal_iconed_section_link" ng-if="chatFull.chat._ != 'chatForbidden'">
<div class="md_modal_iconed_section_wrap md_modal_iconed_section_link" ng-if="hasRights('invite') || chatFull.chat.pFlags.left">
<i class="md_modal_section_icon md_modal_section_icon_person"></i>
<div class="md_modal_section_link_wrap" ng-switch="chatFull.chat.pFlags.left">
@ -52,7 +52,6 @@ @@ -52,7 +52,6 @@
</div>
<div class="md_modal_iconed_section_wrap md_modal_iconed_section_link" ng-if="chatFull.chat._ != 'chatForbidden' && !chatFull.chat.pFlags.left && chatFull.chat.pFlags.creator">
<!-- <i class="md_modal_section_icon md_modal_section_icon_more"></i> -->
<div class="md_modal_section_link_wrap">
<a class="md_modal_section_link" ng-click="inviteViaLink()" my-i18n="group_modal_menu_share_link"></a>

13
app/partials/mobile/channel_modal.html

@ -11,10 +11,10 @@ @@ -11,10 +11,10 @@
<span class="icon-bar"></span>
</a>
<ul class="dropdown-menu">
<li ng-if="chatFull.chat.pFlags.creator">
<li ng-if="hasRights('edit_photo')">
<a ng-click="deletePhoto()" my-i18n="group_modal_menu_delete_photo"></a>
</li>
<li ng-if="chatFull.chat.pFlags.creator">
<li ng-if="hasRights('edit_title')">
<a ng-click="editChannel()" my-i18n="modal_edit"></a>
</li>
<li ng-if="chatFull.chat.pFlags.creator">
@ -75,17 +75,14 @@ @@ -75,17 +75,14 @@
</div>
</div>
<div class="mobile_modal_action_wrap" ng-if="chatFull.chat.pFlags.creator">
<div class="mobile_modal_action_wrap" ng-if="hasRights('invite')">
<a class="mobile_modal_action" ng-click="inviteToChannel()" my-i18n="channel_modal_add_member"></a>
</div>
<div class="mobile_modal_action_wrap" ng-if="chatFull.chat.pFlags.left">
<a class="mobile_modal_action" ng-click="joinChannel()" my-i18n="channel_modal_join"></a>
</div>
<div class="mobile_modal_action_wrap" ng-if="chatFull.chat._ == 'chatForbidden'">
<a class="mobile_modal_action" ng-click="flushHistory()" my-i18n="group_modal_return"></a>
</div>
<div class="mobile_modal_action_wrap" ng-if="chatFull.chat.pFlags.creator &amp;&amp; !photo.updating">
<div class="mobile_modal_action_wrap" ng-if="hasRights('edit_photo') &amp;&amp; !photo.updating">
<span class="mobile_modal_action mobile_modal_upload_action">
<input my-file-upload type="file" multiple="false" class="im_attach_input" size="120" multiple="false" accept="image/x-png, image/png, image/gif, image/jpeg" />
<my-i18n="group_modal_update_photo"></my-i18n>
@ -111,7 +108,7 @@ @@ -111,7 +108,7 @@
<div class="chat_modal_members_list">
<div class="chat_modal_participant_wrap clearfix" ng-repeat="participant in chatFull.participants.participants | orderBy:'-user.sortStatus'">
<div class="chat_modal_participant_wrap clearfix" ng-repeat="participant in chatFull.participants.participants">
<a ng-if="participant.canKick" ng-click="kickFromChannel(participant.user_id)" class="chat_modal_participant_kick pull-right" my-i18n="group_modal_members_kick"></a>
<a ng-if="participant.canLeave" ng-click="leaveChannel()" class="chat_modal_participant_kick pull-right" my-i18n="group_modal_menu_leave"></a>

8
app/partials/mobile/chat_modal.html

@ -11,10 +11,10 @@ @@ -11,10 +11,10 @@
<span class="icon-bar"></span>
</a>
<ul class="dropdown-menu">
<li ng-if="chatFull.thumb.location" ng-if="chatFull.chat._ != 'chatForbidden' &amp;&amp; !chatFull.chat.pFlags.left">
<li ng-if="chatFull.thumb.location" ng-if="hasRights('edit_title')">
<a ng-click="deletePhoto()" my-i18n="group_modal_menu_delete_photo"></a>
</li>
<li ng-if="chatFull.chat._ != 'chatForbidden' &amp;&amp; !chatFull.chat.pFlags.left">
<li ng-if="hasRights('edit_title')">
<a ng-click="editTitle()" my-i18n="group_modal_menu_edit_group"></a>
</li>
<li>
@ -59,7 +59,7 @@ @@ -59,7 +59,7 @@
</div>
<div class="mobile_modal_action_wrap" ng-if="!chatFull.chat.pFlags.left &amp;&amp; chatFull.participants.participants.length">
<div class="mobile_modal_action_wrap" ng-if="hasRights('invite') &amp;&amp; chatFull.participants.participants.length">
<a class="mobile_modal_action" ng-click="inviteToGroup()" my-i18n="group_modal_add_member"></a>
</div>
<div class="mobile_modal_action_wrap" ng-if="chatFull.chat._ != 'chatForbidden' && !chatFull.chat.pFlags.left && chatFull.chat.pFlags.creator">
@ -72,7 +72,7 @@ @@ -72,7 +72,7 @@
<div class="mobile_modal_action_wrap" ng-if="chatFull.chat._ == 'chatForbidden'">
<a class="mobile_modal_action" ng-click="flushHistory()" my-i18n="group_modal_return"></a>
</div>
<div class="mobile_modal_action_wrap" ng-if="chatFull.chat._ != 'chatForbidden' &amp;&amp; !chatFull.chat.pFlags.left &amp;&amp; !photo.updating">
<div class="mobile_modal_action_wrap" ng-if="hasRights('edit_photo') &amp;&amp; !photo.updating">
<span class="mobile_modal_action mobile_modal_upload_action">
<input my-file-upload type="file" multiple="false" class="im_attach_input" size="120" multiple="false" accept="image/x-png, image/png, image/gif, image/jpeg" />
<my-i18n="group_modal_update_photo"></my-i18n>

Loading…
Cancel
Save