mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:49:14 +08:00
UX: show topics where the top links are extracted from in user summary
This commit is contained in:
parent
850f5c3472
commit
2016e1cda1
|
@ -390,17 +390,14 @@ const User = RestModel.extend({
|
|||
summary() {
|
||||
return Discourse.ajax(`/users/${this.get("username_lower")}/summary.json`)
|
||||
.then(json => {
|
||||
const topicMap = {};
|
||||
|
||||
json.topics.forEach(t => {
|
||||
topicMap[t.id] = Topic.create(t);
|
||||
});
|
||||
|
||||
const badgeMap = {};
|
||||
Badge.createFromJson(json).forEach(b => {
|
||||
badgeMap[b.id] = b;
|
||||
});
|
||||
const summary = json["user_summary"];
|
||||
const topicMap = {};
|
||||
const badgeMap = {};
|
||||
|
||||
json.topics.forEach(t => topicMap[t.id] = Topic.create(t));
|
||||
Badge.createFromJson(json).forEach(b => badgeMap[b.id] = b );
|
||||
|
||||
summary.topics = summary.topic_ids.map(id => topicMap[id]);
|
||||
|
||||
summary.replies.forEach(r => {
|
||||
r.topic = topicMap[r.topic_id];
|
||||
|
@ -408,7 +405,10 @@ const User = RestModel.extend({
|
|||
r.createdAt = new Date(r.created_at);
|
||||
});
|
||||
|
||||
summary.topics = summary.topic_ids.map(id => topicMap[id]);
|
||||
summary.links.forEach(l => {
|
||||
l.topic = topicMap[l.topic_id];
|
||||
l.post_url = l.topic.urlForPostNumber(l.post_number);
|
||||
});
|
||||
|
||||
if (summary.badges) {
|
||||
summary.badges = summary.badges.map(ub => {
|
||||
|
@ -417,6 +417,7 @@ const User = RestModel.extend({
|
|||
return badge;
|
||||
});
|
||||
}
|
||||
|
||||
return summary;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -30,9 +30,7 @@
|
|||
{{/if}}
|
||||
</span>
|
||||
<br>
|
||||
<span>
|
||||
<a href="{{reply.url}}">{{{reply.topic.fancyTitle}}}</a>
|
||||
</span>
|
||||
<a href="{{unbound reply.url}}">{{{reply.topic.fancyTitle}}}</a>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
|
@ -57,9 +55,7 @@
|
|||
{{/if}}
|
||||
</span>
|
||||
<br>
|
||||
<span>
|
||||
<a href="{{topic.url}}">{{{topic.fancyTitle}}}</a>
|
||||
</span>
|
||||
<a href="{{unbound topic.url}}">{{{topic.fancyTitle}}}</a>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
|
@ -79,16 +75,10 @@
|
|||
<ul>
|
||||
{{#each link in model.links}}
|
||||
<li>
|
||||
<a class='domain' href='{{unbound link.url}}' title='{{unbound link.title}}' target='_blank'>{{shorten-url link.url}}</a>
|
||||
<span class='badge badge-notification clicks' title='{{i18n 'topic_map.clicks' count=link.clicks}}'>{{link.clicks}}</span>
|
||||
<span class='domain'>{{unbound link.domain}}</span>
|
||||
<br>
|
||||
<a href="{{unbound link.url}}" target="_blank" title="{{unbound link.url}}">
|
||||
{{#if link.title}}
|
||||
{{link.title}}
|
||||
{{else}}
|
||||
{{shorten-url link.url}}
|
||||
{{/if}}
|
||||
</a>
|
||||
<a href="{{unbound link.post_url}}">{{{link.topic.fancyTitle}}}</a>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
|
@ -102,12 +92,10 @@
|
|||
<ul>
|
||||
{{#each user in model.most_liked_by_users}}
|
||||
<li>
|
||||
<span>
|
||||
{{#user-info user=user}}
|
||||
{{fa-icon "heart"}}
|
||||
<span class='likes'>{{user.likes}}</span>
|
||||
{{/user-info}}
|
||||
</span>
|
||||
{{#user-info user=user}}
|
||||
{{fa-icon "heart"}}
|
||||
<span class='likes'>{{user.likes}}</span>
|
||||
{{/user-info}}
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
|
|
|
@ -19,15 +19,14 @@ class UserSummary
|
|||
.visible
|
||||
.where(user: @user)
|
||||
.order('like_count DESC, created_at ASC')
|
||||
.includes(:user, :category)
|
||||
.limit(MAX_SUMMARY_RESULTS)
|
||||
end
|
||||
|
||||
def replies
|
||||
Post
|
||||
.joins(:topic)
|
||||
.includes(:topic)
|
||||
.secured(@guardian)
|
||||
.includes(:user, topic: :category)
|
||||
.references(:topic)
|
||||
.merge(Topic.listable_topics.visible.secured(@guardian))
|
||||
.where(user: @user)
|
||||
.where('post_number > 1')
|
||||
|
@ -39,10 +38,11 @@ class UserSummary
|
|||
def links
|
||||
TopicLink
|
||||
.joins(:topic, :post)
|
||||
.includes(:topic, :post)
|
||||
.where('topics.archetype <> ?', Archetype.private_message)
|
||||
.where(user: @user)
|
||||
.where(internal: false, reflection: false, quote: false)
|
||||
.order('clicks DESC, created_at ASC')
|
||||
.order('clicks DESC, topic_links.created_at ASC')
|
||||
.limit(MAX_SUMMARY_RESULTS)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class UserSummarySerializer < ApplicationSerializer
|
||||
class TopicSerializer < BasicTopicSerializer
|
||||
attributes :like_count, :slug, :created_at
|
||||
|
||||
class TopicSerializer < ApplicationSerializer
|
||||
attributes :id, :created_at, :fancy_title, :slug, :like_count
|
||||
end
|
||||
|
||||
class ReplySerializer < ApplicationSerializer
|
||||
|
@ -9,7 +10,12 @@ class UserSummarySerializer < ApplicationSerializer
|
|||
end
|
||||
|
||||
class LinkSerializer < ApplicationSerializer
|
||||
attributes :url, :title, :clicks, :domain
|
||||
attributes :url, :title, :clicks, :post_number
|
||||
has_one :topic, serializer: TopicSerializer
|
||||
|
||||
def post_number
|
||||
object.post.post_number
|
||||
end
|
||||
end
|
||||
|
||||
class MostLikedByUserSerializer < BasicUserSerializer
|
||||
|
@ -18,9 +24,9 @@ class UserSummarySerializer < ApplicationSerializer
|
|||
|
||||
has_many :topics, serializer: TopicSerializer
|
||||
has_many :replies, serializer: ReplySerializer, embed: :object
|
||||
has_many :badges, serializer: UserBadgeSerializer, embed: :object
|
||||
has_many :links, serializer: LinkSerializer, embed: :object
|
||||
has_many :most_liked_by_users, serializer: MostLikedByUserSerializer, embed: :object
|
||||
has_many :badges, serializer: UserBadgeSerializer, embed: :object
|
||||
|
||||
attributes :likes_given,
|
||||
:likes_received,
|
||||
|
|
Loading…
Reference in New Issue
Block a user