Browse Source

Updated schema

Improved loading dialogs
master
Igor Zhukov 9 years ago
parent
commit
889da274c6
  1. 4
      app/js/lib/config.js
  2. 7
      app/js/lib/schema.tl.txt
  3. 131
      app/js/messages_manager.js

4
app/js/lib/config.js

File diff suppressed because one or more lines are too long

7
app/js/lib/schema.tl.txt

@ -133,13 +133,11 @@ messageActionChatCreate#a6638b9a title:string users:Vector<int> = MessageAction; @@ -133,13 +133,11 @@ messageActionChatCreate#a6638b9a title:string users:Vector<int> = MessageAction;
messageActionChatEditTitle#b5a1ce5a title:string = MessageAction;
messageActionChatEditPhoto#7fcb13a8 photo:Photo = MessageAction;
messageActionChatDeletePhoto#95e3fbef = MessageAction;
messageActionChatAddUser#5e3cfc4b user_id:int = MessageAction;
messageActionChatAddUser#488a7337 users:Vector<int> = MessageAction;
messageActionChatDeleteUser#b2ae9b0c user_id:int = MessageAction;
messageActionChatJoinedByLink#f89cf5e8 inviter_id:int = MessageAction;
messageActionChannelCreate#95d2ac92 title:string = MessageAction;
messageActionChatMigrateTo#51bdb021 channel_id:int = MessageAction;
messageActionChatDeactivate#64ad20a8 = MessageAction;
messageActionChatActivate#40ad8cb2 = MessageAction;
messageActionChannelMigrateFrom#b055eaee title:string chat_id:int = MessageAction;
dialog#c1dd804a peer:Peer top_message:int read_inbox_max_id:int unread_count:int notify_settings:PeerNotifySettings = Dialog;
@ -573,7 +571,7 @@ contacts.search#11f812d8 q:string limit:int = contacts.Found; @@ -573,7 +571,7 @@ contacts.search#11f812d8 q:string limit:int = contacts.Found;
contacts.resolveUsername#f93ccba3 username:string = contacts.ResolvedPeer;
messages.getMessages#4222fa74 id:Vector<int> = messages.Messages;
messages.getDialogs#859b3d3c offset:int limit:int = messages.Dialogs;
messages.getDialogs#6b47f94d offset_date:int offset_id:int offset_peer:InputPeer limit:int = messages.Dialogs;
messages.getHistory#8a8ec2da peer:InputPeer offset_id:int add_offset:int limit:int max_id:int min_id:int = messages.Messages;
messages.search#d4569248 flags:# important_only:flags.0?true peer:InputPeer q:string filter:MessagesFilter min_date:int max_date:int offset:int max_id:int limit:int = messages.Messages;
messages.readHistory#e306d3a peer:InputPeer max_id:int = messages.AffectedMessages;
@ -618,7 +616,6 @@ messages.startBot#e6df7378 bot:InputUser peer:InputPeer random_id:long start_par @@ -618,7 +616,6 @@ messages.startBot#e6df7378 bot:InputUser peer:InputPeer random_id:long start_par
messages.getMessagesViews#c4c8a55d peer:InputPeer id:Vector<int> increment:Bool = Vector<int>;
messages.toggleChatAdmins#ec8bd9e1 chat_id:int enabled:Bool = Updates;
messages.editChatAdmin#a9e69f2e chat_id:int user_id:InputUser is_admin:Bool = Bool;
messages.deactivateChat#626f0b41 chat_id:int enabled:Bool = Updates;
messages.migrateChat#15a3b8e3 chat_id:int = Updates;
messages.searchGlobal#9e3cacb0 q:string offset_date:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages;

131
app/js/messages_manager.js

