From 73f89c783782a0bd4d88084136fe5d1368e4c284 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Thu, 17 Aug 2023 18:47:52 -0700 Subject: [PATCH] Chat country flags: stop at first subdivision --- pkg/geoip/geoip.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/geoip/geoip.go b/pkg/geoip/geoip.go index 14c53a9..1ef4f9d 100644 --- a/pkg/geoip/geoip.go +++ b/pkg/geoip/geoip.go @@ -83,13 +83,17 @@ func GetChatFlagEmoji(r *http.Request) (string, error) { // Subdivisions (states) if len(city.Subdivisions) > 0 { - for _, sub := range city.Subdivisions { - // Can we get its name? - if name, ok := sub.Names["en"]; ok { - flags = append(flags, name) - } else { - flags = append(flags, sub.IsoCode) - } + // Stop at just one subdivision. This will be US states + // and general regions, but without getting too specific + // for UK users especially where the subdivisions can hone + // in on their city of 1,000 population! + sub := city.Subdivisions[0] + + // Can we get its name? + if name, ok := sub.Names["en"]; ok { + flags = append(flags, name) + } else { + flags = append(flags, sub.IsoCode) } }