FEATURE: Introduce a staff only override key for discourse-presence.

FEATURE: Introduce a staff only override key for discourse-presence.

Merge remote-tracking branch ‘origin/coding-standards’ This uses the composer as a bridge for other plugins.

diff --git a/plugins/discourse-presence/assets/javascripts/discourse/components/composer-presence-display.js.es6 b/plugins/discourse-presence/assets/javascripts/discourse/components/composer-presence-display.js.es6
index c896be3..a01c982 100644
--- a/plugins/discourse-presence/assets/javascripts/discourse/components/composer-presence-display.js.es6
+++ b/plugins/discourse-presence/assets/javascripts/discourse/components/composer-presence-display.js.es6
@@ -17,36 +17,30 @@ import { REPLY, EDIT } from "discourse/models/composer";
 
 export default Component.extend({
   // Passed in variables
-  action: null,
-  post: null,
-  topic: null,
-  reply: null,
-  title: null,
-  isWhispering: null,
   presenceManager: service(),
 
-  @discourseComputed("topic.id")
+  @discourseComputed("model.topic.id")
   users(topicId) {
     return this.presenceManager.users(topicId);
   },
 
-  @discourseComputed("topic.id")
+  @discourseComputed("model.topic.id")
   editingUsers(topicId) {
     return this.presenceManager.editingUsers(topicId);
   },
 
-  isReply: equal("action", REPLY),
+  isReply: equal("model.action", REPLY),
 
   @on("didInsertElement")
   subscribe() {
-    this.presenceManager.subscribe(this.get("topic.id"), COMPOSER_TYPE);
+    this.presenceManager.subscribe(this.get("model.topic.id"), COMPOSER_TYPE);
   },
 
   @discourseComputed(
-    "post.id",
+    "model.post.id",
     "editingUsers.@each.last_seen",
     "users.@each.last_seen",
-    "action"
+    "model.action"
   )
   presenceUsers(postId, editingUsers, users, action) {
     if (action === EDIT) {
@@ -59,23 +53,24 @@ export default Component.extend({
 
   shouldDisplay: gt("presenceUsers.length", 0),
 
-  @observes("reply", "title")
+  @observes("model.reply", "model.title")
   typing() {
     throttle(this, this._typing, KEEP_ALIVE_DURATION_SECONDS * 1000);
   },
 
   _typing() {
-    const action = this.action;
+    const action = this.get("model.action");
 
     if (action !== REPLY && action !== EDIT) {
       return;
     }
 
     let data = {
-      topicId: this.get("topic.id"),
+      topicId: this.get("model.topic.id"),
       state: action === EDIT ? EDITING : REPLYING,
-      whisper: this.whisper,
-      postId: this.get("post.id")
+      whisper: this.get("model.whisper"),
+      postId: this.get("model.post.id"),
+      presenceStaffOnly: this.get("model._presenceStaffOnly")
     };
 
     this._prevPublishData = data;
@@ -84,16 +79,17 @@ export default Component.extend({
       data.topicId,
       data.state,
       data.whisper,
-      data.postId
+      data.postId,
+      data.presenceStaffOnly
     );
   },
 
-  @observes("whisper")
+  @observes("model.whisper")
   cancelThrottle() {
     this._cancelThrottle();
   },
 
-  @observes("action", "topic.id")
+  @observes("model.action", "model.topic.id")
   composerState() {
     if (this._prevPublishData) {
       this.presenceManager.publish(
diff --git a/plugins/discourse-presence/assets/javascripts/discourse/lib/presence.js.es6 b/plugins/discourse-presence/assets/javascripts/discourse/lib/presence.js.es6
index 83424e8..1bc90d9 100644
--- a/plugins/discourse-presence/assets/javascripts/discourse/lib/presence.js.es6
+++ b/plugins/discourse-presence/assets/javascripts/discourse/lib/presence.js.es6
@@ -99,7 +99,7 @@ const Presence = EmberObject.extend({
     return `/presence/${topicId}`;
   },
 
-  publish(state, whisper, postId) {
+  publish(state, whisper, postId, staffOnly) {
     if (this.get("currentUser.hide_profile_and_presence")) return;
 
     const data = {
@@ -108,13 +108,17 @@ const Presence = EmberObject.extend({
     };
 
     if (whisper) {
-      data.is_whisper = 1;
+      data.is_whisper = true;
     }
 
     if (postId && state === EDITING) {
       data.post_id = postId;
     }
 
+    if (staffOnly) {
+      data.staff_only = true;
+    }
+
     return ajax("/presence/publish", {
       type: "POST",
       data
diff --git a/plugins/discourse-presence/assets/javascripts/discourse/services/presence-manager.js.es6 b/plugins/discourse-presence/assets/javascripts/discourse/services/presence-manager.js.es6
index 63af48d..3913009 100644
--- a/plugins/discourse-presence/assets/javascripts/discourse/services/presence-manager.js.es6
+++ b/plugins/discourse-presence/assets/javascripts/discourse/services/presence-manager.js.es6
@@ -36,9 +36,14 @@ const PresenceManager = Service.extend({
     return this._getPresence(topicId).editingUsers;
   },
 
-  publish(topicId, state, whisper, postId) {
+  publish(topicId, state, whisper, postId, staffOnly) {
     if (!topicId) return;
-    return this._getPresence(topicId).publish(state, whisper, postId);
+    return this._getPresence(topicId).publish(
+      state,
+      whisper,
+      postId,
+      staffOnly
+    );
   },
 
   cleanUpPresence(type) {
diff --git a/plugins/discourse-presence/assets/javascripts/discourse/templates/connectors/composer-fields/presence.hbs b/plugins/discourse-presence/assets/javascripts/discourse/templates/connectors/composer-fields/presence.hbs
index 8fa1fb3..daae93f 100644
--- a/plugins/discourse-presence/assets/javascripts/discourse/templates/connectors/composer-fields/presence.hbs
+++ b/plugins/discourse-presence/assets/javascripts/discourse/templates/connectors/composer-fields/presence.hbs
@@ -1,8 +1 @@
-{{composer-presence-display
-  action=model.action
-  post=model.post
-  topic=model.topic
-  reply=model.reply
-  title=model.title
-  whisper=model.whisper
-}}
+{{composer-presence-display model=model}}
diff --git a/plugins/discourse-presence/plugin.rb b/plugins/discourse-presence/plugin.rb
index ce91b1a..de6a3e0 100644
--- a/plugins/discourse-presence/plugin.rb
+++ b/plugins/discourse-presence/plugin.rb
@@ -73,61 +73,65 @@ after_initialize do
         max_backlog_age: Presence::MAX_BACKLOG_AGE_SECONDS
       }
 
-      case permitted_params[:state]
-      when EDITING_STATE
+      if permitted_params[:staff_only]
         opts[:group_ids] = [Group::AUTO_GROUPS[:staff]]
+      else
+        case permitted_params[:state]
+        when EDITING_STATE
+          opts[:group_ids] = [Group::AUTO_GROUPS[:staff]]
 
-        if !post.locked? && !permitted_params[:is_whisper]
-          opts[:user_ids] = [post.user_id]
-
-          if topic.private_message?
-            if post.wiki
-              opts[:user_ids] = opts[:user_ids].concat(
-                topic.allowed_users.where(
-                  "trust_level >= ? AND NOT admin OR moderator",
-                  SiteSetting.min_trust_to_edit_wiki_post
-                ).pluck(:id)
-              )
-
-              opts[:user_ids].uniq!
-
-              # Ignore trust level and just publish to all allowed groups since
-              # trying to figure out which users in the allowed groups have
-              # the necessary trust levels can lead to a large array of user ids
-              # if the groups are big.
-              opts[:group_ids] = opts[:group_ids].concat(
-                topic.allowed_groups.pluck(:id)
-              )
+          if !post.locked? && !permitted_params[:is_whisper]
+            opts[:user_ids] = [post.user_id]
+
+            if topic.private_message?
+              if post.wiki
+                opts[:user_ids] = opts[:user_ids].concat(
+                  topic.allowed_users.where(
+                    "trust_level >= ? AND NOT admin OR moderator",
+                    SiteSetting.min_trust_to_edit_wiki_post
+                  ).pluck(:id)
+                )
+
+                opts[:user_ids].uniq!
+
+                # Ignore trust level and just publish to all allowed groups since
+                # trying to figure out which users in the allowed groups have
+                # the necessary trust levels can lead to a large array of user ids
+                # if the groups are big.
+                opts[:group_ids] = opts[:group_ids].concat(
+                  topic.allowed_groups.pluck(:id)
+                )
+              end
+            else

[... diff too long, it was truncated ...]

GitHub sha: 623920f1