FIX: include title in local onebox when linking to a different topic
This commit is contained in:
parent
614b1c8e68
commit
60ec483caa
|
@ -372,7 +372,13 @@ export default Ember.Component.extend({
|
||||||
post.set('refreshedPost', true);
|
post.set('refreshedPost', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$oneboxes.each((_, o) => load({ elem: o, refresh, ajax, categoryId: this.get('composer.category.id') }));
|
$oneboxes.each((_, o) => load({
|
||||||
|
elem: o,
|
||||||
|
refresh,
|
||||||
|
ajax,
|
||||||
|
categoryId: this.get('composer.category.id'),
|
||||||
|
topicId: this.get('composer.topic.id')
|
||||||
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
_warnMentionedGroups($preview) {
|
_warnMentionedGroups($preview) {
|
||||||
|
|
|
@ -86,6 +86,7 @@ export default Ember.Component.extend({
|
||||||
ajax,
|
ajax,
|
||||||
synchronous: true,
|
synchronous: true,
|
||||||
categoryId: this.get('composer.category.id'),
|
categoryId: this.get('composer.category.id'),
|
||||||
|
topicId: this.get('composer.topic.id')
|
||||||
});
|
});
|
||||||
|
|
||||||
if (loadOnebox && loadOnebox.then) {
|
if (loadOnebox && loadOnebox.then) {
|
||||||
|
|
|
@ -43,12 +43,17 @@ function loadNext(ajax) {
|
||||||
|
|
||||||
let timeoutMs = 150;
|
let timeoutMs = 150;
|
||||||
let removeLoading = true;
|
let removeLoading = true;
|
||||||
const { url, refresh, $elem, categoryId } = loadingQueue.shift();
|
const { url, refresh, $elem, categoryId, topicId } = loadingQueue.shift();
|
||||||
|
|
||||||
// Retrieve the onebox
|
// Retrieve the onebox
|
||||||
return ajax("/onebox", {
|
return ajax("/onebox", {
|
||||||
dataType: 'html',
|
dataType: 'html',
|
||||||
data: { url, refresh, category_id: categoryId },
|
data: {
|
||||||
|
url,
|
||||||
|
refresh,
|
||||||
|
category_id: categoryId,
|
||||||
|
topic_id: topicId
|
||||||
|
},
|
||||||
cache: true
|
cache: true
|
||||||
}).then(html => {
|
}).then(html => {
|
||||||
let $html = $(html);
|
let $html = $(html);
|
||||||
|
@ -59,7 +64,7 @@ function loadNext(ajax) {
|
||||||
if (result && result.jqXHR && result.jqXHR.status === 429) {
|
if (result && result.jqXHR && result.jqXHR.status === 429) {
|
||||||
timeoutMs = 2000;
|
timeoutMs = 2000;
|
||||||
removeLoading = false;
|
removeLoading = false;
|
||||||
loadingQueue.unshift({ url, refresh, $elem, categoryId });
|
loadingQueue.unshift({ url, refresh, $elem, categoryId, topicId });
|
||||||
} else {
|
} else {
|
||||||
failedCache[normalize(url)] = true;
|
failedCache[normalize(url)] = true;
|
||||||
}
|
}
|
||||||
|
@ -74,7 +79,7 @@ function loadNext(ajax) {
|
||||||
|
|
||||||
// Perform a lookup of a onebox based an anchor $element.
|
// Perform a lookup of a onebox based an anchor $element.
|
||||||
// It will insert a loading indicator and remove it when the loading is complete or fails.
|
// It will insert a loading indicator and remove it when the loading is complete or fails.
|
||||||
export function load({ elem , refresh = true, ajax, synchronous = false, categoryId }) {
|
export function load({ elem , refresh = true, ajax, synchronous = false, categoryId, topicId }) {
|
||||||
const $elem = $(elem);
|
const $elem = $(elem);
|
||||||
|
|
||||||
// If the onebox has loaded or is loading, return
|
// If the onebox has loaded or is loading, return
|
||||||
|
@ -98,7 +103,7 @@ export function load({ elem , refresh = true, ajax, synchronous = false, categor
|
||||||
$elem.addClass('loading-onebox');
|
$elem.addClass('loading-onebox');
|
||||||
|
|
||||||
// Add to the loading queue
|
// Add to the loading queue
|
||||||
loadingQueue.push({ url, refresh, $elem, categoryId });
|
loadingQueue.push({ url, refresh, $elem, categoryId, topicId });
|
||||||
|
|
||||||
// Load next url in queue
|
// Load next url in queue
|
||||||
if (synchronous) {
|
if (synchronous) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ class OneboxController < ApplicationController
|
||||||
|
|
||||||
user_id = current_user.id
|
user_id = current_user.id
|
||||||
category_id = params[:category_id].to_i
|
category_id = params[:category_id].to_i
|
||||||
|
topic_id = params[:topic_id].to_i
|
||||||
invalidate = params[:refresh] == 'true'
|
invalidate = params[:refresh] == 'true'
|
||||||
url = params[:url]
|
url = params[:url]
|
||||||
|
|
||||||
|
@ -24,7 +25,8 @@ class OneboxController < ApplicationController
|
||||||
preview = Oneboxer.preview(url,
|
preview = Oneboxer.preview(url,
|
||||||
invalidate_oneboxes: invalidate,
|
invalidate_oneboxes: invalidate,
|
||||||
user_id: user_id,
|
user_id: user_id,
|
||||||
category_id: category_id
|
category_id: category_id,
|
||||||
|
topic_id: topic_id
|
||||||
)
|
)
|
||||||
|
|
||||||
preview.strip! if preview.present?
|
preview.strip! if preview.present?
|
||||||
|
|
|
@ -170,6 +170,10 @@ module Oneboxer
|
||||||
return unless Guardian.new(current_user).can_see_category?(current_category)
|
return unless Guardian.new(current_user).can_see_category?(current_category)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if current_topic = Topic.find_by(id: opts[:topic_id])
|
||||||
|
return unless Guardian.new(current_user).can_see_topic?(current_topic)
|
||||||
|
end
|
||||||
|
|
||||||
topic = Topic.find_by(id: route[:topic_id])
|
topic = Topic.find_by(id: route[:topic_id])
|
||||||
|
|
||||||
return unless topic
|
return unless topic
|
||||||
|
@ -187,7 +191,7 @@ module Oneboxer
|
||||||
|
|
||||||
return if !post || post.hidden || post.post_type != Post.types[:regular]
|
return if !post || post.hidden || post.post_type != Post.types[:regular]
|
||||||
|
|
||||||
if post_number > 1
|
if post_number > 1 && current_topic&.id == topic.id
|
||||||
excerpt = post.excerpt(SiteSetting.post_onebox_maxlength)
|
excerpt = post.excerpt(SiteSetting.post_onebox_maxlength)
|
||||||
excerpt.gsub!(/[\r\n]+/, " ")
|
excerpt.gsub!(/[\r\n]+/, " ")
|
||||||
excerpt.gsub!("[/quote]", "[quote]") # don't break my quote
|
excerpt.gsub!("[/quote]", "[quote]") # don't break my quote
|
||||||
|
|
|
@ -18,8 +18,11 @@ describe Oneboxer do
|
||||||
%{<a href="#{url}">#{url}</a>}
|
%{<a href="#{url}">#{url}</a>}
|
||||||
end
|
end
|
||||||
|
|
||||||
def preview(url, user, category = Category.first)
|
def preview(url, user = nil, category = nil, topic = nil)
|
||||||
Oneboxer.preview("#{Discourse.base_url}#{url}", user_id: user.id, category_id: category.id).to_s
|
Oneboxer.preview("#{Discourse.base_url}#{url}",
|
||||||
|
user_id: user&.id,
|
||||||
|
category_id: category&.id,
|
||||||
|
topic_id: topic&.id).to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
it "links to a topic/post" do
|
it "links to a topic/post" do
|
||||||
|
@ -44,7 +47,8 @@ describe Oneboxer do
|
||||||
|
|
||||||
expect(preview(public_topic.relative_url, user, public_category)).to include(public_topic.title)
|
expect(preview(public_topic.relative_url, user, public_category)).to include(public_topic.title)
|
||||||
expect(preview(public_post.url, user, public_category)).to include(public_topic.title)
|
expect(preview(public_post.url, user, public_category)).to include(public_topic.title)
|
||||||
expect(preview(public_reply.url, user, public_category)).to include(public_reply.cooked)
|
expect(preview(public_reply.url, user, public_category)).to include(public_reply.excerpt)
|
||||||
|
expect(preview(public_reply.url, user, public_category, public_topic)).not_to include(public_topic.title)
|
||||||
expect(preview(public_hidden.url, user, public_category)).to match_html(link(public_hidden.url))
|
expect(preview(public_hidden.url, user, public_category)).to match_html(link(public_hidden.url))
|
||||||
expect(preview(secured_topic.relative_url, user, public_category)).to match_html(link(secured_topic.relative_url))
|
expect(preview(secured_topic.relative_url, user, public_category)).to match_html(link(secured_topic.relative_url))
|
||||||
expect(preview(secured_post.url, user, public_category)).to match_html(link(secured_post.url))
|
expect(preview(secured_post.url, user, public_category)).to match_html(link(secured_post.url))
|
||||||
|
@ -57,27 +61,27 @@ describe Oneboxer do
|
||||||
|
|
||||||
expect(preview(public_topic.relative_url, staff, secured_category)).to include(public_topic.title)
|
expect(preview(public_topic.relative_url, staff, secured_category)).to include(public_topic.title)
|
||||||
expect(preview(public_post.url, staff, secured_category)).to include(public_topic.title)
|
expect(preview(public_post.url, staff, secured_category)).to include(public_topic.title)
|
||||||
expect(preview(public_reply.url, staff, secured_category)).to include(public_reply.cooked)
|
expect(preview(public_reply.url, staff, secured_category)).to include(public_reply.excerpt)
|
||||||
expect(preview(public_hidden.url, staff, secured_category)).to match_html(link(public_hidden.url))
|
expect(preview(public_hidden.url, staff, secured_category)).to match_html(link(public_hidden.url))
|
||||||
expect(preview(secured_topic.relative_url, staff, secured_category)).to include(secured_topic.title)
|
expect(preview(secured_topic.relative_url, staff, secured_category)).to include(secured_topic.title)
|
||||||
expect(preview(secured_post.url, staff, secured_category)).to include(secured_topic.title)
|
expect(preview(secured_post.url, staff, secured_category)).to include(secured_topic.title)
|
||||||
expect(preview(secured_reply.url, staff, secured_category)).to include(secured_reply.cooked)
|
expect(preview(secured_reply.url, staff, secured_category)).to include(secured_reply.excerpt)
|
||||||
|
expect(preview(secured_reply.url, staff, secured_category, secured_topic)).not_to include(secured_topic.title)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "links to an user profile" do
|
it "links to an user profile" do
|
||||||
user = Fabricate(:user)
|
user = Fabricate(:user)
|
||||||
|
|
||||||
expect(preview("/u/does-not-exist", user)).to match_html(link("/u/does-not-exist"))
|
expect(preview("/u/does-not-exist")).to match_html(link("/u/does-not-exist"))
|
||||||
expect(preview("/u/#{user.username}", user)).to include(user.name)
|
expect(preview("/u/#{user.username}")).to include(user.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "links to an upload" do
|
it "links to an upload" do
|
||||||
user = Fabricate(:user)
|
|
||||||
path = "/uploads/default/original/3X/e/8/e8fcfa624e4fb6623eea57f54941a58ba797f14d"
|
path = "/uploads/default/original/3X/e/8/e8fcfa624e4fb6623eea57f54941a58ba797f14d"
|
||||||
|
|
||||||
expect(preview("#{path}.pdf", user)).to match_html(link("#{path}.pdf"))
|
expect(preview("#{path}.pdf")).to match_html(link("#{path}.pdf"))
|
||||||
expect(preview("#{path}.MP3", user)).to include("<audio ")
|
expect(preview("#{path}.MP3")).to include("<audio ")
|
||||||
expect(preview("#{path}.mov", user)).to include("<video ")
|
expect(preview("#{path}.mov")).to include("<video ")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue