fix отображения

This commit is contained in:
Artem Tsyrulnikov
2026-01-21 12:34:58 +03:00
parent a32bdc17d3
commit a280d4b190

View File

@@ -80,7 +80,7 @@ func (s *SelectChannelsForPurchase) renderChannelSelection(b *bot.Bot, mode bot.
if ch.PlannedCost != nil { if ch.PlannedCost != nil {
buttonText = fmt.Sprintf("%s — %.0f₽", channelLabel(ch), *ch.PlannedCost) buttonText = fmt.Sprintf("%s — %.0f₽", channelLabel(ch), *ch.PlannedCost)
} }
slots = append(slots, Button(buttonText, fmt.Sprintf("remove_channel:%d", i))) slots = append(slots, Button("✖ "+buttonText, fmt.Sprintf("remove_channel:%d", i)))
} }
if len(s.Channels) > channelsPerPage { if len(s.Channels) > channelsPerPage {
@@ -414,7 +414,7 @@ func channelLabel(ch PurchaseChannelInput) string {
return ch.Title return ch.Title
} }
if ch.InviteLink != "" { if ch.InviteLink != "" {
return "invite link" return formatInviteLabel(ch.InviteLink)
} }
if ch.ChannelID != "" { if ch.ChannelID != "" {
return ch.ChannelID return ch.ChannelID
@@ -454,3 +454,42 @@ func isInviteLink(value string) bool {
} }
return false return false
} }
func formatInviteLabel(inviteLink string) string {
link := strings.TrimSpace(inviteLink)
if link == "" {
return "приватный канал"
}
code := link
if strings.HasPrefix(code, "tg://") || strings.HasPrefix(code, "tg:") {
if idx := strings.Index(code, "invite="); idx != -1 {
code = code[idx+len("invite="):]
if end := strings.IndexAny(code, "&?#"); end != -1 {
code = code[:end]
}
}
} else {
code = strings.TrimPrefix(code, "https://")
code = strings.TrimPrefix(code, "http://")
code = strings.TrimPrefix(code, "t.me/")
code = strings.TrimPrefix(code, "telegram.me/")
code = strings.TrimPrefix(code, "joinchat/")
code = strings.TrimPrefix(code, "+")
if idx := strings.LastIndex(code, "/"); idx != -1 {
code = code[idx+1:]
}
if end := strings.IndexAny(code, "?#"); end != -1 {
code = code[:end]
}
}
code = strings.Trim(code, "/+ ")
if code == "" {
return "приватный канал"
}
if len(code) > 10 {
code = code[:6] + "..." + code[len(code)-2:]
}
return "приватный: " + code
}