diff --git a/public/embico/telegram.png b/public/embico/telegram.png new file mode 100644 index 00000000..00450dce Binary files /dev/null and b/public/embico/telegram.png differ diff --git a/src/components/MdLink.jsx b/src/components/MdLink.jsx index 374e5899..3c2c7343 100644 --- a/src/components/MdLink.jsx +++ b/src/components/MdLink.jsx @@ -15,6 +15,7 @@ const titleAllowed = [ 'matrix.pixelplanet.fun', 'youtube', 'youtu.be', + 't.me', ]; const MdLink = ({ href, title }) => { diff --git a/src/components/Modtools.jsx b/src/components/Modtools.jsx index 2156b1a0..eb8adb68 100644 --- a/src/components/Modtools.jsx +++ b/src/components/Modtools.jsx @@ -7,7 +7,7 @@ import React, { useState, useEffect } from 'react'; import { useSelector, shallowEqual } from 'react-redux'; import { t } from 'ttag'; -import useInterval from './hooks/useInterval'; +import useInterval from './hooks/interval'; import { getToday, dateToString } from '../core/utils'; const keptState = { diff --git a/src/components/embeds/Telegram.jsx b/src/components/embeds/Telegram.jsx new file mode 100644 index 00000000..21d1e41d --- /dev/null +++ b/src/components/embeds/Telegram.jsx @@ -0,0 +1,84 @@ +import React, { useState, useEffect, useRef } from 'react'; + +import usePostMessage from '../hooks/postMessage'; + +const urlStr = 't.me/'; + +function getUserPostFromUrl(url) { + let aPos = url.indexOf(urlStr); + if (aPos === -1) { + return url; + } + aPos += urlStr.length; + if (aPos >= url.length) { + return url; + } + let bPos = url.indexOf('/', aPos); + if (bPos === -1) { + bPos = url.length; + return url.substring(aPos); + } + const user = url.substring(aPos, bPos); + bPos += 1; + if (bPos >= url.length) { + return user; + } + aPos = url.indexOf('/', bPos); + if (aPos === -1) { + aPos = url.length; + } + const post = url.substring(bPos, aPos); + return `${user} | ${post}`; +} + +const Telegram = ({ url }) => { + const [frameHeight, setFrameHeight] = useState(200); + const iFrameRef = useRef(null); + + usePostMessage(iFrameRef, + (data) => { + try { + const pdata = JSON.parse(data); + if (pdata.event === 'resize') { + if (pdata.height) { + setFrameHeight(pdata.height); + } + } + } catch { + console.error(`Could not read postMessage from frame: ${data}`); + } + }, + ); + + const userPost = url.substring(url.indexOf(urlStr) + urlStr.length) + const embedCode = + // eslint-disable-next-line max-len + ``; + +// srcDoc={embedCode} + return ( +