From f8b414f03baf01056493e1b8d87bad40a4331fb7 Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Tue, 18 Jan 2022 21:43:58 +0400 Subject: [PATCH] Replace spoiler pattern Do not render emoji as big if it's hidden Fix displaying start button in regular peers --- src/components/chat/bubbles.ts | 2 +- src/lib/appManagers/appImManager.ts | 2 +- src/lib/richtextprocessor.ts | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/components/chat/bubbles.ts b/src/components/chat/bubbles.ts index 1d11d766..421f06ab 100644 --- a/src/components/chat/bubbles.ts +++ b/src/components/chat/bubbles.ts @@ -2663,7 +2663,7 @@ export default class ChatBubbles { let strLength = messageMessage.length; let emojiStrLength = emojiEntities.reduce((acc, curr) => acc + curr.length, 0); - if(emojiStrLength === strLength && emojiEntities.length <= 3) { + if(emojiStrLength === strLength && emojiEntities.length <= 3 && totalEntities.length === emojiEntities.length) { if(rootScope.settings.emoji.big) { let sticker = this.appStickersManager.getAnimatedEmojiSticker(messageMessage); if(emojiEntities.length === 1 && !messageMedia && sticker) { diff --git a/src/lib/appManagers/appImManager.ts b/src/lib/appManagers/appImManager.ts index cb9417cb..8436cb76 100644 --- a/src/lib/appManagers/appImManager.ts +++ b/src/lib/appManagers/appImManager.ts @@ -413,7 +413,7 @@ export class AppImManager { domain: pathnameParams[0], post: pathnameParams[1], comment: uriParams.comment, - start: 'start' in uriParams && uriParams.start + start: 'start' in uriParams ? uriParams.start : undefined }; } diff --git a/src/lib/richtextprocessor.ts b/src/lib/richtextprocessor.ts index dc7bd982..951c5889 100644 --- a/src/lib/richtextprocessor.ts +++ b/src/lib/richtextprocessor.ts @@ -774,8 +774,9 @@ namespace RichTextProcessor { case 'messageEntitySpoiler': { if(options.noTextFormat) { const before = text.slice(0, entity.offset); + const spoilerBefore = text.slice(entity.offset, entity.offset + entity.length); const after = text.slice(entity.offset + entity.length); - text = before + '▚'.repeat(entity.length) + after; + text = before + spoiler(spoilerBefore)/* '▚'.repeat(entity.length) */ + after; } else if(options.wrappingDraft) { insertPart(entity, '', ''); } else { @@ -887,6 +888,19 @@ namespace RichTextProcessor { } return url; } + + export function spoiler(text: string): string { + const chars = '⠁⠂⠄⠈⠐⠠⡀⢀⠃⠅⠆⠉⠊⠌⠑⠒⠔⠘⠡⠢⠤⠨⠰⡁⡂⡄⡈⡐⡠⢁⢂⢄⢈⢐⢠⣀⠇⠋⠍⠎⠓⠕⠖⠙⠚⠜⠣⠥⠦⠩⠪⠬⠱⠲⠴⠸⡃⡅⡆⡉⡊⡌⡑⡒⡔⡘⡡⡢⡤⡨⡰⢃⢅⢆⢉⢊⢌⢑⢒⢔⢘⢡⢢⢤⢨⢰⣁⣂⣄⣈⣐⣠⠏⠗⠛⠝⠞⠧⠫⠭⠮⠳⠵⠶⠹⠺⠼⡇⡋⡍⡎⡓⡕⡖⡙⡚⡜⡣⡥⡦⡩⡪⡬⡱⡲⡴⡸⢇⢋⢍⢎⢓⢕⢖⢙⢚⢜⢣⢥⢦⢩⢪⢬⢱⢲⢴⢸⣃⣅⣆⣉⣊⣌⣑⣒⣔⣘⣡⣢⣤⣨⣰⠟⠯⠷⠻⠽⠾⡏⡗⡛⡝⡞⡧⡫⡭⡮⡳⡵⡶⡹⡺⡼⢏⢗⢛⢝⢞⢧⢫⢭⢮⢳⢵⢶⢹⢺⢼⣇⣋⣍⣎⣓⣕⣖⣙⣚⣜⣣⣥⣦⣩⣪⣬⣱⣲⣴⣸⠿⡟⡯⡷⡻⡽⡾⢟⢯⢷⢻⢽⢾⣏⣗⣛⣝⣞⣧⣫⣭⣮⣳⣵⣶⣹⣺⣼⡿⢿⣟⣯⣷⣻⣽⣾⣿'; + const charsLength = chars.length; + + const out: string[] = []; + for(let i = 0; i < text.length; ++i) { + let char = text.charCodeAt(i); + out.push(chars[char % charsLength]); + } + + return out.join(''); + } /* export function replaceUrlEncodings(urlWithEncoded: string) { return urlWithEncoded.replace(/(%[A-Z\d]{2})+/g, (str) => {