bengott/meteor-avatar — pull request #20 by erasaur (2014-11-25 00:22:11+00:00)
Title: Improve url retrieval and avatar fallbacks

While the current version works, I've noticed a few quirks. Namely:
- when default type isn't `image`, initials are shown even when email hash and gravatar default are provided (which works for me, but may seem unexpected for some)
- currently a class is used to hide/show initials and avatar, requiring the image element to always be on the dom (not a big deal, but it only takes an if statement to fix this)
- sometimes the fallback is a fake hash, which is pretty hacky imo
- forcing a 404 response to show initials isn't ideal
- the custom `defaultImageUrl` is dependent on there being an email hash, which seems like an unnecessary association

Proposed changes:
- initials show when:
- the user decides to show an image (e.g gravatar or default image) and a legitimate 404 occurs (no more fake 404's)
- the user decides not to show an image (ie deliberately shows the initials)
- `defaultType` is used only for deciding the fallback (doesn't override gravatar default like before). We can easily infer that the user wants to show gravatar when email hash and gravatar default are both provided. (consider renaming `defaultType` to `fallbackType`)
- don't show the image element unless we need to
- no more fake hash. If a hash is not provided or is faulty, then we just show the fallback option.
- 404 response occurs only when it should
- not sure why default image url's were being passed through gravatar (leading to that caveat while running locally). Can't we just use these url's directly?

So the flow is like this:
- if user wants to use a gravatar and we *can* output a gravatar (meaning we have a good email hash and a gravatarDefault) then we do so accordingly
- if we can't output a gravatar, we fallback to either the image or the initials, depending on which is specified as the 'defaultType'
- if defaultType is image, then defaultImageUrl takes precedence like we expect

Examples:
- given: good emailHash, defaultType 'image', gravatarDefault 'identicon', returns: identicon
- given: good/bad emailHash, defaultType 'image', returns: package default image
- given: good/bad emailHash, defaultType 'image', returns: package default image
- given: bad emailHash, defaultType 'image', gravatarDefault 'identicon', returns: package default image
- given: bad emailHash, defaultType 'initials', gravatarDefault 'identicon', returns: initials
- given: good emailHash, defaultType 'initials', gravatarDefault 'identicon', returns: identicon

I haven't tested this extensively but it seems to work so far. And please correct me if I've skewed your intentions with the package behavior; I just changed it according to what is intuitive for me. Apologies in advance for any mistakes.