Fix user online after state
Fix fetch updates after reconnect Fix dialog position due to top offset index
This commit is contained in:
parent
55047b6687
commit
d1a5b22da1
@ -11,7 +11,7 @@ import appUsersManager from "./appUsersManager";
|
|||||||
|
|
||||||
type UpdatesState = {
|
type UpdatesState = {
|
||||||
pendingPtsUpdates: any[],
|
pendingPtsUpdates: any[],
|
||||||
pendingSeqUpdates: any,
|
pendingSeqUpdates?: any,
|
||||||
syncPending: {
|
syncPending: {
|
||||||
seqAwaiting?: number,
|
seqAwaiting?: number,
|
||||||
ptsAwaiting?: true,
|
ptsAwaiting?: true,
|
||||||
@ -36,7 +36,7 @@ export class ApiUpdatesManager {
|
|||||||
public channelStates: {[channelID: number]: UpdatesState} = {};
|
public channelStates: {[channelID: number]: UpdatesState} = {};
|
||||||
private attached = false;
|
private attached = false;
|
||||||
|
|
||||||
private log = logger('UPDATES', LogLevels.error);
|
private log = logger('UPDATES', LogLevels.error/* | LogLevels.log */);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// * false for test purposes
|
// * false for test purposes
|
||||||
@ -219,6 +219,8 @@ export class ApiUpdatesManager {
|
|||||||
}, {
|
}, {
|
||||||
timeout: 0x7fffffff
|
timeout: 0x7fffffff
|
||||||
}).then((differenceResult) => {
|
}).then((differenceResult) => {
|
||||||
|
this.log('Get diff result', differenceResult);
|
||||||
|
|
||||||
if(differenceResult._ == 'updates.differenceEmpty') {
|
if(differenceResult._ == 'updates.differenceEmpty') {
|
||||||
this.log('apply empty diff', differenceResult.seq);
|
this.log('apply empty diff', differenceResult.seq);
|
||||||
updatesState.date = differenceResult.date;
|
updatesState.date = differenceResult.date;
|
||||||
@ -299,14 +301,14 @@ export class ApiUpdatesManager {
|
|||||||
channelState.syncPending = null;
|
channelState.syncPending = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.log('Get channel diff', appChatsManager.getChat(channelID), channelState.pts)
|
//this.log.trace('Get channel diff', appChatsManager.getChat(channelID), channelState.pts);
|
||||||
apiManager.invokeApi('updates.getChannelDifference', {
|
apiManager.invokeApi('updates.getChannelDifference', {
|
||||||
channel: appChatsManager.getChannelInput(channelID),
|
channel: appChatsManager.getChannelInput(channelID),
|
||||||
filter: {_: 'channelMessagesFilterEmpty'},
|
filter: {_: 'channelMessagesFilterEmpty'},
|
||||||
pts: channelState.pts,
|
pts: channelState.pts,
|
||||||
limit: 30
|
limit: 30
|
||||||
}, {timeout: 0x7fffffff}).then((differenceResult) => {
|
}, {timeout: 0x7fffffff}).then((differenceResult) => {
|
||||||
// this.log('channel diff result', differenceResult)
|
this.log('Get channel diff result', differenceResult)
|
||||||
channelState.pts = 'pts' in differenceResult ? differenceResult.pts : undefined;
|
channelState.pts = 'pts' in differenceResult ? differenceResult.pts : undefined;
|
||||||
|
|
||||||
if(differenceResult._ == 'updates.channelDifferenceEmpty') {
|
if(differenceResult._ == 'updates.channelDifferenceEmpty') {
|
||||||
@ -367,7 +369,6 @@ export class ApiUpdatesManager {
|
|||||||
this.channelStates[channelID] = {
|
this.channelStates[channelID] = {
|
||||||
pts,
|
pts,
|
||||||
pendingPtsUpdates: [],
|
pendingPtsUpdates: [],
|
||||||
pendingSeqUpdates: null,
|
|
||||||
syncPending: null,
|
syncPending: null,
|
||||||
syncLoading: false
|
syncLoading: false
|
||||||
};
|
};
|
||||||
|
@ -24,6 +24,7 @@ import { App, MOUNT_CLASS_TO } from "../mtproto/mtproto_config";
|
|||||||
import Button from "../../components/button";
|
import Button from "../../components/button";
|
||||||
import SetTransition from "../../components/singleTransition";
|
import SetTransition from "../../components/singleTransition";
|
||||||
import AppStorage from '../storage';
|
import AppStorage from '../storage';
|
||||||
|
import apiUpdatesManager from "./apiUpdatesManager";
|
||||||
|
|
||||||
type DialogDom = {
|
type DialogDom = {
|
||||||
avatarEl: AvatarElement,
|
avatarEl: AvatarElement,
|
||||||
@ -106,6 +107,10 @@ class ConnectionStatusComponent {
|
|||||||
const status = rootScope.connectionStatus['NET-' + baseDcID];
|
const status = rootScope.connectionStatus['NET-' + baseDcID];
|
||||||
const online = status && status.online;
|
const online = status && status.online;
|
||||||
|
|
||||||
|
if(this.connecting && online) {
|
||||||
|
apiUpdatesManager.forceGetDifference();
|
||||||
|
}
|
||||||
|
|
||||||
this.connecting = !online;
|
this.connecting = !online;
|
||||||
this.log('connecting', this.connecting);
|
this.log('connecting', this.connecting);
|
||||||
this.setState();
|
this.setState();
|
||||||
@ -194,7 +199,7 @@ export class AppDialogsManager {
|
|||||||
|
|
||||||
private accumulateArchivedTimeout: number;
|
private accumulateArchivedTimeout: number;
|
||||||
|
|
||||||
private topOffsetIndex = 0;
|
//private topOffsetIndex = 0;
|
||||||
|
|
||||||
private sliceTimeout: number;
|
private sliceTimeout: number;
|
||||||
|
|
||||||
@ -472,6 +477,19 @@ export class AppDialogsManager {
|
|||||||
mutationObserver.observe */
|
mutationObserver.observe */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get topOffsetIndex() {
|
||||||
|
if(!this.scroll.loadedAll['top']) {
|
||||||
|
const element = this.chatList.firstElementChild;
|
||||||
|
if(element) {
|
||||||
|
const peerID = +element.getAttribute('data-peerID');
|
||||||
|
const dialog = appMessagesManager.getDialogByPeerID(peerID)[0];
|
||||||
|
return dialog.index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
private updateDialog(dialog: Dialog) {
|
private updateDialog(dialog: Dialog) {
|
||||||
if(!dialog) {
|
if(!dialog) {
|
||||||
return;
|
return;
|
||||||
@ -499,7 +517,6 @@ export class AppDialogsManager {
|
|||||||
|
|
||||||
onTabChange = () => {
|
onTabChange = () => {
|
||||||
this.doms = {};
|
this.doms = {};
|
||||||
this.topOffsetIndex = 0;
|
|
||||||
this.scroll.loadedAll.top = true;
|
this.scroll.loadedAll.top = true;
|
||||||
this.scroll.loadedAll.bottom = false;
|
this.scroll.loadedAll.bottom = false;
|
||||||
this.lastActiveListElement = null;
|
this.lastActiveListElement = null;
|
||||||
@ -708,17 +725,6 @@ export class AppDialogsManager {
|
|||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.scroll.loadedAll['top']) {
|
|
||||||
const element = this.chatList.firstElementChild;
|
|
||||||
if(element) {
|
|
||||||
const peerID = +element.getAttribute('data-peerID');
|
|
||||||
const dialog = appMessagesManager.getDialogByPeerID(peerID)[0];
|
|
||||||
this.topOffsetIndex = dialog.index;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.topOffsetIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.log.debug('getDialogs ' + loadCount + ' dialogs by offset:', offsetIndex, result, this.chatList.childElementCount);
|
this.log.debug('getDialogs ' + loadCount + ' dialogs by offset:', offsetIndex, result, this.chatList.childElementCount);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@ -3193,7 +3193,7 @@ export class AppMessagesManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!message.pFlags.out && message.from_id) {
|
if(!message.pFlags.out && message.from_id) {
|
||||||
appUsersManager.forceUserOnline(appPeersManager.getPeerID(message.from_id));
|
appUsersManager.forceUserOnline(appPeersManager.getPeerID(message.from_id), message.date);
|
||||||
}
|
}
|
||||||
|
|
||||||
const randomID = this.pendingByMessageID[message.mid];
|
const randomID = this.pendingByMessageID[message.mid];
|
||||||
@ -3262,7 +3262,7 @@ export class AppMessagesManager {
|
|||||||
const peers = update.folder_peers;
|
const peers = update.folder_peers;
|
||||||
|
|
||||||
this.scheduleHandleNewDialogs();
|
this.scheduleHandleNewDialogs();
|
||||||
peers.forEach((folderPeer: any) => {
|
peers.forEach((folderPeer) => {
|
||||||
const {folder_id, peer} = folderPeer;
|
const {folder_id, peer} = folderPeer;
|
||||||
|
|
||||||
const peerID = appPeersManager.getPeerID(peer);
|
const peerID = appPeersManager.getPeerID(peer);
|
||||||
|
@ -9,6 +9,7 @@ import serverTimeManager from "../mtproto/serverTimeManager";
|
|||||||
import { RichTextProcessor } from "../richtextprocessor";
|
import { RichTextProcessor } from "../richtextprocessor";
|
||||||
import rootScope from "../rootScope";
|
import rootScope from "../rootScope";
|
||||||
import searchIndexManager from "../searchIndexManager";
|
import searchIndexManager from "../searchIndexManager";
|
||||||
|
import apiUpdatesManager from "./apiUpdatesManager";
|
||||||
import appChatsManager from "./appChatsManager";
|
import appChatsManager from "./appChatsManager";
|
||||||
import appPeersManager from "./appPeersManager";
|
import appPeersManager from "./appPeersManager";
|
||||||
import appStateManager from "./appStateManager";
|
import appStateManager from "./appStateManager";
|
||||||
@ -63,6 +64,7 @@ export class AppUsersManager {
|
|||||||
const user = this.users[userID];
|
const user = this.users[userID];
|
||||||
if(user) {
|
if(user) {
|
||||||
this.forceUserOnline(userID);
|
this.forceUserOnline(userID);
|
||||||
|
|
||||||
if(!user.photo) {
|
if(!user.photo) {
|
||||||
user.photo = update.photo;
|
user.photo = update.photo;
|
||||||
} else {
|
} else {
|
||||||
@ -460,11 +462,21 @@ export class AppUsersManager {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public forceUserOnline(id: number) {
|
public forceUserOnline(id: number, eventTimestamp?: number) {
|
||||||
if(this.isBot(id)) {
|
if(this.isBot(id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const timestamp = tsNow(true);
|
||||||
|
const onlineTimeFor = 60;
|
||||||
|
if(eventTimestamp) {
|
||||||
|
if((timestamp - eventTimestamp) >= onlineTimeFor) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if(apiUpdatesManager.updatesState.syncLoading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const user = this.getUser(id);
|
const user = this.getUser(id);
|
||||||
if(user &&
|
if(user &&
|
||||||
user.status &&
|
user.status &&
|
||||||
@ -475,7 +487,7 @@ export class AppUsersManager {
|
|||||||
|
|
||||||
user.status = {
|
user.status = {
|
||||||
_: 'userStatusOnline',
|
_: 'userStatusOnline',
|
||||||
expires: tsNow(true) + 60
|
expires: timestamp + onlineTimeFor
|
||||||
};
|
};
|
||||||
|
|
||||||
user.sortStatus = this.getUserStatusForSort(user.status);
|
user.sortStatus = this.getUserStatusForSort(user.status);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user