DEV: add support for custom post message callbacks

Allows for cleaner subscription to changes by plugins, polls will move to
it.
This commit is contained in:
Sam
2018-05-24 12:10:22 +10:00
parent 2aad91d4a2
commit 11b544ef4e
2 changed files with 36 additions and 2 deletions

View File

@ -25,9 +25,10 @@ import { modifySelectKit } from "select-kit/mixins/plugin-api";
import { addGTMPageChangedCallback } from 'discourse/lib/page-tracker';
import { registerCustomAvatarHelper } from 'discourse/helpers/user-avatar';
import { disableNameSuppression } from 'discourse/widgets/poster-name';
import { registerCustomPostMessageCallback as registerCustomPostMessageCallback1 } from 'discourse/controllers/topic';
// If you add any methods to the API ensure you bump up this number
const PLUGIN_API_VERSION = '0.8.21';
const PLUGIN_API_VERSION = '0.8.22';
class PluginApi {
constructor(version, container) {
@ -426,6 +427,24 @@ class PluginApi {
disableNameSuppression();
}
/**
* Registers a callback that will be invoked when the server calls
* Post#publish_change_to_clients! please ensure your type does not
* match acted,revised,rebaked,recovered, created,move_to_inbox or archived
*
* callback will be called with topicController and Message
*
* Example:
*
* api.registerCustomPostMessageCallback("applied_color", (topicController, message) => {
* let stream = topicController.get("model.postStream");
* // etc
* });
*/
registerCustomPostMessageCallback(type, callback) {
registerCustomPostMessageCallback1(type, callback);
}
/**
* Changes a setting associated with a widget. For example, if
* you wanted small avatars in the post stream: