mirror of
https://github.com/discourse/discourse.git
synced 2025-03-27 09:25:39 +08:00
FEATURE: Display avatars of PM recepients in small topic header when scrolling down
This commit is contained in:
parent
6578d56308
commit
021f11b68e
app/assets
javascripts/discourse
stylesheets/common/base
@ -121,6 +121,10 @@ export default Ember.Mixin.create({
|
|||||||
this.set("isFixed", true);
|
this.set("isFixed", true);
|
||||||
return this._show($target.text().replace(/^@/, ""), $target);
|
return this._show($target.text().replace(/^@/, ""), $target);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.appEvents.on(`topic-header:trigger-${id}`, (username, $target) => {
|
||||||
|
return this._show(username, $target);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_positionCard(target) {
|
_positionCard(target) {
|
||||||
|
@ -5,6 +5,53 @@ import DiscourseURL from "discourse/lib/url";
|
|||||||
import RawHtml from "discourse/widgets/raw-html";
|
import RawHtml from "discourse/widgets/raw-html";
|
||||||
import renderTags from "discourse/lib/render-tags";
|
import renderTags from "discourse/lib/render-tags";
|
||||||
import { topicFeaturedLinkNode } from "discourse/lib/render-topic-featured-link";
|
import { topicFeaturedLinkNode } from "discourse/lib/render-topic-featured-link";
|
||||||
|
import { avatarImg } from "discourse/widgets/post";
|
||||||
|
|
||||||
|
createWidget("topic-header-participant", {
|
||||||
|
tagName: "span",
|
||||||
|
|
||||||
|
buildClasses(attrs) {
|
||||||
|
return `trigger-${attrs.type}-card`;
|
||||||
|
},
|
||||||
|
|
||||||
|
html(attrs) {
|
||||||
|
const { user, group } = attrs;
|
||||||
|
let avatar, url;
|
||||||
|
|
||||||
|
if (attrs.type === "user") {
|
||||||
|
avatar = avatarImg("tiny", {
|
||||||
|
template: user.avatar_template,
|
||||||
|
username: user.username
|
||||||
|
});
|
||||||
|
url = user.get("path");
|
||||||
|
} else {
|
||||||
|
avatar = iconNode("users");
|
||||||
|
url = Discourse.getURL(`/groups/${group.name}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return h(
|
||||||
|
"a.icon",
|
||||||
|
{
|
||||||
|
attributes: {
|
||||||
|
href: url,
|
||||||
|
"data-auto-route": true,
|
||||||
|
title: attrs.username
|
||||||
|
}
|
||||||
|
},
|
||||||
|
avatar
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
click(e) {
|
||||||
|
const $target = $(e.target);
|
||||||
|
this.appEvents.trigger(
|
||||||
|
`topic-header:trigger-${this.attrs.type}-card`,
|
||||||
|
this.attrs.username,
|
||||||
|
$target
|
||||||
|
);
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default createWidget("header-topic-info", {
|
export default createWidget("header-topic-info", {
|
||||||
tagName: "div.extra-info-wrapper",
|
tagName: "div.extra-info-wrapper",
|
||||||
@ -73,6 +120,58 @@ export default createWidget("header-topic-info", {
|
|||||||
extra.push(new RawHtml({ html: tags }));
|
extra.push(new RawHtml({ html: tags }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (showPM) {
|
||||||
|
const maxHeaderParticipants = extra.length > 0 ? 5 : 10;
|
||||||
|
const participants = [];
|
||||||
|
const topicDetails = topic.get("details");
|
||||||
|
const totalParticipants =
|
||||||
|
topicDetails.allowed_users.length +
|
||||||
|
topicDetails.allowed_groups.length;
|
||||||
|
|
||||||
|
topicDetails.allowed_users.some(user => {
|
||||||
|
if (participants.length >= maxHeaderParticipants) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
participants.push(
|
||||||
|
this.attach("topic-header-participant", {
|
||||||
|
type: "user",
|
||||||
|
user: user,
|
||||||
|
username: user.username
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
topicDetails.allowed_groups.some(group => {
|
||||||
|
if (participants.length >= maxHeaderParticipants) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
participants.push(
|
||||||
|
this.attach("topic-header-participant", {
|
||||||
|
type: "group",
|
||||||
|
group: group,
|
||||||
|
username: group.name
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (totalParticipants > maxHeaderParticipants) {
|
||||||
|
const remaining = totalParticipants - maxHeaderParticipants;
|
||||||
|
participants.push(
|
||||||
|
this.attach("link", {
|
||||||
|
className: "more-participants",
|
||||||
|
action: "jumpToTopPost",
|
||||||
|
href,
|
||||||
|
attributes: { "data-topic-id": topic.get("id") },
|
||||||
|
contents: () => `+${remaining}`
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
extra.push(h("div.topic-header-participants", participants));
|
||||||
|
}
|
||||||
|
|
||||||
extra = extra.concat(applyDecorators(this, "after-tags", attrs, state));
|
extra = extra.concat(applyDecorators(this, "after-tags", attrs, state));
|
||||||
|
|
||||||
if (this.siteSettings.topic_featured_link_enabled) {
|
if (this.siteSettings.topic_featured_link_enabled) {
|
||||||
|
@ -299,3 +299,27 @@
|
|||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.topic-header-participants {
|
||||||
|
&:not(:first-child) {
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
> span {
|
||||||
|
margin: 0 2px;
|
||||||
|
display: inline-block;
|
||||||
|
height: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.trigger-group-card {
|
||||||
|
line-height: 20px;
|
||||||
|
margin: 0 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.more-participants {
|
||||||
|
display: inline-block;
|
||||||
|
color: $header_primary-high;
|
||||||
|
line-height: 20px;
|
||||||
|
padding: 0 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user