@ -33,16 +33,18 @@ export type UserTyping = Partial<{userId: number, action: SendMessageAction, tim
@@ -33,16 +33,18 @@ export type UserTyping = Partial<{userId: number, action: SendMessageAction, tim
export class AppChatsManager {
private storage = appStateManager . storages . chats ;
private chats : { [ id : number ] : Chat . channel | Chat . chat | any } = { } ;
//private usernames: any = {} ;
//private channelAccess: any = {} ;
//private megagroups: {[id: number]: true} = {} ;
private chats : { [ id : number ] : Chat . channel | Chat . chat | any } ;
//private usernames: any;
//private channelAccess: any;
//private megagroups: {[id: number]: true};
private megagroupOnlines : { [ id : number ] : { timestamp : number , onlines : number } } = { } ;
private megagroupOnlines : { [ id : number ] : { timestamp : number , onlines : number } } ;
private typingsInPeer : { [ peerId : number ] : UserTyping [ ] } = { } ;
private typingsInPeer : { [ peerId : number ] : UserTyping [ ] } ;
constructor ( ) {
this . clear ( ) ;
rootScope . addMultipleEventsListeners ( {
/ * u p d a t e C h a n n e l : ( u p d a t e ) = > {
const channelId = update . channel_id ;
@ -102,6 +104,26 @@ export class AppChatsManager {
@@ -102,6 +104,26 @@ export class AppChatsManager {
} ) ;
}
public clear() {
if ( this . chats ) {
for ( const chatId in this . chats ) {
if ( ! appStateManager . isPeerNeeded ( - + chatId ) ) {
/ * c o n s t c h a t = t h i s . c h a t s [ c h a t I d ] ;
if ( chat . username ) {
delete this . usernames [ cleanUsername ( chat . username ) ] ;
} * /
delete this . chats [ chatId ] ;
}
}
} else {
this . chats = { } ;
}
this . megagroupOnlines = { } ;
this . typingsInPeer = { } ;
}
private onUpdateUserTyping = ( update : Update.updateUserTyping | Update . updateChatUserTyping | Update . updateChannelUserTyping ) = > {
const fromId = ( update as Update . updateUserTyping ) . user_id || appPeersManager . getPeerId ( ( update as Update . updateChatUserTyping ) . from_id ) ;
if ( rootScope . myId === fromId || update . action . _ === 'speakingInGroupCallAction' ) {