diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index ba13bf1f29..536a268e55 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1 +1 @@ - + diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8a94b40452..511d6a5481 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -111,7 +111,7 @@ jobs: - name: Core RSpec if: matrix.build_type == 'backend' && matrix.target == 'core' - run: bin/turbo_rspec + run: bin/turbo_rspec --verbose - name: Plugin RSpec if: matrix.build_type == 'backend' && matrix.target == 'plugins' diff --git a/COPYRIGHT.md b/COPYRIGHT.md new file mode 100644 index 0000000000..80c989e96b --- /dev/null +++ b/COPYRIGHT.md @@ -0,0 +1,59 @@ +# Legal notice + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program as the file LICENSE.txt; if not, please see +http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. + +## Trademark + +Discourse is a registered trademark of Civilized Discourse Construction Kit. + +## Other copyright notices + +Discourse includes works under other copyright notices and distributed +according to the terms of the GNU General Public License or a compatible +license (where indicated), including: + +- Ember.js - Copyright (c) 2020 Yehuda Katz, Tom Dale and Ember.js contributors + MIT License + +- jQuery - Copyright OpenJS Foundation and other contributors, https://openjsf.org/ + MIT License + +- Rails - Copyright (c) 2005-2021 David Heinemeier Hansson + MIT License + +- Onebox - Copyright (c) 2013 jzeta + MIT License + +MIT License: + +``` +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt deleted file mode 100644 index cb867e5604..0000000000 --- a/COPYRIGHT.txt +++ /dev/null @@ -1,31 +0,0 @@ -All Discourse code is Copyright 2013 by Civilized Discourse Construction Kit, Inc. - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at -your option) any later version. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with this program as the file LICENSE.txt; if not, please see -http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. - -Discourse is a registered trademark of Civilized Discourse Construction Kit. - -Discourse includes works under other copyright notices and distributed -according to the terms of the GNU General Public License or a compatible -license (where indicated), including: - -Javascript - - Ember.js - Copyright (c) 2012-2013 Yehuda Katz, Tom Dale, Charles Jolley and Ember.js contributors - - jQuery - Copyright (c) 2010-2013 John Resig - -Ruby - - Rails - Copyright (c) 2005-2013 David Heinemeier Hansson, Rails Core Team contributors (MIT) diff --git a/Gemfile b/Gemfile index 71ee3f910c..703c5da332 100644 --- a/Gemfile +++ b/Gemfile @@ -60,8 +60,6 @@ gem 'redis-namespace' # better maintained living fork gem 'active_model_serializers', '~> 0.8.3' -gem 'onebox' - gem 'http_accept_language', require: false # Ember related gems need to be pinned cause they control client side @@ -90,9 +88,7 @@ gem 'unf', require: false gem 'email_reply_trimmer' -# Forked until https://github.com/toy/image_optim/pull/162 is merged -# https://github.com/discourse/image_optim -gem 'discourse_image_optim', require: 'image_optim' +gem 'image_optim' gem 'multi_json' gem 'mustache' gem 'nokogiri' @@ -231,6 +227,8 @@ gem 'sshkey', require: false gem 'rchardet', require: false gem 'lz4-ruby', require: false, platform: :ruby +gem 'sanitize' + if ENV["IMPORT"] == "1" gem 'mysql2' gem 'redcarpet' diff --git a/Gemfile.lock b/Gemfile.lock index 2bbc42e7d2..e8ae9ce763 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -92,7 +92,7 @@ GEM chunky_png (1.4.0) coderay (1.1.3) colored2 (3.1.2) - concurrent-ruby (1.1.8) + concurrent-ruby (1.1.9) connection_pool (2.2.5) cose (1.2.0) cbor (~> 0.5.9) @@ -117,12 +117,6 @@ GEM discourse-fonts (0.0.8) discourse_dev (0.2.1) faker (~> 2.16) - discourse_image_optim (0.26.2) - exifr (~> 1.2, >= 1.2.2) - fspath (~> 3.0) - image_size (~> 1.5) - in_threads (~> 1.3) - progress (~> 3.0, >= 3.0.1) docile (1.4.0) ecma-re-validator (0.3.0) regexp_parser (~> 2.0) @@ -134,26 +128,30 @@ GEM sprockets (>= 3.3, < 4.1) ember-source (2.18.2) erubi (1.10.0) - excon (0.81.0) + excon (0.82.0) execjs (2.8.1) exifr (1.3.9) fabrication (2.22.0) - faker (2.17.0) + faker (2.18.0) i18n (>= 1.6, < 2) fakeweb (1.3.0) - faraday (1.4.1) + faraday (1.4.2) + faraday-em_http (~> 1.0) + faraday-em_synchrony (~> 1.0) faraday-excon (~> 1.1) faraday-net_http (~> 1.0) faraday-net_http_persistent (~> 1.1) multipart-post (>= 1.2, < 3) ruby2_keywords (>= 0.0.4) + faraday-em_http (1.0.0) + faraday-em_synchrony (1.0.0) faraday-excon (1.1.0) faraday-net_http (1.0.1) faraday-net_http_persistent (1.1.0) fast_blank (1.0.0) fast_xs (0.8.0) - fastimage (2.2.3) - ffi (1.15.0) + fastimage (2.2.4) + ffi (1.15.1) fspath (3.1.2) gc_tracer (1.5.1) globalid (0.4.2) @@ -168,7 +166,13 @@ GEM http_accept_language (2.1.1) i18n (1.8.10) concurrent-ruby (~> 1.0) - image_size (1.5.0) + image_optim (0.30.0) + exifr (~> 1.2, >= 1.2.2) + fspath (~> 3.0) + image_size (>= 1.5, < 3) + in_threads (~> 1.3) + progress (~> 3.0, >= 3.0.1) + image_size (2.1.0) in_threads (1.5.4) jmespath (1.4.0) jquery-rails (4.4.0) @@ -184,7 +188,7 @@ GEM regexp_parser (~> 2.0) uri_template (~> 0.7) jwt (2.2.3) - kgio (2.11.3) + kgio (2.11.4) libv8-node (15.14.0.1) libv8-node (15.14.0.1-arm64-darwin-20) libv8-node (15.14.0.1-x86_64-darwin-18) @@ -203,18 +207,18 @@ GEM logstash-logger (0.26.1) logstash-event (~> 1.2) logster (2.9.6) - loofah (2.9.1) + loofah (2.10.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) lru_redux (1.1.0) lz4-ruby (0.3.3) maxminddb (0.1.22) memory_profiler (1.0.0) - message_bus (3.3.5) + message_bus (3.3.6) rack (>= 1.1.3) method_source (1.0.0) mini_mime (1.1.0) - mini_portile2 (2.5.1) + mini_portile2 (2.5.3) mini_racer (0.4.0) libv8-node (~> 15.14.0.0) mini_scheduler (0.13.0) @@ -232,14 +236,14 @@ GEM multipart-post (2.1.1) mustache (1.1.1) nio4r (2.5.7) - nokogiri (1.11.3) + nokogiri (1.11.7) mini_portile2 (~> 2.5.0) racc (~> 1.4) - nokogiri (1.11.3-arm64-darwin) + nokogiri (1.11.7-arm64-darwin) racc (~> 1.4) - nokogiri (1.11.3-x86_64-darwin) + nokogiri (1.11.7-x86_64-darwin) racc (~> 1.4) - nokogiri (1.11.3-x86_64-linux) + nokogiri (1.11.7-x86_64-linux) racc (~> 1.4) nokogumbo (2.0.5) nokogiri (~> 1.8, >= 1.8.4) @@ -273,13 +277,6 @@ GEM omniauth-twitter (1.4.0) omniauth-oauth (~> 1.1) rack - onebox (2.2.15) - addressable (~> 2.7.0) - htmlentities (~> 4.3) - multi_json (~> 1.11) - mustache - nokogiri (~> 1.7) - sanitize openssl (2.2.0) openssl-signature_algorithm (1.1.1) openssl (~> 2.0) @@ -300,7 +297,7 @@ GEM pry-rails (0.3.9) pry (>= 0.10.4) public_suffix (4.0.6) - puma (5.3.1) + puma (5.3.2) nio4r (~> 2.0) r2 (0.2.7) racc (1.5.2) @@ -330,7 +327,7 @@ GEM rake (>= 0.8.7) thor (~> 1.0) rainbow (3.0.0) - raindrops (0.19.1) + raindrops (0.19.2) rake (13.0.3) rb-fsevent (0.11.0) rb-inotify (0.10.1) @@ -382,18 +379,18 @@ GEM json-schema (~> 2.2) railties (>= 3.1, < 7.0) rtlit (0.0.5) - rubocop (1.14.0) + rubocop (1.16.0) parallel (~> 1.10) parser (>= 3.0.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml - rubocop-ast (>= 1.5.0, < 2.0) + rubocop-ast (>= 1.7.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.5.0) + rubocop-ast (1.7.0) parser (>= 3.0.1.1) - rubocop-discourse (2.4.1) + rubocop-discourse (2.4.2) rubocop (>= 1.1.0) rubocop-rspec (>= 2.0.0) rubocop-rspec (2.3.0) @@ -459,7 +456,7 @@ GEM raindrops (~> 0.7) uniform_notifier (1.14.2) uri_template (0.7.0) - webmock (3.12.2) + webmock (3.13.0) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) @@ -508,7 +505,6 @@ DEPENDENCIES discourse-ember-source (~> 3.12.2) discourse-fonts discourse_dev - discourse_image_optim email_reply_trimmer ember-handlebars-template (= 0.8.0) excon @@ -522,6 +518,7 @@ DEPENDENCIES highline htmlentities http_accept_language + image_optim json json_schemer listen @@ -554,7 +551,6 @@ DEPENDENCIES omniauth-google-oauth2 omniauth-oauth2 omniauth-twitter - onebox parallel_tests pg pry-byebug @@ -585,6 +581,7 @@ DEPENDENCIES ruby-prof ruby-readability rubyzip + sanitize sassc (= 2.0.1) sassc-rails seed-fu @@ -606,4 +603,4 @@ DEPENDENCIES yaml-lint BUNDLED WITH - 2.2.16 + 2.2.19 diff --git a/LICENSE.txt b/LICENSE.txt index 94fb84639c..d159169d10 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,12 +1,12 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - Preamble + Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public @@ -56,7 +56,7 @@ patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. - GNU GENERAL PUBLIC LICENSE + GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains @@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. - NO WARRANTY + NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN @@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - END OF TERMS AND CONDITIONS + END OF TERMS AND CONDITIONS - How to Apply These Terms to Your New Programs + How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it diff --git a/app/assets/javascripts/admin/addon/components/admin-report.js b/app/assets/javascripts/admin/addon/components/admin-report.js index 3ecf00451d..2fe0ab68d8 100644 --- a/app/assets/javascripts/admin/addon/components/admin-report.js +++ b/app/assets/javascripts/admin/addon/components/admin-report.js @@ -366,7 +366,7 @@ export default Component.extend({ }, _buildPayload(facets) { - let payload = { data: { cache: true, facets } }; + let payload = { data: { facets } }; if (this.startDate) { payload.data.start_date = moment(this.startDate) diff --git a/app/assets/javascripts/admin/addon/components/admin-watched-word.js b/app/assets/javascripts/admin/addon/components/admin-watched-word.js index fb24a6f388..8c5fd51496 100644 --- a/app/assets/javascripts/admin/addon/components/admin-watched-word.js +++ b/app/assets/javascripts/admin/addon/components/admin-watched-word.js @@ -1,10 +1,21 @@ import Component from "@ember/component"; -import I18n from "I18n"; +import { equal } from "@ember/object/computed"; import bootbox from "bootbox"; +import discourseComputed from "discourse-common/utils/decorators"; +import I18n from "I18n"; export default Component.extend({ classNames: ["watched-word"], + isReplace: equal("actionKey", "replace"), + isTag: equal("actionKey", "tag"), + isLink: equal("actionKey", "link"), + + @discourseComputed("word.replacement") + tags(replacement) { + return replacement.split(","); + }, + click() { this.word .destroy() diff --git a/app/assets/javascripts/admin/addon/components/suspension-details.js b/app/assets/javascripts/admin/addon/components/suspension-details.js index e99a7e1c5b..fe931ae12e 100644 --- a/app/assets/javascripts/admin/addon/components/suspension-details.js +++ b/app/assets/javascripts/admin/addon/components/suspension-details.js @@ -13,7 +13,7 @@ export default Component.extend({ reasonKeys: [ "not_listening_to_staff", "consuming_staff_time", - "combatative", + "combative", "in_wrong_place", "no_constructive_purpose", CUSTOM_REASON_KEY, diff --git a/app/assets/javascripts/admin/addon/components/watched-word-form.js b/app/assets/javascripts/admin/addon/components/watched-word-form.js index cf957148e2..89eb6bfe95 100644 --- a/app/assets/javascripts/admin/addon/components/watched-word-form.js +++ b/app/assets/javascripts/admin/addon/components/watched-word-form.js @@ -15,16 +15,24 @@ export default Component.extend({ formSubmitted: false, actionKey: null, showMessage: false, + selectedTags: null, canReplace: equal("actionKey", "replace"), canTag: equal("actionKey", "tag"), + canLink: equal("actionKey", "link"), - @discourseComputed("regularExpressions") - placeholderKey(regularExpressions) { - return ( - "admin.watched_words.form.placeholder" + - (regularExpressions ? "_regexp" : "") - ); + didInsertElement() { + this._super(...arguments); + this.set("selectedTags", []); + }, + + @discourseComputed("siteSettings.watched_words_regular_expressions") + placeholderKey(watchedWordsRegularExpressions) { + if (watchedWordsRegularExpressions) { + return "admin.watched_words.form.placeholder_regexp"; + } else { + return "admin.watched_words.form.placeholder"; + } }, @observes("word") @@ -46,6 +54,13 @@ export default Component.extend({ }, actions: { + changeSelectedTags(tags) { + this.setProperties({ + selectedTags: tags, + replacement: tags.join(","), + }); + }, + submit() { if (!this.isUniqueWord) { this.setProperties({ @@ -60,7 +75,10 @@ export default Component.extend({ const watchedWord = WatchedWord.create({ word: this.word, - replacement: this.canReplace || this.canTag ? this.replacement : null, + replacement: + this.canReplace || this.canTag || this.canLink + ? this.replacement + : null, action: this.actionKey, }); diff --git a/app/assets/javascripts/admin/addon/controllers/admin-dashboard-general.js b/app/assets/javascripts/admin/addon/controllers/admin-dashboard-general.js index a831b686bc..bde2cf574b 100644 --- a/app/assets/javascripts/admin/addon/controllers/admin-dashboard-general.js +++ b/app/assets/javascripts/admin/addon/controllers/admin-dashboard-general.js @@ -1,4 +1,4 @@ -import Controller, { inject } from "@ember/controller"; +import Controller, { inject as controller } from "@ember/controller"; import AdminDashboard from "admin/models/admin-dashboard"; import I18n from "I18n"; import PeriodComputationMixin from "admin/mixins/period-computation"; @@ -18,7 +18,7 @@ function staticReport(reportType) { export default Controller.extend(PeriodComputationMixin, { isLoading: false, dashboardFetchedAt: null, - exceptionController: inject("exception"), + exceptionController: controller("exception"), logSearchQueriesEnabled: setting("log_search_queries"), @discourseComputed("siteSettings.dashboard_general_tab_activity_metrics") diff --git a/app/assets/javascripts/admin/addon/controllers/admin-dashboard.js b/app/assets/javascripts/admin/addon/controllers/admin-dashboard.js index 89955953fb..c7291f1a76 100644 --- a/app/assets/javascripts/admin/addon/controllers/admin-dashboard.js +++ b/app/assets/javascripts/admin/addon/controllers/admin-dashboard.js @@ -1,4 +1,4 @@ -import Controller, { inject } from "@ember/controller"; +import Controller, { inject as controller } from "@ember/controller"; import AdminDashboard from "admin/models/admin-dashboard"; import VersionCheck from "admin/models/version-check"; import { computed } from "@ember/object"; @@ -10,7 +10,7 @@ const PROBLEMS_CHECK_MINUTES = 1; export default Controller.extend({ isLoading: false, dashboardFetchedAt: null, - exceptionController: inject("exception"), + exceptionController: controller("exception"), showVersionChecks: setting("version_checks"), @discourseComputed("problems.length") diff --git a/app/assets/javascripts/admin/addon/controllers/admin-watched-words-action.js b/app/assets/javascripts/admin/addon/controllers/admin-watched-words-action.js index 1265e3d028..d84d80615d 100644 --- a/app/assets/javascripts/admin/addon/controllers/admin-watched-words-action.js +++ b/app/assets/javascripts/admin/addon/controllers/admin-watched-words-action.js @@ -12,20 +12,14 @@ import showModal from "discourse/lib/show-modal"; export default Controller.extend({ adminWatchedWords: controller(), actionNameKey: null, - showWordsList: or( - "adminWatchedWords.filtered", - "adminWatchedWords.showWords" - ), downloadLink: fmt( "actionNameKey", "/admin/customize/watched_words/action/%@/download" ), + showWordsList: or("adminWatchedWords.showWords", "adminWatchedWords.filter"), findAction(actionName) { - return (this.get("adminWatchedWords.model") || []).findBy( - "nameKey", - actionName - ); + return (this.adminWatchedWords.model || []).findBy("nameKey", actionName); }, @discourseComputed("actionNameKey", "adminWatchedWords.model") @@ -33,9 +27,15 @@ export default Controller.extend({ return this.findAction(actionName); }, - @discourseComputed("currentAction.words.[]", "adminWatchedWords.model") - filteredContent(words) { - return words || []; + @discourseComputed("currentAction.words.[]") + regexpError(words) { + for (const { regexp, word } of words) { + try { + RegExp(regexp); + } catch { + return I18n.t("admin.watched_words.invalid_regex", { word }); + } + } }, @discourseComputed("actionNameKey") @@ -43,47 +43,51 @@ export default Controller.extend({ return I18n.t("admin.watched_words.action_descriptions." + actionNameKey); }, - @discourseComputed("currentAction.count") - wordCount(count) { - return count || 0; - }, - actions: { recordAdded(arg) { - const a = this.findAction(this.actionNameKey); - if (a) { - a.words.unshiftObject(arg); - a.incrementProperty("count"); - schedule("afterRender", () => { - // remove from other actions lists - let match = null; - this.get("adminWatchedWords.model").forEach((action) => { - if (match) { - return; - } - - if (action.nameKey !== this.actionNameKey) { - match = action.words.findBy("id", arg.id); - if (match) { - action.words.removeObject(match); - action.decrementProperty("count"); - } - } - }); - }); + const action = this.findAction(this.actionNameKey); + if (!action) { + return; } + + action.words.unshiftObject(arg); + schedule("afterRender", () => { + // remove from other actions lists + let match = null; + this.adminWatchedWords.model.forEach((otherAction) => { + if (match) { + return; + } + + if (otherAction.nameKey !== this.actionNameKey) { + match = otherAction.words.findBy("id", arg.id); + if (match) { + otherAction.words.removeObject(match); + } + } + }); + }); }, recordRemoved(arg) { if (this.currentAction) { this.currentAction.words.removeObject(arg); - this.currentAction.decrementProperty("count"); } }, uploadComplete() { WatchedWord.findAll().then((data) => { - this.set("adminWatchedWords.model", data); + this.adminWatchedWords.set("model", data); + }); + }, + + test() { + WatchedWord.findAll().then((data) => { + this.adminWatchedWords.set("model", data); + showModal("admin-watched-word-test", { + admin: true, + model: this.currentAction, + }); }); }, @@ -102,25 +106,12 @@ export default Controller.extend({ }).then(() => { const action = this.findAction(actionKey); if (action) { - action.setProperties({ - words: [], - count: 0, - }); + action.set("words", []); } }); } } ); }, - - test() { - WatchedWord.findAll().then((data) => { - this.set("adminWatchedWords.model", data); - showModal("admin-watched-word-test", { - admin: true, - model: this.currentAction, - }); - }); - }, }, }); diff --git a/app/assets/javascripts/admin/addon/controllers/admin-watched-words.js b/app/assets/javascripts/admin/addon/controllers/admin-watched-words.js index cfd86c6c22..ce41e741fd 100644 --- a/app/assets/javascripts/admin/addon/controllers/admin-watched-words.js +++ b/app/assets/javascripts/admin/addon/controllers/admin-watched-words.js @@ -1,71 +1,56 @@ import Controller from "@ember/controller"; -import EmberObject from "@ember/object"; +import EmberObject, { action } from "@ember/object"; import { INPUT_DELAY } from "discourse-common/config/environment"; -import { alias } from "@ember/object/computed"; import discourseDebounce from "discourse-common/lib/debounce"; import { isEmpty } from "@ember/utils"; import { observes } from "discourse-common/utils/decorators"; export default Controller.extend({ filter: null, - filtered: false, showWords: false, - disableShowWords: alias("filtered"), - regularExpressions: null, - filterContentNow() { - if (!!isEmpty(this.allWatchedWords)) { + _filterContent() { + if (isEmpty(this.allWatchedWords)) { return; } - let filter; - if (this.filter) { - filter = this.filter.toLowerCase(); - } - - if (filter === undefined || filter.length < 1) { + if (!this.filter) { this.set("model", this.allWatchedWords); return; } - const matchesByAction = []; + const filter = this.filter.toLowerCase(); + const model = []; this.allWatchedWords.forEach((wordsForAction) => { const wordRecords = wordsForAction.words.filter((wordRecord) => { return wordRecord.word.indexOf(filter) > -1; }); - matchesByAction.pushObject( + + model.pushObject( EmberObject.create({ nameKey: wordsForAction.nameKey, name: wordsForAction.name, words: wordRecords, - count: wordRecords.length, }) ); }); - this.set("model", matchesByAction); + this.set("model", model); }, @observes("filter") filterContent() { - discourseDebounce( - this, - function () { - this.filterContentNow(); - this.set("filtered", !isEmpty(this.filter)); - }, - INPUT_DELAY - ); + discourseDebounce(this, this._filterContent, INPUT_DELAY); }, - actions: { - clearFilter() { - this.setProperties({ filter: "" }); - }, + @action + clearFilter() { + this.set("filter", ""); + }, - toggleMenu() { - $(".admin-detail").toggleClass("mobile-closed mobile-open"); - }, + @action + toggleMenu() { + $(".admin-detail").toggleClass("mobile-closed mobile-open"); }, }); diff --git a/app/assets/javascripts/admin/addon/controllers/modals/admin-watched-word-test.js b/app/assets/javascripts/admin/addon/controllers/modals/admin-watched-word-test.js index 215cc08a6d..3ce120419c 100644 --- a/app/assets/javascripts/admin/addon/controllers/modals/admin-watched-word-test.js +++ b/app/assets/javascripts/admin/addon/controllers/modals/admin-watched-word-test.js @@ -1,14 +1,50 @@ import Controller from "@ember/controller"; import ModalFunctionality from "discourse/mixins/modal-functionality"; import discourseComputed from "discourse-common/utils/decorators"; +import { equal } from "@ember/object/computed"; export default Controller.extend(ModalFunctionality, { - @discourseComputed("value", "model.compiledRegularExpression") - matches(value, regexpString) { + isReplace: equal("model.nameKey", "replace"), + isTag: equal("model.nameKey", "tag"), + isLink: equal("model.nameKey", "link"), + + @discourseComputed( + "value", + "model.compiledRegularExpression", + "model.words", + "isReplace", + "isTag", + "isLink" + ) + matches(value, regexpString, words, isReplace, isTag, isLink) { if (!value || !regexpString) { return; } - let censorRegexp = new RegExp(regexpString, "ig"); - return value.match(censorRegexp); + + const regexp = new RegExp(regexpString, "ig"); + const matches = value.match(regexp) || []; + + if (isReplace || isLink) { + return matches.map((match) => ({ + match, + replacement: words.find((word) => + new RegExp(word.regexp, "ig").test(match) + ).replacement, + })); + } else if (isTag) { + return matches.map((match) => { + const tags = new Set(); + + words.forEach((word) => { + if (new RegExp(word.regexp, "ig").test(match)) { + word.replacement.split(",").forEach((tag) => tags.add(tag)); + } + }); + + return { match, tags: Array.from(tags) }; + }); + } + + return matches; }, }); diff --git a/app/assets/javascripts/admin/addon/models/watched-word.js b/app/assets/javascripts/admin/addon/models/watched-word.js index 9aebef18eb..54d20bffff 100644 --- a/app/assets/javascripts/admin/addon/models/watched-word.js +++ b/app/assets/javascripts/admin/addon/models/watched-word.js @@ -31,27 +31,21 @@ WatchedWord.reopenClass({ findAll() { return ajax("/admin/customize/watched_words.json").then((list) => { const actions = {}; - list.words.forEach((s) => { - if (!actions[s.action]) { - actions[s.action] = []; - } - actions[s.action].pushObject(WatchedWord.create(s)); + + list.actions.forEach((action) => { + actions[action] = []; }); - list.actions.forEach((a) => { - if (!actions[a]) { - actions[a] = []; - } + list.words.forEach((watchedWord) => { + actions[watchedWord.action].pushObject(WatchedWord.create(watchedWord)); }); - return Object.keys(actions).map((n) => { + return Object.keys(actions).map((nameKey) => { return EmberObject.create({ - nameKey: n, - name: I18n.t("admin.watched_words.actions." + n), - words: actions[n], - count: actions[n].length, - regularExpressions: list.regular_expressions, - compiledRegularExpression: list.compiled_regular_expressions[n], + nameKey, + name: I18n.t("admin.watched_words.actions." + nameKey), + words: actions[nameKey], + compiledRegularExpression: list.compiled_regular_expressions[nameKey], }); }); }); diff --git a/app/assets/javascripts/admin/addon/routes/admin-watched-words-action.js b/app/assets/javascripts/admin/addon/routes/admin-watched-words-action.js index fe1ce75ab7..5ba55219c7 100644 --- a/app/assets/javascripts/admin/addon/routes/admin-watched-words-action.js +++ b/app/assets/javascripts/admin/addon/routes/admin-watched-words-action.js @@ -4,17 +4,12 @@ import I18n from "I18n"; export default DiscourseRoute.extend({ model(params) { - this.controllerFor("adminWatchedWordsAction").set( - "actionNameKey", - params.action_id - ); - let filteredContent = this.controllerFor("adminWatchedWordsAction").get( - "filteredContent" - ); + const controller = this.controllerFor("adminWatchedWordsAction"); + controller.set("actionNameKey", params.action_id); return EmberObject.create({ nameKey: params.action_id, name: I18n.t("admin.watched_words.actions." + params.action_id), - words: filteredContent, + words: controller.filteredContent, }); }, }); diff --git a/app/assets/javascripts/admin/addon/routes/admin-watched-words.js b/app/assets/javascripts/admin/addon/routes/admin-watched-words.js index d995d09d45..aa793646cb 100644 --- a/app/assets/javascripts/admin/addon/routes/admin-watched-words.js +++ b/app/assets/javascripts/admin/addon/routes/admin-watched-words.js @@ -10,17 +10,8 @@ export default DiscourseRoute.extend({ return WatchedWord.findAll(); }, - setupController(controller, model) { - controller.set("model", model); - if (model && model.length) { - controller.set("regularExpressions", model[0].get("regularExpressions")); - } - }, - - afterModel(watchedWordsList) { - this.controllerFor("adminWatchedWords").set( - "allWatchedWords", - watchedWordsList - ); + afterModel(model) { + const controller = this.controllerFor("adminWatchedWords"); + controller.set("allWatchedWords", model); }, }); diff --git a/app/assets/javascripts/admin/addon/templates/components/admin-watched-word.hbs b/app/assets/javascripts/admin/addon/templates/components/admin-watched-word.hbs index cc03496510..53d61a9b97 100644 --- a/app/assets/javascripts/admin/addon/templates/components/admin-watched-word.hbs +++ b/app/assets/javascripts/admin/addon/templates/components/admin-watched-word.hbs @@ -1 +1,9 @@ -{{d-icon "times"}} {{word.word}} {{#if word.replacement}}→ {{word.replacement}}{{/if}} +{{d-icon "times"}} {{word.word}} +{{#if (or isReplace isLink)}} + → {{word.replacement}} +{{else if isTag}} + → + {{#each tags as |tag|}} + {{tag}} + {{/each}} +{{/if}} diff --git a/app/assets/javascripts/admin/addon/templates/components/watched-word-form.hbs b/app/assets/javascripts/admin/addon/templates/components/watched-word-form.hbs index dbc7c8603f..be6727ca68 100644 --- a/app/assets/javascripts/admin/addon/templates/components/watched-word-form.hbs +++ b/app/assets/javascripts/admin/addon/templates/components/watched-word-form.hbs @@ -5,15 +5,29 @@ {{#if canReplace}}
{{i18n "admin.watched_words.test.found_matches"}}
");
@@ -172,11 +173,21 @@ export function selectedText() {
} else {
$div.append($code);
}
+ } else if ($oneboxTest.length) {
+ // This is a partial quote from a onebox.
+ // Treat it as though the entire onebox was quoted.
+ const oneboxUrl = $($oneboxTest).data("onebox-src");
+ $div.append(oneboxUrl);
} else {
$div.append(range.cloneContents());
}
}
+ $div.find("aside.onebox[data-onebox-src]").each(function () {
+ const oneboxUrl = $(this).data("onebox-src");
+ $(this).replaceWith(oneboxUrl);
+ });
+
return toMarkdown($div.html());
}
@@ -452,9 +463,9 @@ const CODE_BLOCKS_REGEX = /^( |\t).*|`[^`]+`|^```[^]*?^```|\[code\][^]*?\[\/c
// | | | |
// | | | code blocks between [code]
// | | |
-// | | +--- code blocks between three backquote
+// | | +--- code blocks between three backticks
// | |
-// | +----- inline code between backquotes
+// | +----- inline code between backticks
// |
// +------- paragraphs starting with 4 spaces or tab
diff --git a/app/assets/javascripts/discourse/app/lib/webauthn.js b/app/assets/javascripts/discourse/app/lib/webauthn.js
index e33ffc2001..113ef3c06b 100644
--- a/app/assets/javascripts/discourse/app/lib/webauthn.js
+++ b/app/assets/javascripts/discourse/app/lib/webauthn.js
@@ -42,7 +42,7 @@ export function getWebauthnCredential(
timeout: 60000,
// see https://chromium.googlesource.com/chromium/src/+/master/content/browser/webauth/uv_preferred.md for why
- // default value of preferred is not necesarrily what we want, it limits webauthn to only devices that support
+ // default value of preferred is not necessarily what we want, it limits webauthn to only devices that support
// user verification, which usually requires entering a PIN
userVerification: "discouraged",
},
diff --git a/app/assets/javascripts/discourse/app/mixins/buffered-content.js b/app/assets/javascripts/discourse/app/mixins/buffered-content.js
index 2b13f7d1d1..92b44f16fa 100644
--- a/app/assets/javascripts/discourse/app/mixins/buffered-content.js
+++ b/app/assets/javascripts/discourse/app/mixins/buffered-content.js
@@ -1,13 +1,11 @@
-import BufferedMixin from "ember-buffered-proxy/mixin";
import BufferedProxy from "ember-buffered-proxy/proxy";
-import EmberObjectProxy from "@ember/object/proxy";
import Mixin from "@ember/object/mixin";
import { computed } from "@ember/object";
export function bufferedProperty(property) {
const mixin = {
buffered: computed(property, function () {
- return EmberObjectProxy.extend(BufferedMixin || BufferedProxy).create({
+ return BufferedProxy.create({
content: this.get(property),
});
}),
diff --git a/app/assets/javascripts/discourse/app/mixins/bulk-topic-selection.js b/app/assets/javascripts/discourse/app/mixins/bulk-topic-selection.js
index 7ba734c65d..edcae9b7f3 100644
--- a/app/assets/javascripts/discourse/app/mixins/bulk-topic-selection.js
+++ b/app/assets/javascripts/discourse/app/mixins/bulk-topic-selection.js
@@ -1,8 +1,8 @@
import Mixin from "@ember/object/mixin";
+import { or } from "@ember/object/computed";
+import { on } from "discourse-common/utils/decorators";
import { NotificationLevels } from "discourse/lib/notification-levels";
import Topic from "discourse/models/topic";
-import { alias } from "@ember/object/computed";
-import { on } from "discourse-common/utils/decorators";
import { inject as service } from "@ember/service";
export default Mixin.create({
@@ -12,13 +12,20 @@ export default Mixin.create({
autoAddTopicsToBulkSelect: false,
selected: null,
- canBulkSelect: alias("currentUser.staff"),
+ canBulkSelect: or("currentUser.staff", "showDismissRead", "showResetNew"),
@on("init")
resetSelected() {
this.set("selected", []);
},
+ _isFilterPage(filter, filterType) {
+ if (!filter) {
+ return false;
+ }
+ return new RegExp(filterType + "$", "gi").test(filter);
+ },
+
actions: {
toggleBulkSelect() {
this.toggleProperty("bulkSelectEnabled");
@@ -44,9 +51,7 @@ export default Mixin.create({
promise.then((result) => {
if (result && result.topic_ids) {
- const tracker = this.topicTrackingState;
- result.topic_ids.forEach((t) => tracker.removeTopic(t));
- tracker.incrementMessageCount();
+ this.topicTrackingState.removeTopics(result.topic_ids);
}
this.send("closeModal");
diff --git a/app/assets/javascripts/discourse/app/mixins/docking.js b/app/assets/javascripts/discourse/app/mixins/docking.js
index 76ccd3a3f7..e8de346cbc 100644
--- a/app/assets/javascripts/discourse/app/mixins/docking.js
+++ b/app/assets/javascripts/discourse/app/mixins/docking.js
@@ -4,9 +4,9 @@ import { cancel, later } from "@ember/runloop";
const helper = {
offset() {
- const mainOffset = $("#main").offset();
- const offsetTop = mainOffset ? mainOffset.top : 0;
- return (window.pageYOffset || $("html").scrollTop()) - offsetTop;
+ const main = document.querySelector("#main");
+ const offsetTop = main ? main.offsetTop : 0;
+ return window.pageYOffset - offsetTop;
},
};
@@ -32,8 +32,8 @@ export default Mixin.create({
didInsertElement() {
this._super(...arguments);
- $(window).bind("scroll.discourse-dock", this.queueDockCheck);
- $(document).bind("touchmove.discourse-dock", this.queueDockCheck);
+ window.addEventListener("scroll", this.queueDockCheck);
+ document.addEventListener("touchmove", this.queueDockCheck);
// dockCheck might happen too early on full page refresh
this._initialTimer = later(this, this.safeDockCheck, 50);
@@ -47,7 +47,7 @@ export default Mixin.create({
}
cancel(this._initialTimer);
- $(window).unbind("scroll.discourse-dock", this.queueDockCheck);
- $(document).unbind("touchmove.discourse-dock", this.queueDockCheck);
+ window.removeEventListener("scroll", this.queueDockCheck);
+ document.removeEventListener("touchmove", this.queueDockCheck);
},
});
diff --git a/app/assets/javascripts/discourse/app/mixins/open-composer.js b/app/assets/javascripts/discourse/app/mixins/open-composer.js
index 8b21b283a1..250469854a 100644
--- a/app/assets/javascripts/discourse/app/mixins/open-composer.js
+++ b/app/assets/javascripts/discourse/app/mixins/open-composer.js
@@ -14,7 +14,8 @@ export default Mixin.create({
}
this.controllerFor("composer").open({
- categoryId,
+ prioritizedCategoryId: categoryId,
+ topicCategoryId: categoryId,
action: Composer.CREATE_TOPIC,
draftKey: controller.get("model.draft_key") || Composer.NEW_TOPIC_KEY,
draftSequence: controller.get("model.draft_sequence") || 0,
diff --git a/app/assets/javascripts/discourse/app/mixins/pan-events.js b/app/assets/javascripts/discourse/app/mixins/pan-events.js
index b1e1835d95..b40fd68eab 100644
--- a/app/assets/javascripts/discourse/app/mixins/pan-events.js
+++ b/app/assets/javascripts/discourse/app/mixins/pan-events.js
@@ -3,7 +3,6 @@ import Mixin from "@ember/object/mixin";
Pan events is a mixin that allows components to detect and respond to swipe gestures
It fires callbacks for panStart, panEnd, panMove with the pan state, and the original event.
**/
-export const SWIPE_VELOCITY = 40;
export const SWIPE_DISTANCE_THRESHOLD = 50;
export const SWIPE_VELOCITY_THRESHOLD = 0.12;
export const MINIMUM_SWIPE_DISTANCE = 5;
@@ -14,35 +13,38 @@ export default Mixin.create({
didInsertElement() {
this._super(...arguments);
- this.addTouchListeners($(this.element));
+ this.addTouchListeners(this.element);
},
willDestroyElement() {
this._super(...arguments);
- this.removeTouchListeners($(this.element));
+ this.removeTouchListeners(this.element);
},
- addTouchListeners($element) {
+ addTouchListeners(element) {
if (this.site.mobileView) {
- $element
- .on("touchstart", (e) => e.touches && this._panStart(e.touches[0]))
- .on("touchmove", (e) => {
- const touchEvent = e.touches[0];
- touchEvent.type = "pointermove";
- this._panMove(touchEvent, e);
- })
- .on("touchend", (e) => this._panMove({ type: "pointerup" }, e))
- .on("touchcancel", (e) => this._panMove({ type: "pointercancel" }, e));
+ this.touchStart = (e) => e.touches && this._panStart(e.touches[0]);
+ this.touchMove = (e) => {
+ const touchEvent = e.touches[0];
+ touchEvent.type = "pointermove";
+ this._panMove(touchEvent, e);
+ };
+ this.touchEnd = (e) => this._panMove({ type: "pointerup" }, e);
+ this.touchCancel = (e) => this._panMove({ type: "pointercancel" }, e);
+
+ element.addEventListener("touchstart", this.touchStart);
+ element.addEventListener("touchmove", this.touchMove);
+ element.addEventListener("touchend", this.touchEnd);
+ element.addEventListener("touchcancel", this.touchCancel);
}
},
- removeTouchListeners($element) {
+ removeTouchListeners(element) {
if (this.site.mobileView) {
- $element
- .off("touchstart")
- .off("touchmove")
- .off("touchend")
- .off("touchcancel");
+ element.removeEventListener("touchstart", this.touchStart);
+ element.removeEventListener("touchmove", this.touchMove);
+ element.removeEventListener("touchend", this.touchEnd);
+ element.removeEventListener("touchcancel", this.touchCancel);
}
},
diff --git a/app/assets/javascripts/discourse/app/models/bookmark.js b/app/assets/javascripts/discourse/app/models/bookmark.js
index d295ebc74c..52b032e264 100644
--- a/app/assets/javascripts/discourse/app/models/bookmark.js
+++ b/app/assets/javascripts/discourse/app/models/bookmark.js
@@ -137,7 +137,7 @@ const Bookmark = RestModel.extend({
url += "?" + $.param(params);
}
- return ajax(url, { cache: "false" });
+ return ajax(url);
},
loadMore(additionalParams) {
diff --git a/app/assets/javascripts/discourse/app/models/category.js b/app/assets/javascripts/discourse/app/models/category.js
index 4de28e476d..af65076dba 100644
--- a/app/assets/javascripts/discourse/app/models/category.js
+++ b/app/assets/javascripts/discourse/app/models/category.js
@@ -426,7 +426,7 @@ Category.reopenClass({
findBySlugPathWithID(slugPathWithID) {
let parts = slugPathWithID.split("/").filter(Boolean);
- // slugs found by star/glob pathing in emeber do not automatically url decode - ensure that these are decoded
+ // slugs found by star/glob pathing in ember do not automatically url decode - ensure that these are decoded
if (this.slugEncoded()) {
parts = parts.map((urlPart) => decodeURI(urlPart));
}
diff --git a/app/assets/javascripts/discourse/app/models/composer.js b/app/assets/javascripts/discourse/app/models/composer.js
index b36abfb524..5b8f6c6815 100644
--- a/app/assets/javascripts/discourse/app/models/composer.js
+++ b/app/assets/javascripts/discourse/app/models/composer.js
@@ -1,6 +1,6 @@
import EmberObject, { set } from "@ember/object";
import { and, equal, not, or, reads } from "@ember/object/computed";
-import { cancel, later, next, throttle } from "@ember/runloop";
+import { next, throttle } from "@ember/runloop";
import discourseComputed, {
observes,
on,
@@ -113,7 +113,6 @@ const Composer = RestModel.extend({
unlistTopic: false,
noBump: false,
draftSaving: false,
- draftSaved: false,
draftForceSave: false,
archetypes: reads("site.archetypes"),
@@ -693,15 +692,30 @@ const Composer = RestModel.extend({
}
},
- /*
- Open a composer
+ /**
+ Open a composer
- opts:
- action - The action we're performing: edit, reply or createTopic
- post - The post we're replying to, if present
- topic - The topic we're replying to, if present
- quote - If we're opening a reply from a quote, the quote we're making
- */
+ @method open
+ @param {Object} opts
+ @param {String} opts.action The action we're performing: edit, reply, createTopic, createSharedDraft, privateMessage
+ @param {String} opts.draftKey
+ @param {String} opts.draftSequence
+ @param {Post} [opts.post] The post we're replying to, if present
+ @param {Topic} [opts.topic] The topic we're replying to, if present
+ @param {String} [opts.quote] If we're opening a reply from a quote, the quote we're making
+ @param {String} [opts.reply]
+ @param {String} [opts.recipients]
+ @param {Number} [opts.composerTime]
+ @param {Number} [opts.typingTime]
+ @param {Boolean} [opts.whisper]
+ @param {Boolean} [opts.noBump]
+ @param {String} [opts.archetypeId] One of `site.archetypes` e.g. `regular` or `private_message`
+ @param {Object} [opts.metaData]
+ @param {Number} [opts.categoryId]
+ @param {Number} [opts.postId]
+ @param {Number} [opts.destinationCategoryId]
+ @param {String} [opts.title]
+ **/
open(opts) {
let promise = Promise.resolve();
@@ -946,23 +960,29 @@ const Composer = RestModel.extend({
this.set("composeState", SAVING);
const rollback = throwAjaxError((error) => {
- post.set("cooked", oldCooked);
+ post.setProperties({ cooked: oldCooked, staged: false });
+ this.appEvents.trigger("post-stream:refresh", { id: post.id });
+
this.set("composeState", OPEN);
if (error.jqXHR && error.jqXHR.status === 409) {
this.set("editConflict", true);
}
});
+ post.setProperties({ cooked: props.cooked, staged: true });
+ this.appEvents.trigger("post-stream:refresh", { id: post.id });
+
return promise
.then(() => {
- // rest model only sets props after it is saved
- post.set("cooked", props.cooked);
return post.save(props).then((result) => {
this.clearState();
return result;
});
})
- .catch(rollback);
+ .catch(rollback)
+ .finally(() => {
+ post.set("staged", false);
+ });
},
serialize(serializer, dest) {
@@ -1169,16 +1189,10 @@ const Composer = RestModel.extend({
}
this.setProperties({
- draftSaved: false,
draftSaving: true,
draftConflictUser: null,
});
- if (this._clearingStatus) {
- cancel(this._clearingStatus);
- this._clearingStatus = null;
- }
-
let data = this.serialize(_draft_serializer);
if (data.postId && !isEmpty(this.originalText)) {
@@ -1203,7 +1217,7 @@ const Composer = RestModel.extend({
});
} else {
this.setProperties({
- draftSaved: true,
+ draftStatus: null,
draftConflictUser: null,
draftForceSave: false,
});
@@ -1255,23 +1269,6 @@ const Composer = RestModel.extend({
this.set("draftSaving", false);
});
},
-
- @observes("title", "reply")
- dataChanged() {
- const draftStatus = this.draftStatus;
-
- if (draftStatus && !this._clearingStatus) {
- this._clearingStatus = later(
- this,
- () => {
- this.setProperties({ draftStatus: null, draftConflictUser: null });
- this._clearingStatus = null;
- this.setProperties({ draftSaving: false, draftSaved: false });
- },
- Ember.Test ? 0 : 1000
- );
- }
- },
});
Composer.reopenClass({
diff --git a/app/assets/javascripts/discourse/app/models/draft.js b/app/assets/javascripts/discourse/app/models/draft.js
index 5406c7f9b8..37dda0ba76 100644
--- a/app/assets/javascripts/discourse/app/models/draft.js
+++ b/app/assets/javascripts/discourse/app/models/draft.js
@@ -34,6 +34,7 @@ Draft.reopenClass({
owner: clientId,
force_save: forceSave,
},
+ ignoreUnsent: false,
});
},
});
diff --git a/app/assets/javascripts/discourse/app/models/group.js b/app/assets/javascripts/discourse/app/models/group.js
index 429dcd0595..23a8e54f26 100644
--- a/app/assets/javascripts/discourse/app/models/group.js
+++ b/app/assets/javascripts/discourse/app/models/group.js
@@ -217,10 +217,12 @@ const Group = RestModel.extend({
smtp_server: this.smtp_server,
smtp_port: this.smtp_port,
smtp_ssl: this.smtp_ssl,
+ smtp_enabled: this.smtp_enabled,
imap_server: this.imap_server,
imap_port: this.imap_port,
imap_ssl: this.imap_ssl,
imap_mailbox_name: this.imap_mailbox_name,
+ imap_enabled: this.imap_enabled,
email_username: this.email_username,
email_password: this.email_password,
flair_icon: null,
diff --git a/app/assets/javascripts/discourse/app/models/post.js b/app/assets/javascripts/discourse/app/models/post.js
index 77e1967f2e..5da002ab51 100644
--- a/app/assets/javascripts/discourse/app/models/post.js
+++ b/app/assets/javascripts/discourse/app/models/post.js
@@ -172,7 +172,6 @@ const Post = RestModel.extend({
return ajax(`/posts/${this.id}/recover`, {
type: "PUT",
- cache: false,
})
.then((data) => {
this.setProperties({
@@ -208,13 +207,9 @@ const Post = RestModel.extend({
} else {
const key =
this.post_number === 1
- ? "topic.deleted_by_author"
- : "post.deleted_by_author";
- promise = cookAsync(
- I18n.t(key, {
- count: this.siteSettings.delete_removed_posts_after,
- })
- ).then((cooked) => {
+ ? "topic.deleted_by_author_simple"
+ : "post.deleted_by_author_simple";
+ promise = cookAsync(I18n.t(key)).then((cooked) => {
this.setProperties({
cooked: cooked,
can_delete: false,
diff --git a/app/assets/javascripts/discourse/app/models/site.js b/app/assets/javascripts/discourse/app/models/site.js
index fa59e1cc21..9fc38c92de 100644
--- a/app/assets/javascripts/discourse/app/models/site.js
+++ b/app/assets/javascripts/discourse/app/models/site.js
@@ -179,8 +179,10 @@ Site.reopenClass(Singleton, {
}
if (result.trust_levels) {
- result.trustLevels = result.trust_levels.map((tl) =>
- TrustLevel.create(tl)
+ result.trustLevels = Object.entries(result.trust_levels).map(
+ ([key, id]) => {
+ return new TrustLevel(id, key);
+ }
);
delete result.trust_levels;
}
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 b00e8427ba..8b424ec007 100644
--- a/app/assets/javascripts/discourse/app/models/topic-tracking-state.js
+++ b/app/assets/javascripts/discourse/app/models/topic-tracking-state.js
@@ -1,11 +1,11 @@
import EmberObject, { get } from "@ember/object";
import discourseComputed, { on } from "discourse-common/utils/decorators";
import Category from "discourse/models/category";
+import { deepEqual, deepMerge } from "discourse-common/lib/object";
import DiscourseURL from "discourse/lib/url";
import { NotificationLevels } from "discourse/lib/notification-levels";
import PreloadStore from "discourse/lib/preload-store";
import User from "discourse/models/user";
-import { deepEqual } from "discourse-common/lib/object";
import { isEmpty } from "@ember/utils";
function isNew(topic) {
@@ -13,6 +13,7 @@ function isNew(topic) {
topic.last_read_post_number === null &&
((topic.notification_level !== 0 && !topic.notification_level) ||
topic.notification_level >= NotificationLevels.TRACKING) &&
+ topic.created_in_new_period &&
isUnseen(topic)
);
}
@@ -21,7 +22,8 @@ function isUnread(topic) {
return (
topic.last_read_post_number !== null &&
topic.last_read_post_number < topic.highest_post_number &&
- topic.notification_level >= NotificationLevels.TRACKING
+ topic.notification_level >= NotificationLevels.TRACKING &&
+ topic.unread_not_too_old
);
}
@@ -48,105 +50,47 @@ const TopicTrackingState = EmberObject.extend({
_setup() {
this.unreadSequence = [];
this.newSequence = [];
- this.states = {};
+ this.states = new Map();
+ this.messageIncrementCallbacks = {};
+ this.stateChangeCallbacks = {};
+ this._trackedTopicLimit = 4000;
},
+ /**
+ * Subscribe to MessageBus channels which are used for publishing changes
+ * to the tracking state. Each message received will modify state for
+ * a particular topic.
+ *
+ * See app/models/topic_tracking_state.rb for the data payloads published
+ * to each of the channels.
+ *
+ * @method establishChannels
+ */
establishChannels() {
- const tracker = this;
-
- const process = (data) => {
- if (["muted", "unmuted"].includes(data.message_type)) {
- tracker.trackMutedOrUnmutedTopic(data);
- return;
- }
-
- tracker.pruneOldMutedAndUnmutedTopics();
-
- if (tracker.isMutedTopic(data.topic_id)) {
- return;
- }
-
- if (
- this.siteSettings.mute_all_categories_by_default &&
- !tracker.isUnmutedTopic(data.topic_id)
- ) {
- return;
- }
-
- if (data.message_type === "delete") {
- tracker.removeTopic(data.topic_id);
- tracker.incrementMessageCount();
- }
-
- if (["new_topic", "latest"].includes(data.message_type)) {
- const muted_category_ids = User.currentProp("muted_category_ids");
- if (
- muted_category_ids &&
- muted_category_ids.includes(data.payload.category_id)
- ) {
- return;
- }
- }
-
- if (["new_topic", "latest"].includes(data.message_type)) {
- const mutedTagIds = User.currentProp("muted_tag_ids");
- if (
- hasMutedTags(
- data.payload.topic_tag_ids,
- mutedTagIds,
- this.siteSettings
- )
- ) {
- return;
- }
- }
-
- if (data.message_type === "latest") {
- tracker.notify(data);
- }
-
- if (data.message_type === "dismiss_new") {
- tracker.dismissNewTopic(data);
- }
-
- if (["new_topic", "unread", "read"].includes(data.message_type)) {
- tracker.notify(data);
- const old = tracker.states["t" + data.topic_id];
- if (!deepEqual(old, data.payload)) {
- tracker.states["t" + data.topic_id] = data.payload;
- tracker.notifyPropertyChange("states");
- tracker.incrementMessageCount();
- }
- }
- };
-
- this.messageBus.subscribe("/new", process);
- this.messageBus.subscribe("/latest", process);
+ this.messageBus.subscribe("/new", this._processChannelPayload.bind(this));
+ this.messageBus.subscribe(
+ "/latest",
+ this._processChannelPayload.bind(this)
+ );
if (this.currentUser) {
this.messageBus.subscribe(
"/unread/" + this.currentUser.get("id"),
- process
+ this._processChannelPayload.bind(this)
);
}
this.messageBus.subscribe("/delete", (msg) => {
- const old = tracker.states["t" + msg.topic_id];
- if (old) {
- old.deleted = true;
- }
- tracker.incrementMessageCount();
+ this.modifyStateProp(msg, "deleted", true);
+ this.incrementMessageCount();
});
this.messageBus.subscribe("/recover", (msg) => {
- const old = tracker.states["t" + msg.topic_id];
- if (old) {
- delete old.deleted;
- }
- tracker.incrementMessageCount();
+ this.modifyStateProp(msg, "deleted", false);
+ this.incrementMessageCount();
});
this.messageBus.subscribe("/destroy", (msg) => {
- tracker.incrementMessageCount();
+ this.incrementMessageCount();
const currentRoute = DiscourseURL.router.currentRoute.parent;
if (
currentRoute.name === "topic" &&
@@ -181,17 +125,6 @@ const TopicTrackingState = EmberObject.extend({
this.currentUser && this.currentUser.set(key, topics);
},
- dismissNewTopic(data) {
- data.payload.topic_ids.forEach((k) => {
- const topic = this.states[`t${k}`];
- this.states[`t${k}`] = Object.assign({}, topic, {
- is_seen: true,
- });
- });
- this.notifyPropertyChange("states");
- this.incrementMessageCount();
- },
-
pruneOldMutedAndUnmutedTopics() {
const now = Date.now();
let mutedTopics = this.mutedTopics().filter(
@@ -213,22 +146,50 @@ const TopicTrackingState = EmberObject.extend({
return !!this.unmutedTopics().findBy("topicId", topicId);
},
+ /**
+ * Updates the topic's last_read_post_number to the highestSeen post
+ * number, as long as the topic is being tracked.
+ *
+ * Calls onStateChange callbacks.
+ *
+ * @params {Number|String} topicId - The ID of the topic to set last_read_post_number for.
+ * @params {Number} highestSeen - The post number of the topic that should be
+ * used for last_read_post_number.
+ * @method updateSeen
+ */
updateSeen(topicId, highestSeen) {
if (!topicId || !highestSeen) {
return;
}
- const state = this.states["t" + topicId];
+ const state = this.findState(topicId);
+ if (!state) {
+ return;
+ }
+
if (
- state &&
- (!state.last_read_post_number ||
- state.last_read_post_number < highestSeen)
+ !state.last_read_post_number ||
+ state.last_read_post_number < highestSeen
) {
- state.last_read_post_number = highestSeen;
+ this.modifyStateProp(topicId, "last_read_post_number", highestSeen);
this.incrementMessageCount();
}
},
- notify(data) {
+ /**
+ * Used to count incoming topics which will be displayed in a message
+ * at the top of the topic list, if hasIncoming is true (which is if
+ * incomingCount > 0).
+ *
+ * This will do nothing unless resetTracking or trackIncoming has been
+ * called; newIncoming will be null instead of an array. trackIncoming
+ * is called by various topic routes, as is resetTracking.
+ *
+ * @method notifyIncoming
+ * @param {Object} data - The data sent by TopicTrackingState to MessageBus
+ * which includes the message_type, payload of the topic,
+ * and the topic_id.
+ */
+ notifyIncoming(data) {
if (!this.newIncoming) {
return;
}
@@ -240,6 +201,9 @@ const TopicTrackingState = EmberObject.extend({
const filterCategory = this.filterCategory;
const categoryId = data.payload && data.payload.category_id;
+ // if we have a filter category currently and it is not the
+ // same as the topic category from the payload, then do nothing
+ // because it doesn't need to be counted as incoming
if (filterCategory && filterCategory.get("id") !== categoryId) {
const category = categoryId && Category.findById(categoryId);
if (
@@ -250,46 +214,67 @@ const TopicTrackingState = EmberObject.extend({
}
}
+ // always count a new_topic as incoming
if (
["all", "latest", "new"].includes(filter) &&
data.message_type === "new_topic"
) {
- this.addIncoming(data.topic_id);
+ this._addIncoming(data.topic_id);
}
+ // count an unread topic as incoming
if (["all", "unread"].includes(filter) && data.message_type === "unread") {
- const old = this.states["t" + data.topic_id];
+ const old = this.findState(data);
+
+ // the highest post number is equal to last read post number here
+ // because the state has already been modified based on the /unread
+ // messageBus message
if (!old || old.highest_post_number === old.last_read_post_number) {
- this.addIncoming(data.topic_id);
+ this._addIncoming(data.topic_id);
}
}
+ // always add incoming if looking at the latest list and a latest channel
+ // message comes through
if (filter === "latest" && data.message_type === "latest") {
- this.addIncoming(data.topic_id);
+ this._addIncoming(data.topic_id);
}
+ // hasIncoming relies on this count
this.set("incomingCount", this.newIncoming.length);
},
- addIncoming(topicId) {
- if (this.newIncoming.indexOf(topicId) === -1) {
- this.newIncoming.push(topicId);
- }
- },
-
+ /**
+ * Resets the number of incoming topics to 0 and flushes the new topics
+ * from the array. Without calling this or trackIncoming the notifyIncoming
+ * method will do nothing.
+ *
+ * @method resetTracking
+ */
resetTracking() {
this.newIncoming = [];
this.set("incomingCount", 0);
},
- // track how many new topics came for this filter
+ /**
+ * Track how many new topics came for the specified filter.
+ *
+ * Related/intertwined with notifyIncoming; the filter and filterCategory
+ * set here is used to determine whether or not to add incoming counts
+ * based on message types of incoming MessageBus messages (via establishChannels)
+ *
+ * @method trackIncoming
+ * @param {String} filter - Valid values are all, categories, and any topic list
+ * filters e.g. latest, unread, new. As well as this
+ * specific category and tag URLs like /tag/test/l/latest
+ * or c/cat/subcat/6/l/latest.
+ */
trackIncoming(filter) {
this.newIncoming = [];
- const split = filter.split("/");
+ const split = filter.split("/");
if (split.length >= 4) {
filter = split[split.length - 1];
- // c/cat/subcat/6/l/latest
let category = Category.findSingleBySlug(
split.splice(1, split.length - 4).join("/")
);
@@ -302,145 +287,126 @@ const TopicTrackingState = EmberObject.extend({
this.set("incomingCount", 0);
},
+ /**
+ * Used to determine whether toshow the message at the top of the topic list
+ * e.g. "see 1 new or updated topic"
+ *
+ * @method incomingCount
+ */
@discourseComputed("incomingCount")
hasIncoming(incomingCount) {
return incomingCount && incomingCount > 0;
},
- removeTopic(topic_id) {
- delete this.states["t" + topic_id];
+ /**
+ * Removes the topic ID provided from the tracker state.
+ *
+ * Calls onStateChange callbacks.
+ *
+ * @param {Number|String} topicId - The ID of the topic to remove from state.
+ * @method removeTopic
+ */
+ removeTopic(topicId) {
+ this.states.delete(this._stateKey(topicId));
+ this._afterStateChange();
},
- // If we have a cached topic list, we can update it from our tracking information.
+ /**
+ * Removes multiple topics from the state at once, and increments
+ * the message count.
+ *
+ * Calls onStateChange callbacks.
+ *
+ * @param {Array} topicIds - The IDs of the topic to removes from state.
+ * @method removeTopics
+ */
+ removeTopics(topicIds) {
+ topicIds.forEach((topicId) => this.removeTopic(topicId));
+ this.incrementMessageCount();
+ this._afterStateChange();
+ },
+
+ /**
+ * If we have a cached topic list, we can update it from our tracking information
+ * if the last_read_post_number or is_seen property does not match what the
+ * cached topic has.
+ *
+ * @method updateTopics
+ * @param {Array} topics - An array of Topic models.
+ */
updateTopics(topics) {
if (isEmpty(topics)) {
return;
}
- const states = this.states;
- topics.forEach((t) => {
- const state = states["t" + t.get("id")];
+ topics.forEach((topic) => {
+ const state = this.findState(topic.get("id"));
- if (state) {
- const lastRead = t.get("last_read_post_number");
- const isSeen = t.get("is_seen");
- if (
- lastRead !== state.last_read_post_number ||
- isSeen !== state.is_seen
- ) {
- const postsCount = t.get("posts_count");
- let newPosts = postsCount - state.highest_post_number,
- unread = postsCount - state.last_read_post_number;
+ if (!state) {
+ return;
+ }
- if (newPosts < 0) {
- newPosts = 0;
- }
- if (!state.last_read_post_number) {
- unread = 0;
- }
- if (unread < 0) {
- unread = 0;
- }
+ const lastRead = topic.get("last_read_post_number");
+ const isSeen = topic.get("is_seen");
- t.setProperties({
- highest_post_number: state.highest_post_number,
- last_read_post_number: state.last_read_post_number,
- new_posts: newPosts,
- unread: unread,
- is_seen: state.is_seen,
- unseen: !state.last_read_post_number && isUnseen(state),
- });
+ if (
+ lastRead !== state.last_read_post_number ||
+ isSeen !== state.is_seen
+ ) {
+ const postsCount = topic.get("posts_count");
+ let newPosts = postsCount - state.highest_post_number,
+ unread = postsCount - state.last_read_post_number;
+
+ if (newPosts < 0) {
+ newPosts = 0;
}
+ if (!state.last_read_post_number) {
+ unread = 0;
+ }
+ if (unread < 0) {
+ unread = 0;
+ }
+
+ topic.setProperties({
+ highest_post_number: state.highest_post_number,
+ last_read_post_number: state.last_read_post_number,
+ new_posts: newPosts,
+ unread: unread,
+ is_seen: state.is_seen,
+ unseen: !state.last_read_post_number && isUnseen(state),
+ });
}
});
},
+ /**
+ * Uses the provided topic list to apply changes to the in-memory topic
+ * tracking state, remove state as required, and also compensate for missing
+ * in-memory state.
+ *
+ * Any state changes will make a callback to all state change callbacks defined
+ * via onStateChange and all message increment callbacks defined via onMessageIncrement
+ *
+ * @method sync
+ * @param {TopicList} list
+ * @param {String} filter - The filter used for the list e.g. new/unread
+ * @param {Object} queryParams - The query parameters for the list e.g. page
+ */
sync(list, filter, queryParams) {
- const tracker = this,
- states = tracker.states;
-
if (!list || !list.topics) {
return;
}
- // compensate for delayed "new" topics
- // client side we know they are not new, server side we think they are
- for (let i = list.topics.length - 1; i >= 0; i--) {
- const state = states["t" + list.topics[i].id];
- if (state && state.last_read_post_number > 0) {
- if (filter === "new") {
- list.topics.splice(i, 1);
- } else {
- list.topics[i].set("unseen", false);
- list.topics[i].set("dont_sync", true);
- }
- }
- }
+ // make sure any server-side state matches reality in the client side
+ this._fixDelayedServerState(list, filter);
- list.topics.forEach(function (topic) {
- const row = tracker.states["t" + topic.id] || {};
- row.topic_id = topic.id;
- row.notification_level = topic.notification_level;
+ // make sure all the state is up to date with what is accurate
+ // from the server
+ list.topics.forEach(this._syncStateFromListTopic.bind(this));
- if (topic.unseen) {
- row.last_read_post_number = null;
- } else if (topic.unread || topic.new_posts) {
- row.last_read_post_number =
- topic.highest_post_number -
- ((topic.unread || 0) + (topic.new_posts || 0));
- } else {
- if (!topic.dont_sync) {
- delete tracker.states["t" + topic.id];
- }
- return;
- }
-
- row.highest_post_number = topic.highest_post_number;
- if (topic.category) {
- row.category_id = topic.category.id;
- }
-
- if (topic.tags) {
- row.tags = topic.tags;
- }
-
- tracker.states["t" + topic.id] = row;
- });
-
- // Correct missing states, safeguard in case message bus is corrupt
- 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));
-
- Object.keys(tracker.states).forEach((k) => {
- // we are good if we are on the list
- if (ids[k]) {
- return;
- }
-
- const v = tracker.states[k];
-
- if (filter === "unread" && isUnread(v)) {
- // pretend read
- v.last_read_post_number = v.highest_post_number;
- }
-
- if (filter === "new" && isNew(v)) {
- // pretend not new
- v.last_read_post_number = 1;
- }
- });
+ // correct missing states, safeguard in case message bus is corrupt
+ if (this._shouldCompensateState(list, filter, queryParams)) {
+ this._correctMissingState(list, filter);
}
this.incrementMessageCount();
@@ -448,6 +414,27 @@ const TopicTrackingState = EmberObject.extend({
incrementMessageCount() {
this.incrementProperty("messageCount");
+ Object.values(this.messageIncrementCallbacks).forEach((cb) => cb());
+ },
+
+ _generateCallbackId() {
+ return Math.random().toString(12).substr(2, 9);
+ },
+
+ onMessageIncrement(cb) {
+ let callbackId = this._generateCallbackId();
+ this.messageIncrementCallbacks[callbackId] = cb;
+ return callbackId;
+ },
+
+ onStateChange(cb) {
+ let callbackId = this._generateCallbackId();
+ this.stateChangeCallbacks[callbackId] = cb;
+ return callbackId;
+ },
+
+ offStateChange(callbackId) {
+ delete this.stateChangeCallbacks[callbackId];
},
getSubCategoryIds(categoryId) {
@@ -471,11 +458,11 @@ const TopicTrackingState = EmberObject.extend({
: this.getSubCategoryIds(categoryId);
const mutedCategoryIds =
this.currentUser && this.currentUser.muted_category_ids;
- let filter = type === "new" ? isNew : isUnread;
+ let filterFn = type === "new" ? isNew : isUnread;
- return Object.values(this.states).filter(
+ return Array.from(this.states.values()).filter(
(topic) =>
- filter(topic) &&
+ filterFn(topic) &&
topic.archetype !== "private_message" &&
!topic.deleted &&
(!categoryId || subcategoryIds.has(topic.category_id)) &&
@@ -499,46 +486,78 @@ const TopicTrackingState = EmberObject.extend({
);
},
- forEachTracked(fn) {
- Object.values(this.states).forEach((topic) => {
- if (topic.archetype !== "private_message" && !topic.deleted) {
- let newTopic = isNew(topic);
- let unreadTopic = isUnread(topic);
- if (newTopic || unreadTopic) {
- fn(topic, newTopic, unreadTopic);
- }
- }
+ /**
+ * Calls the provided callback for each of the currenty tracked topics
+ * we have in state.
+ *
+ * @method forEachTracked
+ * @param {Function} fn - The callback function to call with the topic,
+ * newTopic which is a boolean result of isNew,
+ * and unreadTopic which is a boolean result of
+ * isUnread.
+ */
+ forEachTracked(fn, opts = {}) {
+ this._trackedTopics(opts).forEach((trackedTopic) => {
+ fn(trackedTopic.topic, trackedTopic.newTopic, trackedTopic.unreadTopic);
});
},
- countTags(tags) {
+ /**
+ * Using the array of tags provided, tallys up all topics via forEachTracked
+ * that we are tracking, separated into new/unread/total.
+ *
+ * Total is only counted if opts.includeTotal is specified.
+ *
+ * Output (from input ["pending", "bug"]):
+ *
+ * {
+ * pending: { unreadCount: 6, newCount: 1, totalCount: 10 },
+ * bug: { unreadCount: 0, newCount: 4, totalCount: 20 }
+ * }
+ *
+ * @method countTags
+ * @param opts - Valid options:
+ * * includeTotal - When true, a totalCount is incremented for
+ * all topics matching a tag.
+ */
+ countTags(tags, opts = {}) {
let counts = {};
tags.forEach((tag) => {
counts[tag] = { unreadCount: 0, newCount: 0 };
- });
-
- this.forEachTracked((topic, newTopic, unreadTopic) => {
- if (topic.tags) {
- tags.forEach((tag) => {
- if (topic.tags.indexOf(tag) > -1) {
- if (unreadTopic) {
- counts[tag].unreadCount++;
- }
- if (newTopic) {
- counts[tag].newCount++;
- }
- }
- });
+ if (opts.includeTotal) {
+ counts[tag].totalCount = 0;
}
});
+ this.forEachTracked(
+ (topic, newTopic, unreadTopic) => {
+ if (topic.tags && topic.tags.length > 0) {
+ tags.forEach((tag) => {
+ if (topic.tags.indexOf(tag) > -1) {
+ if (unreadTopic) {
+ counts[tag].unreadCount++;
+ }
+ if (newTopic) {
+ counts[tag].newCount++;
+ }
+
+ if (opts.includeTotal) {
+ counts[tag].totalCount++;
+ }
+ }
+ });
+ }
+ },
+ { includeAll: opts.includeTotal }
+ );
+
return counts;
},
countCategory(category_id, tagId) {
let sum = 0;
- Object.values(this.states).forEach((topic) => {
+ for (let topic of this.states.values()) {
if (
topic.category_id === category_id &&
!topic.deleted &&
@@ -550,7 +569,7 @@ const TopicTrackingState = EmberObject.extend({
? 1
: 0;
}
- });
+ }
return sum;
},
@@ -577,21 +596,272 @@ const TopicTrackingState = EmberObject.extend({
},
loadStates(data) {
- const states = this.states;
+ (data || []).forEach((topic) => {
+ this.modifyState(topic, topic);
+ });
+ },
- // I am taking some shortcuts here to avoid 500 gets for a large list
- if (data) {
- data.forEach((topic) => {
- states["t" + topic.topic_id] = topic;
+ modifyState(topic, data) {
+ this.states.set(this._stateKey(topic), data);
+ this._afterStateChange();
+ },
+
+ modifyStateProp(topic, prop, data) {
+ const state = this.findState(topic);
+ if (state) {
+ state[prop] = data;
+ this._afterStateChange();
+ }
+ },
+
+ findState(topicOrId) {
+ return this.states.get(this._stateKey(topicOrId));
+ },
+
+ /*
+ * private
+ */
+
+ // fix delayed "new" topics by removing the now seen
+ // topic from the list (for the "new" list) or setting the topic
+ // to "seen" for other lists.
+ //
+ // client side we know they are not new, server side we think they are.
+ // this can happen if the list is cached or the update to the state
+ // for a particular seen topic has not yet reached the server.
+ _fixDelayedServerState(list, filter) {
+ for (let index = list.topics.length - 1; index >= 0; index--) {
+ const state = this.findState(list.topics[index].id);
+ if (state && state.last_read_post_number > 0) {
+ if (filter === "new") {
+ list.topics.splice(index, 1);
+ } else {
+ list.topics[index].set("unseen", false);
+ list.topics[index].set("prevent_sync", true);
+ }
+ }
+ }
+ },
+
+ // this updates the topic in the state to match the
+ // topic from the list (e.g. updates category, highest read post
+ // number, tags etc.)
+ _syncStateFromListTopic(topic) {
+ const state = this.findState(topic.id) || {};
+
+ // make a new copy so we aren't modifying the state object directly while
+ // we make changes
+ const newState = { ...state };
+
+ newState.topic_id = topic.id;
+ newState.notification_level = topic.notification_level;
+
+ // see ListableTopicSerializer for unread/unseen/new_posts and other
+ // topic property logic
+ if (topic.unseen) {
+ newState.last_read_post_number = null;
+ } else if (topic.unread || topic.new_posts) {
+ newState.last_read_post_number =
+ topic.highest_post_number -
+ ((topic.unread || 0) + (topic.new_posts || 0));
+ } else {
+ // remove the topic if it is no longer unread/new (it has been seen)
+ // and if there are too many topics in memory
+ if (!topic.prevent_sync && this._maxStateSizeReached()) {
+ this.removeTopic(topic.id);
+ }
+ return;
+ }
+
+ newState.highest_post_number = topic.highest_post_number;
+ if (topic.category) {
+ newState.category_id = topic.category.id;
+ }
+
+ if (topic.tags) {
+ newState.tags = topic.tags;
+ }
+
+ this.modifyState(topic.id, newState);
+ },
+
+ // this stops sync of tracking state when list is filtered, in the past this
+ // would cause the tracking state to become inconsistent.
+ _shouldCompensateState(list, filter, queryParams) {
+ 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;
+ }
});
}
+
+ return shouldCompensate;
+ },
+
+ // any state that is not in the provided list must be updated
+ // based on the filter selected so we do not have any incorrect
+ // state in the list
+ _correctMissingState(list, filter) {
+ const ids = {};
+ list.topics.forEach((topic) => (ids[this._stateKey(topic.id)] = true));
+
+ for (let topicKey of this.states.keys()) {
+ // if the topic is already in the list then there is
+ // no compensation needed; we already have latest state
+ // from the backend
+ if (ids[topicKey]) {
+ return;
+ }
+
+ const newState = { ...this.findState(topicKey) };
+ if (filter === "unread" && isUnread(newState)) {
+ // pretend read. if unread, the highest_post_number will be greater
+ // than the last_read_post_number
+ newState.last_read_post_number = newState.highest_post_number;
+ }
+
+ if (filter === "new" && isNew(newState)) {
+ // pretend not new. if the topic is new, then last_read_post_number
+ // will be null.
+ newState.last_read_post_number = 1;
+ }
+
+ this.modifyState(topicKey, newState);
+ }
+ },
+
+ // processes the data sent via messageBus, called by establishChannels
+ _processChannelPayload(data) {
+ if (["muted", "unmuted"].includes(data.message_type)) {
+ this.trackMutedOrUnmutedTopic(data);
+ return;
+ }
+
+ this.pruneOldMutedAndUnmutedTopics();
+
+ if (this.isMutedTopic(data.topic_id)) {
+ return;
+ }
+
+ if (
+ this.siteSettings.mute_all_categories_by_default &&
+ !this.isUnmutedTopic(data.topic_id)
+ ) {
+ return;
+ }
+
+ if (["new_topic", "latest"].includes(data.message_type)) {
+ const muted_category_ids = User.currentProp("muted_category_ids");
+ if (
+ muted_category_ids &&
+ muted_category_ids.includes(data.payload.category_id)
+ ) {
+ return;
+ }
+ }
+
+ if (["new_topic", "latest"].includes(data.message_type)) {
+ const mutedTagIds = User.currentProp("muted_tag_ids");
+ if (
+ hasMutedTags(data.payload.topic_tag_ids, mutedTagIds, this.siteSettings)
+ ) {
+ return;
+ }
+ }
+
+ const old = this.findState(data);
+
+ if (data.message_type === "latest") {
+ this.notifyIncoming(data);
+
+ if ((old && old.tags) !== data.payload.tags) {
+ this.modifyStateProp(data, "tags", data.payload.tags);
+ this.incrementMessageCount();
+ }
+ }
+
+ if (data.message_type === "dismiss_new") {
+ this._dismissNewTopics(data.payload.topic_ids);
+ }
+
+ if (["new_topic", "unread", "read"].includes(data.message_type)) {
+ this.notifyIncoming(data);
+ if (!deepEqual(old, data.payload)) {
+ if (data.message_type === "read") {
+ let mergeData = {};
+
+ // we have to do this because the "read" event does not
+ // include tags; we don't want them to be overridden
+ if (old) {
+ mergeData = {
+ tags: old.tags,
+ topic_tag_ids: old.topic_tag_ids,
+ };
+ }
+
+ this.modifyState(data, deepMerge(data.payload, mergeData));
+ } else {
+ this.modifyState(data, data.payload);
+ }
+ this.incrementMessageCount();
+ }
+ }
+ },
+
+ _dismissNewTopics(topicIds) {
+ topicIds.forEach((topicId) => {
+ this.modifyStateProp(topicId, "is_seen", true);
+ });
+ this.incrementMessageCount();
+ },
+
+ _addIncoming(topicId) {
+ if (this.newIncoming.indexOf(topicId) === -1) {
+ this.newIncoming.push(topicId);
+ }
+ },
+
+ _trackedTopics(opts = {}) {
+ return Array.from(this.states.values())
+ .map((topic) => {
+ if (topic.archetype !== "private_message" && !topic.deleted) {
+ let newTopic = isNew(topic);
+ let unreadTopic = isUnread(topic);
+ if (newTopic || unreadTopic || opts.includeAll) {
+ return { topic, newTopic, unreadTopic };
+ }
+ }
+ })
+ .compact();
+ },
+
+ _stateKey(topicOrId) {
+ if (typeof topicOrId === "number") {
+ return `t${topicOrId}`;
+ } else if (typeof topicOrId === "string" && topicOrId.indexOf("t") > -1) {
+ return topicOrId;
+ } else {
+ return `t${topicOrId.topic_id}`;
+ }
+ },
+
+ _afterStateChange() {
+ this.notifyPropertyChange("states");
+ Object.values(this.stateChangeCallbacks).forEach((cb) => cb());
+ },
+
+ _maxStateSizeReached() {
+ return this.states.size >= this._trackedTopicLimit;
},
});
export function startTracking(tracking) {
const data = PreloadStore.get("topicTrackingStates");
tracking.loadStates(data);
- tracking.initialStatesLength = data && data.length;
tracking.establishChannels();
PreloadStore.remove("topicTrackingStates");
}
diff --git a/app/assets/javascripts/discourse/app/models/topic.js b/app/assets/javascripts/discourse/app/models/topic.js
index 37be80796c..deef4b89f4 100644
--- a/app/assets/javascripts/discourse/app/models/topic.js
+++ b/app/assets/javascripts/discourse/app/models/topic.js
@@ -20,7 +20,7 @@ import getURL from "discourse-common/lib/get-url";
import { longDate } from "discourse/lib/formatter";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { resolveShareUrl } from "discourse/helpers/share-url";
-import { userPath } from "discourse/lib/url";
+import DiscourseURL, { userPath } from "discourse/lib/url";
export function loadTopicView(topic, args) {
const data = deepMerge({}, args);
@@ -172,12 +172,7 @@ const Topic = RestModel.extend({
@discourseComputed("related_messages")
relatedMessages(relatedMessages) {
if (relatedMessages) {
- const store = this.store;
-
- return this.set(
- "related_messages",
- relatedMessages.map((st) => store.createRecord("topic", st))
- );
+ return relatedMessages.map((st) => this.store.createRecord("topic", st));
}
},
@@ -429,6 +424,9 @@ const Topic = RestModel.extend({
"details.can_delete": false,
"details.can_recover": true,
});
+ if (!deleted_by.staff) {
+ DiscourseURL.redirectTo("/");
+ }
})
.catch(popupAjaxError);
},
@@ -756,7 +754,14 @@ Topic.reopenClass({
});
},
- resetNew(category, include_subcategories, tracked = false, tag = false) {
+ resetNew(category, include_subcategories, opts = {}) {
+ let { tracked, tag, topicIds } = {
+ tracked: false,
+ tag: null,
+ topicIds: null,
+ ...opts,
+ };
+
const data = { tracked };
if (category) {
data.category_id = category.id;
@@ -765,6 +770,9 @@ Topic.reopenClass({
if (tag) {
data.tag_id = tag.id;
}
+ if (topicIds) {
+ data.topic_ids = topicIds;
+ }
return ajax("/topics/reset-new", { type: "PUT", data });
},
diff --git a/app/assets/javascripts/discourse/app/models/trust-level.js b/app/assets/javascripts/discourse/app/models/trust-level.js
index b793195506..2ee5136fda 100644
--- a/app/assets/javascripts/discourse/app/models/trust-level.js
+++ b/app/assets/javascripts/discourse/app/models/trust-level.js
@@ -1,6 +1,22 @@
-import RestModel from "discourse/models/rest";
-import { fmt } from "discourse/lib/computed";
+import { computed } from "@ember/object";
+import I18n from "I18n";
-export default RestModel.extend({
- detailedName: fmt("id", "name", "%@ - %@"),
-});
+export default class TrustLevel {
+ constructor(id, key) {
+ this.id = id;
+ this._key = key;
+ }
+
+ @computed
+ get name() {
+ return I18n.t(`trust_levels.names.${this._key}`);
+ }
+
+ @computed
+ get detailedName() {
+ return I18n.t("trust_levels.detailed_name", {
+ level: this.id,
+ name: this.name,
+ });
+ }
+}
diff --git a/app/assets/javascripts/discourse/app/models/user-badge.js b/app/assets/javascripts/discourse/app/models/user-badge.js
index 0aaff3f561..a4c090354f 100644
--- a/app/assets/javascripts/discourse/app/models/user-badge.js
+++ b/app/assets/javascripts/discourse/app/models/user-badge.js
@@ -4,8 +4,11 @@ import { Promise } from "rsvp";
import Topic from "discourse/models/topic";
import User from "discourse/models/user";
import { ajax } from "discourse/lib/ajax";
+import { popupAjaxError } from "discourse/lib/ajax-error";
import discourseComputed from "discourse-common/utils/decorators";
+const DEFAULT_USER_BADGES_META = { max_favorites: 2 };
+
const UserBadge = EmberObject.extend({
@discourseComputed
postUrl: function () {
@@ -19,6 +22,15 @@ const UserBadge = EmberObject.extend({
type: "DELETE",
});
},
+
+ favorite() {
+ return ajax(`/user_badges/${this.id}/toggle_favorite`, { type: "PUT" })
+ .then((json) => {
+ this.set("is_favorite", json.user_badge.is_favorite);
+ return this;
+ })
+ .catch(popupAjaxError);
+ },
});
UserBadge.reopenClass({
@@ -86,6 +98,7 @@ UserBadge.reopenClass({
userBadges.grant_count = json.user_badge_info.grant_count;
userBadges.username = json.user_badge_info.username;
}
+ userBadges.meta = json.meta || DEFAULT_USER_BADGES_META;
return userBadges;
}
},
diff --git a/app/assets/javascripts/discourse/app/models/user-drafts-stream.js b/app/assets/javascripts/discourse/app/models/user-drafts-stream.js
index 90864e13ff..e703e5acb8 100644
--- a/app/assets/javascripts/discourse/app/models/user-drafts-stream.js
+++ b/app/assets/javascripts/discourse/app/models/user-drafts-stream.js
@@ -66,7 +66,7 @@ export default RestModel.extend({
this.set("loading", true);
- return ajax(findUrl, { cache: "false" })
+ return ajax(findUrl)
.then((result) => {
if (result && result.no_results_help) {
this.set("noContentHelp", result.no_results_help);
diff --git a/app/assets/javascripts/discourse/app/models/user-posts-stream.js b/app/assets/javascripts/discourse/app/models/user-posts-stream.js
index b152630bc1..53f48c9f24 100644
--- a/app/assets/javascripts/discourse/app/models/user-posts-stream.js
+++ b/app/assets/javascripts/discourse/app/models/user-posts-stream.js
@@ -50,7 +50,7 @@ export default EmberObject.extend({
this.set("loading", true);
- return ajax(this.url, { cache: false })
+ return ajax(this.url)
.then((result) => {
if (result) {
const posts = result.map((post) => UserAction.create(post));
diff --git a/app/assets/javascripts/discourse/app/models/user-stream.js b/app/assets/javascripts/discourse/app/models/user-stream.js
index b66c95d516..21b6b53d2c 100644
--- a/app/assets/javascripts/discourse/app/models/user-stream.js
+++ b/app/assets/javascripts/discourse/app/models/user-stream.js
@@ -100,7 +100,7 @@ export default RestModel.extend({
}
this.set("loading", true);
- return ajax(findUrl, { cache: "false" })
+ return ajax(findUrl)
.then((result) => {
if (result && result.no_results_help) {
this.set("noContentHelp", result.no_results_help);
diff --git a/app/assets/javascripts/discourse/app/models/user.js b/app/assets/javascripts/discourse/app/models/user.js
index 6d09211cd1..4d8a9cfe08 100644
--- a/app/assets/javascripts/discourse/app/models/user.js
+++ b/app/assets/javascripts/discourse/app/models/user.js
@@ -229,7 +229,7 @@ const User = RestModel.extend({
const allowedUsers = details && details.get("allowed_users");
const groups = details && details.get("allowed_groups");
- // directly targetted so go to inbox
+ // directly targeted so go to inbox
if (!groups || (allowedUsers && allowedUsers.findBy("id", userId))) {
return userPath(`${username}/messages`);
} else {
@@ -524,27 +524,23 @@ const User = RestModel.extend({
loadUserAction(id) {
const stream = this.stream;
- return ajax(`/user_actions/${id}.json`, { cache: "false" }).then(
- (result) => {
- if (result && result.user_action) {
- const ua = result.user_action;
+ return ajax(`/user_actions/${id}.json`).then((result) => {
+ if (result && result.user_action) {
+ const ua = result.user_action;
- if (
- (this.get("stream.filter") || ua.action_type) !== ua.action_type
- ) {
- return;
- }
- if (!this.get("stream.filter") && !this.inAllStream(ua)) {
- return;
- }
-
- ua.title = emojiUnescape(escapeExpression(ua.title));
- const action = UserAction.collapseStream([UserAction.create(ua)]);
- stream.set("itemsLoaded", stream.get("itemsLoaded") + 1);
- stream.get("content").insertAt(0, action[0]);
+ if ((this.get("stream.filter") || ua.action_type) !== ua.action_type) {
+ return;
}
+ if (!this.get("stream.filter") && !this.inAllStream(ua)) {
+ return;
+ }
+
+ ua.title = emojiUnescape(escapeExpression(ua.title));
+ const action = UserAction.collapseStream([UserAction.create(ua)]);
+ stream.set("itemsLoaded", stream.get("itemsLoaded") + 1);
+ stream.get("content").insertAt(0, action[0]);
}
- );
+ });
},
inAllStream(ua) {
diff --git a/app/assets/javascripts/discourse/app/pre-initializers/theme-errors-handler.js b/app/assets/javascripts/discourse/app/pre-initializers/theme-errors-handler.js
index 05a9a0e153..dd08a637ce 100644
--- a/app/assets/javascripts/discourse/app/pre-initializers/theme-errors-handler.js
+++ b/app/assets/javascripts/discourse/app/pre-initializers/theme-errors-handler.js
@@ -29,7 +29,6 @@ function reportToLogster(name, error) {
Ember.$.ajax(getURL("/logs/report_js_error"), {
data,
type: "POST",
- cache: false,
});
}
diff --git a/app/assets/javascripts/discourse/app/routes/edit-category.js b/app/assets/javascripts/discourse/app/routes/edit-category.js
index f9ebcf1255..a3c43dbff5 100644
--- a/app/assets/javascripts/discourse/app/routes/edit-category.js
+++ b/app/assets/javascripts/discourse/app/routes/edit-category.js
@@ -11,6 +11,13 @@ export default DiscourseRoute.extend({
);
},
+ afterModel(model) {
+ if (!model.can_edit) {
+ this.replaceWith("/404");
+ return;
+ }
+ },
+
titleToken() {
return I18n.t("category.edit_dialog_title", {
categoryName: this.currentModel.name,
diff --git a/app/assets/javascripts/discourse/app/routes/group-manage-email.js b/app/assets/javascripts/discourse/app/routes/group-manage-email.js
index 1ba2f5d5b5..5f8a26e43b 100644
--- a/app/assets/javascripts/discourse/app/routes/group-manage-email.js
+++ b/app/assets/javascripts/discourse/app/routes/group-manage-email.js
@@ -5,7 +5,8 @@ export default DiscourseRoute.extend({
showFooter: true,
beforeModel() {
- if (!this.siteSettings.enable_imap && !this.siteSettings.enable_smtp) {
+ // cannot configure IMAP without SMTP being enabled
+ if (!this.siteSettings.enable_smtp) {
return this.transitionTo("group.manage.profile");
}
},
diff --git a/app/assets/javascripts/discourse/app/routes/groups-index.js b/app/assets/javascripts/discourse/app/routes/groups-index.js
index 41684664ea..a054f348c7 100644
--- a/app/assets/javascripts/discourse/app/routes/groups-index.js
+++ b/app/assets/javascripts/discourse/app/routes/groups-index.js
@@ -1,24 +1,24 @@
import DiscourseRoute from "discourse/routes/discourse";
import I18n from "I18n";
-export default DiscourseRoute.extend({
+export default class GroupsIndexRoute extends DiscourseRoute {
titleToken() {
return I18n.t("groups.index.title");
- },
+ }
- queryParams: {
+ queryParams = {
order: { refreshModel: true, replace: true },
asc: { refreshModel: true, replace: true },
filter: { refreshModel: true },
type: { refreshModel: true, replace: true },
username: { refreshModel: true },
- },
+ };
model(params) {
return params;
- },
+ }
setupController(controller, params) {
controller.loadGroups(params);
- },
-});
+ }
+}
diff --git a/app/assets/javascripts/discourse/app/routes/review-index.js b/app/assets/javascripts/discourse/app/routes/review-index.js
index b4d15e68e1..187c91c953 100644
--- a/app/assets/javascripts/discourse/app/routes/review-index.js
+++ b/app/assets/javascripts/discourse/app/routes/review-index.js
@@ -55,6 +55,18 @@ export default DiscourseRoute.extend({
});
}
});
+
+ this.messageBus.subscribe("/reviewable_counts", (data) => {
+ if (data.updates) {
+ this.controller.reviewables.forEach((reviewable) => {
+ const updates = data.updates[reviewable.id];
+ if (updates) {
+ reviewable.setProperties(updates);
+ reviewable.set("stale", true);
+ }
+ });
+ }
+ });
},
deactivate() {
diff --git a/app/assets/javascripts/discourse/app/routes/users.js b/app/assets/javascripts/discourse/app/routes/users.js
index c055d4e2cc..8c059adab8 100644
--- a/app/assets/javascripts/discourse/app/routes/users.js
+++ b/app/assets/javascripts/discourse/app/routes/users.js
@@ -1,5 +1,6 @@
import DiscourseRoute from "discourse/routes/discourse";
import I18n from "I18n";
+import PreloadStore from "discourse/lib/preload-store";
export default DiscourseRoute.extend({
queryParams: {
@@ -36,11 +37,14 @@ export default DiscourseRoute.extend({
},
model(params) {
- return params;
+ const columns = PreloadStore.get("directoryColumns");
+ params.order = params.order || columns[0].name;
+ return { params, columns };
},
- setupController(controller, params) {
- controller.loadUsers(params);
+ setupController(controller, model) {
+ controller.set("columns", model.columns);
+ controller.loadUsers(model.params);
},
actions: {
diff --git a/app/assets/javascripts/discourse/app/templates/application.hbs b/app/assets/javascripts/discourse/app/templates/application.hbs
index 8b3ecd788e..9296b8b8b9 100644
--- a/app/assets/javascripts/discourse/app/templates/application.hbs
+++ b/app/assets/javascripts/discourse/app/templates/application.hbs
@@ -8,7 +8,7 @@
toggleMobileView=(route-action "toggleMobileView")
toggleAnonymous=(route-action "toggleAnonymous")
logout=(route-action "logout")}}
- {{software-update-prompt id="software-update-prompt"}}
+ {{software-update-prompt}}
{{plugin-outlet name="below-site-header" tagName="" args=(hash currentPath=router._router.currentPath)}}
diff --git a/app/assets/javascripts/discourse/app/templates/components/badge-card.hbs b/app/assets/javascripts/discourse/app/templates/components/badge-card.hbs
index 415e4738c0..fc05530843 100644
--- a/app/assets/javascripts/discourse/app/templates/components/badge-card.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/badge-card.hbs
@@ -4,7 +4,26 @@
{{#if badge.has_badge}}
{{d-icon "check"}}
{{/if}}
-
+
+{{#if canFavorite}}
+ {{#if isFavorite}}
+ {{d-button
+ icon="star"
+ class="favorite-btn"
+ action=onFavoriteClick
+ }}
+ {{else}}
+ {{d-button
+ icon="far-star"
+ class="favorite-btn"
+ action=onFavoriteClick
+ title=(if canFavoriteMoreBadges "badges.favorite_max_not_reached" "badges.favorite_max_reached")
+ disabled=(not canFavoriteMoreBadges)
+ }}
+ {{/if}}
+{{/if}}
+
+
diff --git a/app/assets/javascripts/discourse/app/templates/components/bread-crumbs.hbs b/app/assets/javascripts/discourse/app/templates/components/bread-crumbs.hbs
index 354e4de4ec..df1de24a36 100644
--- a/app/assets/javascripts/discourse/app/templates/components/bread-crumbs.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/bread-crumbs.hbs
@@ -4,6 +4,8 @@
category=breadcrumb.category
categories=breadcrumb.options
tagId=tag.id
+ editingCategory=editingCategory
+ editingCategoryTab=editingCategoryTab
options=(hash
parentCategory=breadcrumb.parentCategory
subCategory=breadcrumb.isSubcategory
@@ -14,7 +16,7 @@
{{/if}}
{{/each}}
-{{#if siteSettings.tagging_enabled}}
+{{#if showTagsSection}}
{{#if additionalTags}}
{{tags-intersection-chooser
currentCategory=category
diff --git a/app/assets/javascripts/discourse/app/templates/components/bulk-select-button.hbs b/app/assets/javascripts/discourse/app/templates/components/bulk-select-button.hbs
index bdc803ae47..77306f93e1 100644
--- a/app/assets/javascripts/discourse/app/templates/components/bulk-select-button.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/bulk-select-button.hbs
@@ -1,5 +1,7 @@
-{{#if selected}}
-
- {{d-button class="btn-default bulk-select-btn" action=(action "showBulkActions") icon="wrench"}}
-
+{{#if canDoBulkActions}}
+ {{#if selected}}
+
+ {{d-button class="btn-default bulk-select-btn" action=(action "showBulkActions") icon="wrench"}}
+
+ {{/if}}
{{/if}}
diff --git a/app/assets/javascripts/discourse/app/templates/components/choose-topic.hbs b/app/assets/javascripts/discourse/app/templates/components/choose-topic.hbs
index bae33d6b87..7d384bccb2 100644
--- a/app/assets/javascripts/discourse/app/templates/components/choose-topic.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/choose-topic.hbs
@@ -1,4 +1,6 @@
-
+
{{text-field value=topicTitle placeholderKey="choose_topic.title.placeholder" id="choose-topic-title"}}
diff --git a/app/assets/javascripts/discourse/app/templates/components/d-modal.hbs b/app/assets/javascripts/discourse/app/templates/components/d-modal.hbs
index 6b57bd1c21..7067f487ef 100644
--- a/app/assets/javascripts/discourse/app/templates/components/d-modal.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/d-modal.hbs
@@ -3,7 +3,7 @@
{{#if dismissable}}
- {{d-button icon="times" action=(route-action "closeModal" "initiatedByCloseButton") class="btn-flat modal-close close" title="modal.close"}}
+ {{d-button icon="times" action=(route-action "closeModal" "initiatedByCloseButton") class="btn-flat modal-close close" title="modal.close" ariaLabel="modal.close"}}
{{/if}}
{{#if title}}
diff --git a/app/assets/javascripts/discourse/app/templates/components/d-navigation.hbs b/app/assets/javascripts/discourse/app/templates/components/d-navigation.hbs
index 5919b91f98..7d3abc4e98 100644
--- a/app/assets/javascripts/discourse/app/templates/components/d-navigation.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/d-navigation.hbs
@@ -24,14 +24,14 @@
class="btn-default edit-category"
action=editCategory
icon="wrench"
- label="category.edit"}}
+ ariaLabel="category.edit"}}
{{/if}}
{{/unless}}
{{/if}}
{{#if tag}}
{{#if showToggleInfo}}
- {{d-button icon="tag" class="btn-default" label="tagging.info" action=toggleInfo id="show-tag-info"}}
+ {{d-button icon="wrench" class="btn-default" ariaLabel="tagging.info" action=toggleInfo id="show-tag-info"}}
{{/if}}
{{/if}}
diff --git a/app/assets/javascripts/discourse/app/templates/components/directory-item.hbs b/app/assets/javascripts/discourse/app/templates/components/directory-item.hbs
index d939e353b4..0d4fece411 100644
--- a/app/assets/javascripts/discourse/app/templates/components/directory-item.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/directory-item.hbs
@@ -1,11 +1,14 @@
{{user-info user=item.user}}
-{{number item.likes_received}}
-{{number item.likes_given}}
-{{number item.topic_count}}
-{{number item.post_count}}
-{{number item.topics_entered}}
-{{number item.posts_read}}
-{{number item.days_visited}}
+{{#each columns as |column|}}
+
+ {{#if column.automatic}}
+ {{directory-item-value item=item column=column}}
+ {{else}}
+ {{directory-item-user-field-value item=item column=column}}
+ {{/if}}
+
+{{/each}}
+
{{#if showTimeRead}}
{{format-duration item.time_read}}
{{/if}}
diff --git a/app/assets/javascripts/discourse/app/templates/components/directory-table.hbs b/app/assets/javascripts/discourse/app/templates/components/directory-table.hbs
new file mode 100644
index 0000000000..1aafa640cc
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/templates/components/directory-table.hbs
@@ -0,0 +1,24 @@
+
+
+ {{table-header-toggle field="username" order=order asc=asc}}
+ {{#each columns as |column|}}
+ {{table-header-toggle
+ field=column.name
+ icon=column.icon
+ order=order
+ asc=asc
+ translated=column.user_field_id
+ onActiveRender=setActiveHeader
+ }}
+ {{/each}}
+
+ {{#if showTimeRead}}
+ {{i18n "directory.time_read"}}
+ {{/if}}
+
+
+ {{#each items as |item|}}
+ {{directory-item item=item columns=columns showTimeRead=showTimeRead}}
+ {{/each}}
+
+
diff --git a/app/assets/javascripts/discourse/app/templates/components/future-date-input.hbs b/app/assets/javascripts/discourse/app/templates/components/future-date-input.hbs
index bb629c4527..2ff6e7de08 100644
--- a/app/assets/javascripts/discourse/app/templates/components/future-date-input.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/future-date-input.hbs
@@ -1,6 +1,8 @@
-
+
{{future-date-input-selector
minimumResultsForSearch=-1
statusType=statusType
diff --git a/app/assets/javascripts/discourse/app/templates/components/group-imap-email-settings.hbs b/app/assets/javascripts/discourse/app/templates/components/group-imap-email-settings.hbs
new file mode 100644
index 0000000000..2c6025d4ac
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/templates/components/group-imap-email-settings.hbs
@@ -0,0 +1,80 @@
+
+
+
+
+
+
+
+ {{#unless mailboxSelected}}
+
+ {{i18n "groups.manage.email.imap_mailbox_not_selected"}}
+
+ {{/unless}}
+
+
+
+
+ {{i18n "groups.manage.email.imap_additional_settings"}}
+
+ {{i18n "groups.manage.email.settings.allow_unknown_sender_topic_replies_hint"}}
+
+
diff --git a/app/assets/javascripts/discourse/app/templates/components/group-manage-email-settings.hbs b/app/assets/javascripts/discourse/app/templates/components/group-manage-email-settings.hbs
new file mode 100644
index 0000000000..97f08c5348
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/templates/components/group-manage-email-settings.hbs
@@ -0,0 +1,38 @@
+
+ {{i18n "groups.manage.email.smtp_title"}}
+ {{i18n "groups.manage.email.smtp_instructions"}}
+
+
+
+ {{#if group.smtp_enabled}}
+ {{group-smtp-email-settings group=group smtpSettingsValid=smtpSettingsValid}}
+ {{/if}}
+
+ {{#if siteSettings.enable_imap}}
+
+
+
+ {{i18n "groups.manage.email.imap_title"}}
+
+ {{html-safe (i18n "groups.manage.email.imap_instructions")}}
+
+
+ {{i18n "groups.manage.email.imap_alpha_warning"}}
+
+
+
+ {{#if group.imap_enabled}}
+ {{group-imap-email-settings group=group imapSettingsValid=imapSettingsValid}}
+ {{/if}}
+
+ {{/if}}
+
+
+ {{group-manage-save-button model=group disabled=(not emailSettingsValid) beforeSave=beforeSave afterSave=afterSave tabindex="14"}}
+
diff --git a/app/assets/javascripts/discourse/app/templates/components/group-manage-save-button.hbs b/app/assets/javascripts/discourse/app/templates/components/group-manage-save-button.hbs
index 11b4167c70..d4b358d00f 100644
--- a/app/assets/javascripts/discourse/app/templates/components/group-manage-save-button.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/group-manage-save-button.hbs
@@ -1,6 +1,6 @@
-