Browse Source

Improved channel updates

master
Igor Zhukov 9 years ago
parent
commit
6d9aa03695
  1. 26
      app/js/controllers.js
  2. 4
      app/js/directives.js
  3. 19
      app/js/messages_manager.js
  4. 196
      app/js/services.js
  5. 4
      app/less/app.less
  6. 11
      app/partials/desktop/channel_modal.html
  7. 2
      app/partials/desktop/chat_modal.html
  8. 4
      app/partials/desktop/dialog_service.html
  9. 2
      app/partials/desktop/settings_modal.html
  10. 2
      app/partials/desktop/user_modal.html

26
app/js/controllers.js

@ -616,7 +616,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -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']) @@ -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']) @@ -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');
})
}
});
@ -2075,7 +2073,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -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']) @@ -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']) @@ -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']) @@ -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']) @@ -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']) @@ -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;
});

4
app/js/directives.js

@ -2512,7 +2512,7 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -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']) @@ -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) {

19
app/js/messages_manager.js

@ -1274,6 +1274,9 @@ angular.module('myApp.services') @@ -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') @@ -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') @@ -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') @@ -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') @@ -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') @@ -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);

196
app/js/services.js

@ -551,8 +551,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -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']) @@ -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']) @@ -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']) @@ -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']) @@ -1108,10 +1019,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
function getPeerBots (peerID) {
var peerBots = [];
if (peerID >= 0) {
if (!AppUsersManager.isBot(peerID)) {
if (peerID >= 0 && !AppUsersManager.isBot(peerID) ||
AppPeersManager.isChannel(peerID)) {
return $q.when(peerBots);
}
if (peerID >= 0) {
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']) @@ -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']) @@ -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
}
})

4
app/less/app.less

@ -665,7 +665,7 @@ a.tg_checkbox { @@ -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 { @@ -3720,7 +3720,7 @@ a.countries_modal_search_clear {
.md_modal_section {
&s {
padding-top: 17px
padding-top: 17px;
}
&_icon {

11
app/partials/desktop/channel_modal.html

@ -27,18 +27,21 @@ @@ -27,18 +27,21 @@
</div>
</div>
<div class="md_modal_split_actions_wrap" ng-if="chatFull.chat.pFlags.creator">
<div class="md_modal_split_actions">
<div class="md_modal_split_action">
<div class="md_modal_split_actions_wrap">
<div class="md_modal_split_actions" ng-switch="chatFull.chat.pFlags.creator">
<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>
</div>
<a ng-switch-default class="md_modal_split_action" href="" ng-click="goToHistory()" title="{{'user_modal_send_message' | i18n}}">
<i class="md_modal_split_action_msg"></i>
</a>
</div>
</div>
<div class="md_modal_body">
<div class="md_modal_sections">
<div class="md_modal_sections clearfix">
<div class="md_modal_iconed_section_wrap md_modal_iconed_section_number" ng-if="chatFull.rAbout || chatFull.chat.username || chatFull.chat.pFlags.creator">
<i class="md_modal_section_icon md_modal_section_icon_about"></i>

2
app/partials/desktop/chat_modal.html

@ -38,7 +38,7 @@ @@ -38,7 +38,7 @@
<div class="md_modal_body">
<div class="md_modal_sections">
<div class="md_modal_sections clearfix">
<div class="md_modal_iconed_section_wrap md_modal_iconed_section_link" ng-if="chatFull.chat._ != 'chatForbidden'">
<i class="md_modal_section_icon md_modal_section_icon_person"></i>

4
app/partials/desktop/dialog_service.html

@ -17,8 +17,8 @@ @@ -17,8 +17,8 @@
</span>
<span ng-switch-when="messageActionChatJoinedByLink" my-i18n="conversation_joined_by_link"></span>
<span ng-switch-when="messageActionChannelCreate" my-i18n-format="conversation_created_channel"></span>
<span ng-switch-when="messageActionChannelEditTitle" my-i18n-format="conversation_changed_channel_name"></span>
<span ng-switch-when="messageActionChannelCreate" my-i18n="conversation_created_channel"></span>
<span ng-switch-when="messageActionChannelEditTitle" my-i18n="conversation_changed_channel_name"></span>
<span ng-switch-when="messageActionChannelEditPhoto" my-i18n="conversation_changed_channel_photo"></span>
<span ng-switch-when="messageActionChannelDeletePhoto" my-i18n="conversation_removed_channel_photo"></span>
</span>

2
app/partials/desktop/settings_modal.html

@ -34,7 +34,7 @@ @@ -34,7 +34,7 @@
<div class="md_modal_body">
<div class="md_modal_sections">
<div class="md_modal_sections clearfix">
<div class="md_modal_iconed_section_wrap md_modal_iconed_section_number">
<i class="md_modal_section_icon md_modal_section_icon_phone"></i>

2
app/partials/desktop/user_modal.html

@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
<div class="md_modal_body">
<div class="md_modal_sections">
<div class="md_modal_sections clearfix">
<div class="md_modal_iconed_section_wrap md_modal_iconed_section_number" ng-if="user.phone || user.username">
<i class="md_modal_section_icon md_modal_section_icon_phone"></i>

Loading…
Cancel
Save