Improved dialogs
This commit is contained in:
parent
95f9fc02db
commit
a56a7a8162
@ -48,14 +48,14 @@
|
|||||||
|
|
||||||
|
|
||||||
<script type="text/javascript" src="js/lib/config.js"></script>
|
<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/util.js"></script>
|
||||||
<script type="text/javascript" src="js/app.js?5"></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/services.js?8"></script>
|
||||||
<script type="text/javascript" src="js/controllers.js?12"></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/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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -133,14 +133,8 @@ angular.module('myApp.controllers', [])
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// $scope.userID = 0;
|
|
||||||
// MtpApiManager.getUserID().then(function (userID) {
|
|
||||||
// $scope.userID = userID;
|
|
||||||
// });
|
|
||||||
|
|
||||||
updateCurDialog();
|
updateCurDialog();
|
||||||
|
|
||||||
|
|
||||||
function updateCurDialog() {
|
function updateCurDialog() {
|
||||||
$scope.curDialog = {
|
$scope.curDialog = {
|
||||||
peer: $routeParams.p || false
|
peer: $routeParams.p || false
|
||||||
@ -150,15 +144,19 @@ angular.module('myApp.controllers', [])
|
|||||||
|
|
||||||
.controller('AppImDialogsController', function ($scope, $location, MtpApiManager, AppUsersManager, AppChatsManager, AppMessagesManager, AppPeersManager) {
|
.controller('AppImDialogsController', function ($scope, $location, MtpApiManager, AppUsersManager, AppChatsManager, AppMessagesManager, AppPeersManager) {
|
||||||
|
|
||||||
|
// console.log('init controller');
|
||||||
|
|
||||||
$scope.dialogs = [];
|
$scope.dialogs = [];
|
||||||
|
|
||||||
var offset = 0,
|
var offset = 0,
|
||||||
|
maxID = 0,
|
||||||
hasMore = false,
|
hasMore = false,
|
||||||
limit = 20;
|
limit = 20;
|
||||||
|
|
||||||
|
|
||||||
MtpApiManager.invokeApi('account.updateStatus', {offline: false});
|
MtpApiManager.invokeApi('account.updateStatus', {offline: false});
|
||||||
$scope.$on('dialogs_need_more', function () {
|
$scope.$on('dialogs_need_more', function () {
|
||||||
|
// console.log('on need more');
|
||||||
showMoreDialogs();
|
showMoreDialogs();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -193,11 +191,13 @@ angular.module('myApp.controllers', [])
|
|||||||
|
|
||||||
function loadDialogs (startLimit) {
|
function loadDialogs (startLimit) {
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
maxID = 0;
|
||||||
hasMore = false;
|
hasMore = false;
|
||||||
startLimit = startLimit || limit;
|
startLimit = startLimit || limit;
|
||||||
|
|
||||||
AppMessagesManager.getDialogs(offset, startLimit).then(function (dialogsResult) {
|
AppMessagesManager.getDialogs(maxID, startLimit).then(function (dialogsResult) {
|
||||||
offset += startLimit;
|
offset += startLimit;
|
||||||
|
maxID = dialogsResult.dialogs[dialogsResult.dialogs.length - 1].top_message;
|
||||||
hasMore = offset < dialogsResult.count;
|
hasMore = offset < dialogsResult.count;
|
||||||
|
|
||||||
$scope.dialogs = [];
|
$scope.dialogs = [];
|
||||||
@ -218,8 +218,9 @@ angular.module('myApp.controllers', [])
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AppMessagesManager.getDialogs(offset, limit).then(function (dialogsResult) {
|
AppMessagesManager.getDialogs(maxID, limit).then(function (dialogsResult) {
|
||||||
offset += limit;
|
offset += limit;
|
||||||
|
maxID = dialogsResult.dialogs[dialogsResult.dialogs.length - 1].top_message;
|
||||||
hasMore = offset < dialogsResult.count;
|
hasMore = offset < dialogsResult.count;
|
||||||
|
|
||||||
angular.forEach(dialogsResult.dialogs, function (dialog) {
|
angular.forEach(dialogsResult.dialogs, function (dialog) {
|
||||||
|
@ -35,10 +35,13 @@ angular.module('myApp.directives', ['myApp.filters'])
|
|||||||
link: link
|
link: link
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function link (scope, element, attrs) {
|
function link (scope, element, attrs) {
|
||||||
var dialogsWrap = $('.im_dialogs_wrap')[0],
|
// console.log('init directive', element);
|
||||||
scrollableWrap = $('.im_dialogs_scrollable_wrap')[0],
|
|
||||||
// dialogsSearch = $('im_dialogs_search')[0],
|
var dialogsWrap = $('.im_dialogs_wrap', element)[0],
|
||||||
|
scrollableWrap = $('.im_dialogs_scrollable_wrap', element)[0],
|
||||||
|
// dialogsSearch = $('im_dialogs_search', element)[0],
|
||||||
moreNotified = false;
|
moreNotified = false;
|
||||||
|
|
||||||
onContentLoaded(function () {
|
onContentLoaded(function () {
|
||||||
@ -69,7 +72,9 @@ angular.module('myApp.directives', ['myApp.filters'])
|
|||||||
});
|
});
|
||||||
|
|
||||||
$(scrollableWrap).on('scroll', function (e) {
|
$(scrollableWrap).on('scroll', function (e) {
|
||||||
|
// console.log('scroll', moreNotified);
|
||||||
if (!moreNotified && scrollableWrap.scrollTop >= scrollableWrap.scrollHeight - scrollableWrap.clientHeight - 300) {
|
if (!moreNotified && scrollableWrap.scrollTop >= scrollableWrap.scrollHeight - scrollableWrap.clientHeight - 300) {
|
||||||
|
// console.log('emit need more');
|
||||||
scope.$emit('dialogs_need_more');
|
scope.$emit('dialogs_need_more');
|
||||||
moreNotified = true;
|
moreNotified = true;
|
||||||
}
|
}
|
||||||
@ -96,10 +101,10 @@ angular.module('myApp.directives', ['myApp.filters'])
|
|||||||
};
|
};
|
||||||
|
|
||||||
function link (scope, element, attrs) {
|
function link (scope, element, attrs) {
|
||||||
var historyWrap = $('.im_history_wrap')[0],
|
var historyWrap = $('.im_history_wrap', element)[0],
|
||||||
historyEl = $('.im_history')[0],
|
historyEl = $('.im_history', element)[0],
|
||||||
scrollableWrap = $('.im_history_scrollable_wrap')[0],
|
scrollableWrap = $('.im_history_scrollable_wrap', element)[0],
|
||||||
scrollable = $('.im_history_scrollable')[0],
|
scrollable = $('.im_history_scrollable', element)[0],
|
||||||
panelWrap = $('.im_history_panel_wrap', element)[0],
|
panelWrap = $('.im_history_panel_wrap', element)[0],
|
||||||
sendFormWrap = $('.im_send_form_wrap', element)[0],
|
sendFormWrap = $('.im_send_form_wrap', element)[0],
|
||||||
moreNotified = false;
|
moreNotified = false;
|
||||||
@ -244,7 +249,7 @@ angular.module('myApp.directives', ['myApp.filters'])
|
|||||||
editorElement = messageField,
|
editorElement = messageField,
|
||||||
dragStarted, dragTimeout,
|
dragStarted, dragTimeout,
|
||||||
emojiArea = $(messageField).emojiarea({button: emojiButton}),
|
emojiArea = $(messageField).emojiarea({button: emojiButton}),
|
||||||
emojiMenu = $('.emoji-menu')[0],
|
emojiMenu = $('.emoji-menu', element)[0],
|
||||||
richTextarea = $('.emoji-wysiwyg-editor', element)[0];
|
richTextarea = $('.emoji-wysiwyg-editor', element)[0];
|
||||||
|
|
||||||
if (richTextarea) {
|
if (richTextarea) {
|
||||||
|
@ -2144,7 +2144,11 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (deferred) {
|
if (deferred) {
|
||||||
|
if (window._debugMode) {
|
||||||
|
console.log('rpc response', message.result);
|
||||||
|
} else {
|
||||||
console.log('rpc response', message.result._);
|
console.log('rpc response', message.result._);
|
||||||
|
}
|
||||||
sentMessage.deferred.resolve(message.result);
|
sentMessage.deferred.resolve(message.result);
|
||||||
}
|
}
|
||||||
if (sentMessage.isAPI) {
|
if (sentMessage.isAPI) {
|
||||||
|
@ -422,7 +422,16 @@ angular.module('myApp.services', [])
|
|||||||
|
|
||||||
NotificationsManager.start();
|
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 && (
|
if (dialogsStorage.count !== null && (
|
||||||
dialogsStorage.dialogs.length >= offset + limit ||
|
dialogsStorage.dialogs.length >= offset + limit ||
|
||||||
dialogsStorage.dialogs.length == dialogsStorage.count
|
dialogsStorage.dialogs.length == dialogsStorage.count
|
||||||
@ -438,16 +447,25 @@ angular.module('myApp.services', [])
|
|||||||
MtpApiManager.invokeApi('messages.getDialogs', {
|
MtpApiManager.invokeApi('messages.getDialogs', {
|
||||||
offset: offset,
|
offset: offset,
|
||||||
limit: limit,
|
limit: limit,
|
||||||
max_id: 0
|
max_id: maxID || 0
|
||||||
}).then(function (dialogsResult) {
|
}).then(function (dialogsResult) {
|
||||||
AppUsersManager.saveApiUsers(dialogsResult.users);
|
AppUsersManager.saveApiUsers(dialogsResult.users);
|
||||||
AppChatsManager.saveApiChats(dialogsResult.chats);
|
AppChatsManager.saveApiChats(dialogsResult.chats);
|
||||||
saveMessages(dialogsResult.messages);
|
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'
|
dialogsStorage.count = dialogsResult._ == 'messages.dialogsSlice'
|
||||||
? dialogsResult.count
|
? dialogsResult.count
|
||||||
: dialogsResult.dialogs.length;
|
: dialogsResult.dialogs.length;
|
||||||
|
|
||||||
|
dialogsStorage.dialogs.splice(offset, dialogsStorage.dialogs.length - offset);
|
||||||
angular.forEach(dialogsResult.dialogs, function (dialog) {
|
angular.forEach(dialogsResult.dialogs, function (dialog) {
|
||||||
dialogsStorage.dialogs.push({
|
dialogsStorage.dialogs.push({
|
||||||
peerID: AppPeersManager.getPeerID(dialog.peer),
|
peerID: AppPeersManager.getPeerID(dialog.peer),
|
||||||
@ -491,7 +509,10 @@ angular.module('myApp.services', [])
|
|||||||
}
|
}
|
||||||
// console.log('history storage', angular.copy(historyStorage.history), maxID, offset);
|
// 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({
|
return $q.when({
|
||||||
count: historyStorage.count,
|
count: historyStorage.count,
|
||||||
history: resultPending.concat(historyStorage.history.slice(offset, offset + limit))
|
history: resultPending.concat(historyStorage.history.slice(offset, offset + limit))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user