mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:52:11 +08:00
FIX: polls requires a refresh to work when inserted in the stream
This commit is contained in:
parent
19a89bb501
commit
6af71bd601
|
@ -21,6 +21,15 @@ export default {
|
|||
|
||||
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
|
||||
PostView.reopen({
|
||||
_createPollViews: function($post) {
|
||||
|
|
|
@ -273,6 +273,12 @@ after_initialize do
|
|||
whitelisted
|
||||
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, :include_polls?) { post_custom_fields.present? && post_custom_fields[POLLS_CUSTOM_FIELD].present? }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user