From 4c90cfb97a8de0ac10f43bc2e5aa09898f0f4aca Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Fri, 20 Aug 2021 17:12:35 +0300 Subject: [PATCH] Don't show send when online if user hid his online --- src/components/chat/input.ts | 4 +++- src/components/popups/schedule.ts | 17 ++++++++++------- src/lib/appManagers/appUsersManager.ts | 4 ++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/components/chat/input.ts b/src/components/chat/input.ts index 87f985f8..d8193c3a 100644 --- a/src/components/chat/input.ts +++ b/src/components/chat/input.ts @@ -654,6 +654,8 @@ export default class ChatInput { } public scheduleSending = (callback: () => void = this.sendMessage.bind(this, true), initDate = new Date()) => { + const canSendWhenOnline = this.chat.peerId > 0 && this.appUsersManager.isUserOnlineVisible(this.chat.peerId); + new PopupSchedule(initDate, (timestamp) => { const minTimestamp = (Date.now() / 1000 | 0) + 10; if(timestamp <= minTimestamp) { @@ -666,7 +668,7 @@ export default class ChatInput { if(this.chat.type !== 'scheduled' && timestamp) { this.appImManager.openScheduled(this.chat.peerId); } - }).show(); + }, canSendWhenOnline).show(); }; public setUnreadCount() { diff --git a/src/components/popups/schedule.ts b/src/components/popups/schedule.ts index acce71cd..5703fc15 100644 --- a/src/components/popups/schedule.ts +++ b/src/components/popups/schedule.ts @@ -28,7 +28,7 @@ const checkDate = (date: Date) => { }; export default class PopupSchedule extends PopupDatePicker { - constructor(initDate: Date, onPick: (timestamp: number) => void) { + constructor(initDate: Date, onPick: (timestamp: number) => void, canSendWhenOnline: boolean) { super(checkDate(initDate), onPick, { noButtons: true, noTitle: true, @@ -43,13 +43,16 @@ export default class PopupSchedule extends PopupDatePicker { this.element.classList.add('popup-schedule'); this.header.append(this.controlsDiv); this.title.replaceWith(this.monthTitle); + this.body.append(this.btnConfirm); - const btnSendWhenOnline = Button('btn-primary btn-secondary btn-primary-transparent primary', {text: 'Schedule.SendWhenOnline'}); - this.body.append(this.btnConfirm, btnSendWhenOnline); + if(canSendWhenOnline) { + const btnSendWhenOnline = Button('btn-primary btn-secondary btn-primary-transparent primary', {text: 'Schedule.SendWhenOnline'}); + this.body.append(btnSendWhenOnline); - attachClickEvent(btnSendWhenOnline, () => { - onPick(SEND_WHEN_ONLINE_TIMESTAMP); - this.hide(); - }); + attachClickEvent(btnSendWhenOnline, () => { + onPick(SEND_WHEN_ONLINE_TIMESTAMP); + this.hide(); + }); + } } } diff --git a/src/lib/appManagers/appUsersManager.ts b/src/lib/appManagers/appUsersManager.ts index 1a0513ce..c279d635 100644 --- a/src/lib/appManagers/appUsersManager.ts +++ b/src/lib/appManagers/appUsersManager.ts @@ -427,6 +427,10 @@ export class AppUsersManager { return '+' + formatPhoneNumber(phone).formatted; } + public isUserOnlineVisible(id: number) { + return this.getUserStatusForSort(id) > 3; + } + public getUserStatusForSort(status: User['status'] | number) { if(typeof(status) === 'number') { status = this.getUser(status).status;