diff --git a/app/assets/javascripts/discourse/app/controllers/create-account.js b/app/assets/javascripts/discourse/app/controllers/create-account.js index 047c73ce02..1799033a68 100644 --- a/app/assets/javascripts/discourse/app/controllers/create-account.js +++ b/app/assets/javascripts/discourse/app/controllers/create-account.js @@ -23,6 +23,7 @@ import { notEmpty } from "@ember/object/computed"; import { setting } from "discourse/lib/computed"; import { userPath } from "discourse/lib/url"; import { helperContext } from "discourse-common/lib/helpers"; +import { emojiBasePath } from "discourse/lib/settings"; export default Controller.extend( ModalFunctionality, @@ -84,7 +85,7 @@ export default Controller.extend( // random number between 2 -6 to render multiple skin tone waving hands const random = Math.floor(Math.random() * (7 - 2) + 2); - return getURL(`/images/emoji/${emojiSet}/wave/${random}.png`); + return getURL(`${emojiBasePath()}/${emojiSet}/wave/${random}.png`); }, @discourseComputed( diff --git a/app/assets/javascripts/discourse/app/controllers/login.js b/app/assets/javascripts/discourse/app/controllers/login.js index 5d25aec81c..a1ff3240b9 100644 --- a/app/assets/javascripts/discourse/app/controllers/login.js +++ b/app/assets/javascripts/discourse/app/controllers/login.js @@ -19,6 +19,7 @@ import { isEmpty } from "@ember/utils"; import { setting } from "discourse/lib/computed"; import showModal from "discourse/lib/show-modal"; import { helperContext } from "discourse-common/lib/helpers"; +import { emojiBasePath } from "discourse/lib/settings"; // This is happening outside of the app via popup const AuthErrors = [ @@ -71,7 +72,7 @@ export default Controller.extend(ModalFunctionality, { // random number between 2 -6 to render multiple skin tone waving hands const random = Math.floor(Math.random() * (7 - 2) + 2); - return getURL(`/images/emoji/${emojiSet}/wave/${random}.png`); + return getURL(`${emojiBasePath()}/${emojiSet}/wave/${random}.png`); }, @discourseComputed("showSecondFactor", "showSecurityKey") diff --git a/app/assets/javascripts/discourse/app/lib/settings.js b/app/assets/javascripts/discourse/app/lib/settings.js index 2de9fb7f35..4351817c12 100644 --- a/app/assets/javascripts/discourse/app/lib/settings.js +++ b/app/assets/javascripts/discourse/app/lib/settings.js @@ -7,3 +7,11 @@ export function prioritizeNameInUx(name) { !siteSettings.prioritize_username_in_ux && name && name.trim().length > 0 ); } + +export function emojiBasePath() { + let siteSettings = helperContext().siteSettings; + + return siteSettings.external_emoji_url === "" + ? "/images/emojis" + : siteSettings.external_emoji_url; +} diff --git a/app/assets/javascripts/discourse/app/lib/text.js b/app/assets/javascripts/discourse/app/lib/text.js index 588d0dab3d..f12acbfab7 100644 --- a/app/assets/javascripts/discourse/app/lib/text.js +++ b/app/assets/javascripts/discourse/app/lib/text.js @@ -90,6 +90,7 @@ function emojiOptions() { emojiSet: siteSettings.emoji_set, enableEmojiShortcuts: siteSettings.enable_emoji_shortcuts, inlineEmoji: siteSettings.enable_inline_emoji_translation, + emojiCDNUrl: siteSettings.external_emoji_url, }; } diff --git a/app/assets/javascripts/discourse/tests/helpers/site-settings.js b/app/assets/javascripts/discourse/tests/helpers/site-settings.js index 74de61bff1..3726d18108 100644 --- a/app/assets/javascripts/discourse/tests/helpers/site-settings.js +++ b/app/assets/javascripts/discourse/tests/helpers/site-settings.js @@ -97,6 +97,7 @@ const ORIGINAL_SETTINGS = { enable_personal_messages: true, unicode_usernames: false, secure_media: false, + external_emoji_url: "", }; let siteSettings = Object.assign({}, ORIGINAL_SETTINGS); diff --git a/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js b/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js index a00ad68b54..a02cf063b2 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js @@ -17,6 +17,7 @@ const rawOpts = { enable_emoji_shortcuts: true, enable_mentions: true, emoji_set: "google_classic", + external_emoji_url: "", highlighted_languages: "json|ruby|javascript", default_code_lang: "auto", enable_markdown_linkify: true, @@ -1519,6 +1520,19 @@ var bar = 'bar'; ); }); + test("emoji - emojiCDN", function (assert) { + assert.cookedOptions( + ":smile:", + { + siteSettings: { + emoji_set: "twitter", + external_emoji_url: "https://emoji.hosting.service", + }, + }, + `

++This is a quote with a regular emoji
+
++This is a quote with an emoji shortcut
+
++ HTML + + expect(cook(md)).to eq(html.strip) + end + + it "does use emoji CDN when others CDNs are also enabled" do + set_cdn_url('https://cdn.com') + setup_s3 + SiteSetting.s3_cdn_url = "https://s3.cdn.com" + SiteSetting.external_emoji_url = "https://emoji.cdn.com" + + html = <<~HTML +This is a quote with a Unicode emoji
+
++This is a quote with a regular emoji
+
++This is a quote with an emoji shortcut
+
++ HTML + + expect(cook(md)).to eq(html.strip) + end end it "do off topic quoting of posts from secure categories" do diff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rb index 64ed3f3b7b..3faa9195b8 100644 --- a/spec/jobs/pull_hotlinked_images_spec.rb +++ b/spec/jobs/pull_hotlinked_images_spec.rb @@ -440,6 +440,23 @@ describe Jobs::PullHotlinkedImages do expect(subject.should_download_image?(src)).to eq(false) end + it "returns false for emoji when emoji CDN configured" do + SiteSetting.external_emoji_url = "https://emoji.cdn.com" + + src = UrlHelper.cook_url(Emoji.url_for("testemoji.png")) + expect(subject.should_download_image?(src)).to eq(false) + end + + it "returns false for emoji when app, S3 *and* emoji CDNs configured" do + setup_s3 + SiteSetting.s3_cdn_url = "https://s3.cdn.com" + SiteSetting.external_emoji_url = "https://emoji.cdn.com" + set_cdn_url "https://mydomain.cdn/test" + + src = UrlHelper.cook_url(Emoji.url_for("testemoji.png")) + expect(subject.should_download_image?(src)).to eq(false) + end + it "returns false for plugin assets" do src = UrlHelper.cook_url("/plugins/discourse-amazing-plugin/myasset.png") expect(subject.should_download_image?(src)).to eq(false)This is a quote with a Unicode emoji
+