FIX: polls requires a refresh to work when inserted in the stream

This commit is contained in:
Régis Hanol 2015-04-27 18:59:29 +02:00
parent 19a89bb501
commit 6af71bd601
2 changed files with 15 additions and 0 deletions

View file

@ -21,6 +21,15 @@ export default {
initialize(container) { initialize(container) {
const messageBus = container.lookup("message-bus:main");
// listen for back-end to tell us when a post has a poll
messageBus.subscribe("/polls", data => {
const post = container.lookup("controller:topic").get("postStream").findLoadedPost(data.post_id);
// HACK to trigger the "postViewUpdated" event
post.set("cooked", post.get("cooked") + " ");
});
// overwrite polls // overwrite polls
PostView.reopen({ PostView.reopen({
_createPollViews: function($post) { _createPollViews: function($post) {

View file

@ -273,6 +273,12 @@ after_initialize do
whitelisted whitelisted
end end
# tells the front-end we have a poll for that post
on(:post_created) do |post|
next if post.is_first_post? || post.custom_fields[POLLS_CUSTOM_FIELD].blank?
DiscourseBus.publish("/polls", { post_id: post.id })
end
add_to_serializer(:post, :polls, false) { post_custom_fields[POLLS_CUSTOM_FIELD] } add_to_serializer(:post, :polls, false) { post_custom_fields[POLLS_CUSTOM_FIELD] }
add_to_serializer(:post, :include_polls?) { post_custom_fields.present? && post_custom_fields[POLLS_CUSTOM_FIELD].present? } add_to_serializer(:post, :include_polls?) { post_custom_fields.present? && post_custom_fields[POLLS_CUSTOM_FIELD].present? }