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;
|
||||
|
||||
if (options.lookupInlineOnebox) {
|
||||
onebox = options.lookupInlineOnebox(href);
|
||||
onebox = options.lookupInlineOnebox(href, options.invalidateOneboxes);
|
||||
}
|
||||
|
||||
if (onebox && onebox.title) {
|
||||
|
|
|
@ -31,7 +31,8 @@ export function buildOptions(state) {
|
|||
previewing,
|
||||
linkify,
|
||||
censoredWords,
|
||||
mentionLookup
|
||||
mentionLookup,
|
||||
invalidateOneboxes
|
||||
} = state;
|
||||
|
||||
let features = {
|
||||
|
@ -80,7 +81,8 @@ export function buildOptions(state) {
|
|||
markdownIt: true,
|
||||
injectLineNumbersToPreview:
|
||||
siteSettings.enable_advanced_editor_preview_sync,
|
||||
previewing
|
||||
previewing,
|
||||
invalidateOneboxes
|
||||
};
|
||||
|
||||
// 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)
|
||||
opts ||= {}
|
||||
opts = opts.with_indifferent_access
|
||||
|
||||
unless opts[:skip_cache]
|
||||
unless opts[:skip_cache] || opts[:invalidate]
|
||||
cached = cache_lookup(url)
|
||||
return cached if cached.present?
|
||||
end
|
||||
|
|
|
@ -172,6 +172,10 @@ module PrettyText
|
|||
buffer << "__optInput.userId = #{opts[:user_id].to_i};\n"
|
||||
end
|
||||
|
||||
if opts[:invalidate_oneboxes]
|
||||
buffer << "__optInput.invalidateOneboxes = true;\n"
|
||||
end
|
||||
|
||||
buffer << "__textOptions = __buildOptions(__optInput);\n"
|
||||
|
||||
buffer << ("__pt = new __PrettyText(__textOptions);")
|
||||
|
|
|
@ -77,8 +77,8 @@ module PrettyText
|
|||
result
|
||||
end
|
||||
|
||||
def lookup_inline_onebox(url)
|
||||
InlineOneboxer.lookup(url)
|
||||
def lookup_inline_onebox(url, opts = {})
|
||||
InlineOneboxer.lookup(url, opts)
|
||||
end
|
||||
|
||||
def get_topic_info(topic_id)
|
||||
|
|
|
@ -49,8 +49,14 @@ function __getURL(url) {
|
|||
return url;
|
||||
}
|
||||
|
||||
function __lookupInlineOnebox(url) {
|
||||
return __helpers.lookup_inline_onebox(url);
|
||||
function __lookupInlineOnebox(url, invalidate = false) {
|
||||
const opts = {};
|
||||
|
||||
if (invalidate) {
|
||||
opts["invalidate"] = true;
|
||||
}
|
||||
|
||||
return __helpers.lookup_inline_onebox(url, opts);
|
||||
}
|
||||
|
||||
function __lookupImageUrls(urls) {
|
||||
|
|
|
@ -1195,6 +1195,25 @@ HTML
|
|||
|
||||
expect(PrettyText.cook(raw)).to eq(cooked.strip)
|
||||
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
|
||||
|
||||
describe "image decoding" do
|
||||
|
|
Loading…
Reference in New Issue