|
|
@ -2405,6 +2405,13 @@ export class AppMessagesManager { |
|
|
|
public applyConversations(dialogsResult: MessagesPeerDialogs.messagesPeerDialogs) { |
|
|
|
public applyConversations(dialogsResult: MessagesPeerDialogs.messagesPeerDialogs) { |
|
|
|
// * В эту функцию попадут только те диалоги, в которых есть read_inbox_max_id и read_outbox_max_id, в отличие от тех, что будут в getTopMessages
|
|
|
|
// * В эту функцию попадут только те диалоги, в которых есть read_inbox_max_id и read_outbox_max_id, в отличие от тех, что будут в getTopMessages
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ! fix 'dialogFolder', maybe there is better way to do it, this only can happen by 'messages.getPinnedDialogs' by folder_id: 0
|
|
|
|
|
|
|
|
dialogsResult.dialogs.forEachReverse((dialog, idx) => { |
|
|
|
|
|
|
|
if(dialog._ == 'dialogFolder') { |
|
|
|
|
|
|
|
dialogsResult.dialogs.splice(idx, 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
appUsersManager.saveApiUsers(dialogsResult.users); |
|
|
|
appUsersManager.saveApiUsers(dialogsResult.users); |
|
|
|
appChatsManager.saveApiChats(dialogsResult.chats); |
|
|
|
appChatsManager.saveApiChats(dialogsResult.chats); |
|
|
|
this.saveMessages(dialogsResult.messages); |
|
|
|
this.saveMessages(dialogsResult.messages); |
|
|
@ -2412,7 +2419,6 @@ export class AppMessagesManager { |
|
|
|
//this.log('applyConversation', dialogsResult);
|
|
|
|
//this.log('applyConversation', dialogsResult);
|
|
|
|
|
|
|
|
|
|
|
|
const updatedDialogs: {[peerID: number]: Dialog} = {}; |
|
|
|
const updatedDialogs: {[peerID: number]: Dialog} = {}; |
|
|
|
let hasUpdated = false; |
|
|
|
|
|
|
|
(dialogsResult.dialogs as Dialog[]).forEach((dialog) => { |
|
|
|
(dialogsResult.dialogs as Dialog[]).forEach((dialog) => { |
|
|
|
const peerID = appPeersManager.getPeerID(dialog.peer); |
|
|
|
const peerID = appPeersManager.getPeerID(dialog.peer); |
|
|
|
let topMessage = dialog.top_message; |
|
|
|
let topMessage = dialog.top_message; |
|
|
@ -2444,8 +2450,9 @@ export class AppMessagesManager { |
|
|
|
/* if(wasDialogBefore) { |
|
|
|
/* if(wasDialogBefore) { |
|
|
|
rootScope.$broadcast('dialog_top', dialog); |
|
|
|
rootScope.$broadcast('dialog_top', dialog); |
|
|
|
} else { */ |
|
|
|
} else { */ |
|
|
|
updatedDialogs[peerID] = dialog; |
|
|
|
//if(wasDialogBefore?.top_message != topMessage) {
|
|
|
|
hasUpdated = true; |
|
|
|
updatedDialogs[peerID] = dialog; |
|
|
|
|
|
|
|
//}
|
|
|
|
//}
|
|
|
|
//}
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const dropped = this.dialogsStorage.dropDialog(peerID); |
|
|
|
const dropped = this.dialogsStorage.dropDialog(peerID); |
|
|
@ -2464,7 +2471,7 @@ export class AppMessagesManager { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if(hasUpdated) { |
|
|
|
if(Object.keys(updatedDialogs).length) { |
|
|
|
rootScope.broadcast('dialogs_multiupdate', updatedDialogs); |
|
|
|
rootScope.broadcast('dialogs_multiupdate', updatedDialogs); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -3328,16 +3335,55 @@ export class AppMessagesManager { |
|
|
|
case 'updatePinnedDialogs': { |
|
|
|
case 'updatePinnedDialogs': { |
|
|
|
const folderID = update.folder_id ?? 0; |
|
|
|
const folderID = update.folder_id ?? 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleOrder = (order: number[]) => { |
|
|
|
|
|
|
|
this.dialogsStorage.pinnedOrders[folderID].length = 0; |
|
|
|
|
|
|
|
let willHandle = false; |
|
|
|
|
|
|
|
order.reverse(); // index must be higher
|
|
|
|
|
|
|
|
order.forEach((peerID) => { |
|
|
|
|
|
|
|
newPinned[peerID] = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const foundDialog = this.getDialogByPeerID(peerID); |
|
|
|
|
|
|
|
if(!foundDialog.length) { |
|
|
|
|
|
|
|
this.newDialogsToHandle[peerID] = {reload: true}; |
|
|
|
|
|
|
|
willHandle = true; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const dialog = foundDialog[0]; |
|
|
|
|
|
|
|
dialog.pFlags.pinned = true; |
|
|
|
|
|
|
|
this.dialogsStorage.generateIndexForDialog(dialog); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.newDialogsToHandle[peerID] = dialog; |
|
|
|
|
|
|
|
willHandle = true; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.dialogsStorage.getFolder(folderID).forEach(dialog => { |
|
|
|
|
|
|
|
const peerID = dialog.peerID; |
|
|
|
|
|
|
|
if(dialog.pFlags.pinned && !newPinned[peerID]) { |
|
|
|
|
|
|
|
this.newDialogsToHandle[peerID] = {reload: true}; |
|
|
|
|
|
|
|
willHandle = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(willHandle) { |
|
|
|
|
|
|
|
this.scheduleHandleNewDialogs(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
this.log('updatePinnedDialogs', update); |
|
|
|
this.log('updatePinnedDialogs', update); |
|
|
|
const newPinned: {[peerID: number]: true} = {}; |
|
|
|
const newPinned: {[peerID: number]: true} = {}; |
|
|
|
if(!update.order) { |
|
|
|
if(!update.order) { |
|
|
|
apiManager.invokeApi('messages.getPinnedDialogs', { |
|
|
|
apiManager.invokeApi('messages.getPinnedDialogs', { |
|
|
|
folder_id: folderID |
|
|
|
folder_id: folderID |
|
|
|
}).then((dialogsResult) => { |
|
|
|
}).then((dialogsResult) => { |
|
|
|
dialogsResult.dialogs.reverse(); |
|
|
|
// * for test reordering and rendering
|
|
|
|
|
|
|
|
// dialogsResult.dialogs.reverse();
|
|
|
|
|
|
|
|
|
|
|
|
this.applyConversations(dialogsResult); |
|
|
|
this.applyConversations(dialogsResult); |
|
|
|
|
|
|
|
|
|
|
|
dialogsResult.dialogs.forEach((dialog) => { |
|
|
|
handleOrder(dialogsResult.dialogs.map(d => d.peerID)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* dialogsResult.dialogs.forEach((dialog) => { |
|
|
|
newPinned[dialog.peerID] = true; |
|
|
|
newPinned[dialog.peerID] = true; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -3347,7 +3393,7 @@ export class AppMessagesManager { |
|
|
|
this.newDialogsToHandle[peerID] = {reload: true}; |
|
|
|
this.newDialogsToHandle[peerID] = {reload: true}; |
|
|
|
this.scheduleHandleNewDialogs(); |
|
|
|
this.scheduleHandleNewDialogs(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); */ |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
@ -3355,39 +3401,7 @@ export class AppMessagesManager { |
|
|
|
|
|
|
|
|
|
|
|
//this.log('before order:', this.dialogsStorage[0].map(d => d.peerID));
|
|
|
|
//this.log('before order:', this.dialogsStorage[0].map(d => d.peerID));
|
|
|
|
|
|
|
|
|
|
|
|
this.dialogsStorage.pinnedOrders[folderID].length = 0; |
|
|
|
handleOrder(update.order.map(peer => appPeersManager.getPeerID((peer as DialogPeer.dialogPeer).peer))); |
|
|
|
let willHandle = false; |
|
|
|
|
|
|
|
update.order.reverse(); // index must be higher
|
|
|
|
|
|
|
|
update.order.forEach((peer: any) => { |
|
|
|
|
|
|
|
const peerID = appPeersManager.getPeerID(peer.peer); |
|
|
|
|
|
|
|
newPinned[peerID] = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const foundDialog = this.getDialogByPeerID(peerID); |
|
|
|
|
|
|
|
if(!foundDialog.length) { |
|
|
|
|
|
|
|
this.newDialogsToHandle[peerID] = {reload: true}; |
|
|
|
|
|
|
|
willHandle = true; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const dialog = foundDialog[0]; |
|
|
|
|
|
|
|
dialog.pFlags.pinned = true; |
|
|
|
|
|
|
|
this.dialogsStorage.generateIndexForDialog(dialog); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.newDialogsToHandle[peerID] = dialog; |
|
|
|
|
|
|
|
willHandle = true; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.dialogsStorage.getFolder(folderID).forEach(dialog => { |
|
|
|
|
|
|
|
const peerID = dialog.peerID; |
|
|
|
|
|
|
|
if(dialog.pFlags.pinned && !newPinned[peerID]) { |
|
|
|
|
|
|
|
this.newDialogsToHandle[peerID] = {reload: true}; |
|
|
|
|
|
|
|
willHandle = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(willHandle) { |
|
|
|
|
|
|
|
this.scheduleHandleNewDialogs(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|