mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
Make embedded comments look nicer
This commit is contained in:
@ -23,6 +23,7 @@ article.post {
|
|||||||
color: #4a6b82;
|
color: #4a6b82;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
word-wrap: break-word;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,11 +37,27 @@ article.post {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post-replies {
|
||||||
|
background-color: #eee;
|
||||||
|
padding: 5px;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.in-reply-to {
|
||||||
|
font-size: 13px;
|
||||||
|
margin-top: 4px;
|
||||||
|
display: inline-block;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.replies {
|
||||||
|
font-size: 15px;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
header {
|
header {
|
||||||
padding: 10px 10px 20px 10px;
|
padding: 10px 10px 20px 10px;
|
||||||
|
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
|
|
||||||
border-bottom: 1px solid #ddd;
|
border-bottom: 1px solid #ddd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,12 +5,12 @@ class EmbedController < ApplicationController
|
|||||||
|
|
||||||
layout 'embed'
|
layout 'embed'
|
||||||
|
|
||||||
def best
|
def comments
|
||||||
embed_url = params.require(:embed_url)
|
embed_url = params.require(:embed_url)
|
||||||
topic_id = TopicEmbed.topic_id_for_embed(embed_url)
|
topic_id = TopicEmbed.topic_id_for_embed(embed_url)
|
||||||
|
|
||||||
if topic_id
|
if topic_id
|
||||||
@topic_view = TopicView.new(topic_id, current_user, {best: 5})
|
@topic_view = TopicView.new(topic_id, current_user, limit: SiteSetting.embed_post_limit, exclude_first: true)
|
||||||
@second_post_url = "#{@topic_view.topic.url}/2" if @topic_view
|
@second_post_url = "#{@topic_view.topic.url}/2" if @topic_view
|
||||||
else
|
else
|
||||||
Jobs.enqueue(:retrieve_topic, user_id: current_user.try(:id), embed_url: embed_url)
|
Jobs.enqueue(:retrieve_topic, user_id: current_user.try(:id), embed_url: embed_url)
|
||||||
|
@ -218,6 +218,13 @@ class Post < ActiveRecord::Base
|
|||||||
(quote_count == 0) && (reply_to_post_number.present?)
|
(quote_count == 0) && (reply_to_post_number.present?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reply_to_post
|
||||||
|
return if reply_to_post_number.blank?
|
||||||
|
@reply_to_post ||= Post.where("topic_id = :topic_id AND post_number = :post_number",
|
||||||
|
topic_id: topic_id,
|
||||||
|
post_number: reply_to_post_number).first
|
||||||
|
end
|
||||||
|
|
||||||
def reply_notification_target
|
def reply_notification_target
|
||||||
return if reply_to_post_number.blank?
|
return if reply_to_post_number.blank?
|
||||||
Post.where("topic_id = :topic_id AND post_number = :post_number AND user_id <> :user_id",
|
Post.where("topic_id = :topic_id AND post_number = :post_number AND user_id <> :user_id",
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
<header>
|
<header>
|
||||||
<%- if @topic_view.posts.present? %>
|
<%- if @topic_view.posts.present? %>
|
||||||
<%= link_to(I18n.t('embed.title'), @second_post_url, class: 'button', target: '_blank') %>
|
<%= link_to(I18n.t('embed.continue'), @second_post_url, class: 'button', target: '_blank') %>
|
||||||
|
<span class='replies'><%= I18n.t('embed.replies', count: @topic_view.topic.posts_count) %></span>
|
||||||
|
|
||||||
<%- else %>
|
<%- else %>
|
||||||
<%= link_to(I18n.t('embed.start_discussion'), @topic_view.topic.url, class: 'button', target: '_blank') %>
|
<%= link_to(I18n.t('embed.start_discussion'), @topic_view.topic.url, class: 'button', target: '_blank') %>
|
||||||
<%- end if %>
|
<%- end if %>
|
||||||
@ -12,17 +14,29 @@
|
|||||||
<%- @topic_view.posts.each do |post| %>
|
<%- @topic_view.posts.each do |post| %>
|
||||||
<article class='post'>
|
<article class='post'>
|
||||||
<%= link_to post.created_at.strftime("%e %b %Y"), post.url, class: 'post-date', target: "_blank" %>
|
<%= link_to post.created_at.strftime("%e %b %Y"), post.url, class: 'post-date', target: "_blank" %>
|
||||||
|
<%- if post.reply_to_post.present? %>
|
||||||
|
<%= link_to I18n.t('embed.in_reply_to', username: post.reply_to_post.username), post.reply_to_post.url, class: 'in-reply-to', target: "_blank" %>
|
||||||
|
<%- end %>
|
||||||
|
|
||||||
<div class='author'>
|
<div class='author'>
|
||||||
<img src='<%= post.user.small_avatar_url %>'>
|
<img src='<%= post.user.small_avatar_url %>'>
|
||||||
<h3><%= post.user.username %></h3>
|
<h3 class='username'><%= post.user.username %></h3>
|
||||||
</div>
|
</div>
|
||||||
<div class='cooked'><%= raw post.cooked %></div>
|
<div class='cooked'>
|
||||||
|
<%= raw post.cooked %>
|
||||||
|
|
||||||
|
<%- if post.reply_count > 0 %>
|
||||||
|
<%= link_to I18n.t('embed.replies', count: post.reply_count), post.url, class: 'post-replies', target: "_blank" %>
|
||||||
|
<%- end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div style='clear: both'></div>
|
<div style='clear: both'></div>
|
||||||
</article>
|
</article>
|
||||||
<%- end %>
|
<%- end %>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
<%= link_to(I18n.t('embed.continue'), @second_post_url, class: 'button', target: '_blank') %>
|
<%= link_to(I18n.t('embed.continue'), @second_post_url, class: 'button', target: '_blank') %>
|
||||||
|
<span class='replies'><%= I18n.t('embed.replies', count: @topic_view.topic.posts_count) %></span>
|
||||||
<%= link_to(image_tag(SiteSetting.logo_url, class: 'logo'), Discourse.base_url, target: '_blank') %>
|
<%= link_to(image_tag(SiteSetting.logo_url, class: 'logo'), Discourse.base_url, target: '_blank') %>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
@ -30,12 +30,15 @@ en:
|
|||||||
too_many_replies: "Sorry you can't reply any more times in that topic."
|
too_many_replies: "Sorry you can't reply any more times in that topic."
|
||||||
|
|
||||||
embed:
|
embed:
|
||||||
title: "Discussion Highlights"
|
|
||||||
start_discussion: "Begin the Discussion"
|
start_discussion: "Begin the Discussion"
|
||||||
continue: "Continue the Discussion"
|
continue: "Continue the Discussion"
|
||||||
loading: "Loading Discussion..."
|
loading: "Loading Discussion..."
|
||||||
permalink: "Permalink"
|
permalink: "Permalink"
|
||||||
imported_from: "Imported from: %{link}"
|
imported_from: "Imported from: %{link}"
|
||||||
|
in_reply_to: "in reply to %{username}"
|
||||||
|
replies:
|
||||||
|
one: "1 reply"
|
||||||
|
other: "%{count} replies"
|
||||||
|
|
||||||
too_many_mentions:
|
too_many_mentions:
|
||||||
zero: "Sorry, you can't mention other users."
|
zero: "Sorry, you can't mention other users."
|
||||||
@ -773,6 +776,7 @@ en:
|
|||||||
feed_polling_enabled: "Whether to import a RSS/ATOM feed as posts"
|
feed_polling_enabled: "Whether to import a RSS/ATOM feed as posts"
|
||||||
feed_polling_url: "URL of RSS/ATOM feed to import"
|
feed_polling_url: "URL of RSS/ATOM feed to import"
|
||||||
embed_by_username: "Discourse username of the user who creates the topics"
|
embed_by_username: "Discourse username of the user who creates the topics"
|
||||||
|
embed_post_limit: "Maximum number of posts to embed"
|
||||||
|
|
||||||
notification_types:
|
notification_types:
|
||||||
mentioned: "%{display_username} mentioned you in %{link}"
|
mentioned: "%{display_username} mentioned you in %{link}"
|
||||||
|
@ -242,7 +242,7 @@ Discourse::Application.routes.draw do
|
|||||||
get "topics/private-messages-sent/:username" => "list#private_messages_sent", as: "topics_private_messages_sent", constraints: {username: USERNAME_ROUTE_FORMAT}
|
get "topics/private-messages-sent/:username" => "list#private_messages_sent", as: "topics_private_messages_sent", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
get "topics/private-messages-unread/:username" => "list#private_messages_unread", as: "topics_private_messages_unread", constraints: {username: USERNAME_ROUTE_FORMAT}
|
get "topics/private-messages-unread/:username" => "list#private_messages_unread", as: "topics_private_messages_unread", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
|
|
||||||
get 'embed/best' => 'embed#best'
|
get 'embed/comments' => 'embed#comments'
|
||||||
|
|
||||||
# Topic routes
|
# Topic routes
|
||||||
get "t/:slug/:topic_id/wordpress" => "topics#wordpress", constraints: {topic_id: /\d+/}
|
get "t/:slug/:topic_id/wordpress" => "topics#wordpress", constraints: {topic_id: /\d+/}
|
||||||
|
@ -356,6 +356,7 @@ embedding:
|
|||||||
feed_polling_enabled: false
|
feed_polling_enabled: false
|
||||||
feed_polling_url: ''
|
feed_polling_url: ''
|
||||||
embed_by_username: ''
|
embed_by_username: ''
|
||||||
|
embed_post_limit: 100
|
||||||
|
|
||||||
uncategorized:
|
uncategorized:
|
||||||
tos_url:
|
tos_url:
|
||||||
|
@ -37,7 +37,7 @@ class TopicView
|
|||||||
def canonical_path
|
def canonical_path
|
||||||
path = @topic.relative_url
|
path = @topic.relative_url
|
||||||
path << if @post_number
|
path << if @post_number
|
||||||
page = ((@post_number.to_i - 1) / SiteSetting.posts_per_page) + 1
|
page = ((@post_number.to_i - 1) / @limit) + 1
|
||||||
(page > 1) ? "?page=#{page}" : ""
|
(page > 1) ? "?page=#{page}" : ""
|
||||||
else
|
else
|
||||||
(@page && @page.to_i > 1) ? "?page=#{@page}" : ""
|
(@page && @page.to_i > 1) ? "?page=#{@page}" : ""
|
||||||
@ -130,8 +130,12 @@ class TopicView
|
|||||||
|
|
||||||
def filter_posts_paged(page)
|
def filter_posts_paged(page)
|
||||||
page = [page, 1].max
|
page = [page, 1].max
|
||||||
min = SiteSetting.posts_per_page * (page - 1)
|
min = @limit * (page - 1)
|
||||||
max = (min + SiteSetting.posts_per_page) - 1
|
|
||||||
|
# Sometimes we don't care about the OP, for example when embedding comments
|
||||||
|
min = 1 if min == 0 && @exclude_first
|
||||||
|
|
||||||
|
max = (min + @limit) - 1
|
||||||
|
|
||||||
filter_posts_in_range(min, max)
|
filter_posts_in_range(min, max)
|
||||||
end
|
end
|
||||||
@ -317,12 +321,12 @@ class TopicView
|
|||||||
return nil if closest_index.nil?
|
return nil if closest_index.nil?
|
||||||
|
|
||||||
# Make sure to get at least one post before, even with rounding
|
# Make sure to get at least one post before, even with rounding
|
||||||
posts_before = (SiteSetting.posts_per_page.to_f / 4).floor
|
posts_before = (@limit.to_f / 4).floor
|
||||||
posts_before = 1 if posts_before.zero?
|
posts_before = 1 if posts_before.zero?
|
||||||
|
|
||||||
min_idx = closest_index - posts_before
|
min_idx = closest_index - posts_before
|
||||||
min_idx = 0 if min_idx < 0
|
min_idx = 0 if min_idx < 0
|
||||||
max_idx = min_idx + (SiteSetting.posts_per_page - 1)
|
max_idx = min_idx + (@limit - 1)
|
||||||
|
|
||||||
# Get a full page even if at the end
|
# Get a full page even if at the end
|
||||||
ensure_full_page(min_idx, max_idx)
|
ensure_full_page(min_idx, max_idx)
|
||||||
@ -331,7 +335,7 @@ class TopicView
|
|||||||
def ensure_full_page(min, max)
|
def ensure_full_page(min, max)
|
||||||
upper_limit = (filtered_post_ids.length - 1)
|
upper_limit = (filtered_post_ids.length - 1)
|
||||||
if max >= upper_limit
|
if max >= upper_limit
|
||||||
return (upper_limit - SiteSetting.posts_per_page) + 1, upper_limit
|
return (upper_limit - @limit) + 1, upper_limit
|
||||||
else
|
else
|
||||||
return min, max
|
return min, max
|
||||||
end
|
end
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
var comments = document.getElementById('discourse-comments'),
|
var comments = document.getElementById('discourse-comments'),
|
||||||
iframe = document.createElement('iframe');
|
iframe = document.createElement('iframe');
|
||||||
iframe.src = discourseUrl + "embed/best?embed_url=" + encodeURIComponent(discourseEmbedUrl);
|
iframe.src = discourseUrl + "embed/comments?embed_url=" + encodeURIComponent(discourseEmbedUrl);
|
||||||
iframe.id = 'discourse-embed-frame';
|
iframe.id = 'discourse-embed-frame';
|
||||||
iframe.width = "100%";
|
iframe.width = "100%";
|
||||||
iframe.frameBorder = "0";
|
iframe.frameBorder = "0";
|
||||||
|
@ -6,13 +6,13 @@ describe EmbedController do
|
|||||||
let(:embed_url) { "http://eviltrout.com/2013/02/10/why-discourse-uses-emberjs.html" }
|
let(:embed_url) { "http://eviltrout.com/2013/02/10/why-discourse-uses-emberjs.html" }
|
||||||
|
|
||||||
it "is 404 without an embed_url" do
|
it "is 404 without an embed_url" do
|
||||||
get :best
|
get :comments
|
||||||
response.should_not be_success
|
response.should_not be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an error with a missing host" do
|
it "raises an error with a missing host" do
|
||||||
SiteSetting.stubs(:embeddable_host).returns(nil)
|
SiteSetting.stubs(:embeddable_host).returns(nil)
|
||||||
get :best, embed_url: embed_url
|
get :comments, embed_url: embed_url
|
||||||
response.should_not be_success
|
response.should_not be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ describe EmbedController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "raises an error with no referer" do
|
it "raises an error with no referer" do
|
||||||
get :best, embed_url: embed_url
|
get :comments, embed_url: embed_url
|
||||||
response.should_not be_success
|
response.should_not be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -42,13 +42,13 @@ describe EmbedController do
|
|||||||
retriever = mock
|
retriever = mock
|
||||||
TopicRetriever.expects(:new).returns(retriever)
|
TopicRetriever.expects(:new).returns(retriever)
|
||||||
retriever.expects(:retrieve)
|
retriever.expects(:retrieve)
|
||||||
get :best, embed_url: embed_url
|
get :comments, embed_url: embed_url
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates a topic view when a topic_id is found" do
|
it "creates a topic view when a topic_id is found" do
|
||||||
TopicEmbed.expects(:topic_id_for_embed).returns(123)
|
TopicEmbed.expects(:topic_id_for_embed).returns(123)
|
||||||
TopicView.expects(:new).with(123, nil, {best: 5})
|
TopicView.expects(:new).with(123, nil, {limit: 100, exclude_first: true})
|
||||||
get :best, embed_url: embed_url
|
get :comments, embed_url: embed_url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user