Skip to content

Commit

Permalink
feat: don't use rich header if message contains urls
Browse files Browse the repository at this point in the history
  • Loading branch information
sakarie9 committed Mar 18, 2024
1 parent df17634 commit 9937fd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions main/src/services/ForwardService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
segment,
Sendable,
} from 'icqq';
import { fetchFile, getBigFaceUrl, getImageUrlByMd5 } from '../utils/urls';
import { fetchFile, getBigFaceUrl, getImageUrlByMd5, isContainsUrl } from '../utils/urls';
import { ButtonLike, FileLike } from 'telegram/define';
import { getLogger, Logger } from 'log4js';
import path from 'path';
Expand Down Expand Up @@ -386,7 +386,9 @@ export default class ForwardService {
else if (files.length) {
messageToSend.file = files;
}
else if (event.message_type === 'group' && (pair.flags | this.instance.flags) & flags.RICH_HEADER && env.WEB_ENDPOINT) {
else if (event.message_type === 'group' && (pair.flags | this.instance.flags) & flags.RICH_HEADER && env.WEB_ENDPOINT
// 当消息包含链接时不显示 RICH HEADER
&& !isContainsUrl(message)) {
// 没有文件时才能显示链接预览
richHeaderUsed = true;
// https://github.com/tdlib/td/blob/437c2d0c6e0ad104022d5ad86ddc8aedc41cb7a8/td/telegram/MessageContent.cpp#L2575
Expand Down
4 changes: 4 additions & 0 deletions main/src/utils/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ export async function fetchFile(url: string): Promise<Buffer> {
export function getAvatar(room: number | Friend | Group) {
return fetchFile(getAvatarUrl(room));
}

export function isContainsUrl(msg: string): boolean {
return msg.includes("https://") || msg.includes("http://")
}

0 comments on commit 9937fd5

Please sign in to comment.