FIX: Show poll voters in Oneboxed posts. (#7768)

This commit is contained in:
Bianca Nenciu 2019-10-24 14:00:25 +03:00 committed by GitHub
parent e9897d295f
commit 690db4fd36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 14 deletions

View File

@ -165,7 +165,13 @@ export default class PostCooked {
ajax(`/posts/by_number/${topicId}/${postId}`)
.then(result => {
const post = this.decoratorHelper.getModel();
const quotedPosts = post.quoted || {};
quotedPosts[result.id] = result;
post.set("quoted", quotedPosts);
const div = $("<div class='expanded-quote'></div>");
div.data("post-id", result.id);
div.html(result.cooked);
_decorators.forEach(cb => cb(div, this.decoratorHelper));

View File

@ -55,37 +55,44 @@ function initializePolls(api) {
function attachPolls($elem, helper) {
const $polls = $(".poll", $elem);
if (!$polls.length) {
if (!$polls.length || !helper) {
return;
}
if (!helper) {
return;
}
const post = helper.getModel();
let post = helper.getModel();
api.preventCloak(post.id);
const votes = post.get("polls_votes") || {};
post.pollsChanged();
const polls = post.get("pollsObject");
if (!polls) {
return;
}
const polls = post.pollsObject || {};
const votes = post.polls_votes || {};
_interval = _interval || setInterval(rerender, 30000);
$polls.each((idx, pollElem) => {
const $poll = $(pollElem);
const pollName = $poll.data("poll-name");
const poll = polls[pollName];
let poll = polls[pollName];
let vote = votes[pollName] || [];
const quotedId = $poll.parent(".expanded-quote").data("post-id");
if (quotedId) {
const quotedPost = post.quoted[quotedId];
if (quotedPost) {
post = Ember.Object.create(quotedPost);
poll = Ember.Object.create(
quotedPost.polls.find(p => p.name === pollName)
);
vote = quotedPost.polls_votes || {};
vote = vote[pollName] || [];
}
}
if (poll) {
const glue = new WidgetGlue("discourse-poll", register, {
id: `${pollName}-${post.id}`,
post,
poll,
vote: votes[pollName] || []
vote
});
glue.appendTo(pollElem);
_glued.push(glue);