приватные каналы
This commit is contained in:
@@ -2,7 +2,6 @@ package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -24,7 +23,6 @@ var simpleHTMLTags = map[echotron.MessageEntityType]htmlTag{
|
||||
}
|
||||
|
||||
// FormatMessageHTML converts Telegram entities to HTML and escapes the rest.
|
||||
// Invite links are normalized into <a class="tg-link"> placeholders for previews.
|
||||
func FormatMessageHTML(message *echotron.Message) string {
|
||||
if message == nil {
|
||||
return ""
|
||||
@@ -138,22 +136,12 @@ func FormatMessageHTML(message *echotron.Message) string {
|
||||
openTag, closeTag = tag.open, tag.close
|
||||
} else if entity.Type == echotron.UrlEntity {
|
||||
entityText := string(runes[start:end])
|
||||
if isInviteLink(entityText) {
|
||||
openTag = `<a class="tg-link">`
|
||||
closeTag = "</a>"
|
||||
} else {
|
||||
openTag = fmt.Sprintf("<a href=\"%s\">", entityText)
|
||||
closeTag = "</a>"
|
||||
}
|
||||
openTag = fmt.Sprintf("<a href=\"%s\">", entityText)
|
||||
closeTag = "</a>"
|
||||
} else if entity.Type == echotron.TextLinkEntity {
|
||||
if entity.URL != "" {
|
||||
if isInviteLink(entity.URL) {
|
||||
openTag = `<a class="tg-link">`
|
||||
closeTag = "</a>"
|
||||
} else {
|
||||
openTag = fmt.Sprintf("<a href=\"%s\">", entity.URL)
|
||||
closeTag = "</a>"
|
||||
}
|
||||
openTag = fmt.Sprintf("<a href=\"%s\">", entity.URL)
|
||||
closeTag = "</a>"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,12 +192,7 @@ func FormatMessageHTML(message *echotron.Message) string {
|
||||
}
|
||||
}
|
||||
|
||||
return normalizeInviteLinkTags(normalizeHTMLTags(result.String()))
|
||||
}
|
||||
|
||||
// isInviteLink detects Telegram invite links used in creatives.
|
||||
func isInviteLink(url string) bool {
|
||||
return strings.Contains(url, "t.me/+") || strings.Contains(url, "t.me/joinchat/")
|
||||
return normalizeHTMLTags(result.String())
|
||||
}
|
||||
|
||||
func normalizeHTMLTags(input string) string {
|
||||
@@ -291,15 +274,6 @@ func normalizeHTMLTags(input string) string {
|
||||
return out.String()
|
||||
}
|
||||
|
||||
func normalizeInviteLinkTags(input string) string {
|
||||
if input == "" {
|
||||
return input
|
||||
}
|
||||
|
||||
re := regexp.MustCompile(`<a\s+class="tg-link">\s*https?://t\.me/(?:\+|joinchat/)[a-zA-Z0-9_-]+\s*</a>`)
|
||||
return re.ReplaceAllString(input, `<a class="tg-link"></a>`)
|
||||
}
|
||||
|
||||
// EscapeHTML escapes HTML special characters for safe output.
|
||||
func EscapeHTML(s string) string {
|
||||
s = strings.ReplaceAll(s, "&", "&")
|
||||
|
||||
Reference in New Issue
Block a user