Chat country flags: stop at first subdivision

This commit is contained in:
Noah Petherbridge 2023-08-17 18:47:52 -07:00
parent bf71ed421c
commit 73f89c7837

View File

@ -83,13 +83,17 @@ func GetChatFlagEmoji(r *http.Request) (string, error) {
// Subdivisions (states) // Subdivisions (states)
if len(city.Subdivisions) > 0 { if len(city.Subdivisions) > 0 {
for _, sub := range city.Subdivisions { // Stop at just one subdivision. This will be US states
// Can we get its name? // and general regions, but without getting too specific
if name, ok := sub.Names["en"]; ok { // for UK users especially where the subdivisions can hone
flags = append(flags, name) // in on their city of 1,000 population!
} else { sub := city.Subdivisions[0]
flags = append(flags, sub.IsoCode)
} // Can we get its name?
if name, ok := sub.Names["en"]; ok {
flags = append(flags, name)
} else {
flags = append(flags, sub.IsoCode)
} }
} }