1
This commit is contained in:
parent
6334af6014
commit
55c643529f
@ -19,6 +19,7 @@ import { ConnectionStatus } from "../lib/mtproto/connectionStatus";
|
|||||||
import cancelEvent from "../helpers/dom/cancelEvent";
|
import cancelEvent from "../helpers/dom/cancelEvent";
|
||||||
import apiManager from "../lib/mtproto/mtprotoworker";
|
import apiManager from "../lib/mtproto/mtprotoworker";
|
||||||
import { attachClickEvent } from "../helpers/dom/clickEvent";
|
import { attachClickEvent } from "../helpers/dom/clickEvent";
|
||||||
|
import { AppManagers } from "../lib/appManagers/managers";
|
||||||
|
|
||||||
export default class ConnectionStatusComponent {
|
export default class ConnectionStatusComponent {
|
||||||
public static CHANGE_STATE_DELAY = 1000;
|
public static CHANGE_STATE_DELAY = 1000;
|
||||||
@ -40,7 +41,7 @@ export default class ConnectionStatusComponent {
|
|||||||
private setFirstConnectionTimeout: number;
|
private setFirstConnectionTimeout: number;
|
||||||
private setStateTimeout: number;
|
private setStateTimeout: number;
|
||||||
|
|
||||||
constructor(private apiUpdatesManager: ApiUpdatesManager, chatsContainer: HTMLElement) {
|
constructor(private managers: AppManagers, chatsContainer: HTMLElement) {
|
||||||
this.log = logger('CS', undefined, undefined);
|
this.log = logger('CS', undefined, undefined);
|
||||||
|
|
||||||
this.statusContainer = document.createElement('div');
|
this.statusContainer = document.createElement('div');
|
||||||
@ -108,7 +109,7 @@ export default class ConnectionStatusComponent {
|
|||||||
const online = status && status.status === ConnectionStatus.Connected;
|
const online = status && status.status === ConnectionStatus.Connected;
|
||||||
|
|
||||||
if(this.connecting && online) {
|
if(this.connecting && online) {
|
||||||
this.apiUpdatesManager.forceGetDifference();
|
this.managers.apiUpdatesManager.forceGetDifference();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(online && !this.hadConnect) {
|
if(online && !this.hadConnect) {
|
||||||
|
@ -378,7 +378,7 @@ export class AppDialogsManager {
|
|||||||
this.changeFiltersAllChatsKey();
|
this.changeFiltersAllChatsKey();
|
||||||
});
|
});
|
||||||
|
|
||||||
new ConnectionStatusComponent(this.managers.apiUpdatesManager, this.chatsContainer);
|
new ConnectionStatusComponent(this.managers, this.chatsContainer);
|
||||||
this.chatsContainer.append(bottomPart);
|
this.chatsContainer.append(bottomPart);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -1574,25 +1574,22 @@ export class AppDialogsManager {
|
|||||||
bold.append(i18n('Draft'), ': ');
|
bold.append(i18n('Draft'), ': ');
|
||||||
dom.lastMessageSpan.prepend(bold);
|
dom.lastMessageSpan.prepend(bold);
|
||||||
} else if(peerId.isAnyChat() && peerId !== lastMessage.fromId && !lastMessage.action) {
|
} else if(peerId.isAnyChat() && peerId !== lastMessage.fromId && !lastMessage.action) {
|
||||||
const sender = this.managers.appPeersManager.getPeer(lastMessage.fromId);
|
const senderBold = document.createElement('b');
|
||||||
if(sender && sender.id) {
|
|
||||||
const senderBold = document.createElement('b');
|
|
||||||
|
|
||||||
if(sender.id === rootScope.myId) {
|
if(lastMessage.fromId === rootScope.myId) {
|
||||||
senderBold.append(i18n('FromYou'));
|
senderBold.append(i18n('FromYou'));
|
||||||
} else {
|
} else {
|
||||||
//str = sender.first_name || sender.last_name || sender.username;
|
//str = sender.first_name || sender.last_name || sender.username;
|
||||||
senderBold.append(new PeerTitle({
|
senderBold.append(new PeerTitle({
|
||||||
peerId: lastMessage.fromId,
|
peerId: lastMessage.fromId,
|
||||||
onlyFirstName: true,
|
onlyFirstName: true,
|
||||||
}).element);
|
}).element);
|
||||||
}
|
}
|
||||||
|
|
||||||
senderBold.append(': ');
|
senderBold.append(': ');
|
||||||
//console.log(sender, senderBold.innerText);
|
//console.log(sender, senderBold.innerText);
|
||||||
dom.lastMessageSpan.prepend(senderBold);
|
dom.lastMessageSpan.prepend(senderBold);
|
||||||
} //////// else console.log('no sender', lastMessage, peerId);
|
} //////// else console.log('no sender', lastMessage, peerId);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!lastMessage.deleted || draftMessage/* && lastMessage._ !== 'draftMessage' */) {
|
if(!lastMessage.deleted || draftMessage/* && lastMessage._ !== 'draftMessage' */) {
|
||||||
@ -1609,14 +1606,14 @@ export class AppDialogsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private setUnreadMessages(dialog: Dialog, dom = this.getDialogDom(dialog.peerId), isBatch = false) {
|
private async setUnreadMessages(dialog: Dialog, dom = this.getDialogDom(dialog.peerId), isBatch = false) {
|
||||||
if(!dom) {
|
if(!dom) {
|
||||||
//this.log.error('setUnreadMessages no dom!', dialog);
|
//this.log.error('setUnreadMessages no dom!', dialog);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isBatch) {
|
if(!isBatch) {
|
||||||
const isMuted = this.managers.appNotificationsManager.isPeerLocalMuted(dialog.peerId, true);
|
const isMuted = await this.managers.appNotificationsManager.isPeerLocalMuted(dialog.peerId, true);
|
||||||
const wasMuted = dom.listEl.classList.contains('is-muted');
|
const wasMuted = dom.listEl.classList.contains('is-muted');
|
||||||
if(isMuted !== wasMuted) {
|
if(isMuted !== wasMuted) {
|
||||||
SetTransition(dom.listEl, 'is-muted', isMuted, 200);
|
SetTransition(dom.listEl, 'is-muted', isMuted, 200);
|
||||||
@ -1625,7 +1622,7 @@ export class AppDialogsManager {
|
|||||||
|
|
||||||
let setStatusMessage: MyMessage;
|
let setStatusMessage: MyMessage;
|
||||||
if(dialog.draft?._ !== 'draftMessage') {
|
if(dialog.draft?._ !== 'draftMessage') {
|
||||||
const lastMessage: MyMessage = this.managers.appMessagesManager.getMessageByPeer(dialog.peerId, dialog.top_message);
|
const lastMessage: MyMessage = await this.managers.appMessagesManager.getMessageByPeer(dialog.peerId, dialog.top_message);
|
||||||
if(!lastMessage.deleted && lastMessage.pFlags.out && lastMessage.peerId !== rootScope.myId) {
|
if(!lastMessage.deleted && lastMessage.pFlags.out && lastMessage.peerId !== rootScope.myId) {
|
||||||
setStatusMessage = lastMessage;
|
setStatusMessage = lastMessage;
|
||||||
}
|
}
|
||||||
@ -1633,7 +1630,7 @@ export class AppDialogsManager {
|
|||||||
|
|
||||||
setSendingStatus(dom.statusSpan, setStatusMessage, true);
|
setSendingStatus(dom.statusSpan, setStatusMessage, true);
|
||||||
|
|
||||||
const filter = this.managers.appMessagesManager.filtersStorage.getFilter(this.filterId);
|
const filter = await this.managers.appMessagesManager.filtersStorage.getFilter(this.filterId);
|
||||||
let isPinned: boolean;
|
let isPinned: boolean;
|
||||||
if(filter) {
|
if(filter) {
|
||||||
isPinned = filter.pinnedPeerIds.indexOf(dialog.peerId) !== -1;
|
isPinned = filter.pinnedPeerIds.indexOf(dialog.peerId) !== -1;
|
||||||
@ -1641,7 +1638,7 @@ export class AppDialogsManager {
|
|||||||
isPinned = !!dialog.pFlags.pinned;
|
isPinned = !!dialog.pFlags.pinned;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isDialogUnread = this.managers.appMessagesManager.isDialogUnread(dialog);
|
const isDialogUnread = await this.managers.appMessagesManager.isDialogUnread(dialog);
|
||||||
const hasUnreadBadge = isPinned || isDialogUnread;
|
const hasUnreadBadge = isPinned || isDialogUnread;
|
||||||
// dom.messageEl.classList.toggle('has-badge', hasBadge);
|
// dom.messageEl.classList.toggle('has-badge', hasBadge);
|
||||||
|
|
||||||
@ -1707,16 +1704,16 @@ export class AppDialogsManager {
|
|||||||
return element?.dom;
|
return element?.dom;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getDialog(dialog: Dialog | PeerId): Dialog {
|
private async getDialog(dialog: Dialog | PeerId) {
|
||||||
if(typeof(dialog) !== 'object') {
|
if(typeof(dialog) !== 'object') {
|
||||||
const originalDialog = this.managers.appMessagesManager.getDialogOnly(dialog);
|
const originalDialog = await this.managers.appMessagesManager.getDialogOnly(dialog);
|
||||||
if(!originalDialog) {
|
if(!originalDialog) {
|
||||||
const peerId = dialog || NULL_PEER_ID;
|
const peerId = dialog || NULL_PEER_ID;
|
||||||
return {
|
return {
|
||||||
peerId,
|
peerId,
|
||||||
peer: this.managers.appPeersManager.getOutputPeer(peerId),
|
peer: await this.managers.appPeersManager.getOutputPeer(peerId),
|
||||||
pFlags: {}
|
pFlags: {}
|
||||||
} as any;
|
} as any as Dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
return originalDialog;
|
return originalDialog;
|
||||||
@ -1745,30 +1742,30 @@ export class AppDialogsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public addListDialog(options: Parameters<AppDialogsManager['addDialogNew']>[0] & {isBatch?: boolean}) {
|
public addListDialog(options: Parameters<AppDialogsManager['addDialogNew']>[0] & {isBatch?: boolean}) {
|
||||||
const dialog = this.getDialog(options.dialog);
|
|
||||||
|
|
||||||
options.autonomous = false;
|
options.autonomous = false;
|
||||||
|
|
||||||
const ret = this.addDialogNew(options);
|
const ret = this.addDialogNew(options);
|
||||||
|
|
||||||
if(ret) {
|
if(ret) {
|
||||||
const {peerId} = dialog;
|
this.getDialog(options.dialog).then(async(dialog) => {
|
||||||
const isMuted = this.managers.appNotificationsManager.isPeerLocalMuted(peerId, true);
|
const {peerId} = dialog;
|
||||||
if(isMuted) {
|
const isMuted = await this.managers.appNotificationsManager.isPeerLocalMuted(peerId, true);
|
||||||
ret.dom.listEl.classList.add('is-muted');
|
if(isMuted) {
|
||||||
}
|
ret.dom.listEl.classList.add('is-muted');
|
||||||
|
}
|
||||||
if(!peerId.isUser()) {
|
|
||||||
this.processDialogForCallStatus(dialog, ret.dom);
|
if(!peerId.isUser()) {
|
||||||
}
|
this.processDialogForCallStatus(dialog, ret.dom);
|
||||||
|
}
|
||||||
this.setLastMessage(dialog, undefined, ret.dom, undefined, options.loadPromises, options.isBatch, true);
|
|
||||||
|
this.setLastMessage(dialog, undefined, ret.dom, undefined, options.loadPromises, options.isBatch, true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private processDialogForCallStatus(dialog: Dialog, dom?: DialogDom) {
|
private async processDialogForCallStatus(dialog: Dialog, dom?: DialogDom) {
|
||||||
if(!IS_GROUP_CALL_SUPPORTED) {
|
if(!IS_GROUP_CALL_SUPPORTED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1776,23 +1773,23 @@ export class AppDialogsManager {
|
|||||||
if(!dom) dom = this.getDialogDom(dialog.peerId);
|
if(!dom) dom = this.getDialogDom(dialog.peerId);
|
||||||
if(!dom) return;
|
if(!dom) return;
|
||||||
|
|
||||||
const chat: Chat.chat | Chat.channel = this.managers.appChatsManager.getChat(dialog.peerId.toChatId());
|
const chat: Chat.chat | Chat.channel = await this.managers.appChatsManager.getChat(dialog.peerId.toChatId());
|
||||||
this.setCallStatus(dom, !!(chat.pFlags.call_active && chat.pFlags.call_not_empty));
|
this.setCallStatus(dom, !!(chat.pFlags.call_active && chat.pFlags.call_not_empty));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* use for rendering search result
|
* use for rendering search result
|
||||||
*/
|
*/
|
||||||
public addDialogAndSetLastMessage(options: Omit<Parameters<AppDialogsManager['addDialogNew']>[0], 'dialog'> & {
|
public async addDialogAndSetLastMessage(options: Omit<Parameters<AppDialogsManager['addDialogNew']>[0], 'dialog'> & {
|
||||||
message: MyMessage,
|
message: MyMessage,
|
||||||
peerId: PeerId,
|
peerId: PeerId,
|
||||||
query?: string
|
query?: string
|
||||||
}) {
|
}) {
|
||||||
const {peerId, message, query} = options;
|
const {peerId, message, query} = options;
|
||||||
const ret = this.addDialogNew({
|
const ret = await this.addDialogNew({
|
||||||
...options,
|
...options,
|
||||||
...getMessageSenderPeerIdOrName(message),
|
...getMessageSenderPeerIdOrName(message),
|
||||||
dialog: this.getDialog(peerId),
|
dialog: await this.getDialog(peerId),
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setLastMessage(ret.dialog, message, ret.dom, query);
|
this.setLastMessage(ret.dialog, message, ret.dom, query);
|
||||||
@ -1821,7 +1818,7 @@ export class AppDialogsManager {
|
|||||||
return this.addDialog(options.dialog, options.container, options.drawStatus, options.rippleEnabled, options.onlyFirstName, options.meAsSaved, options.append, options.avatarSize, options.autonomous, options.lazyLoadQueue, options.loadPromises, options.fromName);
|
return this.addDialog(options.dialog, options.container, options.drawStatus, options.rippleEnabled, options.onlyFirstName, options.meAsSaved, options.append, options.avatarSize, options.autonomous, options.lazyLoadQueue, options.loadPromises, options.fromName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public addDialog(
|
public async addDialog(
|
||||||
_dialog: Parameters<AppDialogsManager['getDialog']>[0],
|
_dialog: Parameters<AppDialogsManager['getDialog']>[0],
|
||||||
container?: HTMLElement | Scrollable | DocumentFragment | false,
|
container?: HTMLElement | Scrollable | DocumentFragment | false,
|
||||||
drawStatus = true,
|
drawStatus = true,
|
||||||
@ -1835,7 +1832,7 @@ export class AppDialogsManager {
|
|||||||
loadPromises?: Promise<any>[],
|
loadPromises?: Promise<any>[],
|
||||||
fromName?: string
|
fromName?: string
|
||||||
) {
|
) {
|
||||||
const dialog = this.getDialog(_dialog);
|
const dialog = await this.getDialog(_dialog);
|
||||||
const peerId = dialog.peerId;
|
const peerId = dialog.peerId;
|
||||||
|
|
||||||
const avatarEl = new AvatarElement();
|
const avatarEl = new AvatarElement();
|
||||||
@ -1849,7 +1846,7 @@ export class AppDialogsManager {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if(drawStatus && peerId !== rootScope.myId && peerId.isUser()) {
|
if(drawStatus && peerId !== rootScope.myId && peerId.isUser()) {
|
||||||
const user = this.managers.appUsersManager.getUser(peerId);
|
const user = await this.managers.appUsersManager.getUser(peerId);
|
||||||
if(user.status?._ === 'userStatusOnline') {
|
if(user.status?._ === 'userStatusOnline') {
|
||||||
this.setOnlineStatus(avatarEl, true);
|
this.setOnlineStatus(avatarEl, true);
|
||||||
}
|
}
|
||||||
|
@ -87,8 +87,8 @@ function createManagers() {
|
|||||||
proxied[name as keyof T] = createProxy(manager);
|
proxied[name as keyof T] = createProxy(manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
// return proxied/* as any as T */;
|
return proxied/* as any as T */;
|
||||||
return managers;
|
// return managers;
|
||||||
}
|
}
|
||||||
|
|
||||||
let managers: ReturnType<typeof createManagers>;
|
let managers: ReturnType<typeof createManagers>;
|
||||||
|
Loading…
Reference in New Issue
Block a user