FIX: missing short image resolution on queued posts
This commit is contained in:
parent
3ac7d041ae
commit
232311aa8c
|
@ -13,9 +13,7 @@ import { tinyAvatar,
|
|||
displayErrorForUpload,
|
||||
getUploadMarkdown,
|
||||
validateUploadedFiles } from 'discourse/lib/utilities';
|
||||
import { lookupCachedUploadUrl,
|
||||
lookupUncachedUploadUrls,
|
||||
cacheShortUploadUrl } from 'pretty-text/image-short-url';
|
||||
import { cacheShortUploadUrl, resolveAllShortUrls } from 'pretty-text/image-short-url';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
classNameBindings: ['showToolbar:toolbar-visible', ':wmd-controls'],
|
||||
|
@ -180,24 +178,6 @@ export default Ember.Component.extend({
|
|||
$oneboxes.each((_, o) => load(o, refresh, ajax, this.currentUser.id));
|
||||
},
|
||||
|
||||
_loadShortUrls($images) {
|
||||
const urls = _.map($images, img => $(img).data('orig-src'));
|
||||
lookupUncachedUploadUrls(urls, ajax).then(() => this._loadCachedShortUrls($images));
|
||||
},
|
||||
|
||||
_loadCachedShortUrls($images) {
|
||||
$images.each((idx, image) => {
|
||||
let $image = $(image);
|
||||
let url = lookupCachedUploadUrl($image.data('orig-src'));
|
||||
if (url) {
|
||||
$image.removeAttr('data-orig-src');
|
||||
if (url !== "missing") {
|
||||
$image.attr('src', url);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
_warnMentionedGroups($preview) {
|
||||
Ember.run.scheduleOnce('afterRender', () => {
|
||||
var found = this.get('warnedGroupMentions') || [];
|
||||
|
@ -584,18 +564,8 @@ export default Ember.Component.extend({
|
|||
Ember.run.debounce(this, this._loadOneboxes, $oneboxes, 450);
|
||||
}
|
||||
|
||||
// Short upload urls
|
||||
let $shortUploadUrls = $('img[data-orig-src]');
|
||||
|
||||
if ($shortUploadUrls.length > 0) {
|
||||
this._loadCachedShortUrls($shortUploadUrls);
|
||||
|
||||
$shortUploadUrls = $('img[data-orig-src]');
|
||||
if ($shortUploadUrls.length > 0) {
|
||||
// this is carefully batched so we can do an leading debounce (trigger right away)
|
||||
Ember.run.debounce(this, this._loadShortUrls, $shortUploadUrls, 450, true);
|
||||
}
|
||||
}
|
||||
// Short upload urls need resolution
|
||||
resolveAllShortUrls(ajax);
|
||||
|
||||
let inline = {};
|
||||
$('a.inline-onebox-loading', $preview).each(function(index, link) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { cookAsync } from 'discourse/lib/text';
|
||||
import { ajax } from 'discourse/lib/ajax';
|
||||
|
||||
const CookText = Ember.Component.extend({
|
||||
tagName: '',
|
||||
|
@ -6,7 +7,16 @@ const CookText = Ember.Component.extend({
|
|||
|
||||
didReceiveAttrs() {
|
||||
this._super(...arguments);
|
||||
cookAsync(this.get('rawText')).then(cooked => this.set('cooked', cooked));
|
||||
cookAsync(this.get('rawText')).then(
|
||||
cooked => {
|
||||
this.set('cooked', cooked);
|
||||
// no choice but to defer this cause
|
||||
// pretty text may only be loaded now
|
||||
Em.run.next(() =>
|
||||
window.requireModule('pretty-text/image-short-url').resolveAllShortUrls(ajax)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -16,3 +16,35 @@ export function lookupUncachedUploadUrls(urls, ajax) {
|
|||
export function cacheShortUploadUrl(shortUrl, url) {
|
||||
_cache[shortUrl] = url;
|
||||
}
|
||||
|
||||
function _loadCachedShortUrls($images) {
|
||||
$images.each((idx, image) => {
|
||||
let $image = $(image);
|
||||
let url = lookupCachedUploadUrl($image.data('orig-src'));
|
||||
if (url) {
|
||||
$image.removeAttr('data-orig-src');
|
||||
if (url !== "missing") {
|
||||
$image.attr('src', url);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function _loadShortUrls($images, ajax) {
|
||||
const urls = _.map($images, img => $(img).data('orig-src'));
|
||||
lookupUncachedUploadUrls(urls, ajax).then(() => _loadCachedShortUrls($images));
|
||||
}
|
||||
|
||||
export function resolveAllShortUrls(ajax) {
|
||||
let $shortUploadUrls = $('img[data-orig-src]');
|
||||
|
||||
if ($shortUploadUrls.length > 0) {
|
||||
_loadCachedShortUrls($shortUploadUrls);
|
||||
|
||||
$shortUploadUrls = $('img[data-orig-src]');
|
||||
if ($shortUploadUrls.length > 0) {
|
||||
// this is carefully batched so we can do a leading debounce (trigger right away)
|
||||
Ember.run.debounce(null, () => { _loadShortUrls($shortUploadUrls, ajax); }, 450, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue