aboutsummaryrefslogtreecommitdiff
path: root/vnext
diff options
context:
space:
mode:
Diffstat (limited to 'vnext')
-rw-r--r--vnext/server/common/MessageUtils.js5
-rw-r--r--vnext/server/durov.js2
-rw-r--r--vnext/src/utils/embed.js22
3 files changed, 19 insertions, 10 deletions
diff --git a/vnext/server/common/MessageUtils.js b/vnext/server/common/MessageUtils.js
index bb3d791f..d3c6a0f5 100644
--- a/vnext/server/common/MessageUtils.js
+++ b/vnext/server/common/MessageUtils.js
@@ -39,11 +39,12 @@ export function formatTitle(msg) {
/**
* format notification quote
* @param { import('../../src/api').Message } msg message
+ * @param { boolean } isDurov format to Telegram markup
* @returns {string} formatted quote line
*/
-export function formatQuote(msg) {
+export function formatQuote(msg, isDurov = false) {
if (isReply(msg)) {
- return msg.replyQuote || ''
+ return msg.replyQuote ? isDurov ? `<blockquote>${msg.replyQuote.substring(1)}</blockquote>` : msg.replyQuote : ''
} else if (isPM(msg)) {
return ''
}
diff --git a/vnext/server/durov.js b/vnext/server/durov.js
index 6ab1831f..51996b9e 100644
--- a/vnext/server/durov.js
+++ b/vnext/server/durov.js
@@ -41,7 +41,7 @@ export const sendTelegramNotification = (msg, subscribers) => {
log(`Telegram event: ${JSON.stringify(msg)}, ${subscribers} ${subscribers.length}`)
if (!msg.service) {
if (subscribers && subscribers.includes(demouser)) {
- const message = `${formatTitle(msg)}\n${formatQuote(msg)}\n${format(msg.body, msg.uid, false)}`
+ const message = `${formatTitle(msg)}\n${formatQuote(msg, true)}\n${format(msg.body, msg.uid, false, true)}`
log(message)
sender.sendMessage(demouser, message, {
parse_mode: 'HTML',
diff --git a/vnext/src/utils/embed.js b/vnext/src/utils/embed.js
index 6a5c9c95..b6bbde14 100644
--- a/vnext/src/utils/embed.js
+++ b/vnext/src/utils/embed.js
@@ -122,27 +122,35 @@ function messageReplyReplace(messageId) {
* @param {string} txt text message
* @param {string} messageId current message id
* @param {boolean} isCode set when message contains *code tag
+ * @param {boolean} isDurov skip rules non-compatible with Telegram
* @returns {string} formatted message
*/
-function juickFormat(txt, messageId, isCode) {
+function juickFormat(txt, messageId, isCode, isDurov) {
const urlRe = /(?:\[([^\][]+)\](?:\[([^\]]+)\]|\(((?:[a-z]+:\/\/|www\.|ftp\.)(?:\([-\S+*&@#/%=~|$?!:;,.]*\)|[-\S+*&@#/%=~|$?!:;,.])*(?:\([-\S+*&@#/%=~|$?!:;,.]*\)|[\S+*&@#/%=~|$]))\))|\b(?:[a-z]+:\/\/|www\.|ftp\.)(?:\([-\S+*&@#/%=~|$?!:;,.]*\)|[-\S+*&@#/%=~|$?!:;,.])*(?:\([-\S+*&@#/%=~|$?!:;,.]*\)|[\S+*&@#/%=~|$]))/gi
const bqReplace = m => m.replace(/^(?:>|&gt;)\s?/gmi, '')
- return (isCode)
- ? formatText(txt, [
+ if (isCode) {
+ return formatText(txt, [
{ pr: 1, re: urlRe, with: urlReplaceInCode },
{ pr: 1, re: /\B(?:#(\d+))?(?:\/(\d+))?\b/g, with: messageReplyReplace(messageId) },
{ pr: 1, re: /\B@([\w-]+)\b/gi, with: '<a href="/$1">@$1</a>' },
])
- : formatText(txt, [
- { pr: 0, re: /((?:^(?:>|&gt;)\s?[\s\S]+?$\n?)+)/gmi, brackets: true, with: ['<q>', '</q>', bqReplace] },
+ } else {
+ const rules = [
+ { pr: 0, re: /((?:^(?:>|&gt;)\s?[\s\S]+?$\n?)+)/gmi, brackets: true, with: ['<blockquote>', '</blockquote>', bqReplace] },
{ pr: 1, re: urlRe, with: urlReplace },
{ pr: 1, re: /\B(?:#(\d+))?(?:\/(\d+))?\b/g, with: messageReplyReplace(messageId) },
{ pr: 1, re: /\B@([\w-]+)\b/gi, with: '<a href="/$1">@$1</a>' },
{ pr: 2, re: /\B\*([^\n]+?)\*((?=\s)|(?=$)|(?=[!"#$%&'*+,\-./:;<=>?@[\]^_`{|}~()]+))/g, brackets: true, with: ['<b>', '</b>'] },
{ pr: 2, re: /\B\/([^\n]+?)\/((?=\s)|(?=$)|(?=[!"#$%&'*+,\-./:;<=>?@[\]^_`{|}~()]+))/g, brackets: true, with: ['<i>', '</i>'] },
{ pr: 2, re: /\b_([^\n]+?)_((?=\s)|(?=$)|(?=[!"#$%&'*+,\-./:;<=>?@[\]^_`{|}~()]+))/g, brackets: true, with: ['<u>', '</u>'] },
- { pr: 3, re: /\n/g, with: '<br/>' },
- ])
+ ]
+ if (!isDurov) {
+ rules.push(
+ { pr: 3, re: /\n/g, with: '<br/>' }
+ )
+ }
+ return formatText(txt, rules)
+ }
}
/**
* @external RegExpExecArray