From 001477de61a83b4fa50ef7c60d118be97219b771 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Tue, 15 Aug 2023 21:03:41 -0700 Subject: [PATCH] Test chat room flags some more --- pkg/geoip/geoip.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pkg/geoip/geoip.go b/pkg/geoip/geoip.go index cad2d47..2d30a4f 100644 --- a/pkg/geoip/geoip.go +++ b/pkg/geoip/geoip.go @@ -71,17 +71,29 @@ func GetChatFlagEmoji(r *http.Request) (string, error) { return emoji, err } - var flags = []string{ - emoji, - city.Country.IsoCode, + // The components of text location part of the string. + var flags = []string{} + + // The country. Name or ISO code? + if name, ok := city.Country.Names[city.Country.IsoCode]; ok { + flags = append(flags, name) + } else { + flags = append(flags, city.Country.IsoCode) } + + // Subdivisions (states) if len(city.Subdivisions) > 0 { for _, sub := range city.Subdivisions { - flags = append(flags, sub.IsoCode) + // Can we get its name? + if name, ok := sub.Names[sub.IsoCode]; ok { + flags = append(flags, name) + } else { + flags = append(flags, sub.IsoCode) + } } } - return strings.Join(flags, " "), nil + return emoji + " " + strings.Join(flags, ", "), nil } // GetCity queries the GeoIP database for city information for an IP address.