Skip to content

Commit

Permalink
Revert "emoji: Validate parameters with Zod."
Browse files Browse the repository at this point in the history
This reverts commit d5cc7d7.
  • Loading branch information
timabbott committed Jun 22, 2024
1 parent d4c0a61 commit 904aa61
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
26 changes: 19 additions & 7 deletions web/src/emoji.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import _ from "lodash";
import type {z} from "zod";

import * as blueslip from "./blueslip";
import type {StateData, realm_emoji_map_schema, server_emoji_schema} from "./state_data";
import type {User} from "./people";

// This is the data structure that we get from the server on initialization.
export type ServerEmoji = z.infer<typeof server_emoji_schema>;
export type ServerEmoji = {
id: string;
author_id: number;
deactivated: boolean;
name: string;
source_url: string;
still_url: string | null;

type RealmEmojiMap = z.infer<typeof realm_emoji_map_schema>;
// Added later in `settings_emoji.ts` when setting up the emoji settings.
author?: User | null;
};

type RealmEmojiMap = Record<string, ServerEmoji>;

// The data the server provides about unicode emojis.
type ServerUnicodeEmojiData = {
Expand All @@ -18,6 +27,11 @@ type ServerUnicodeEmojiData = {
names: string[];
};

type EmojiParams = {
realm_emoji: RealmEmojiMap;
emoji_codes: ServerUnicodeEmojiData;
};

export type EmoticonTranslation = {
regex: RegExp;
replacement_text: string;
Expand Down Expand Up @@ -365,9 +379,7 @@ function build_default_emoji_aliases({
return map;
}

export function initialize(
params: StateData["emoji"] & {emoji_codes: ServerUnicodeEmojiData},
): void {
export function initialize(params: EmojiParams): void {
emoji_codes = params.emoji_codes;

emoticon_translations = build_emoticon_translations({
Expand Down
16 changes: 1 addition & 15 deletions web/src/state_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,6 @@ export const cross_realm_bot_schema = user_schema.and(
}),
);

export const server_emoji_schema = z.object({
id: z.string(),
author_id: z.number(),
deactivated: z.boolean(),
name: z.string(),
source_url: z.string(),
still_url: z.string().nullable(),

// Added later in `settings_emoji.ts` when setting up the emoji settings.
author: user_schema.nullish(),
});

export const realm_emoji_map_schema = z.record(server_emoji_schema);

// Sync this with zerver.lib.events.do_events_register.
const current_user_schema = z.object({
avatar_source: z.string(),
Expand Down Expand Up @@ -325,7 +311,7 @@ const realm_schema = z.object({
export const state_data_schema = z
.object({alert_words: NOT_TYPED_YET})
.transform((alert_words) => ({alert_words}))
.and(z.object({realm_emoji: realm_emoji_map_schema}).transform((emoji) => ({emoji})))
.and(z.object({realm_emoji: NOT_TYPED_YET}).transform((emoji) => ({emoji})))
.and(z.object({realm_bots: NOT_TYPED_YET}).transform((bot) => ({bot})))
.and(
z
Expand Down
2 changes: 1 addition & 1 deletion web/src/ui_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ export function initialize_everything(state_data) {
// The emoji module must be initialized before the right sidebar
// module, so that we can display custom emoji in statuses.
emoji.initialize({
...state_data.emoji,
realm_emoji: state_data.emoji.realm_emoji,
emoji_codes: generated_emoji_codes,
});

Expand Down

0 comments on commit 904aa61

Please sign in to comment.