Browse Source

Improved dialogs

master
Igor Zhukov 11 years ago
parent
commit
a56a7a8162
  1. 8
      app/index.html
  2. 17
      app/js/controllers.js
  3. 21
      app/js/directives.js
  4. 6
      app/js/lib/mtproto.js
  5. 27
      app/js/services.js

8
app/index.html

@ -48,14 +48,14 @@ @@ -48,14 +48,14 @@
<script type="text/javascript" src="js/lib/config.js"></script>
<script type="text/javascript" src="js/lib/mtproto.js?16"></script>
<script type="text/javascript" src="js/lib/mtproto.js?17"></script>
<script type="text/javascript" src="js/util.js"></script>
<script type="text/javascript" src="js/app.js?5"></script>
<script type="text/javascript" src="js/services.js?7"></script>
<script type="text/javascript" src="js/controllers.js?12"></script>
<script type="text/javascript" src="js/services.js?8"></script>
<script type="text/javascript" src="js/controllers.js?13"></script>
<script type="text/javascript" src="js/filters.js?3"></script>
<script type="text/javascript" src="js/directives.js?7"></script>
<script type="text/javascript" src="js/directives.js?8"></script>
</body>
</html>

17
app/js/controllers.js

@ -133,14 +133,8 @@ angular.module('myApp.controllers', []) @@ -133,14 +133,8 @@ angular.module('myApp.controllers', [])
});
}
// $scope.userID = 0;
// MtpApiManager.getUserID().then(function (userID) {
// $scope.userID = userID;
// });
updateCurDialog();
function updateCurDialog() {
$scope.curDialog = {
peer: $routeParams.p || false
@ -150,15 +144,19 @@ angular.module('myApp.controllers', []) @@ -150,15 +144,19 @@ angular.module('myApp.controllers', [])
.controller('AppImDialogsController', function ($scope, $location, MtpApiManager, AppUsersManager, AppChatsManager, AppMessagesManager, AppPeersManager) {
// console.log('init controller');
$scope.dialogs = [];
var offset = 0,
maxID = 0,
hasMore = false,
limit = 20;
MtpApiManager.invokeApi('account.updateStatus', {offline: false});
$scope.$on('dialogs_need_more', function () {
// console.log('on need more');
showMoreDialogs();
});
@ -193,11 +191,13 @@ angular.module('myApp.controllers', []) @@ -193,11 +191,13 @@ angular.module('myApp.controllers', [])
function loadDialogs (startLimit) {
offset = 0;
maxID = 0;
hasMore = false;
startLimit = startLimit || limit;
AppMessagesManager.getDialogs(offset, startLimit).then(function (dialogsResult) {
AppMessagesManager.getDialogs(maxID, startLimit).then(function (dialogsResult) {
offset += startLimit;
maxID = dialogsResult.dialogs[dialogsResult.dialogs.length - 1].top_message;
hasMore = offset < dialogsResult.count;
$scope.dialogs = [];
@ -218,8 +218,9 @@ angular.module('myApp.controllers', []) @@ -218,8 +218,9 @@ angular.module('myApp.controllers', [])
return;
}
AppMessagesManager.getDialogs(offset, limit).then(function (dialogsResult) {
AppMessagesManager.getDialogs(maxID, limit).then(function (dialogsResult) {
offset += limit;
maxID = dialogsResult.dialogs[dialogsResult.dialogs.length - 1].top_message;
hasMore = offset < dialogsResult.count;
angular.forEach(dialogsResult.dialogs, function (dialog) {

21
app/js/directives.js

@ -35,10 +35,13 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -35,10 +35,13 @@ angular.module('myApp.directives', ['myApp.filters'])
link: link
};
function link (scope, element, attrs) {
var dialogsWrap = $('.im_dialogs_wrap')[0],
scrollableWrap = $('.im_dialogs_scrollable_wrap')[0],
// dialogsSearch = $('im_dialogs_search')[0],
// console.log('init directive', element);
var dialogsWrap = $('.im_dialogs_wrap', element)[0],
scrollableWrap = $('.im_dialogs_scrollable_wrap', element)[0],
// dialogsSearch = $('im_dialogs_search', element)[0],
moreNotified = false;
onContentLoaded(function () {
@ -69,7 +72,9 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -69,7 +72,9 @@ angular.module('myApp.directives', ['myApp.filters'])
});
$(scrollableWrap).on('scroll', function (e) {
// console.log('scroll', moreNotified);
if (!moreNotified && scrollableWrap.scrollTop >= scrollableWrap.scrollHeight - scrollableWrap.clientHeight - 300) {
// console.log('emit need more');
scope.$emit('dialogs_need_more');
moreNotified = true;
}
@ -96,10 +101,10 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -96,10 +101,10 @@ angular.module('myApp.directives', ['myApp.filters'])
};
function link (scope, element, attrs) {
var historyWrap = $('.im_history_wrap')[0],
historyEl = $('.im_history')[0],
scrollableWrap = $('.im_history_scrollable_wrap')[0],
scrollable = $('.im_history_scrollable')[0],
var historyWrap = $('.im_history_wrap', element)[0],
historyEl = $('.im_history', element)[0],
scrollableWrap = $('.im_history_scrollable_wrap', element)[0],
scrollable = $('.im_history_scrollable', element)[0],
panelWrap = $('.im_history_panel_wrap', element)[0],
sendFormWrap = $('.im_send_form_wrap', element)[0],
moreNotified = false;
@ -244,7 +249,7 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -244,7 +249,7 @@ angular.module('myApp.directives', ['myApp.filters'])
editorElement = messageField,
dragStarted, dragTimeout,
emojiArea = $(messageField).emojiarea({button: emojiButton}),
emojiMenu = $('.emoji-menu')[0],
emojiMenu = $('.emoji-menu', element)[0],
richTextarea = $('.emoji-wysiwyg-editor', element)[0];
if (richTextarea) {

6
app/js/lib/mtproto.js

@ -2144,7 +2144,11 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato @@ -2144,7 +2144,11 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
}
} else {
if (deferred) {
console.log('rpc response', message.result._);
if (window._debugMode) {
console.log('rpc response', message.result);
} else {
console.log('rpc response', message.result._);
}
sentMessage.deferred.resolve(message.result);
}
if (sentMessage.isAPI) {

27
app/js/services.js

@ -422,7 +422,16 @@ angular.module('myApp.services', []) @@ -422,7 +422,16 @@ angular.module('myApp.services', [])
NotificationsManager.start();
function getDialogs (offset, limit) {
function getDialogs (maxID, limit) {
var offset = 0;
if (maxID > 0) {
for (offset = 0; offset < dialogsStorage.dialogs.length; offset++) {
if (maxID > dialogsStorage.dialogs[offset].top_message) {
break;
}
}
}
if (dialogsStorage.count !== null && (
dialogsStorage.dialogs.length >= offset + limit ||
dialogsStorage.dialogs.length == dialogsStorage.count
@ -438,16 +447,25 @@ angular.module('myApp.services', []) @@ -438,16 +447,25 @@ angular.module('myApp.services', [])
MtpApiManager.invokeApi('messages.getDialogs', {
offset: offset,
limit: limit,
max_id: 0
max_id: maxID || 0
}).then(function (dialogsResult) {
AppUsersManager.saveApiUsers(dialogsResult.users);
AppChatsManager.saveApiChats(dialogsResult.chats);
saveMessages(dialogsResult.messages);
if (maxID > 0) {
for (offset = 0; offset < dialogsStorage.dialogs.length; offset++) {
if (maxID > dialogsStorage.dialogs[offset].top_message) {
break;
}
}
}
dialogsStorage.count = dialogsResult._ == 'messages.dialogsSlice'
? dialogsResult.count
: dialogsResult.dialogs.length;
dialogsStorage.dialogs.splice(offset, dialogsStorage.dialogs.length - offset);
angular.forEach(dialogsResult.dialogs, function (dialog) {
dialogsStorage.dialogs.push({
peerID: AppPeersManager.getPeerID(dialog.peer),
@ -491,7 +509,10 @@ angular.module('myApp.services', []) @@ -491,7 +509,10 @@ angular.module('myApp.services', [])
}
// console.log('history storage', angular.copy(historyStorage.history), maxID, offset);
if (historyStorage.count !== null && historyStorage.history.length >= offset + limit) {
if (historyStorage.count !== null && (
historyStorage.history.length >= offset + limit ||
historyStorage.history.length == historyStorage.count
)) {
return $q.when({
count: historyStorage.count,
history: resultPending.concat(historyStorage.history.slice(offset, offset + limit))

Loading…
Cancel
Save