Fix migrated peers
This commit is contained in:
parent
805b7bcf43
commit
6ce8a2619e
@ -4,6 +4,7 @@ import rootScope from "../lib/rootScope";
|
||||
import { attachClickEvent, cancelEvent } from "../helpers/dom";
|
||||
import AppMediaViewer, { AppMediaViewerAvatar } from "./appMediaViewer";
|
||||
import { Photo } from "../layer";
|
||||
import appPeersManager from "../lib/appManagers/appPeersManager";
|
||||
//import type { LazyLoadQueueIntersector } from "./lazyLoadQueue";
|
||||
|
||||
rootScope.on('avatar_update', (e) => {
|
||||
@ -126,7 +127,7 @@ export default class AvatarElement extends HTMLElement {
|
||||
return;
|
||||
}
|
||||
|
||||
this.peerId = +newValue;
|
||||
this.peerId = appPeersManager.getPeerMigratedTo(+newValue) || +newValue;
|
||||
this.update();
|
||||
} else if(name === 'peer-title') {
|
||||
this.peerTitle = newValue;
|
||||
|
@ -1403,7 +1403,7 @@ export default class ChatBubbles {
|
||||
}
|
||||
}
|
||||
|
||||
const isJump = lastMsgId !== topMessage && topMessage !== 0 && lastMsgId !== 0;
|
||||
const isJump = lastMsgId !== topMessage;
|
||||
|
||||
if(samePeer) {
|
||||
const mounted = this.getMountedBubble(lastMsgId);
|
||||
|
3
src/layer.d.ts
vendored
3
src/layer.d.ts
vendored
@ -592,7 +592,8 @@ export namespace Chat {
|
||||
version: number,
|
||||
migrated_to?: InputChannel,
|
||||
admin_rights?: ChatAdminRights,
|
||||
default_banned_rights?: ChatBannedRights
|
||||
default_banned_rights?: ChatBannedRights,
|
||||
rTitle?: string
|
||||
};
|
||||
|
||||
export type chatForbidden = {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { MOUNT_CLASS_TO } from "../../config/debug";
|
||||
import { numberThousandSplitter } from "../../helpers/number";
|
||||
import { isObject, safeReplaceObject, copy } from "../../helpers/object";
|
||||
import { ChatAdminRights, ChatBannedRights, ChatFull, ChatParticipants, InputChannel, InputChatPhoto, InputFile, InputPeer, SendMessageAction, Updates } from "../../layer";
|
||||
import { Chat, ChatAdminRights, ChatBannedRights, ChatFull, ChatParticipants, InputChannel, InputChatPhoto, InputFile, InputPeer, SendMessageAction, Updates } from "../../layer";
|
||||
import apiManager from '../mtproto/mtprotoworker';
|
||||
import { RichTextProcessor } from "../richtextprocessor";
|
||||
import rootScope from "../rootScope";
|
||||
@ -11,63 +11,14 @@ import appProfileManager from "./appProfileManager";
|
||||
import appStateManager from "./appStateManager";
|
||||
import appUsersManager from "./appUsersManager";
|
||||
|
||||
export type Channel = {
|
||||
_: 'channel',
|
||||
flags: number,
|
||||
pFlags: Partial<{
|
||||
creator: true,
|
||||
left: true,
|
||||
broadcast: true,
|
||||
verified: true,
|
||||
megagroup: true,
|
||||
restricted: true,
|
||||
signatures: true,
|
||||
min: true,
|
||||
scam: true,
|
||||
has_link: true,
|
||||
has_geo: true,
|
||||
slowmode_enabled: true
|
||||
}>,
|
||||
id: number,
|
||||
access_hash?: string,
|
||||
title: string,
|
||||
username?: string,
|
||||
photo: any,
|
||||
date: number,
|
||||
version: number,
|
||||
restriction_reason?: any,
|
||||
admin_rights?: any,
|
||||
banned_rights?: any,
|
||||
default_banned_rights?: any,
|
||||
participants_count: number
|
||||
};
|
||||
|
||||
export type Chat = {
|
||||
_: 'chat',
|
||||
flags: number,
|
||||
pFlags: Partial<{
|
||||
creator: true,
|
||||
kicked: true,
|
||||
left: true,
|
||||
deactivated: true
|
||||
}>,
|
||||
id: number,
|
||||
title: string,
|
||||
photo: any,
|
||||
participants_count: number,
|
||||
date: number,
|
||||
version: number,
|
||||
migrated_to?: any,
|
||||
admin_rights?: any,
|
||||
default_banned_rights?: any
|
||||
};
|
||||
export type Channel = Chat.channel;
|
||||
|
||||
export type ChatRights = 'send' | 'edit_title' | 'edit_photo' | 'invite' | 'pin' | 'deleteRevoke' | 'delete';
|
||||
|
||||
export type UserTyping = Partial<{userId: number, action: SendMessageAction, timeout: number}>;
|
||||
|
||||
export class AppChatsManager {
|
||||
public chats: {[id: number]: Channel | Chat | any} = {};
|
||||
public chats: {[id: number]: Chat.channel | Chat.chat | any} = {};
|
||||
//public usernames: any = {};
|
||||
//public channelAccess: any = {};
|
||||
//public megagroups: {[id: number]: true} = {};
|
||||
|
@ -22,7 +22,7 @@ import DialogsStorage from "../storages/dialogs";
|
||||
import FiltersStorage from "../storages/filters";
|
||||
//import { telegramMeWebService } from "../mtproto/mtproto";
|
||||
import apiUpdatesManager from "./apiUpdatesManager";
|
||||
import appChatsManager, { Channel } from "./appChatsManager";
|
||||
import appChatsManager from "./appChatsManager";
|
||||
import appDocsManager, { MyDocument } from "./appDocsManager";
|
||||
import appDownloadManager from "./appDownloadManager";
|
||||
import appPeersManager from "./appPeersManager";
|
||||
@ -2884,8 +2884,8 @@ export class AppMessagesManager {
|
||||
const wasDialogBefore = this.getDialogByPeerId(peerId)[0];
|
||||
|
||||
dialog.top_message = mid;
|
||||
dialog.read_inbox_max_id = wasDialogBefore && !dialog.read_inbox_max_id ? wasDialogBefore.read_inbox_max_id : this.generateMessageId(dialog.read_inbox_max_id);
|
||||
dialog.read_outbox_max_id = wasDialogBefore && !dialog.read_outbox_max_id ? wasDialogBefore.read_outbox_max_id : this.generateMessageId(dialog.read_outbox_max_id);
|
||||
dialog.read_inbox_max_id = this.generateMessageId(wasDialogBefore && !dialog.read_inbox_max_id ? wasDialogBefore.read_inbox_max_id : dialog.read_inbox_max_id);
|
||||
dialog.read_outbox_max_id = this.generateMessageId(wasDialogBefore && !dialog.read_outbox_max_id ? wasDialogBefore.read_outbox_max_id : dialog.read_outbox_max_id);
|
||||
|
||||
if(!dialog.hasOwnProperty('folder_id')) {
|
||||
if(dialog._ === 'dialog') {
|
||||
@ -4573,16 +4573,15 @@ export class AppMessagesManager {
|
||||
}
|
||||
|
||||
public getHistory(peerId: number, maxId = 0, limit: number, backLimit?: number, threadId?: number): Promise<HistoryResult> | HistoryResult {
|
||||
if(this.migratedFromTo[peerId]) {
|
||||
/* if(this.migratedFromTo[peerId]) {
|
||||
peerId = this.migratedFromTo[peerId];
|
||||
}
|
||||
} */
|
||||
|
||||
const historyStorage = this.getHistoryStorage(peerId, threadId);
|
||||
|
||||
let offset = 0;
|
||||
let offsetNotFound = false;
|
||||
|
||||
const isMigrated = !!this.migratedToFrom[peerId];
|
||||
const reqPeerId = peerId;
|
||||
|
||||
if(maxId) {
|
||||
@ -4626,9 +4625,9 @@ export class AppMessagesManager {
|
||||
|
||||
return this.requestHistory(reqPeerId, maxId, limit, offset, undefined, threadId).then((historyResult) => {
|
||||
historyStorage.count = (historyResult as MessagesMessages.messagesMessagesSlice).count || historyResult.messages.length;
|
||||
if(isMigrated) {
|
||||
/* if(!!this.migratedToFrom[peerId]) {
|
||||
historyStorage.count++;
|
||||
}
|
||||
} */
|
||||
|
||||
const history = (historyResult.messages as MyMessage[]).map(message => message.mid);
|
||||
return {
|
||||
@ -4660,7 +4659,8 @@ export class AppMessagesManager {
|
||||
|
||||
public fillHistoryStorage(peerId: number, maxId: number, fullLimit: number, historyStorage: HistoryStorage, threadId?: number): Promise<boolean> {
|
||||
// this.log('fill history storage', peerId, maxId, fullLimit, angular.copy(historyStorage))
|
||||
const offset = (this.migratedFromTo[peerId] && !maxId) ? 1 : 0;
|
||||
//const offset = (this.migratedFromTo[peerId] && !maxId) ? 1 : 0;
|
||||
const offset = 0;
|
||||
return this.requestHistory(peerId, maxId, fullLimit, offset, undefined, threadId).then((historyResult) => {
|
||||
historyStorage.count = (historyResult as MessagesMessages.messagesMessagesSlice).count || historyResult.messages.length;
|
||||
|
||||
@ -4691,17 +4691,17 @@ export class AppMessagesManager {
|
||||
const totalCount = historyStorage.history.length;
|
||||
fullLimit -= (totalCount - wasTotalCount);
|
||||
|
||||
const migratedNextPeer = this.migratedFromTo[peerId];
|
||||
/* const migratedNextPeer = this.migratedFromTo[peerId];
|
||||
const migratedPrevPeer = this.migratedToFrom[peerId]
|
||||
const isMigrated = migratedNextPeer !== undefined || migratedPrevPeer !== undefined;
|
||||
|
||||
if(isMigrated) {
|
||||
historyStorage.count = Math.max(historyStorage.count, totalCount) + 1;
|
||||
}
|
||||
} */
|
||||
|
||||
if(fullLimit > 0) {
|
||||
maxId = historyStorage.history[totalCount - 1];
|
||||
if(isMigrated) {
|
||||
/* if(isMigrated) {
|
||||
if(!historyResult.messages.length) {
|
||||
if(migratedPrevPeer) {
|
||||
maxId = 0;
|
||||
@ -4713,7 +4713,7 @@ export class AppMessagesManager {
|
||||
}
|
||||
|
||||
return this.fillHistoryStorage(peerId, maxId, fullLimit, historyStorage, threadId);
|
||||
} else if(totalCount < historyStorage.count) {
|
||||
} else */if(totalCount < historyStorage.count) {
|
||||
return this.fillHistoryStorage(peerId, maxId, fullLimit, historyStorage, threadId);
|
||||
}
|
||||
}
|
||||
|
@ -139,4 +139,9 @@
|
||||
{"name": "rReply", "type": "string"},
|
||||
{"name": "rMessage", "type": "string"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "chat",
|
||||
"params": [
|
||||
{"name": "rTitle", "type": "string"}
|
||||
]
|
||||
}]
|
Loading…
Reference in New Issue
Block a user