Browse Source

Sanitize wrong chars for document extension

master
Eduard Kuzmenko 3 years ago
parent
commit
75b61e8d6a
  1. 22
      src/components/chat/bubbles.ts
  2. 5
      src/components/wrappers.ts

22
src/components/chat/bubbles.ts

@ -314,7 +314,7 @@ export default class ChatBubbles {
if(message.media?.webpage && !bubble.querySelector('.web')) { if(message.media?.webpage && !bubble.querySelector('.web')) {
getHeavyAnimationPromise().then(() => { getHeavyAnimationPromise().then(() => {
this.renderMessage(message, true, false, bubble, false); this.safeRenderMessage(message, true, false, bubble, false);
this.scrollToBubbleIfLast(bubble); this.scrollToBubbleIfLast(bubble);
}); });
/* const mounted = this.getMountedBubble(mid); /* const mounted = this.getMountedBubble(mid);
@ -371,7 +371,7 @@ export default class ChatBubbles {
const updatePosition = this.chat.type === 'scheduled'; const updatePosition = this.chat.type === 'scheduled';
const scrolledDown = this.scrolledDown; const scrolledDown = this.scrolledDown;
this.renderMessage(mounted.message, true, false, mounted.bubble, updatePosition); this.safeRenderMessage(mounted.message, true, false, mounted.bubble, updatePosition);
if(scrolledDown) { if(scrolledDown) {
this.scrollToBubbleIfLast(mounted.bubble); this.scrollToBubbleIfLast(mounted.bubble);
} }
@ -395,7 +395,7 @@ export default class ChatBubbles {
const renderMaxId = getObjectKeysAndSort(this.appMessagesManager.groupedMessagesStorage[groupId], 'asc').pop(); const renderMaxId = getObjectKeysAndSort(this.appMessagesManager.groupedMessagesStorage[groupId], 'asc').pop();
this.renderMessage(this.chat.getMessage(renderMaxId), true, false, this.bubbles[renderedId], false); this.safeRenderMessage(this.chat.getMessage(renderMaxId), true, false, this.bubbles[renderedId], false);
//}); //});
}); });
@ -579,7 +579,7 @@ export default class ChatBubbles {
const bubble = this.bubbles[mid]; const bubble = this.bubbles[mid];
if(bubble.classList.contains('can-have-big-emoji')) { if(bubble.classList.contains('can-have-big-emoji')) {
const message = this.chat.getMessage(mid); const message = this.chat.getMessage(mid);
this.renderMessage(message, undefined, false, bubble); this.safeRenderMessage(message, undefined, false, bubble);
// this.bubbleGroups.addBubble(bubble, message, false); // this.bubbleGroups.addBubble(bubble, message, false);
} }
}); });
@ -2085,7 +2085,7 @@ export default class ChatBubbles {
} }
// reverse means top // reverse means top
public renderMessage(message: any, reverse = false, multipleRender = false, bubble: HTMLDivElement = null, updatePosition = true) { private renderMessage(message: any, reverse = false, multipleRender = false, bubble: HTMLDivElement = null, updatePosition = true) {
/* if(DEBUG) { /* if(DEBUG) {
this.log.debug('message to render:', message); this.log.debug('message to render:', message);
} */ } */
@ -2966,6 +2966,14 @@ export default class ChatBubbles {
return bubble; return bubble;
} }
private safeRenderMessage(message: any, reverse?: boolean, multipleRender?: boolean, bubble?: HTMLDivElement, updatePosition?: boolean) {
try {
return this.renderMessage(message, reverse, multipleRender, bubble, updatePosition);
} catch(err) {
this.log.error('renderMessage error:', err);
}
}
public async performHistoryResult(history: number[], reverse: boolean, isBackLimit: boolean, additionMsgId?: number) { public async performHistoryResult(history: number[], reverse: boolean, isBackLimit: boolean, additionMsgId?: number) {
// commented bot getProfile in getHistory! // commented bot getProfile in getHistory!
// if(!history/* .filter((id: number) => id > 0) */.length) { // if(!history/* .filter((id: number) => id > 0) */.length) {
@ -3040,7 +3048,7 @@ export default class ChatBubbles {
const cb = (mid: number) => { const cb = (mid: number) => {
const message = this.chat.getMessage(mid); const message = this.chat.getMessage(mid);
if(message.id > 0) { if(message.id > 0) {
this.renderMessage(message, reverse, true); this.safeRenderMessage(message, reverse, true);
} else { } else {
this.processLocalMessageRender(message); this.processLocalMessageRender(message);
} }
@ -3396,7 +3404,7 @@ export default class ChatBubbles {
} }
private processLocalMessageRender(message: Message.message | Message.messageService) { private processLocalMessageRender(message: Message.message | Message.messageService) {
const bubble = this.renderMessage(message, undefined, undefined, undefined, false); const bubble = this.safeRenderMessage(message, undefined, undefined, undefined, false);
bubble.classList.add('bubble-first', 'is-group-last', 'is-group-first'); bubble.classList.add('bubble-first', 'is-group-last', 'is-group-first');
bubble.classList.remove('can-have-tail', 'is-in'); bubble.classList.remove('can-have-tail', 'is-in');

5
src/components/wrappers.ts

@ -42,6 +42,7 @@ import { cancelEvent } from '../helpers/dom/cancelEvent';
import { attachClickEvent } from '../helpers/dom/clickEvent'; import { attachClickEvent } from '../helpers/dom/clickEvent';
import isInDOM from '../helpers/dom/isInDOM'; import isInDOM from '../helpers/dom/isInDOM';
import lottieLoader from '../lib/lottieLoader'; import lottieLoader from '../lib/lottieLoader';
import { clearBadCharsAndTrim } from '../helpers/cleanSearchText';
const MAX_VIDEO_AUTOPLAY_SIZE = 50 * 1024 * 1024; // 50 MB const MAX_VIDEO_AUTOPLAY_SIZE = 50 * 1024 * 1024; // 50 MB
@ -480,7 +481,9 @@ export function wrapDocument({message, withTime, fontWeight, voiceAsMusic, showS
let extSplitted = doc.file_name ? doc.file_name.split('.') : ''; let extSplitted = doc.file_name ? doc.file_name.split('.') : '';
let ext = ''; let ext = '';
ext = extSplitted.length > 1 && Array.isArray(extSplitted) ? extSplitted.pop().toLowerCase() : 'file'; ext = extSplitted.length > 1 && Array.isArray(extSplitted) ?
clearBadCharsAndTrim(extSplitted.pop().split(' ', 1)[0].toLowerCase()) :
'file';
let docDiv = document.createElement('div'); let docDiv = document.createElement('div');
docDiv.classList.add('document', `ext-${ext}`); docDiv.classList.add('document', `ext-${ext}`);

Loading…
Cancel
Save