Fix links in inline buttons

This commit is contained in:
Eduard Kuzmenko 2021-04-24 18:36:53 +04:00
parent aff64e5390
commit 3a9e995458
2 changed files with 18 additions and 14 deletions

View File

@ -15,7 +15,7 @@ import type { AppPeersManager } from "../../lib/appManagers/appPeersManager";
import type sessionStorage from '../../lib/sessionStorage'; import type sessionStorage from '../../lib/sessionStorage';
import type Chat from "./chat"; import type Chat from "./chat";
import { CHAT_ANIMATION_GROUP } from "../../lib/appManagers/appImManager"; import { CHAT_ANIMATION_GROUP } from "../../lib/appManagers/appImManager";
import { cancelEvent, whichChild, attachClickEvent, positionElementByIndex, reflowScrollableElement, replaceContent } from "../../helpers/dom"; import { cancelEvent, whichChild, attachClickEvent, positionElementByIndex, reflowScrollableElement, replaceContent, htmlToDocumentFragment } from "../../helpers/dom";
import { getObjectKeysAndSort } from "../../helpers/object"; import { getObjectKeysAndSort } from "../../helpers/object";
import { isTouchSupported } from "../../helpers/touchSupport"; import { isTouchSupported } from "../../helpers/touchSupport";
import { logger } from "../../lib/logger"; import { logger } from "../../lib/logger";
@ -1989,13 +1989,16 @@ export default class ChatBubbles {
switch(button._) { switch(button._) {
case 'keyboardButtonUrl': { case 'keyboardButtonUrl': {
const from = this.appUsersManager.getUser(message.fromId); const r = RichTextProcessor.wrapRichText(' ', {
const unsafe = !(from && from.pFlags && from.pFlags.verified); entities: [{
const url = RichTextProcessor.wrapUrl(button.url, unsafe); _: 'messageEntityTextUrl',
buttonEl = document.createElement('a'); length: 1,
buttonEl.href = url; offset: 0,
buttonEl.rel = 'noopener noreferrer'; url: button.url
buttonEl.target = '_blank'; }]
});
buttonEl = htmlToDocumentFragment(r).firstElementChild as HTMLAnchorElement;
buttonEl.classList.add('is-link', 'tgico'); buttonEl.classList.add('is-link', 'tgico');
break; break;
@ -2006,7 +2009,7 @@ export default class ChatBubbles {
break; break;
} }
} }
buttonEl.classList.add('reply-markup-button', 'rp'); buttonEl.classList.add('reply-markup-button', 'rp');
buttonEl.innerHTML = text; buttonEl.innerHTML = text;
@ -2019,11 +2022,12 @@ export default class ChatBubbles {
}); });
attachClickEvent(containerDiv, (e) => { attachClickEvent(containerDiv, (e) => {
cancelEvent(e);
let target = e.target as HTMLElement; let target = e.target as HTMLElement;
if(!target.classList.contains('reply-markup-button')) target = findUpClassName(target, 'reply-markup-button'); if(!target.classList.contains('reply-markup-button')) target = findUpClassName(target, 'reply-markup-button');
if(!target) return; if(!target || target.classList.contains('is-link')) return;
cancelEvent(e);
const column = whichChild(target); const column = whichChild(target);
const row = rows[whichChild(target.parentElement)]; const row = rows[whichChild(target.parentElement)];

View File

@ -2122,7 +2122,7 @@ $bubble-margin: .25rem;
//line-height: var(--line-height); //line-height: var(--line-height);
background: var(--message-highlightning-color); background: var(--message-highlightning-color);
&:before { &:after {
content: " "; content: " ";
display: block; display: block;
position: absolute; position: absolute;
@ -2141,7 +2141,7 @@ $bubble-margin: .25rem;
} }
@include hover() { @include hover() {
&:before { &:after {
opacity: var(--hover-alpha); opacity: var(--hover-alpha);
} }
} }