Browse Source

Fix user online after state

Fix fetch updates after reconnect
Fix dialog position due to top offset index
master
Eduard Kuzmenko 4 years ago
parent
commit
d1a5b22da1
  1. 11
      src/lib/appManagers/apiUpdatesManager.ts
  2. 32
      src/lib/appManagers/appDialogsManager.ts
  3. 4
      src/lib/appManagers/appMessagesManager.ts
  4. 16
      src/lib/appManagers/appUsersManager.ts

11
src/lib/appManagers/apiUpdatesManager.ts

@ -11,7 +11,7 @@ import appUsersManager from "./appUsersManager"; @@ -11,7 +11,7 @@ import appUsersManager from "./appUsersManager";
type UpdatesState = {
pendingPtsUpdates: any[],
pendingSeqUpdates: any,
pendingSeqUpdates?: any,
syncPending: {
seqAwaiting?: number,
ptsAwaiting?: true,
@ -36,7 +36,7 @@ export class ApiUpdatesManager { @@ -36,7 +36,7 @@ export class ApiUpdatesManager {
public channelStates: {[channelID: number]: UpdatesState} = {};
private attached = false;
private log = logger('UPDATES', LogLevels.error);
private log = logger('UPDATES', LogLevels.error/* | LogLevels.log */);
constructor() {
// * false for test purposes
@ -219,6 +219,8 @@ export class ApiUpdatesManager { @@ -219,6 +219,8 @@ export class ApiUpdatesManager {
}, {
timeout: 0x7fffffff
}).then((differenceResult) => {
this.log('Get diff result', differenceResult);
if(differenceResult._ == 'updates.differenceEmpty') {
this.log('apply empty diff', differenceResult.seq);
updatesState.date = differenceResult.date;
@ -299,14 +301,14 @@ export class ApiUpdatesManager { @@ -299,14 +301,14 @@ export class ApiUpdatesManager {
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', {
channel: appChatsManager.getChannelInput(channelID),
filter: {_: 'channelMessagesFilterEmpty'},
pts: channelState.pts,
limit: 30
}, {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;
if(differenceResult._ == 'updates.channelDifferenceEmpty') {
@ -367,7 +369,6 @@ export class ApiUpdatesManager { @@ -367,7 +369,6 @@ export class ApiUpdatesManager {
this.channelStates[channelID] = {
pts,
pendingPtsUpdates: [],
pendingSeqUpdates: null,
syncPending: null,
syncLoading: false
};

32
src/lib/appManagers/appDialogsManager.ts

@ -24,6 +24,7 @@ import { App, MOUNT_CLASS_TO } from "../mtproto/mtproto_config"; @@ -24,6 +24,7 @@ import { App, MOUNT_CLASS_TO } from "../mtproto/mtproto_config";
import Button from "../../components/button";
import SetTransition from "../../components/singleTransition";
import AppStorage from '../storage';
import apiUpdatesManager from "./apiUpdatesManager";
type DialogDom = {
avatarEl: AvatarElement,
@ -106,6 +107,10 @@ class ConnectionStatusComponent { @@ -106,6 +107,10 @@ class ConnectionStatusComponent {
const status = rootScope.connectionStatus['NET-' + baseDcID];
const online = status && status.online;
if(this.connecting && online) {
apiUpdatesManager.forceGetDifference();
}
this.connecting = !online;
this.log('connecting', this.connecting);
this.setState();
@ -194,7 +199,7 @@ export class AppDialogsManager { @@ -194,7 +199,7 @@ export class AppDialogsManager {
private accumulateArchivedTimeout: number;
private topOffsetIndex = 0;
//private topOffsetIndex = 0;
private sliceTimeout: number;
@ -472,6 +477,19 @@ export class AppDialogsManager { @@ -472,6 +477,19 @@ export class AppDialogsManager {
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) {
if(!dialog) {
return;
@ -499,7 +517,6 @@ export class AppDialogsManager { @@ -499,7 +517,6 @@ export class AppDialogsManager {
onTabChange = () => {
this.doms = {};
this.topOffsetIndex = 0;
this.scroll.loadedAll.top = true;
this.scroll.loadedAll.bottom = false;
this.lastActiveListElement = null;
@ -708,17 +725,6 @@ export class AppDialogsManager { @@ -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);
setTimeout(() => {

4
src/lib/appManagers/appMessagesManager.ts

@ -3193,7 +3193,7 @@ export class AppMessagesManager { @@ -3193,7 +3193,7 @@ export class AppMessagesManager {
}
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];
@ -3262,7 +3262,7 @@ export class AppMessagesManager { @@ -3262,7 +3262,7 @@ export class AppMessagesManager {
const peers = update.folder_peers;
this.scheduleHandleNewDialogs();
peers.forEach((folderPeer: any) => {
peers.forEach((folderPeer) => {
const {folder_id, peer} = folderPeer;
const peerID = appPeersManager.getPeerID(peer);

16
src/lib/appManagers/appUsersManager.ts

@ -9,6 +9,7 @@ import serverTimeManager from "../mtproto/serverTimeManager"; @@ -9,6 +9,7 @@ import serverTimeManager from "../mtproto/serverTimeManager";
import { RichTextProcessor } from "../richtextprocessor";
import rootScope from "../rootScope";
import searchIndexManager from "../searchIndexManager";
import apiUpdatesManager from "./apiUpdatesManager";
import appChatsManager from "./appChatsManager";
import appPeersManager from "./appPeersManager";
import appStateManager from "./appStateManager";
@ -63,6 +64,7 @@ export class AppUsersManager { @@ -63,6 +64,7 @@ export class AppUsersManager {
const user = this.users[userID];
if(user) {
this.forceUserOnline(userID);
if(!user.photo) {
user.photo = update.photo;
} else {
@ -460,11 +462,21 @@ export class AppUsersManager { @@ -460,11 +462,21 @@ export class AppUsersManager {
}
};
public forceUserOnline(id: number) {
public forceUserOnline(id: number, eventTimestamp?: number) {
if(this.isBot(id)) {
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);
if(user &&
user.status &&
@ -475,7 +487,7 @@ export class AppUsersManager { @@ -475,7 +487,7 @@ export class AppUsersManager {
user.status = {
_: 'userStatusOnline',
expires: tsNow(true) + 60
expires: timestamp + onlineTimeFor
};
user.sortStatus = this.getUserStatusForSort(user.status);

Loading…
Cancel
Save