FIX: Respect invalidate_oneboxes option for inline oneboxes
This commit is contained in:
parent
ecf60c0c33
commit
24a14af15a
|
@ -100,7 +100,7 @@ function applyOnebox(state, silent) {
|
||||||
let options = state.md.options.discourse;
|
let options = state.md.options.discourse;
|
||||||
|
|
||||||
if (options.lookupInlineOnebox) {
|
if (options.lookupInlineOnebox) {
|
||||||
onebox = options.lookupInlineOnebox(href);
|
onebox = options.lookupInlineOnebox(href, options.invalidateOneboxes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onebox && onebox.title) {
|
if (onebox && onebox.title) {
|
||||||
|
|
|
@ -31,7 +31,8 @@ export function buildOptions(state) {
|
||||||
previewing,
|
previewing,
|
||||||
linkify,
|
linkify,
|
||||||
censoredWords,
|
censoredWords,
|
||||||
mentionLookup
|
mentionLookup,
|
||||||
|
invalidateOneboxes
|
||||||
} = state;
|
} = state;
|
||||||
|
|
||||||
let features = {
|
let features = {
|
||||||
|
@ -80,7 +81,8 @@ export function buildOptions(state) {
|
||||||
markdownIt: true,
|
markdownIt: true,
|
||||||
injectLineNumbersToPreview:
|
injectLineNumbersToPreview:
|
||||||
siteSettings.enable_advanced_editor_preview_sync,
|
siteSettings.enable_advanced_editor_preview_sync,
|
||||||
previewing
|
previewing,
|
||||||
|
invalidateOneboxes
|
||||||
};
|
};
|
||||||
|
|
||||||
// note, this will mutate options due to the way the API is designed
|
// note, this will mutate options due to the way the API is designed
|
||||||
|
|
|
@ -23,8 +23,9 @@ class InlineOneboxer
|
||||||
|
|
||||||
def self.lookup(url, opts = nil)
|
def self.lookup(url, opts = nil)
|
||||||
opts ||= {}
|
opts ||= {}
|
||||||
|
opts = opts.with_indifferent_access
|
||||||
|
|
||||||
unless opts[:skip_cache]
|
unless opts[:skip_cache] || opts[:invalidate]
|
||||||
cached = cache_lookup(url)
|
cached = cache_lookup(url)
|
||||||
return cached if cached.present?
|
return cached if cached.present?
|
||||||
end
|
end
|
||||||
|
|
|
@ -172,6 +172,10 @@ module PrettyText
|
||||||
buffer << "__optInput.userId = #{opts[:user_id].to_i};\n"
|
buffer << "__optInput.userId = #{opts[:user_id].to_i};\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if opts[:invalidate_oneboxes]
|
||||||
|
buffer << "__optInput.invalidateOneboxes = true;\n"
|
||||||
|
end
|
||||||
|
|
||||||
buffer << "__textOptions = __buildOptions(__optInput);\n"
|
buffer << "__textOptions = __buildOptions(__optInput);\n"
|
||||||
|
|
||||||
buffer << ("__pt = new __PrettyText(__textOptions);")
|
buffer << ("__pt = new __PrettyText(__textOptions);")
|
||||||
|
|
|
@ -77,8 +77,8 @@ module PrettyText
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def lookup_inline_onebox(url)
|
def lookup_inline_onebox(url, opts = {})
|
||||||
InlineOneboxer.lookup(url)
|
InlineOneboxer.lookup(url, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_topic_info(topic_id)
|
def get_topic_info(topic_id)
|
||||||
|
|
|
@ -49,8 +49,14 @@ function __getURL(url) {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
function __lookupInlineOnebox(url) {
|
function __lookupInlineOnebox(url, invalidate = false) {
|
||||||
return __helpers.lookup_inline_onebox(url);
|
const opts = {};
|
||||||
|
|
||||||
|
if (invalidate) {
|
||||||
|
opts["invalidate"] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return __helpers.lookup_inline_onebox(url, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
function __lookupImageUrls(urls) {
|
function __lookupImageUrls(urls) {
|
||||||
|
|
|
@ -1195,6 +1195,25 @@ HTML
|
||||||
|
|
||||||
expect(PrettyText.cook(raw)).to eq(cooked.strip)
|
expect(PrettyText.cook(raw)).to eq(cooked.strip)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "invalidates the onebox url" do
|
||||||
|
topic = Fabricate(:topic)
|
||||||
|
url = topic.url
|
||||||
|
raw = "Hello #{url}"
|
||||||
|
|
||||||
|
PrettyText.cook(raw)
|
||||||
|
|
||||||
|
topic.title = "Updated: #{topic.title}"
|
||||||
|
topic.save
|
||||||
|
|
||||||
|
cooked = <<~HTML
|
||||||
|
<p>Hello <a href="#{url}">#{topic.title}</a></p>
|
||||||
|
HTML
|
||||||
|
|
||||||
|
expect(PrettyText.cook(raw)).not_to eq(cooked.strip)
|
||||||
|
expect(PrettyText.cook(raw, invalidate_oneboxes: true)).to eq(cooked.strip)
|
||||||
|
expect(PrettyText.cook(raw)).to eq(cooked.strip)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "image decoding" do
|
describe "image decoding" do
|
||||||
|
|
Loading…
Reference in New Issue