Browse Source

Fix links in inline buttons

master
Eduard Kuzmenko 4 years ago
parent
commit
3a9e995458
  1. 28
      src/components/chat/bubbles.ts
  2. 4
      src/scss/partials/_chatBubble.scss

28
src/components/chat/bubbles.ts

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

4
src/scss/partials/_chatBubble.scss

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

Loading…
Cancel
Save