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"; @@ -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<Message.messageService['action']['_']> = new Set([
@ -1509,9 +1510,13 @@ export default class ChatBubbles { @@ -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 { @@ -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';

32
src/components/popups/schedule.ts

@ -4,6 +4,9 @@ @@ -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 = () => { @@ -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 { @@ -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();
});
}
}

4
src/lang.ts

@ -548,6 +548,7 @@ const lang = { @@ -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 = { @@ -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 = { @@ -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",

1
src/lib/mtproto/constants.ts

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