Test chat room flags some more

face-detect
Noah Petherbridge 2023-08-15 21:03:41 -07:00
parent ece83a0b23
commit 001477de61
1 changed files with 17 additions and 5 deletions

View File

@ -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.