From ba482c251c5687aa9003707aedd0236fddd5cae0 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Thu, 6 Aug 2020 16:33:45 +1000 Subject: [PATCH] FIX: stop sync of tracking state when list is filtered This stops sync of tracking state when list is filtered, in the past this would cause the tracking state to go off wack. Additionally this introduces an alias for "filter=tracking", called "f=tracking" This was done cause the term "filter" is used internally in 2 different ways the main way is for /unread /new filtering. Trying to also call a query param "filter" causes enormous amounts of internal pain, this circumvents the issue. --- .../app/controllers/discovery-sortable.js | 3 ++- .../discourse/app/models/topic-tracking-state.js | 15 +++++++++++++-- .../discourse/app/routes/build-topic-route.js | 2 +- lib/topic_query.rb | 3 ++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/app/controllers/discovery-sortable.js b/app/assets/javascripts/discourse/app/controllers/discovery-sortable.js index d286a37dab3..5972e5e25e9 100644 --- a/app/assets/javascripts/discourse/app/controllers/discovery-sortable.js +++ b/app/assets/javascripts/discourse/app/controllers/discovery-sortable.js @@ -14,7 +14,8 @@ export const queryParams = { q: { replace: true, refreshModel: true }, tags: { replace: true }, before: { replace: true, refreshModel: true }, - bumped_before: { replace: true, refreshModel: true } + bumped_before: { replace: true, refreshModel: true }, + f: { replace: true, refreshModel: true } }; // Basic controller options diff --git a/app/assets/javascripts/discourse/app/models/topic-tracking-state.js b/app/assets/javascripts/discourse/app/models/topic-tracking-state.js index bd596908ea8..a2ce7c63fa2 100644 --- a/app/assets/javascripts/discourse/app/models/topic-tracking-state.js +++ b/app/assets/javascripts/discourse/app/models/topic-tracking-state.js @@ -315,7 +315,7 @@ const TopicTrackingState = EmberObject.extend({ }); }, - sync(list, filter) { + sync(list, filter, queryParams) { const tracker = this, states = tracker.states; @@ -368,7 +368,18 @@ const TopicTrackingState = EmberObject.extend({ }); // Correct missing states, safeguard in case message bus is corrupt - if ((filter === "new" || filter === "unread") && !list.more_topics_url) { + let shouldCompensate = + (filter === "new" || filter === "unread") && !list.more_topics_url; + + if (shouldCompensate && queryParams) { + Object.keys(queryParams).forEach(k => { + if (k !== "ascending" && k !== "order") { + shouldCompensate = false; + } + }); + } + + if (shouldCompensate) { const ids = {}; list.topics.forEach(r => (ids["t" + r.id] = true)); diff --git a/app/assets/javascripts/discourse/app/routes/build-topic-route.js b/app/assets/javascripts/discourse/app/routes/build-topic-route.js index cfa069fed0c..e175c703c9e 100644 --- a/app/assets/javascripts/discourse/app/routes/build-topic-route.js +++ b/app/assets/javascripts/discourse/app/routes/build-topic-route.js @@ -65,7 +65,7 @@ function findTopicList(store, tracking, filter, filterParams, extras) { }).then(function(list) { list.set("listParams", filterParams); if (tracking) { - tracking.sync(list, list.filter); + tracking.sync(list, list.filter, filterParams); tracking.trackIncoming(list.filter); } Session.currentProp("topicList", list); diff --git a/lib/topic_query.rb b/lib/topic_query.rb index a838e79e174..7c073b963cd 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -52,6 +52,7 @@ class TopicQuery state search q + f group_name tags match_all_tags @@ -806,7 +807,7 @@ class TopicQuery end end - if (filter = options[:filter]) && @user + if (filter = (options[:filter] || options[:f])) && @user action = if filter == "bookmarked" PostActionType.types[:bookmark]