National Flags

Inspired by the phpBB Plugin, I’ve put together a similar plugin for Discourse.

After installing and enabling in Admin/Plugins, users will have a new custom setting called ‘National Flag’. After selecting a country code from the dropdown, the flag image will be displayed alongside their name in topics and also displayed on their user profile.

In its current state, it’s fairly ‘hacky’ and there’s plenty of room for improvement. I’d appreciate some help with the code if anyone is willing to offer their assistance!

Thoughts and ideas are welcome, I plan to update and improve this in the future!

37 Likes

It’ll take me a while until I’ve written a melody for the “wish concert”, but the chorus goes something like “great, can you make it do a whole lot more?”.

On a more serious note…

What we wanted was to autopropagate the nationality based on the ip the user registered from (chances are that is where the user is actually from). Allowing the users to override that, would be a second wish.

2 Likes

a similar thing was discussed in the other thread. So, basically an IP Lookup when the user registers. the ‘nationalflag_iso’ would then be autofilled?

For me, personally, my forum is based around expats. So the country where the user lives is rarely the country they’re originally from.

I’d like to make the plugin more effecient first, but I’ll certainly keep this request in mind.

Yes, that was what we were looking for.

What we wanted was a reliable location/timezone indication (our forum is worldwide, so the ability to see if someone is in your timezone, near a car you wanted someone to go and have a look at was what we were initially looking for).

Users being what they are, they’ll want to be adding all kinds of alternative truth hoods to their profiles - “I live in Arizona, but I was born in Scotland.” kind of thing. Sweet, in a meatbag kind of a way, but not all that reliable (in a meatbag kind of a way).

With our forum, I wouldn’t want to show any information which would indicate that a user was away from home. By that I mean a difference between the “registered” flag, and the “last login” could be construed as an invitation to come and steal my classic car, if I had been so silly as to give enough information to allow someone to figure out where I lived.

That’s what I am looking for. But why you uses countries prefix instead of using full country names. Short country names may confuse users.

Hi, thanks for the reply!

I chose to use the ISO Country Codes for a few reasons, the main one being laziness! :wink: the original files were already named with their country code. I realise it could potentially cause problems for users, but a quick Google search will get you your answer. (and using the codes avoids solves the translation issue ;))

I do hope to make some changes to the plugin in the near future and I’ll definitely look into displaying the countries in a more user-friendly manner.

1 Like

Since adding the plugin we seem to be getting a lot of warning messages in /logs, including:

TypeError: e.attrs.userCustomFields is null
Unable to get property ‘nationalflag_iso’ of undefined or null reference
TypeError: null is not an object (evaluating ‘e.attrs.userCustomFields.nationalflag_iso’)
Uncaught TypeError: Cannot read property ‘nationalflag_iso’ of null

Is anyone else seeing this?

If the cause of these log events is merely that a user hasn’t chosen a flag, then shouldn’t they just be Info messages, rather than Warnings?

1 Like

thanks for the feedback!
Yes, it looks like I’m not setting the default value for the custom field. This means all users who don’t have a national flag, don’t have a default value and its returning null.

I’ll have a look at it when I get a chance. It’s an unsightly warning message, but nevertheless just a warning message. :slight_smile:

This is fixed now. Just pushed the update to Github.
(I just added a conditional to the show-user-card connector, now you shouldn’t be getting any more warnings)

2 Likes

I was waiting for this fix before putting on my site. I just loaded the plugin on my site and I’m getting the errors. I’m also getting this weird bug when a user posts the dialogue box disappears and the post only shows if you refresh the page.

We saw something similar to your refresh issue after going to v1.8.0.beta5, it went away on it’s own.

That’s good to know. It wasn’t happening consistently, just intermittently for a few users…but enough for them to start complaining about it. Have your warning messages gone away? As soon as I loaded the plugin, I started getting them.

Can’t say yet, just updating my sandbox site now.

1 Like

The error messages stopped with the next update. (Thanks @Ebs )

1 Like

Ups, spoke too soon. I just updated the live site to latest, first user post after the update gives:

TypeError: null is not an object (evaluating 'e.attrs.userCustomFields.nationalflag_iso')
1 Like

Alright, that’s on the post decorator. Easy fix. I’ll do it tonight (and properly test it this time ;))

2 Likes

Thanks for your attention to this. In the few moments I had it up and running it was a big hit with my users. I run a political forum (don’t ever do that) and my users were quite excited to display the flags of the countries the post from, identify with, or just to pick flags based on countries that have policies that align with their political views. Great plugin and should be a part of core in my view (at least as an option).

7 Likes

:laughing: words to live by

10 Likes

I just upgradet to the latest version (720206f) but I still don’t get the National Flag option in my user preferences. :anguished: Might there be a conflict with another plugin? Or where should I start fixing this?

Have you enabled it in /admin/site_settings/category/plugins?filter=nationalflag?

1 Like