REFACTOR: Use core `default_results` function (#111)

REFACTOR: Use core default_results function (#111)

This significantly reduces the amount of logic we need to carry in the discourse-assign plugin. One side effect is that I had to rename the ‘q’ parameter to ‘search’, so that it matches core’s implementation.

diff --git a/assets/javascripts/discourse-assign/controllers/group-assigned-show.js.es6 b/assets/javascripts/discourse-assign/controllers/group-assigned-show.js.es6
index 6566d07..f32e68e 100644
--- a/assets/javascripts/discourse-assign/controllers/group-assigned-show.js.es6
+++ b/assets/javascripts/discourse-assign/controllers/group-assigned-show.js.es6
@@ -9,20 +9,20 @@ export default UserTopicsList.extend({
   taskActions: Ember.inject.service(),
   order: "",
   ascending: false,
-  q: "",
+  search: "",
   bulkSelectEnabled: false,
   selected: [],
   canBulkSelect: alias("currentUser.staff"),
 
-  queryParams: ["order", "ascending", "q"],
+  queryParams: ["order", "ascending", "search"],
 
-  @discourseComputed("q")
-  searchTerm(q) {
-    return q;
+  @discourseComputed("search")
+  searchTerm(search) {
+    return search;
   },
 
   _setSearchTerm(searchTerm) {
-    this.set("q", searchTerm);
+    this.set("search", searchTerm);
     this.refreshModel();
   },
 
@@ -34,7 +34,7 @@ export default UserTopicsList.extend({
         params: {
           order: this.order,
           ascending: this.ascending,
-          q: this.q,
+          search: this.search,
         },
       })
       .then((result) => this.set("model", result))
diff --git a/assets/javascripts/discourse-assign/controllers/group-assigned.js.es6 b/assets/javascripts/discourse-assign/controllers/group-assigned.js.es6
index 8493999..a30a4c8 100644
--- a/assets/javascripts/discourse-assign/controllers/group-assigned.js.es6
+++ b/assets/javascripts/discourse-assign/controllers/group-assigned.js.es6
@@ -24,9 +24,9 @@ export default Controller.extend({
     return ascending || false;
   },
 
-  @discourseComputed("router.currentRoute.queryParams.q")
-  q(q) {
-    return q || "";
+  @discourseComputed("router.currentRoute.queryParams.search")
+  search(search) {
+    return search || "";
   },
 
   @discourseComputed("site.mobileView")
diff --git a/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6 b/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6
index aafa582..306adf1 100644
--- a/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6
+++ b/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6
@@ -6,18 +6,18 @@ import { INPUT_DELAY } from "discourse-common/config/environment";
 export default UserTopicsList.extend({
   user: Ember.inject.controller(),
   taskActions: Ember.inject.service(),
-  queryParams: ["order", "ascending", "q"],
+  queryParams: ["order", "ascending", "search"],
   order: "",
   ascending: false,
-  q: "",
+  search: "",
 
-  @discourseComputed("q")
-  searchTerm(q) {
-    return q;
+  @discourseComputed("search")
+  searchTerm(search) {
+    return search;
   },
 
   _setSearchTerm(searchTerm) {
-    this.set("q", searchTerm);
+    this.set("search", searchTerm);
     this.refreshModel();
   },
 
@@ -29,7 +29,7 @@ export default UserTopicsList.extend({
         params: {
           order: this.order,
           ascending: this.ascending,
-          q: this.q,
+          search: this.search,
         },
       })
       .then((result) => this.set("model", result))
diff --git a/assets/javascripts/discourse-assign/routes/group-assigned-show.js.es6 b/assets/javascripts/discourse-assign/routes/group-assigned-show.js.es6
index 6cd13c8..7e6acde 100644
--- a/assets/javascripts/discourse-assign/routes/group-assigned-show.js.es6
+++ b/assets/javascripts/discourse-assign/routes/group-assigned-show.js.es6
@@ -28,7 +28,7 @@ export default DiscourseRoute.extend({
           params: {
             order: params.order,
             ascending: params.ascending,
-            q: params.q,
+            search: params.search,
           },
         });
   },
@@ -36,7 +36,7 @@ export default DiscourseRoute.extend({
   setupController(controller, model) {
     controller.setProperties({
       model,
-      searchTerm: this.currentModel.params.q,
+      searchTerm: this.currentModel.params.search,
     });
   },
 
diff --git a/assets/javascripts/discourse-assign/routes/user-activity-assigned.js.es6 b/assets/javascripts/discourse-assign/routes/user-activity-assigned.js.es6
index 1356b4e..07bc5dd 100644
--- a/assets/javascripts/discourse-assign/routes/user-activity-assigned.js.es6
+++ b/assets/javascripts/discourse-assign/routes/user-activity-assigned.js.es6
@@ -15,7 +15,7 @@ export default UserTopicListRoute.extend({
         exclude_category_ids: [-1],
         order: params.order,
         ascending: params.ascending,
-        q: params.q,
+        search: params.search,
       },
     });
   },
diff --git a/assets/javascripts/discourse/templates/components/group-assigned-filter.hbs b/assets/javascripts/discourse/templates/components/group-assigned-filter.hbs
index 672adee..ccaa9cf 100644
--- a/assets/javascripts/discourse/templates/components/group-assigned-filter.hbs
+++ b/assets/javascripts/discourse/templates/components/group-assigned-filter.hbs
@@ -1,5 +1,5 @@
 {{#if show-avatar}}
-  {{#link-to "group.assigned.show" filter.username_lower (query-params order=order ascending=ascending q=q)}}
+  {{#link-to "group.assigned.show" filter.username_lower (query-params order=order ascending=ascending search=search)}}
     <div class="assign-image">
       <a href={{filter.userPath}} data-user-card={{filter.username}}>{{avatar filter imageSize="large"}}</a>
     </div>
@@ -14,7 +14,7 @@
     </div>
   {{/link-to}}
 {{else}}
-  {{#link-to "group.assigned.show" filter (query-params order=order ascending=ascending q=q)}}
+  {{#link-to "group.assigned.show" filter (query-params order=order ascending=ascending search=search)}}
     <div class="assign-everyone">
       {{i18n "discourse_assign.group_everyone"}}
     </div>
diff --git a/assets/javascripts/discourse/templates/group/assigned.hbs b/assets/javascripts/discourse/templates/group/assigned.hbs
index 255ff11..7536ed4 100644
--- a/assets/javascripts/discourse/templates/group/assigned.hbs
+++ b/assets/javascripts/discourse/templates/group/assigned.hbs
@@ -17,7 +17,7 @@
         filter="everyone"
         routeType=route_type
         assignmentCount=group.assignment_count
-        q=q
+        search=search
         ascending=ascending
         order=order}}
       {{#each members as |member|}}
@@ -25,7 +25,7 @@
           show-avatar=true
           filter=member
           routeType=route_type
-          q=q
+          search=search
           ascending=ascending
           order=order}}
       {{/each}}
diff --git a/plugin.rb b/plugin.rb
index f13fda2..7a48c21 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -20,8 +20,8 @@ load File.expand_path('../lib/discourse_assign/helpers.rb', __FILE__)
 Discourse::Application.routes.append do
   mount ::DiscourseAssign::Engine, at: "/assign"
   get "topics/private-messages-assigned/:username" => "list#private_messages_assigned", as: "topics_private_messages_assigned", constraints: { username: ::RouteFormat.username }
-  get "/topics/messages-assigned/:username" => "list#messages_assigned", constraints: { username: ::RouteFormat.username }
-  get "/topics/group-topics-assigned/:groupname" => "list#group_topics_assigned", constraints: { username: ::RouteFormat.username }
+  get "/topics/messages-assigned/:username" => "list#messages_assigned", constraints: { username: ::RouteFormat.username }, as: "messages_assigned"
+  get "/topics/group-topics-assigned/:groupname" => "list#group_topics_assigned", constraints: { username: ::RouteFormat.username }, as: "group_topics_assigned"
   get "/g/:id/assigned" => "groups#index"
   get "/g/:id/assigned/:route_type" => "groups#index"
 end
@@ -233,92 +233,46 @@ after_initialize do
   end
 
   add_to_class(:topic_query, :list_messages_assigned) do |user|
-    secure = Topic.listable_topics.secured(@guardian).or(Topic.private_messages_for_user(@user))
-    list = joined_topic_user.where("
+    list = default_results(include_pms: true)
+
+    list = list.where("

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

GitHub sha: c4aefd59

This commit appears in #111 which was approved by eviltrout. It was merged by davidtaylorhq.