mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
emoji refactor: Pass in emoji_codes from ui_init.
We don't want emoji.js to depend on a JSON file (and specifically the location of said JSON file) when we start sharing our code with mobile.
This commit is contained in:
@@ -89,6 +89,11 @@ people.add_active_user(test_user);
|
|||||||
|
|
||||||
message_store.add_message_metadata(test_message);
|
message_store.add_message_metadata(test_message);
|
||||||
|
|
||||||
|
const realm_emoji = {};
|
||||||
|
const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json");
|
||||||
|
|
||||||
|
emoji.initialize({realm_emoji, emoji_codes});
|
||||||
|
|
||||||
function assert_same(actual, expected) {
|
function assert_same(actual, expected) {
|
||||||
// This helper prevents us from getting false positives
|
// This helper prevents us from getting false positives
|
||||||
// where actual and expected are both undefined.
|
// where actual and expected are both undefined.
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
|
const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json");
|
||||||
|
|
||||||
const events = require("./lib/events.js");
|
const events = require("./lib/events.js");
|
||||||
|
|
||||||
zrequire("emoji");
|
zrequire("emoji");
|
||||||
|
|
||||||
const realm_emojis = events.fixtures.realm_emoji.realm_emoji;
|
const realm_emoji = events.fixtures.realm_emoji.realm_emoji;
|
||||||
|
|
||||||
emoji.update_emojis(realm_emojis);
|
emoji.initialize({realm_emoji, emoji_codes});
|
||||||
|
|
||||||
run_test("sanity check", () => {
|
run_test("sanity check", () => {
|
||||||
assert.equal(emoji.get_server_realm_emoji_data(), realm_emojis);
|
assert.equal(emoji.get_server_realm_emoji_data(), realm_emoji);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("get_canonical_name", () => {
|
run_test("get_canonical_name", () => {
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
zrequire("emoji");
|
zrequire("emoji");
|
||||||
zrequire("emoji_picker");
|
zrequire("emoji_picker");
|
||||||
|
|
||||||
|
const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json");
|
||||||
|
|
||||||
run_test("initialize", () => {
|
run_test("initialize", () => {
|
||||||
emoji.update_emojis({});
|
emoji.initialize({
|
||||||
|
realm_emoji: {},
|
||||||
|
emoji_codes,
|
||||||
|
});
|
||||||
emoji_picker.initialize();
|
emoji_picker.initialize();
|
||||||
|
|
||||||
const complete_emoji_catalog = _.sortBy(emoji_picker.complete_emoji_catalog, "name");
|
const complete_emoji_catalog = _.sortBy(emoji_picker.complete_emoji_catalog, "name");
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
// it calls any external module other than `ui.foo`, it'll crash.
|
// it calls any external module other than `ui.foo`, it'll crash.
|
||||||
// Future work includes making sure it actually does call `ui.foo()`.
|
// Future work includes making sure it actually does call `ui.foo()`.
|
||||||
|
|
||||||
|
const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json");
|
||||||
|
|
||||||
set_global("activity", {});
|
set_global("activity", {});
|
||||||
|
|
||||||
set_global("navigator", {
|
set_global("navigator", {
|
||||||
@@ -26,6 +28,12 @@ set_global("document", "document-stub");
|
|||||||
set_global("$", global.make_zjquery());
|
set_global("$", global.make_zjquery());
|
||||||
|
|
||||||
zrequire("emoji");
|
zrequire("emoji");
|
||||||
|
|
||||||
|
emoji.initialize({
|
||||||
|
realm_emoji: {},
|
||||||
|
emoji_codes,
|
||||||
|
});
|
||||||
|
|
||||||
const hotkey = zrequire("hotkey");
|
const hotkey = zrequire("hotkey");
|
||||||
zrequire("common");
|
zrequire("common");
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ const emoji_params = {
|
|||||||
deactivated: false,
|
deactivated: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
emoji_codes,
|
||||||
};
|
};
|
||||||
|
|
||||||
set_global("page_params", {
|
set_global("page_params", {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
set_global("document", "document-stub");
|
set_global("document", "document-stub");
|
||||||
set_global("$", global.make_zjquery());
|
set_global("$", global.make_zjquery());
|
||||||
|
|
||||||
|
const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json");
|
||||||
|
|
||||||
zrequire("emoji");
|
zrequire("emoji");
|
||||||
zrequire("people");
|
zrequire("people");
|
||||||
zrequire("reactions");
|
zrequire("reactions");
|
||||||
@@ -30,6 +32,7 @@ const emoji_params = {
|
|||||||
deactivated: false,
|
deactivated: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
emoji_codes,
|
||||||
};
|
};
|
||||||
|
|
||||||
emoji.initialize(emoji_params);
|
emoji.initialize(emoji_params);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
const emoji_codes = require("../generated/emoji/emoji_codes.json");
|
|
||||||
|
|
||||||
const util = require("./util");
|
const util = require("./util");
|
||||||
|
|
||||||
|
// We will get actual values when we get initialized.
|
||||||
|
let emoji_codes = {};
|
||||||
|
|
||||||
// `emojis_by_name` is the central data source that is supposed to be
|
// `emojis_by_name` is the central data source that is supposed to be
|
||||||
// used by every widget in the webapp for gathering data for displaying
|
// used by every widget in the webapp for gathering data for displaying
|
||||||
// emojis. Emoji picker uses this data to derive data for its own use.
|
// emojis. Emoji picker uses this data to derive data for its own use.
|
||||||
@@ -22,7 +23,9 @@ let server_realm_emoji_data = {};
|
|||||||
// We really want to deprecate this, too.
|
// We really want to deprecate this, too.
|
||||||
exports.get_server_realm_emoji_data = () => server_realm_emoji_data;
|
exports.get_server_realm_emoji_data = () => server_realm_emoji_data;
|
||||||
|
|
||||||
const emoticon_translations = (() => {
|
let emoticon_translations = [];
|
||||||
|
|
||||||
|
function build_emoticon_translations() {
|
||||||
/*
|
/*
|
||||||
|
|
||||||
Build a data structure that looks like something
|
Build a data structure that looks like something
|
||||||
@@ -56,8 +59,8 @@ const emoticon_translations = (() => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return translations;
|
emoticon_translations = translations;
|
||||||
})();
|
}
|
||||||
|
|
||||||
const zulip_emoji = {
|
const zulip_emoji = {
|
||||||
id: "zulip",
|
id: "zulip",
|
||||||
@@ -167,6 +170,10 @@ exports.update_emojis = function (realm_emojis) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.initialize = function initialize(params) {
|
exports.initialize = function initialize(params) {
|
||||||
|
emoji_codes = params.emoji_codes;
|
||||||
|
|
||||||
|
build_emoticon_translations();
|
||||||
|
|
||||||
for (const value of emoji_codes.names) {
|
for (const value of emoji_codes.names) {
|
||||||
const base_name = exports.get_emoji_codepoint(value);
|
const base_name = exports.get_emoji_codepoint(value);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
const generated_emoji_codes = require("../generated/emoji/emoji_codes.json");
|
||||||
|
|
||||||
const emojisets = require("./emojisets");
|
const emojisets = require("./emojisets");
|
||||||
const markdown_config = require("./markdown_config");
|
const markdown_config = require("./markdown_config");
|
||||||
|
|
||||||
@@ -448,7 +450,10 @@ exports.initialize_everything = function () {
|
|||||||
bot_data.initialize(bot_params); // Must happen after people.initialize()
|
bot_data.initialize(bot_params); // Must happen after people.initialize()
|
||||||
message_fetch.initialize();
|
message_fetch.initialize();
|
||||||
message_scroll.initialize();
|
message_scroll.initialize();
|
||||||
emoji.initialize(emoji_params);
|
emoji.initialize({
|
||||||
|
realm_emoji: emoji_params.realm_emoji,
|
||||||
|
emoji_codes: generated_emoji_codes,
|
||||||
|
});
|
||||||
markdown.initialize(page_params.realm_filters, markdown_config.get_helpers());
|
markdown.initialize(page_params.realm_filters, markdown_config.get_helpers());
|
||||||
compose.initialize();
|
compose.initialize();
|
||||||
composebox_typeahead.initialize(); // Must happen after compose.initialize()
|
composebox_typeahead.initialize(); // Must happen after compose.initialize()
|
||||||
|
|||||||
Reference in New Issue
Block a user