Media caption length limit to 1024

This commit is contained in:
morethanwords 2020-10-15 20:55:07 +03:00
parent 2a5f859ed7
commit 2c9056abe1
2 changed files with 13 additions and 5 deletions

View File

@ -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';

View File

@ -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);
}