|
|
@ -1,6 +1,6 @@ |
|
|
|
import ProgressivePreloader from "../../components/preloader"; |
|
|
|
import ProgressivePreloader from "../../components/preloader"; |
|
|
|
import { CancellablePromise, deferredPromise } from "../../helpers/cancellablePromise"; |
|
|
|
import { CancellablePromise, deferredPromise } from "../../helpers/cancellablePromise"; |
|
|
|
import { Dialog as MTDialog, DialogFilter, DocumentAttribute, InputMessage, Message, MessagesDialogs, MessagesFilter, MessagesMessages, MessagesPeerDialogs, MethodDeclMap, PhotoSize } from "../../layer"; |
|
|
|
import { Dialog as MTDialog, DialogFilter, DialogPeer, DocumentAttribute, InputMessage, Message, MessagesDialogs, MessagesFilter, MessagesMessages, MessagesPeerDialogs, MethodDeclMap, PhotoSize, Update } from "../../layer"; |
|
|
|
import { Modify } from "../../types"; |
|
|
|
import { Modify } from "../../types"; |
|
|
|
import { bigint, nextRandomInt } from "../bin_utils"; |
|
|
|
import { bigint, nextRandomInt } from "../bin_utils"; |
|
|
|
import { logger } from "../logger"; |
|
|
|
import { logger } from "../logger"; |
|
|
@ -240,12 +240,12 @@ export class FiltersStorage { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public handleUpdate(update: any) { |
|
|
|
public handleUpdate(update: Update) { |
|
|
|
switch(update._) { |
|
|
|
switch(update._) { |
|
|
|
case 'updateDialogFilter': { |
|
|
|
case 'updateDialogFilter': { |
|
|
|
//console.log('updateDialogFilter', update);
|
|
|
|
//console.log('updateDialogFilter', update);
|
|
|
|
if(update.filter) { |
|
|
|
if(update.filter) { |
|
|
|
this.saveDialogFilter(update.filter); |
|
|
|
this.saveDialogFilter(update.filter as any); |
|
|
|
} else if(this.filters[update.id]) { // Папка удалена
|
|
|
|
} else if(this.filters[update.id]) { // Папка удалена
|
|
|
|
//this.getDialogFilters(true);
|
|
|
|
//this.getDialogFilters(true);
|
|
|
|
$rootScope.$broadcast('filter_delete', this.filters[update.id]); |
|
|
|
$rootScope.$broadcast('filter_delete', this.filters[update.id]); |
|
|
@ -361,7 +361,7 @@ export class FiltersStorage { |
|
|
|
this.handleUpdate({ |
|
|
|
this.handleUpdate({ |
|
|
|
_: 'updateDialogFilter', |
|
|
|
_: 'updateDialogFilter', |
|
|
|
id: filter.id, |
|
|
|
id: filter.id, |
|
|
|
filter: remove ? undefined : filter |
|
|
|
filter: remove ? undefined : filter as any |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2521,20 +2521,18 @@ export class AppMessagesManager { |
|
|
|
const dialog = this.getDialogByPeerID(peerID)[0]; |
|
|
|
const dialog = this.getDialogByPeerID(peerID)[0]; |
|
|
|
if(!dialog) return Promise.reject(); |
|
|
|
if(!dialog) return Promise.reject(); |
|
|
|
|
|
|
|
|
|
|
|
const peer = appPeersManager.getInputDialogPeerByID(peerID); |
|
|
|
const pinned = dialog.pFlags?.pinned ? undefined : true; |
|
|
|
|
|
|
|
|
|
|
|
const flags = dialog.pFlags?.pinned ? 0 : 1; |
|
|
|
|
|
|
|
return apiManager.invokeApi('messages.toggleDialogPin', { |
|
|
|
return apiManager.invokeApi('messages.toggleDialogPin', { |
|
|
|
flags, |
|
|
|
peer: appPeersManager.getInputDialogPeerByID(peerID), |
|
|
|
peer |
|
|
|
pinned |
|
|
|
}).then(bool => { |
|
|
|
}).then(bool => { |
|
|
|
if(bool) { |
|
|
|
if(bool) { |
|
|
|
|
|
|
|
const pFlags: Update.updateDialogPinned['pFlags'] = pinned ? {pinned} : {}; |
|
|
|
this.handleUpdate({ |
|
|
|
this.handleUpdate({ |
|
|
|
_: 'updateDialogPinned', |
|
|
|
_: 'updateDialogPinned', |
|
|
|
peer: peer, |
|
|
|
peer: appPeersManager.getDialogPeer(peerID), |
|
|
|
pFlags: { |
|
|
|
folder_id: filterID, |
|
|
|
pinned: flags |
|
|
|
pFlags |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -2544,20 +2542,17 @@ export class AppMessagesManager { |
|
|
|
const dialog = this.getDialogByPeerID(peerID)[0]; |
|
|
|
const dialog = this.getDialogByPeerID(peerID)[0]; |
|
|
|
if(!dialog) return Promise.reject(); |
|
|
|
if(!dialog) return Promise.reject(); |
|
|
|
|
|
|
|
|
|
|
|
const peer = appPeersManager.getInputDialogPeerByID(peerID); |
|
|
|
const unread = read || dialog.pFlags?.unread_mark ? undefined : true; |
|
|
|
|
|
|
|
|
|
|
|
const flags = read || dialog.pFlags?.unread_mark ? 0 : 1; |
|
|
|
|
|
|
|
return apiManager.invokeApi('messages.markDialogUnread', { |
|
|
|
return apiManager.invokeApi('messages.markDialogUnread', { |
|
|
|
flags, |
|
|
|
peer: appPeersManager.getInputDialogPeerByID(peerID), |
|
|
|
peer |
|
|
|
unread |
|
|
|
}).then(bool => { |
|
|
|
}).then(bool => { |
|
|
|
if(bool) { |
|
|
|
if(bool) { |
|
|
|
|
|
|
|
const pFlags: Update.updateDialogUnreadMark['pFlags'] = unread ? {unread} : {}; |
|
|
|
this.handleUpdate({ |
|
|
|
this.handleUpdate({ |
|
|
|
_: 'updateDialogUnreadMark', |
|
|
|
_: 'updateDialogUnreadMark', |
|
|
|
peer: peer, |
|
|
|
peer: appPeersManager.getDialogPeer(peerID), |
|
|
|
pFlags: { |
|
|
|
pFlags |
|
|
|
unread: flags |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -3336,22 +3331,22 @@ export class AppMessagesManager { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public handleUpdate(update: any) { |
|
|
|
public handleUpdate(update: Update) { |
|
|
|
this.log.debug('AMM: handleUpdate:', update._); |
|
|
|
this.log.debug('AMM: handleUpdate:', update._); |
|
|
|
switch(update._) { |
|
|
|
switch(update._) { |
|
|
|
case 'updateMessageID': { |
|
|
|
case 'updateMessageID': { |
|
|
|
var randomID = update.random_id; |
|
|
|
const randomID = update.random_id; |
|
|
|
var pendingData = this.pendingByRandomID[randomID]; |
|
|
|
const pendingData = this.pendingByRandomID[randomID]; |
|
|
|
//this.log('AMM updateMessageID:', update, pendingData);
|
|
|
|
//this.log('AMM updateMessageID:', update, pendingData);
|
|
|
|
if(pendingData) { |
|
|
|
if(pendingData) { |
|
|
|
var peerID: number = pendingData[0]; |
|
|
|
const peerID: number = pendingData[0]; |
|
|
|
var tempID = pendingData[1]; |
|
|
|
const tempID = pendingData[1]; |
|
|
|
var channelID = appPeersManager.isChannel(peerID) ? -peerID : 0; |
|
|
|
const channelID = appPeersManager.isChannel(peerID) ? -peerID : 0; |
|
|
|
var mid = appMessagesIDsManager.getFullMessageID(update.id, channelID); |
|
|
|
const mid = appMessagesIDsManager.getFullMessageID(update.id, channelID); |
|
|
|
var message = this.messagesStorage[mid]; |
|
|
|
const message = this.messagesStorage[mid]; |
|
|
|
if(message) { |
|
|
|
if(message) { |
|
|
|
var historyStorage = this.historiesStorage[peerID]; |
|
|
|
const historyStorage = this.historiesStorage[peerID]; |
|
|
|
var pos = historyStorage.pending.indexOf(tempID); |
|
|
|
const pos = historyStorage.pending.indexOf(tempID); |
|
|
|
if(pos != -1) { |
|
|
|
if(pos != -1) { |
|
|
|
historyStorage.pending.splice(pos, 1); |
|
|
|
historyStorage.pending.splice(pos, 1); |
|
|
|
} |
|
|
|
} |
|
|
@ -3367,10 +3362,9 @@ export class AppMessagesManager { |
|
|
|
|
|
|
|
|
|
|
|
case 'updateNewMessage': |
|
|
|
case 'updateNewMessage': |
|
|
|
case 'updateNewChannelMessage': { |
|
|
|
case 'updateNewChannelMessage': { |
|
|
|
var message = update.message; |
|
|
|
const message = update.message as MyMessage; |
|
|
|
var peerID = this.getMessagePeer(message); |
|
|
|
const peerID = this.getMessagePeer(message); |
|
|
|
var historyStorage = this.historiesStorage[peerID]; |
|
|
|
const foundDialog = this.getDialogByPeerID(peerID); |
|
|
|
let foundDialog = this.getDialogByPeerID(peerID); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!foundDialog.length) { |
|
|
|
if(!foundDialog.length) { |
|
|
|
this.newDialogsToHandle[peerID] = {reload: true}; |
|
|
|
this.newDialogsToHandle[peerID] = {reload: true}; |
|
|
@ -3383,7 +3377,7 @@ export class AppMessagesManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(update._ == 'updateNewChannelMessage') { |
|
|
|
if(update._ == 'updateNewChannelMessage') { |
|
|
|
var chat = appChatsManager.getChat(-peerID); |
|
|
|
const chat = appChatsManager.getChat(-peerID); |
|
|
|
if(chat.pFlags && (chat.pFlags.left || chat.pFlags.kicked)) { |
|
|
|
if(chat.pFlags && (chat.pFlags.left || chat.pFlags.kicked)) { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -3392,6 +3386,7 @@ export class AppMessagesManager { |
|
|
|
this.saveMessages([message]); |
|
|
|
this.saveMessages([message]); |
|
|
|
// this.log.warn(dT(), 'message unread', message.mid, message.pFlags.unread)
|
|
|
|
// this.log.warn(dT(), 'message unread', message.mid, message.pFlags.unread)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let historyStorage = this.historiesStorage[peerID]; |
|
|
|
if(historyStorage === undefined) { |
|
|
|
if(historyStorage === undefined) { |
|
|
|
historyStorage = this.historiesStorage[peerID] = { |
|
|
|
historyStorage = this.historiesStorage[peerID] = { |
|
|
|
count: null, |
|
|
|
count: null, |
|
|
@ -3400,11 +3395,11 @@ export class AppMessagesManager { |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var history = message.mid > 0 ? historyStorage.history : historyStorage.pending; |
|
|
|
const history = message.mid > 0 ? historyStorage.history : historyStorage.pending; |
|
|
|
if(history.indexOf(message.mid) != -1) { |
|
|
|
if(history.indexOf(message.mid) != -1) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
var topMsgID = history[0]; |
|
|
|
const topMsgID = history[0]; |
|
|
|
history.unshift(message.mid); |
|
|
|
history.unshift(message.mid); |
|
|
|
if(message.mid > 0 && message.mid < topMsgID) { |
|
|
|
if(message.mid > 0 && message.mid < topMsgID) { |
|
|
|
history.sort((a, b) => { |
|
|
|
history.sort((a, b) => { |
|
|
@ -3425,8 +3420,8 @@ export class AppMessagesManager { |
|
|
|
appUsersManager.forceUserOnline(appPeersManager.getPeerID(message.from_id)); |
|
|
|
appUsersManager.forceUserOnline(appPeersManager.getPeerID(message.from_id)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var randomID = this.pendingByMessageID[message.mid], |
|
|
|
const randomID = this.pendingByMessageID[message.mid]; |
|
|
|
pendingMessage; |
|
|
|
let pendingMessage: any; |
|
|
|
|
|
|
|
|
|
|
|
if(randomID) { |
|
|
|
if(randomID) { |
|
|
|
if(pendingMessage = this.finalizePendingMessage(randomID, message)) { |
|
|
|
if(pendingMessage = this.finalizePendingMessage(randomID, message)) { |
|
|
@ -3447,8 +3442,8 @@ export class AppMessagesManager { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var inboxUnread = !message.pFlags.out && message.pFlags.unread; |
|
|
|
const inboxUnread = !message.pFlags.out && message.pFlags.unread; |
|
|
|
var dialog = foundDialog[0]; |
|
|
|
const dialog = foundDialog[0]; |
|
|
|
dialog.top_message = message.mid; |
|
|
|
dialog.top_message = message.mid; |
|
|
|
if(inboxUnread) { |
|
|
|
if(inboxUnread) { |
|
|
|
dialog.unread_count++; |
|
|
|
dialog.unread_count++; |
|
|
@ -3465,14 +3460,14 @@ export class AppMessagesManager { |
|
|
|
|
|
|
|
|
|
|
|
case 'updateDialogUnreadMark': { |
|
|
|
case 'updateDialogUnreadMark': { |
|
|
|
this.log('updateDialogUnreadMark', update); |
|
|
|
this.log('updateDialogUnreadMark', update); |
|
|
|
let peerID = appPeersManager.getPeerID(update.peer.peer); |
|
|
|
const peerID = appPeersManager.getPeerID((update.peer as DialogPeer.dialogPeer).peer); |
|
|
|
let foundDialog = this.getDialogByPeerID(peerID); |
|
|
|
const foundDialog = this.getDialogByPeerID(peerID); |
|
|
|
|
|
|
|
|
|
|
|
if(!foundDialog.length) { |
|
|
|
if(!foundDialog.length) { |
|
|
|
this.newDialogsToHandle[peerID] = {reload: true}; |
|
|
|
this.newDialogsToHandle[peerID] = {reload: true}; |
|
|
|
this.scheduleHandleNewDialogs(); |
|
|
|
this.scheduleHandleNewDialogs(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
let dialog = foundDialog[0]; |
|
|
|
const dialog = foundDialog[0]; |
|
|
|
|
|
|
|
|
|
|
|
if(!update.pFlags.unread) { |
|
|
|
if(!update.pFlags.unread) { |
|
|
|
delete dialog.pFlags.unread_mark; |
|
|
|
delete dialog.pFlags.unread_mark; |
|
|
@ -3519,7 +3514,7 @@ export class AppMessagesManager { |
|
|
|
case 'updateDialogPinned': { |
|
|
|
case 'updateDialogPinned': { |
|
|
|
const folderID = update.folder_id ?? 0; |
|
|
|
const folderID = update.folder_id ?? 0; |
|
|
|
this.log('updateDialogPinned', update); |
|
|
|
this.log('updateDialogPinned', update); |
|
|
|
const peerID = appPeersManager.getPeerID(update.peer.peer); |
|
|
|
const peerID = appPeersManager.getPeerID((update.peer as DialogPeer.dialogPeer).peer); |
|
|
|
const foundDialog = this.getDialogByPeerID(peerID); |
|
|
|
const foundDialog = this.getDialogByPeerID(peerID); |
|
|
|
|
|
|
|
|
|
|
|
// этот код внизу никогда не сработает, в папках за пиннед отвечает updateDialogFilter
|
|
|
|
// этот код внизу никогда не сработает, в папках за пиннед отвечает updateDialogFilter
|
|
|
@ -3621,10 +3616,10 @@ export class AppMessagesManager { |
|
|
|
|
|
|
|
|
|
|
|
case 'updateEditMessage': |
|
|
|
case 'updateEditMessage': |
|
|
|
case 'updateEditChannelMessage': { |
|
|
|
case 'updateEditChannelMessage': { |
|
|
|
var message = update.message; |
|
|
|
const message = update.message as MyMessage; |
|
|
|
var peerID = this.getMessagePeer(message); |
|
|
|
const peerID = this.getMessagePeer(message); |
|
|
|
var channelID = message.peer_id._ == 'peerChannel' ? -peerID : 0; |
|
|
|
const channelID = message.peer_id._ == 'peerChannel' ? -peerID : 0; |
|
|
|
var mid = appMessagesIDsManager.getFullMessageID(message.id, channelID); |
|
|
|
const mid = appMessagesIDsManager.getFullMessageID(message.id, channelID); |
|
|
|
if(this.messagesStorage[mid] === undefined) { |
|
|
|
if(this.messagesStorage[mid] === undefined) { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -3633,8 +3628,9 @@ export class AppMessagesManager { |
|
|
|
this.saveMessages([message], {isEdited: true}); |
|
|
|
this.saveMessages([message], {isEdited: true}); |
|
|
|
safeReplaceObject(this.messagesStorage[mid], message); |
|
|
|
safeReplaceObject(this.messagesStorage[mid], message); |
|
|
|
|
|
|
|
|
|
|
|
var dialog = this.getDialogByPeerID(peerID)[0]; |
|
|
|
const dialog = this.getDialogByPeerID(peerID)[0]; |
|
|
|
var isTopMessage = dialog && dialog.top_message == mid; |
|
|
|
const isTopMessage = dialog && dialog.top_message == mid; |
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
if(message.clear_history) { // that's will never happen
|
|
|
|
if(message.clear_history) { // that's will never happen
|
|
|
|
if(isTopMessage) { |
|
|
|
if(isTopMessage) { |
|
|
|
$rootScope.$broadcast('dialog_flush', {peerID: peerID}); |
|
|
|
$rootScope.$broadcast('dialog_flush', {peerID: peerID}); |
|
|
@ -3648,7 +3644,7 @@ export class AppMessagesManager { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if(isTopMessage) { |
|
|
|
if(isTopMessage) { |
|
|
|
var updatedDialogs: {[peerID: number]: Dialog} = {}; |
|
|
|
const updatedDialogs: {[peerID: number]: Dialog} = {}; |
|
|
|
updatedDialogs[peerID] = dialog; |
|
|
|
updatedDialogs[peerID] = dialog; |
|
|
|
$rootScope.$broadcast('dialogs_multiupdate', updatedDialogs); |
|
|
|
$rootScope.$broadcast('dialogs_multiupdate', updatedDialogs); |
|
|
|
} |
|
|
|
} |
|
|
@ -3660,9 +3656,9 @@ export class AppMessagesManager { |
|
|
|
case 'updateReadHistoryOutbox': |
|
|
|
case 'updateReadHistoryOutbox': |
|
|
|
case 'updateReadChannelInbox': |
|
|
|
case 'updateReadChannelInbox': |
|
|
|
case 'updateReadChannelOutbox': { |
|
|
|
case 'updateReadChannelOutbox': { |
|
|
|
const channelID: number = update.channel_id; |
|
|
|
const channelID: number = (update as Update.updateReadChannelInbox).channel_id; |
|
|
|
const maxID = appMessagesIDsManager.getFullMessageID(update.max_id, channelID); |
|
|
|
const maxID = appMessagesIDsManager.getFullMessageID(update.max_id, channelID); |
|
|
|
const peerID = channelID ? -channelID : appPeersManager.getPeerID(update.peer); |
|
|
|
const peerID = channelID ? -channelID : appPeersManager.getPeerID((update as Update.updateReadHistoryInbox).peer); |
|
|
|
const isOut = update._ == 'updateReadHistoryOutbox' || update._ == 'updateReadChannelOutbox' ? true : undefined; |
|
|
|
const isOut = update._ == 'updateReadHistoryOutbox' || update._ == 'updateReadChannelOutbox' ? true : undefined; |
|
|
|
const foundDialog = this.getDialogByPeerID(peerID)[0]; |
|
|
|
const foundDialog = this.getDialogByPeerID(peerID)[0]; |
|
|
|
const history = getObjectKeysAndSort(this.messagesStorageByPeerID[peerID] || {}, 'desc'); |
|
|
|
const history = getObjectKeysAndSort(this.messagesStorageByPeerID[peerID] || {}, 'desc'); |
|
|
@ -3753,10 +3749,10 @@ export class AppMessagesManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
case 'updateChannelAvailableMessages': { |
|
|
|
case 'updateChannelAvailableMessages': { |
|
|
|
var channelID: number = update.channel_id; |
|
|
|
const channelID: number = update.channel_id; |
|
|
|
var messages: any[] = []; |
|
|
|
const messages: number[] = []; |
|
|
|
var peerID: number = -channelID; |
|
|
|
const peerID: number = -channelID; |
|
|
|
var history = (this.historiesStorage[peerID] || {}).history || []; |
|
|
|
const history = (this.historiesStorage[peerID] || {}).history || []; |
|
|
|
if(history.length) { |
|
|
|
if(history.length) { |
|
|
|
history.forEach((msgID: number) => { |
|
|
|
history.forEach((msgID: number) => { |
|
|
|
if(!update.available_min_id || |
|
|
|
if(!update.available_min_id || |
|
|
@ -3765,24 +3761,26 @@ export class AppMessagesManager { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
update.messages = messages; |
|
|
|
|
|
|
|
|
|
|
|
(update as any as Update.updateDeleteChannelMessages).messages = messages; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
case 'updateDeleteMessages': |
|
|
|
case 'updateDeleteMessages': |
|
|
|
case 'updateDeleteChannelMessages': { |
|
|
|
case 'updateDeleteChannelMessages': { |
|
|
|
let historiesUpdated: {[peerID: number]: {count: number, unread: number, msgs: {[mid: number]: true}}} = {}; |
|
|
|
const historiesUpdated: {[peerID: number]: {count: number, unread: number, msgs: {[mid: number]: true}}} = {}; |
|
|
|
let channelID: number = update.channel_id; |
|
|
|
const channelID: number = (update as Update.updateDeleteChannelMessages).channel_id; |
|
|
|
|
|
|
|
const messages = (update as any as Update.updateDeleteChannelMessages).messages; |
|
|
|
|
|
|
|
|
|
|
|
for(let i = 0; i < update.messages.length; i++) { |
|
|
|
for(let i = 0; i < messages.length; i++) { |
|
|
|
let messageID = appMessagesIDsManager.getFullMessageID(update.messages[i], channelID); |
|
|
|
const messageID = appMessagesIDsManager.getFullMessageID(messages[i], channelID); |
|
|
|
let message: MyMessage = this.messagesStorage[messageID]; |
|
|
|
const message: MyMessage = this.messagesStorage[messageID]; |
|
|
|
if(message) { |
|
|
|
if(message) { |
|
|
|
let peerID = this.getMessagePeer(message); |
|
|
|
const peerID = this.getMessagePeer(message); |
|
|
|
let history = historiesUpdated[peerID] || (historiesUpdated[peerID] = {count: 0, unread: 0, msgs: {}}); |
|
|
|
const history = historiesUpdated[peerID] || (historiesUpdated[peerID] = {count: 0, unread: 0, msgs: {}}); |
|
|
|
|
|
|
|
|
|
|
|
if((message as Message.message).media) { |
|
|
|
if((message as Message.message).media) { |
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
let c = message.media.webpage || message.media; |
|
|
|
const c = message.media.webpage || message.media; |
|
|
|
const smth = c.photo || c.document; |
|
|
|
const smth = c.photo || c.document; |
|
|
|
|
|
|
|
|
|
|
|
if(smth?.file_reference) { |
|
|
|
if(smth?.file_reference) { |
|
|
@ -3806,9 +3804,9 @@ export class AppMessagesManager { |
|
|
|
date: message.date |
|
|
|
date: message.date |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
let peerMessagesToHandle = this.newMessagesToHandle[peerID]; |
|
|
|
const peerMessagesToHandle = this.newMessagesToHandle[peerID]; |
|
|
|
if(peerMessagesToHandle && peerMessagesToHandle.length) { |
|
|
|
if(peerMessagesToHandle && peerMessagesToHandle.length) { |
|
|
|
let peerMessagesHandlePos = peerMessagesToHandle.indexOf(messageID); |
|
|
|
const peerMessagesHandlePos = peerMessagesToHandle.indexOf(messageID); |
|
|
|
if(peerMessagesHandlePos != -1) { |
|
|
|
if(peerMessagesHandlePos != -1) { |
|
|
|
peerMessagesToHandle.splice(peerMessagesHandlePos); |
|
|
|
peerMessagesToHandle.splice(peerMessagesHandlePos); |
|
|
|
} |
|
|
|
} |
|
|
@ -3818,11 +3816,11 @@ export class AppMessagesManager { |
|
|
|
|
|
|
|
|
|
|
|
Object.keys(historiesUpdated).forEach(_peerID => { |
|
|
|
Object.keys(historiesUpdated).forEach(_peerID => { |
|
|
|
const peerID = +_peerID; |
|
|
|
const peerID = +_peerID; |
|
|
|
let updatedData = historiesUpdated[peerID]; |
|
|
|
const updatedData = historiesUpdated[peerID]; |
|
|
|
let historyStorage = this.historiesStorage[peerID]; |
|
|
|
const historyStorage = this.historiesStorage[peerID]; |
|
|
|
if(historyStorage !== undefined) { |
|
|
|
if(historyStorage !== undefined) { |
|
|
|
let newHistory: number[] = []; |
|
|
|
const newHistory: number[] = []; |
|
|
|
let newPending: number[] = []; |
|
|
|
const newPending: number[] = []; |
|
|
|
for(let i = 0; i < historyStorage.history.length; i++) { |
|
|
|
for(let i = 0; i < historyStorage.history.length; i++) { |
|
|
|
if(!updatedData.msgs[historyStorage.history[i]]) { |
|
|
|
if(!updatedData.msgs[historyStorage.history[i]]) { |
|
|
|
newHistory.push(historyStorage.history[i]); |
|
|
|
newHistory.push(historyStorage.history[i]); |
|
|
@ -3838,9 +3836,9 @@ export class AppMessagesManager { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for(let i = 0; i < historyStorage.pending.length; i++) { |
|
|
|
for(const mid of historyStorage.pending) { |
|
|
|
if(!updatedData.msgs[historyStorage.pending[i]]) { |
|
|
|
if(!updatedData.msgs[mid]) { |
|
|
|
newPending.push(historyStorage.pending[i]); |
|
|
|
newPending.push(mid); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
historyStorage.pending = newPending; |
|
|
|
historyStorage.pending = newPending; |
|
|
@ -3848,7 +3846,7 @@ export class AppMessagesManager { |
|
|
|
$rootScope.$broadcast('history_delete', {peerID, msgs: updatedData.msgs}); |
|
|
|
$rootScope.$broadcast('history_delete', {peerID, msgs: updatedData.msgs}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let foundDialog = this.getDialogByPeerID(peerID)[0]; |
|
|
|
const foundDialog = this.getDialogByPeerID(peerID)[0]; |
|
|
|
if(foundDialog) { |
|
|
|
if(foundDialog) { |
|
|
|
if(updatedData.unread) { |
|
|
|
if(updatedData.unread) { |
|
|
|
foundDialog.unread_count -= updatedData.unread; |
|
|
|
foundDialog.unread_count -= updatedData.unread; |
|
|
@ -3899,7 +3897,9 @@ export class AppMessagesManager { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
case 'updateChannelReload': { |
|
|
|
case 'updateChannelReload': { |
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
const channelID: number = update.channel_id; |
|
|
|
const channelID: number = update.channel_id; |
|
|
|
const peerID = -channelID; |
|
|
|
const peerID = -channelID; |
|
|
|
|
|
|
|
|
|
|
@ -3914,9 +3914,9 @@ export class AppMessagesManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
case 'updateChannelMessageViews': { |
|
|
|
case 'updateChannelMessageViews': { |
|
|
|
let views = update.views; |
|
|
|
const views = update.views; |
|
|
|
let mid = appMessagesIDsManager.getFullMessageID(update.id, update.channel_id); |
|
|
|
const mid = appMessagesIDsManager.getFullMessageID(update.id, update.channel_id); |
|
|
|
let message = this.getMessage(mid); |
|
|
|
const message = this.getMessage(mid); |
|
|
|
if(message && message.views && message.views < views) { |
|
|
|
if(message && message.views && message.views < views) { |
|
|
|
message.views = views; |
|
|
|
message.views = views; |
|
|
|
$rootScope.$broadcast('message_views', {mid, views}); |
|
|
|
$rootScope.$broadcast('message_views', {mid, views}); |
|
|
@ -3926,10 +3926,10 @@ export class AppMessagesManager { |
|
|
|
|
|
|
|
|
|
|
|
case 'updateServiceNotification': { |
|
|
|
case 'updateServiceNotification': { |
|
|
|
this.log('updateServiceNotification', update); |
|
|
|
this.log('updateServiceNotification', update); |
|
|
|
var fromID = 777000; |
|
|
|
const fromID = 777000; |
|
|
|
var peerID = fromID; |
|
|
|
const peerID = fromID; |
|
|
|
var messageID = this.tempID--; |
|
|
|
const messageID = this.tempID--; |
|
|
|
var message: any = { |
|
|
|
const message: any = { |
|
|
|
_: 'message', |
|
|
|
_: 'message', |
|
|
|
id: messageID, |
|
|
|
id: messageID, |
|
|
|
from_id: appPeersManager.getOutputPeer(fromID), |
|
|
|
from_id: appPeersManager.getOutputPeer(fromID), |
|
|
@ -3957,19 +3957,18 @@ export class AppMessagesManager { |
|
|
|
this.handleUpdate({ |
|
|
|
this.handleUpdate({ |
|
|
|
_: 'updateNewMessage', |
|
|
|
_: 'updateNewMessage', |
|
|
|
message: message |
|
|
|
message: message |
|
|
|
}); |
|
|
|
} as any); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'updateChannelPinnedMessage': |
|
|
|
case 'updateChatPinnedMessage': |
|
|
|
case 'updateChatPinnedMessage': |
|
|
|
case 'updateUserPinnedMessage': { |
|
|
|
case 'updateUserPinnedMessage': { |
|
|
|
let {id} = update; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// hz nado li tut appMessagesIDsManager.getFullMessageID(update.max_id, channelID);
|
|
|
|
// hz nado li tut appMessagesIDsManager.getFullMessageID(update.max_id, channelID);
|
|
|
|
let peerID = update.user_id || -update.chat_id || -update.channel_id; |
|
|
|
const peerID = appPeersManager.getPeerID(update); |
|
|
|
this.savePinnedMessage(peerID, id); |
|
|
|
this.savePinnedMessage(peerID, update.id); |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|