@ -65,8 +65,6 @@ angular.module('myApp.services') @@ -65,8 +65,6 @@ angular.module('myApp.services')
NotificationsManager.start();
var allChannelsLoaded = false;
var channelsLoadPromise = false;
var allDialogsLoaded = false
var loadedDialogsCount = 0;
var dialogsNum = 0;
@ -108,7 +106,7 @@ angular.module('myApp.services') @@ -108,7 +106,7 @@ angular.module('myApp.services')
if (
isSearch ||
(allChannelsLoaded && allDialogsLoaded) ||
allDialogsLoaded ||
(
curDialogStorage.dialogs.length >= offset + limit &&
curDialogStorage.dialogs[offset + limit - 1].index >= minDialogsIndex
@ -119,7 +117,7 @@ angular.module('myApp.services') @@ -119,7 +117,7 @@ angular.module('myApp.services')
});
}
return $q.all([getAllChannels(), getTopMessages(loadedDialogsCount, limit)]).then(function () {
return getTopMessages(limit).then(function () {
offset = 0;
if (offsetIndex > 0) {
for (offset = 0; offset < curDialogStorage.dialogs.length; offset++) {
@ -149,8 +147,13 @@ angular.module('myApp.services') @@ -149,8 +147,13 @@ angular.module('myApp.services')
var peerText = AppPeersManager.getPeerSearchText(peerID);
SearchIndexManager.indexObject(peerID, peerText, dialogsIndex);
var mid = getFullMessageID(dialog.top_important_message, channelID);
dialog.top_message = mid;
var isMegagroup = AppChatsManager.isMegagroup(channelID);
if (isMegagroup) {
var mid = getFullMessageID(dialog.top_message, channelID);
} else {
var mid = getFullMessageID(dialog.top_important_message, channelID);
dialog.top_message = mid;
}
dialog.unread_count = dialog.unread_important_count;
dialog.read_inbox_max_id = getFullMessageID(dialog.read_inbox_max_id, channelID);
@ -180,46 +183,35 @@ angular.module('myApp.services') @@ -180,46 +183,35 @@ angular.module('myApp.services')
ApiUpdatesManager.addChannelState(channelID, dialog.pts);
}
function getAllChannels () {
if (channelsLoadPromise) {
return channelsLoadPromise;
function getTopMessages (limit) {
var first = true;
var dialogs = dialogsStorage.dialogs;
var len = dialogs && dialogs.length;
var offsetDate = 0;
var offsetID = 0;
var offsetPeerID = 0;
if (len) {
var dialog = dialogs[len - 1];
var index = dialog.index;
if (index) {
offsetDate = Math.ceil(index / 0x10000);
offsetID = dialog.top_message;
offsetPeerID = dialog.peerID;
}
}
return channelsLoadPromise = MtpApiManager.invokeApi('channels.getDialogs', {
offset: 0,
limit: 100
}, {
timeout: 300
}).then(function (dialogsResult) {
AppUsersManager.saveApiUsers(dialogsResult.users);
AppChatsManager.saveApiChats(dialogsResult.chats);
saveMessages(dialogsResult.messages);
angular.forEach(dialogsResult.dialogs, function (dialog) {
var peerID = AppPeersManager.getPeerID(dialog.peer);
var channelID = -peerID;
saveChannelDialog(channelID, dialog);
ApiUpdatesManager.addChannelState(channelID, dialog.pts);
});
allChannelsLoaded = true;
});
}
function getTopMessages (offset, limit) {
return MtpApiManager.invokeApi('messages.getDialogs', {
offset: offset,
offset_date: offsetDate,
offset_id: getMessageLocalID(offsetID),
offset_peer: AppPeersManager.getInputPeerByID(offsetPeerID),
limit: limit
}, {
timeout: 300
}).then(function (dialogsResult) {
if (!offset) {
console.log('dialogs result', dialogsResult);
if (!offsetDate) {
TelegramMeWebService.setAuthorized(true);
}
// Server-side bug
if (dialogsResult.count && offset >= dialogsResult.count) {
dialogsResult.dialogs = [];
}
AppUsersManager.saveApiUsers(dialogsResult.users);
AppChatsManager.saveApiChats(dialogsResult.chats);
saveMessages(dialogsResult.messages);
@ -227,44 +219,53 @@ angular.module('myApp.services') @@ -227,44 +219,53 @@ angular.module('myApp.services')
if (!dialogsResult.dialogs.length) {
allDialogsLoaded = true;
}
else if (!offset) {
incrementMaxSeenID(dialogsResult.dialogs[0].top_message);
}
var maxSeenIdIncremented = offsetDate ? true : false;
angular.forEach(dialogsResult.dialogs, function (dialog) {
var peerID = AppPeersManager.getPeerID(dialog.peer);
var peerText = AppPeersManager.getPeerSearchText(peerID);
SearchIndexManager.indexObject(peerID, peerText, dialogsIndex);
if (dialog._ == 'dialogChannel') {
var channelID = -peerID;
saveChannelDialog(channelID, dialog);
ApiUpdatesManager.addChannelState(channelID, dialog.pts);
} else {
var peerText = AppPeersManager.getPeerSearchText(peerID);
SearchIndexManager.indexObject(peerID, peerText, dialogsIndex);
var message = getMessage(dialog.top_message);
var message = getMessage(dialog.top_message);
dialog.index = generateDialogIndex(message.date);
dialog.peerID = peerID;
dialog.index = generateDialogIndex(message.date);
dialog.peerID = peerID;
pushDialogToStorage(dialog);
pushDialogToStorage(dialog);
if (historiesStorage[peerID] === undefined) {
var historyStorage = {count: null, history: [dialog.top_message], pending: []};
historiesStorage[peerID] = historyStorage;
if (mergeReplyKeyboard(historyStorage, message)) {
$rootScope.$broadcast('history_reply_markup', {peerID: peerID});
if (!maxSeenIdIncremented) {
incrementMaxSeenID(dialog.top_message);
maxSeenIdIncremented = true;
}
}
NotificationsManager.savePeerSettings(peerID, dialog.notify_settings);
if (historiesStorage[peerID] === undefined) {
var historyStorage = {count: null, history: [dialog.top_message], pending: []};
historiesStorage[peerID] = historyStorage;
if (mergeReplyKeyboard(historyStorage, message)) {
$rootScope.$broadcast('history_reply_markup', {peerID: peerID});
}
}
if (
dialog.unread_count > 0 &&
maxSeenID &&
dialog.top_message > maxSeenID
) {
var notifyPeer = message.flags & 16 ? message.from_id : peerID;
if (message.pFlags.unread && !message.pFlags.out) {
NotificationsManager.getPeerMuted(notifyPeer).then(function (muted) {
if (!muted) {
notifyAboutMessage(message);
}
});
NotificationsManager.savePeerSettings(peerID, dialog.notify_settings);
if (
dialog.unread_count > 0 &&
maxSeenID &&
dialog.top_message > maxSeenID
) {
var notifyPeer = message.flags & 16 ? message.from_id : peerID;
if (message.pFlags.unread && !message.pFlags.out) {
NotificationsManager.getPeerMuted(notifyPeer).then(function (muted) {
if (!muted) {
notifyAboutMessage(message);
}
});
}
}
}
});

Loading…
Cancel
Save