diff --git a/tg_bot/screens/select_channels_for_purchase.go b/tg_bot/screens/select_channels_for_purchase.go index 7ada8ee..cad15bc 100644 --- a/tg_bot/screens/select_channels_for_purchase.go +++ b/tg_bot/screens/select_channels_for_purchase.go @@ -80,7 +80,7 @@ func (s *SelectChannelsForPurchase) renderChannelSelection(b *bot.Bot, mode bot. if ch.PlannedCost != nil { 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 { @@ -414,7 +414,7 @@ func channelLabel(ch PurchaseChannelInput) string { return ch.Title } if ch.InviteLink != "" { - return "invite link" + return formatInviteLabel(ch.InviteLink) } if ch.ChannelID != "" { return ch.ChannelID @@ -454,3 +454,42 @@ func isInviteLink(value string) bool { } 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 +}