Slack import: Cache emoji.json in static/generated/emoji.

Previously, emoji.json was read from
"$ZULIP_PATH/node_modules/emoji-datasource-google/emoji.json".
This path doesn't exist in production when installing from scratch from
a release tarball. And so, we ensure emoji.json exists by copying it to
`static/generated/emoji`.

With tweaks to comments by tabbott.

Fixes: #23469
This commit is contained in:
rht 2022-11-15 01:19:59 -05:00 committed by Tim Abbott
parent 7e883add5b
commit 5ce2103b87
2 changed files with 12 additions and 7 deletions

View File

@ -421,6 +421,11 @@ def dump_emojis(cache_path: str) -> None:
setup_emoji_farms(cache_path, emoji_data)
setup_old_emoji_farm(cache_path, emoji_map, emoji_data)
# This file is needed to translate emoji when importing data from Slack.
shutil.copyfile(
EMOJI_DATA_FILE_PATH, os.path.join(cache_path, "emoji-datasource-google-emoji.json")
)
# Generate various map files.
generate_map_files(cache_path, emoji_catalog)

View File

@ -42,6 +42,7 @@ from zerver.data_import.slack_message_conversion import (
)
from zerver.lib.emoji import codepoint_to_name
from zerver.lib.export import MESSAGE_BATCH_CHUNK_SIZE
from zerver.lib.storage import static_path
from zerver.lib.upload import resize_logo, sanitize_name
from zerver.models import (
CustomProfileField,
@ -61,13 +62,12 @@ SlackToZulipRecipientT = Dict[str, int]
# Generic type for SlackBotEmail class
SlackBotEmailT = TypeVar("SlackBotEmailT", bound="SlackBotEmail")
# Initialize iamcal emoji data, because Slack seems to use emoji naming from iamcal.
# According to https://emojipedia.org/slack/, Slack's emoji shortcodes are
# derived from https://github.com/iamcal/emoji-data.
ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../")
NODE_MODULES_PATH = os.path.join(ZULIP_PATH, "node_modules")
EMOJI_DATA_FILE_PATH = os.path.join(NODE_MODULES_PATH, "emoji-datasource-google", "emoji.json")
with open(EMOJI_DATA_FILE_PATH, "rb") as emoji_data_file:
# We can look up unicode codepoints for Slack emoji using iamcal emoji
# data. https://emojipedia.org/slack/, documents Slack's emoji names
# are derived from https://github.com/iamcal/emoji-data; this seems
# likely to remain true since Cal is a Slack's cofounder.
emoji_data_file_path = static_path("generated/emoji/emoji-datasource-google-emoji.json")
with open(emoji_data_file_path, "rb") as emoji_data_file:
emoji_data = orjson.loads(emoji_data_file.read())