diff --git a/app/assets/javascripts/discourse/lib/autocomplete.js.es6 b/app/assets/javascripts/discourse/lib/autocomplete.js.es6 index 0fb1ed3a3..6848c8b9c 100644 --- a/app/assets/javascripts/discourse/lib/autocomplete.js.es6 +++ b/app/assets/javascripts/discourse/lib/autocomplete.js.es6 @@ -58,7 +58,13 @@ export default function(options) { } if (this.length !== 1) { - alert("only supporting one matcher at the moment"); + if (window.console) { + window.console.log("WARNING: passed multiple elements to $.autocomplete, skipping."); + if (window.Error) { + window.console.log((new window.Error()).stack); + } + } + return this; } var disabled = options && options.disabled; diff --git a/app/assets/stylesheets/common/components/banner.css.scss b/app/assets/stylesheets/common/components/banner.css.scss index 3c800e9b1..fbaff6d0b 100644 --- a/app/assets/stylesheets/common/components/banner.css.scss +++ b/app/assets/stylesheets/common/components/banner.css.scss @@ -16,9 +16,10 @@ } .close { - font-size: 1.786em !important; - margin-top: -10px !important; - color: darken($tertiary, 45%); + font-size: 1.786em; + margin-top: -10px; + color: scale-color($tertiary, $lightness: 70%); + padding-left: 5px; } .meta { diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb index 542744d39..018fba102 100644 --- a/app/mailers/user_notifications.rb +++ b/app/mailers/user_notifications.rb @@ -236,25 +236,20 @@ class UserNotifications < ActionMailer::Base user_name = name unless name.blank? end - title = notification_data[:topic_title] allow_reply_by_email = opts[:allow_reply_by_email] unless user.suspended? - use_site_subject = opts[:use_site_subject] - add_re_to_subject = opts[:add_re_to_subject] - show_category_in_subject = opts[:show_category_in_subject] - use_template_html = opts[:use_template_html] original_username = notification_data[:original_username] || notification_data[:display_username] send_notification_email( - title: title, + title: notification_data[:topic_title], post: post, username: original_username, from_alias: user_name, allow_reply_by_email: allow_reply_by_email, - use_site_subject: use_site_subject, - add_re_to_subject: add_re_to_subject, - show_category_in_subject: show_category_in_subject, + use_site_subject: opts[:use_site_subject], + add_re_to_subject: opts[:add_re_to_subject], + show_category_in_subject: opts[:show_category_in_subject], notification_type: notification_type, - use_template_html: use_template_html, + use_template_html: opts[:use_template_html], user: user ) end diff --git a/app/models/notification.rb b/app/models/notification.rb index d21875c8b..2f8090abc 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -98,8 +98,8 @@ class Notification < ActiveRecord::Base # Be wary of calling this frequently. O(n) JSON parsing can suck. def data_hash @data_hash ||= begin - return nil if data.blank? + parsed = JSON.parse(data) return nil if parsed.blank? diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb index 5ee0ad8e1..29b9ec1aa 100644 --- a/app/services/post_alerter.rb +++ b/app/services/post_alerter.rb @@ -259,8 +259,16 @@ class PostAlerter UserActionObserver.log_notification(original_post, user, type, opts[:acting_user_id]) + topic_title = post.topic.title + # when sending a private message email, keep the original title + if post.topic.private_message? && modifications = post.revisions.map(&:modifications).to_a + if first_title_modification = modifications.first { |m| m.has_key?("title") } + topic_title = first_title_modification["title"][0] + end + end + notification_data = { - topic_title: post.topic.title, + topic_title: topic_title, original_post_id: original_post.id, original_post_type: original_post.post_type, original_username: original_username, diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index fe8476363..f3b3e1391 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1490,7 +1490,7 @@ en: - If you run your own mail server, check to make sure the IPs of your mail server are [not on any email blacklists][4]. Also verify that it is definitely sending a fully-qualified hostname that resolves in DNS in its HELO message. If not, this will cause your email to be rejected by many mail services. - - Send a test email to [mail-tester.com][mt] to verify that everything is working correctly. + - Send a test email to [mail-tester.com][mt] to verify that everything is working correctly. (The *easy* way is to create a free account on [Mandrill][md] or [Mailgun][mg] or [Mailjet][mj], which have free generous free mailing plans and will be fine for small communities. You'll still need to set up the SPF and DKIM records in your DNS, though!) @@ -1515,13 +1515,11 @@ en: new_version_mailer: subject_template: "[%{site_name}] New Discourse version, update available" text_body_template: | - A new version of [Discourse](http://www.discourse.org) is available. + Hooray, a new version of [Discourse](http://www.discourse.org) is available! :) Your version: %{installed_version} New version: **%{new_version}** - You may want to: - - See what's new in the [GitHub changelog](https://github.com/discourse/discourse/commits/master). - Upgrade from your browser at [%{base_url}/admin/upgrade](%{base_url}/admin/upgrade). @@ -1531,13 +1529,11 @@ en: new_version_mailer_with_notes: subject_template: "[%{site_name}] update available" text_body_template: | - A new version of [Discourse](http://www.discourse.org) is available. + Hooray, a new version of [Discourse](http://www.discourse.org) is available! :) Your version: %{installed_version} New version: **%{new_version}** - You may want to: - - See what's new in the [GitHub changelog](https://github.com/discourse/discourse/commits/master). - Upgrade from your browser at [%{base_url}/admin/upgrade](%{base_url}/admin/upgrade). diff --git a/lib/freedom_patches/translate_accelerator.rb b/lib/freedom_patches/translate_accelerator.rb index 8b131d324..517357d59 100644 --- a/lib/freedom_patches/translate_accelerator.rb +++ b/lib/freedom_patches/translate_accelerator.rb @@ -28,6 +28,7 @@ module I18n @overrides_by_site = {} reload_no_cache! + ensure_all_loaded! end LOAD_MUTEX = Mutex.new @@ -105,8 +106,7 @@ module I18n by_site = @overrides_by_site[site] - by_locale = nil - unless by_site + unless by_site && by_site.has_key?(locale) by_site = @overrides_by_site[site] = {} # Load overrides diff --git a/lib/i18n/backend/discourse_i18n.rb b/lib/i18n/backend/discourse_i18n.rb index c4bccbf12..8b2ea2375 100644 --- a/lib/i18n/backend/discourse_i18n.rb +++ b/lib/i18n/backend/discourse_i18n.rb @@ -43,7 +43,13 @@ module I18n end def search(locale, query) - find_results(/#{query}/i, {}, translations[locale]) + results = {} + + fallbacks(locale).each do |fallback| + find_results(/#{query}/i, results, translations[fallback]) + end + + results end protected @@ -54,7 +60,9 @@ module I18n k = k_sym.to_s key_path = path ? "#{path}.#{k}" : k if v.is_a?(String) - results[key_path] = v if key_path =~ regexp || v =~ regexp + unless results.has_key?(key_path) + results[key_path] = v if key_path =~ regexp || v =~ regexp + end elsif v.is_a?(Hash) find_results(regexp, results, v, key_path) end diff --git a/spec/components/discourse_i18n_spec.rb b/spec/components/discourse_i18n_spec.rb index 40dbf4a2e..f41b9caaf 100644 --- a/spec/components/discourse_i18n_spec.rb +++ b/spec/components/discourse_i18n_spec.rb @@ -15,6 +15,7 @@ describe I18n::Backend::DiscourseI18n do end after do + I18n.locale = :en I18n.reload! end @@ -40,6 +41,11 @@ describe I18n::Backend::DiscourseI18n do expect(results['items.other']).to eq('%{count} items') end + it 'uses fallback locales for searching' do + expect(backend.search(:de, 'bar')).to eq({'bar' => 'Bar in :de'}) + expect(backend.search(:de, 'foo')).to eq({'foo' => 'Foo in :en'}) + end + describe '#exists?' do it 'returns true when a key is given that exists' do expect(backend.exists?(:de, :bar)).to eq(true) @@ -73,15 +79,23 @@ describe I18n::Backend::DiscourseI18n do end describe 'with overrides' do - it 'returns the overriden key' do + it 'returns the overridden key' do TranslationOverride.upsert!('en', 'foo', 'Overwritten foo') expect(I18n.translate('foo')).to eq('Overwritten foo') TranslationOverride.upsert!('en', 'foo', 'new value') - I18n.reload! expect(I18n.translate('foo')).to eq('new value') end + it 'returns the overridden key after switching the locale' do + TranslationOverride.upsert!('en', 'foo', 'Overwritten foo in EN') + TranslationOverride.upsert!('de', 'foo', 'Overwritten foo in DE') + + expect(I18n.translate('foo')).to eq('Overwritten foo in EN') + I18n.locale = :de + expect(I18n.translate('foo')).to eq('Overwritten foo in DE') + end + it "can be searched" do TranslationOverride.upsert!('en', 'wat', 'Overwritten value') expect(I18n.search('wat', backend: backend)).to eq({'wat' => 'Overwritten value'}) diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb index 882e680dc..10f4c10b0 100644 --- a/spec/services/post_alerter_spec.rb +++ b/spec/services/post_alerter_spec.rb @@ -150,4 +150,26 @@ describe PostAlerter do end end + + + describe ".create_notification" do + + it "keeps the original title for PMs" do + user = Fabricate(:user) + topic = Fabricate(:private_message_topic, user: user, created_at: 1.hour.ago) + post = Fabricate(:post, topic: topic, created_at: 1.hour.ago) + + original_title = topic.title + + post.revise(user, { title: "This is the revised title" }, revised_at: Time.now) + + expect { + PostAlerter.new.create_notification(user, Notification.types[:private_message], post) + }.to change { user.notifications.count } + + expect(user.notifications.last.data_hash["topic_title"]).to eq(original_title) + end + + end + end