diff --git a/src/components/popupNewMedia.ts b/src/components/popupNewMedia.ts index e1004f1e..df30199d 100644 --- a/src/components/popupNewMedia.ts +++ b/src/components/popupNewMedia.ts @@ -6,6 +6,7 @@ import { Layouter, RectPart } from "./groupedLayout"; import InputField from "./inputField"; import { PopupElement } from "./popup"; import { ripple } from "./ripple"; +import { toast } from "./toast"; import { wrapDocument } from "./wrappers"; type SendFileParams = Partial<{ @@ -16,6 +17,8 @@ type SendFileParams = Partial<{ duration: number }>; +const MAX_LENGTH_CAPTION = 1024; + export default class PopupNewMedia extends PopupElement { private btnSend: HTMLElement; private input: HTMLInputElement; @@ -38,14 +41,14 @@ export default class PopupNewMedia extends PopupElement { this.btnSend.className = 'btn-primary'; this.btnSend.innerText = 'SEND'; ripple(this.btnSend); - this.btnSend.addEventListener('click', this.send, {once: true}); + this.btnSend.addEventListener('click', this.send); this.header.append(this.btnSend); this.mediaContainer = document.createElement('div'); this.mediaContainer.classList.add('popup-photo'); - const inputField = InputField('Add a caption...', 'Caption', 'photo-caption'); + const inputField = InputField('Add a caption...', 'Caption', 'photo-caption', MAX_LENGTH_CAPTION, 80); this.input = inputField.firstElementChild as HTMLInputElement; this.container.append(this.mediaContainer, inputField); @@ -64,8 +67,13 @@ export default class PopupNewMedia extends PopupElement { }; public send = () => { + let caption = this.input.value.trim(); + if(caption.length > MAX_LENGTH_CAPTION) { + toast('Caption is too long.'); + return; + } + this.destroy(); - let caption = this.input.value; const willAttach = this.willAttach; willAttach.isMedia = willAttach.type == 'media'; diff --git a/src/lib/mtproto/networker.ts b/src/lib/mtproto/networker.ts index d06f7456..3d972f66 100644 --- a/src/lib/mtproto/networker.ts +++ b/src/lib/mtproto/networker.ts @@ -1153,8 +1153,8 @@ export default class MTPNetworker { break; case 'bad_msg_notification': - this.log.error('Bad msg notification', message); var sentMessage = this.sentMessages[message.bad_msg_id]; + this.log.error('Bad msg notification', message, sentMessage); if(!sentMessage || sentMessage.seq_no != message.bad_msg_seqno) { this.log(message.bad_msg_id, message.bad_msg_seqno); throw new Error('[MT] Bad msg notification for invalid message'); @@ -1168,7 +1168,7 @@ export default class MTPNetworker { this.updateSession(); } - var badMessage = this.updateSentMessage(message.bad_msg_id); + const badMessage = this.updateSentMessage(message.bad_msg_id); if(badMessage) this.pushResend(badMessage.msg_id); // fix 23.01.2020 this.ackMessage(messageID); }