Sometimes you want stale data right away, then refresh it async. This adds `findStale` to the store for that case. If it returns an object with `hasResults` you can get the `results` and display them. It also returns a `refresh()` method to freshen up the stale data. To enable `localStorage` support for stale data, just include the mixin `StaleLocalStorage` into an adapter for that model. This commit includes a sample of doing that for `Notifications`.
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
import { hashString } from 'discourse/lib/hash';
|
|
|
|
let _splitAvatars;
|
|
|
|
function defaultAvatar(username) {
|
|
const defaultAvatars = Discourse.SiteSettings.default_avatars;
|
|
if (defaultAvatars && defaultAvatars.length) {
|
|
_splitAvatars = _splitAvatars || defaultAvatars.split("\n");
|
|
|
|
if (_splitAvatars.length) {
|
|
const hash = hashString(username);
|
|
return _splitAvatars[Math.abs(hash) % _splitAvatars.length];
|
|
}
|
|
}
|
|
|
|
return Discourse.getURLWithCDN("/letter_avatar/" +
|
|
username.toLowerCase() +
|
|
"/{size}/" +
|
|
Discourse.LetterAvatarVersion + ".png");
|
|
}
|
|
|
|
export default function(username, uploadedAvatarId) {
|
|
if (uploadedAvatarId) {
|
|
return Discourse.getURLWithCDN("/user_avatar/" +
|
|
Discourse.BaseUrl +
|
|
"/" +
|
|
username.toLowerCase() +
|
|
"/{size}/" +
|
|
uploadedAvatarId + ".png");
|
|
}
|
|
return defaultAvatar(username);
|
|
}
|