Test chat room flags some more

This commit is contained in:
Noah Petherbridge 2023-08-15 21:03:41 -07:00
parent ece83a0b23
commit 001477de61

View File

@ -71,17 +71,29 @@ func GetChatFlagEmoji(r *http.Request) (string, error) {
return emoji, err return emoji, err
} }
var flags = []string{ // The components of text location part of the string.
emoji, var flags = []string{}
city.Country.IsoCode,
// 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 { if len(city.Subdivisions) > 0 {
for _, sub := range city.Subdivisions { 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. // GetCity queries the GeoIP database for city information for an IP address.