diff --git a/lib/v2/telegram/channel.js b/lib/v2/telegram/channel.js
index 2f6e09dde..43483f721 100644
--- a/lib/v2/telegram/channel.js
+++ b/lib/v2/telegram/channel.js
@@ -122,7 +122,7 @@ module.exports = async (ctx) => {
item = $(item);
/* message types */
- const msgTypes = [];
+ let msgTypes = [];
if (item.find('.service_message').length) {
// service message can have an image (avatar changed)
msgTypes.push(SERVICE);
@@ -189,16 +189,6 @@ module.exports = async (ctx) => {
}
}
- /* media tag */
- let mediaTag = '';
- if (showMediaTagInTitle) {
- msgTypes.forEach((type) => {
- if (type !== REPLY || type !== FORWARDED || type !== VIA_BOT || (type === REPLY && showReplyTo) || (type === FORWARDED && showFwdFrom) || (type === VIA_BOT && showViaBot)) {
- mediaTag += showMediaTagAsEmoji ? mediaTagDict[type][1] : mediaTagDict[type][0];
- }
- });
- }
-
/* fix emoji */
item.find('.emoji').each((_, emoji) => {
emoji = $(emoji);
@@ -273,11 +263,12 @@ module.exports = async (ctx) => {
if (!nodes.length) {
return '';
}
- let tag_media = '';
+ let tag_media_all = '';
const pictureNodes = nodes.find('picture');
const imgNodes = nodes.find('img');
nodes.each((_, node) => {
const $node = $(node);
+ let tag_media = '';
if (node.attribs && node.attribs.class && node.attribs.class.search(/(^|\s)tgme_widget_message_video_player(\s|$)/) !== -1) {
// video
const videoLink = $node.find('.tgme_widget_message_video').attr('src');
@@ -312,13 +303,11 @@ module.exports = async (ctx) => {
});
tag_media += '';
});
- return tag_media;
} else if (imgNodes.length) {
// service message
imgNodes.each((_, img) => {
tag_media += $(img).toString();
});
- return tag_media;
} else {
// image message, location
const background = $node.css('background-image');
@@ -326,8 +315,12 @@ module.exports = async (ctx) => {
const backgroundUrlSrc = backgroundUrl && backgroundUrl[1];
tag_media += backgroundUrlSrc ? `` : '';
}
+ if (tag_media) {
+ tag_media_all += tag_media;
+ $node.find('.message_media_not_supported').remove();
+ }
});
- return tag_media;
+ return tag_media_all;
};
// ordinary message photos, service message photos, stickers, animated stickers, video
const messageMedia = generateMedia('.tgme_widget_message_photo_wrap,.tgme_widget_message_service_photo,.tgme_widget_message_sticker,.tgme_widget_message_tgsticker,.tgme_widget_message_video_player');
@@ -379,24 +372,6 @@ module.exports = async (ctx) => {
}
};
- /* unsupported */
- let unsupportedHtml = '';
- let unsupportedTitle = '';
- const unsupportedNodes = item.find('.message_media_not_supported');
- if (msgTypes.indexOf(UNSUPPORTED) !== -1 && unsupportedNodes.length) {
- unsupportedHtml += '
'; - unsupportedNodes.find('.message_media_not_supported_label').each(function () { - const $this = $(this); - unsupportedTitle += $this.text(); - unsupportedHtml += `'; - } - /* link preview */ const linkPreview = () => { const linkPreviewSiteObj = item.find('.link_preview_site_name'); @@ -498,9 +473,44 @@ module.exports = async (ctx) => { inlineButtons += ''; } + /* unsupported */ + let unsupportedHtml = ''; + let unsupportedTitle = ''; + const unsupportedNodes = item.find('.message_media_not_supported'); + if (msgTypes.includes(UNSUPPORTED)) { + if (unsupportedNodes.length) { + unsupportedHtml += '${$this.text()}
`; - }); - unsupportedNodes.find('.message_media_view_in_telegram').each(function () { - const $this = $(this); - unsupportedHtml += $this.attr('href') ? `` : `${$this.text()}
`; - }); - unsupportedHtml += '
'; + unsupportedNodes.find('.message_media_not_supported_label').each(function () { + const $this = $(this); + unsupportedTitle += $this.text(); + unsupportedHtml += `'; + } else { + // remove unsupported type, previous parsing has proved that it is not unsupported + msgTypes = msgTypes.filter((type) => type !== UNSUPPORTED); + } + } + /* pubDate */ const pubDate = parseDate(item.find('.tgme_widget_message_date time').attr('datetime')); + /* ----- finished parsing ----- */ + + /* media tag */ + let mediaTag = ''; + if (showMediaTagInTitle) { + msgTypes.forEach((type) => { + if (type !== REPLY || type !== FORWARDED || type !== VIA_BOT || (type === REPLY && showReplyTo) || (type === FORWARDED && showFwdFrom) || (type === VIA_BOT && showViaBot)) { + mediaTag += showMediaTagAsEmoji ? mediaTagDict[type][1] : mediaTagDict[type][0]; + } + }); + } + /* message text & title */ const messageTextObj = item.find(`.${msgTypes.includes(PARTIALLY_UNSUPPORTED) ? 'media_supported_cont' : 'tgme_widget_message_bubble'} > .tgme_widget_message_text`); let messageHtml = '',${$this.text()}
`; + }); + unsupportedNodes.find('.message_media_view_in_telegram').each(function () { + const $this = $(this); + unsupportedHtml += $this.attr('href') ? `` : `${$this.text()}
`; + }); + unsupportedHtml += '