From ff6174a4ea4e4a9f154ca639e5d237ed5f36d201 Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Fri, 20 Aug 2021 11:56:23 +0300 Subject: [PATCH] Send when online --- src/components/chat/bubbles.ts | 13 +++++++------ src/components/popups/schedule.ts | 32 +++++++++++++++++++++++-------- src/lang.ts | 4 ++-- src/lib/mtproto/constants.ts | 1 + 4 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 src/lib/mtproto/constants.ts diff --git a/src/components/chat/bubbles.ts b/src/components/chat/bubbles.ts index a2bf01a9..b964e0b0 100644 --- a/src/components/chat/bubbles.ts +++ b/src/components/chat/bubbles.ts @@ -73,6 +73,7 @@ import assumeType from "../../helpers/assumeType"; import { EmoticonsDropdown } from "../emoticonsDropdown"; import debounce from "../../helpers/schedulers/debounce"; import { formatNumber } from "../../helpers/number"; +import { SEND_WHEN_ONLINE_TIMESTAMP } from "../../lib/mtproto/constants"; const USE_MEDIA_TAILS = false; const IGNORE_ACTIONS: Set = new Set([ @@ -1509,9 +1510,13 @@ export default class ChatBubbles { const today = new Date(); today.setHours(0, 0, 0, 0); + + const isScheduled = this.chat.type === 'scheduled'; if(today.getTime() === date.getTime()) { - dateElement = i18n(this.chat.type === 'scheduled' ? 'Chat.Date.ScheduledForToday' : 'Date.Today'); + dateElement = i18n(isScheduled ? 'Chat.Date.ScheduledForToday' : 'Date.Today'); + } else if(isScheduled && message.date === SEND_WHEN_ONLINE_TIMESTAMP) { + dateElement = i18n('MessageScheduledUntilOnline'); } else { const options: Intl.DateTimeFormatOptions = { day: 'numeric', @@ -1527,14 +1532,10 @@ export default class ChatBubbles { options }).element; - if(this.chat.type === 'scheduled') { + if(isScheduled) { dateElement = i18n('Chat.Date.ScheduledFor', [dateElement]); } } - - /* if(this.chat.type === 'scheduled') { - str = 'Scheduled for ' + str; - } */ const div = document.createElement('div'); div.className = 'bubble service is-date'; diff --git a/src/components/popups/schedule.ts b/src/components/popups/schedule.ts index 07f049fa..acce71cd 100644 --- a/src/components/popups/schedule.ts +++ b/src/components/popups/schedule.ts @@ -4,6 +4,9 @@ * https://github.com/morethanwords/tweb/blob/master/LICENSE */ +import { attachClickEvent } from "../../helpers/dom/clickEvent"; +import { SEND_WHEN_ONLINE_TIMESTAMP } from "../../lib/mtproto/constants"; +import Button from "../button"; import PopupDatePicker from "./datePicker"; const getMinDate = () => { @@ -13,20 +16,26 @@ const getMinDate = () => { return date; }; +const getMaxDate = () => { + const date = new Date(); + date.setFullYear(date.getFullYear() + 1); + date.setDate(date.getDate() - 1); + return date; +}; + +const checkDate = (date: Date) => { + return date.getTime() > getMaxDate().getTime() ? new Date() : date; +}; + export default class PopupSchedule extends PopupDatePicker { constructor(initDate: Date, onPick: (timestamp: number) => void) { - super(initDate, onPick, { + super(checkDate(initDate), onPick, { noButtons: true, noTitle: true, closable: true, withConfirm: true, minDate: getMinDate(), - maxDate: (() => { - const date = new Date(); - date.setFullYear(date.getFullYear() + 1); - date.setDate(date.getDate() - 1); - return date; - })(), + maxDate: getMaxDate(), withTime: true, showOverflowMonths: true }); @@ -34,6 +43,13 @@ 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); + + attachClickEvent(btnSendWhenOnline, () => { + onPick(SEND_WHEN_ONLINE_TIMESTAMP); + this.hide(); + }); } } diff --git a/src/lang.ts b/src/lang.ts index 3fa0ee93..b959ad68 100644 --- a/src/lang.ts +++ b/src/lang.ts @@ -548,6 +548,7 @@ const lang = { "LinkNotFound": "Unfortunately, you can\'t access this message. You are not a member of the chat where it was posted.", "Create": "Create", "ViewDiscussion": "View discussion", + "MessageScheduledUntilOnline": "Scheduled until online", // * macos "AccountSettings.Filters": "Chat Folders", @@ -562,7 +563,6 @@ const lang = { "Chat.CopySelectedText": "Copy Selected Text", "Chat.Confirm.Unpin": "Would you like to unpin this message?", "Chat.Date.ScheduledFor": "Scheduled for %@", - //"Chat.Date.ScheduledUntilOnline": "Scheduled until online", "Chat.Date.ScheduledForToday": "Scheduled for today", "Chat.DropTitle": "Drop files here to send them", "Chat.DropQuickDesc": "in a quick way", @@ -791,7 +791,7 @@ const lang = { "ScheduleController.at": "at", "Schedule.SendToday": "Send today at %@", "Schedule.SendDate": "Send on %@ at %@", - //"Schedule.SendWhenOnline": "Send When Online", + "Schedule.SendWhenOnline": "Send When Online", "Stickers.Recent": "Recent", //"Stickers.Favorite": "Favorite", "Text.Context.Copy.Username": "Copy Username", diff --git a/src/lib/mtproto/constants.ts b/src/lib/mtproto/constants.ts new file mode 100644 index 00000000..e9e4a161 --- /dev/null +++ b/src/lib/mtproto/constants.ts @@ -0,0 +1 @@ +export const SEND_WHEN_ONLINE_TIMESTAMP = 0x7FFFFFFE;