Browse Source

Send when online

master
Eduard Kuzmenko 3 years ago
parent
commit
ff6174a4ea
  1. 13
      src/components/chat/bubbles.ts
  2. 32
      src/components/popups/schedule.ts
  3. 4
      src/lang.ts
  4. 1
      src/lib/mtproto/constants.ts

13
src/components/chat/bubbles.ts

@ -73,6 +73,7 @@ import assumeType from "../../helpers/assumeType";
import { EmoticonsDropdown } from "../emoticonsDropdown"; import { EmoticonsDropdown } from "../emoticonsDropdown";
import debounce from "../../helpers/schedulers/debounce"; import debounce from "../../helpers/schedulers/debounce";
import { formatNumber } from "../../helpers/number"; import { formatNumber } from "../../helpers/number";
import { SEND_WHEN_ONLINE_TIMESTAMP } from "../../lib/mtproto/constants";
const USE_MEDIA_TAILS = false; const USE_MEDIA_TAILS = false;
const IGNORE_ACTIONS: Set<Message.messageService['action']['_']> = new Set([ const IGNORE_ACTIONS: Set<Message.messageService['action']['_']> = new Set([
@ -1509,9 +1510,13 @@ export default class ChatBubbles {
const today = new Date(); const today = new Date();
today.setHours(0, 0, 0, 0); today.setHours(0, 0, 0, 0);
const isScheduled = this.chat.type === 'scheduled';
if(today.getTime() === date.getTime()) { 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 { } else {
const options: Intl.DateTimeFormatOptions = { const options: Intl.DateTimeFormatOptions = {
day: 'numeric', day: 'numeric',
@ -1527,14 +1532,10 @@ export default class ChatBubbles {
options options
}).element; }).element;
if(this.chat.type === 'scheduled') { if(isScheduled) {
dateElement = i18n('Chat.Date.ScheduledFor', [dateElement]); dateElement = i18n('Chat.Date.ScheduledFor', [dateElement]);
} }
} }
/* if(this.chat.type === 'scheduled') {
str = 'Scheduled for ' + str;
} */
const div = document.createElement('div'); const div = document.createElement('div');
div.className = 'bubble service is-date'; div.className = 'bubble service is-date';

32
src/components/popups/schedule.ts

@ -4,6 +4,9 @@
* https://github.com/morethanwords/tweb/blob/master/LICENSE * 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"; import PopupDatePicker from "./datePicker";
const getMinDate = () => { const getMinDate = () => {
@ -13,20 +16,26 @@ const getMinDate = () => {
return date; 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 { export default class PopupSchedule extends PopupDatePicker {
constructor(initDate: Date, onPick: (timestamp: number) => void) { constructor(initDate: Date, onPick: (timestamp: number) => void) {
super(initDate, onPick, { super(checkDate(initDate), onPick, {
noButtons: true, noButtons: true,
noTitle: true, noTitle: true,
closable: true, closable: true,
withConfirm: true, withConfirm: true,
minDate: getMinDate(), minDate: getMinDate(),
maxDate: (() => { maxDate: getMaxDate(),
const date = new Date();
date.setFullYear(date.getFullYear() + 1);
date.setDate(date.getDate() - 1);
return date;
})(),
withTime: true, withTime: true,
showOverflowMonths: true showOverflowMonths: true
}); });
@ -34,6 +43,13 @@ export default class PopupSchedule extends PopupDatePicker {
this.element.classList.add('popup-schedule'); this.element.classList.add('popup-schedule');
this.header.append(this.controlsDiv); this.header.append(this.controlsDiv);
this.title.replaceWith(this.monthTitle); 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();
});
} }
} }

4
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.", "LinkNotFound": "Unfortunately, you can\'t access this message. You are not a member of the chat where it was posted.",
"Create": "Create", "Create": "Create",
"ViewDiscussion": "View discussion", "ViewDiscussion": "View discussion",
"MessageScheduledUntilOnline": "Scheduled until online",
// * macos // * macos
"AccountSettings.Filters": "Chat Folders", "AccountSettings.Filters": "Chat Folders",
@ -562,7 +563,6 @@ const lang = {
"Chat.CopySelectedText": "Copy Selected Text", "Chat.CopySelectedText": "Copy Selected Text",
"Chat.Confirm.Unpin": "Would you like to unpin this message?", "Chat.Confirm.Unpin": "Would you like to unpin this message?",
"Chat.Date.ScheduledFor": "Scheduled for %@", "Chat.Date.ScheduledFor": "Scheduled for %@",
//"Chat.Date.ScheduledUntilOnline": "Scheduled until online",
"Chat.Date.ScheduledForToday": "Scheduled for today", "Chat.Date.ScheduledForToday": "Scheduled for today",
"Chat.DropTitle": "Drop files here to send them", "Chat.DropTitle": "Drop files here to send them",
"Chat.DropQuickDesc": "in a quick way", "Chat.DropQuickDesc": "in a quick way",
@ -791,7 +791,7 @@ const lang = {
"ScheduleController.at": "at", "ScheduleController.at": "at",
"Schedule.SendToday": "Send today at %@", "Schedule.SendToday": "Send today at %@",
"Schedule.SendDate": "Send on %@ at %@", "Schedule.SendDate": "Send on %@ at %@",
//"Schedule.SendWhenOnline": "Send When Online", "Schedule.SendWhenOnline": "Send When Online",
"Stickers.Recent": "Recent", "Stickers.Recent": "Recent",
//"Stickers.Favorite": "Favorite", //"Stickers.Favorite": "Favorite",
"Text.Context.Copy.Username": "Copy Username", "Text.Context.Copy.Username": "Copy Username",

1
src/lib/mtproto/constants.ts

@ -0,0 +1 @@
export const SEND_WHEN_ONLINE_TIMESTAMP = 0x7FFFFFFE;
Loading…
Cancel
Save