Skip to content

Commit c04a809

Browse files
showelltimabbott
authored andcommitted
mypy: Add EmojiInfo type.
We now serialize still_url as None for non-animated emojis, instead of omitting the field. The webapp does proper checks for falsiness here. The mobile app does not yet use the field (to my knowledge). We bump the API version here. More discussion here: https://chat.zulip.org/#narrow/stream/378-api-design/topic/still_url/near/1302573
1 parent a6201b4 commit c04a809

File tree

7 files changed

+34
-15
lines changed

7 files changed

+34
-15
lines changed

frontend_tests/node_tests/lib/events.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ exports.test_realm_emojis = {
8484
author_id: 222,
8585
deactivated: false,
8686
source_url: "/some/path/to/emoji",
87+
still_url: null,
8788
},
8889
};
8990

templates/zerver/api/changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ format used by the Zulip server that they are interacting with.
2020

2121
## Changes in Zulip 5.0
2222

23+
**Feature level 113**
24+
25+
* `GET /realm/emoji`, `POST /realm/emoji/{emoji_name}`, [`GET
26+
/events`](/api/get-events), [`POST /register`](/api/register-queue):
27+
The `still_url` field for custom emoji objects is now always
28+
present, with a value of null for non-animated emoji. Previously, it
29+
only was present for animated emoji.
30+
2331
**Feature level 112**
2432

2533
* [`GET /events`](/api/get-events): Updated `update_message` event type

version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# Changes should be accompanied by documentation explaining what the
3434
# new level means in templates/zerver/api/changelog.md, as well as
3535
# "**Changes**" entries in the endpoint's documentation in `zulip.yaml`.
36-
API_FEATURE_LEVEL = 112
36+
API_FEATURE_LEVEL = 113
3737

3838
# Bump the minor PROVISION_VERSION to indicate that folks should provision
3939
# only when going from an old version of the code to a newer version. Bump

zerver/lib/event_schema.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,7 @@ def check_realm_playgrounds(var_name: str, event: Dict[str, object]) -> None:
712712
("source_url", str),
713713
("deactivated", bool),
714714
("author_id", int),
715-
],
716-
optional_keys=[
717-
("still_url", str),
715+
("still_url", OptionalType(str)),
718716
],
719717
)
720718

zerver/lib/markdown/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ def handleMatch(self, match: Match[str]) -> Optional[Union[str, Element]]:
15031503
orig_syntax = match.group("syntax")
15041504
name = orig_syntax[1:-1]
15051505

1506-
active_realm_emoji: Dict[str, Dict[str, str]] = {}
1506+
active_realm_emoji: Dict[str, EmojiInfo] = {}
15071507
db_data = self.md.zulip_db_data
15081508
if db_data is not None:
15091509
active_realm_emoji = db_data["active_realm_emoji"]

zerver/models.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from django.utils.translation import gettext as _
3838
from django.utils.translation import gettext_lazy
3939
from django_cte import CTEManager
40+
from typing_extensions import TypedDict
4041

4142
from confirmation import settings as confirmation_settings
4243
from zerver.lib import cache
@@ -100,6 +101,15 @@
100101
STREAM_NAMES = TypeVar("STREAM_NAMES", Sequence[str], AbstractSet[str])
101102

102103

104+
class EmojiInfo(TypedDict):
105+
id: str
106+
name: str
107+
source_url: str
108+
deactivated: bool
109+
author_id: Optional[int]
110+
still_url: Optional[str]
111+
112+
103113
def query_for_ids(query: QuerySet, user_ids: List[int], field: str) -> QuerySet:
104114
"""
105115
This function optimizes searches of the form
@@ -726,11 +736,11 @@ def __str__(self) -> str:
726736
return f"<Realm: {self.string_id} {self.id}>"
727737

728738
@cache_with_key(get_realm_emoji_cache_key, timeout=3600 * 24 * 7)
729-
def get_emoji(self) -> Dict[str, Dict[str, Any]]:
739+
def get_emoji(self) -> Dict[str, EmojiInfo]:
730740
return get_realm_emoji_uncached(self)
731741

732742
@cache_with_key(get_active_realm_emoji_cache_key, timeout=3600 * 24 * 7)
733-
def get_active_emoji(self) -> Dict[str, Dict[str, Any]]:
743+
def get_active_emoji(self) -> Dict[str, EmojiInfo]:
734744
return get_active_realm_emoji_uncached(self)
735745

736746
def get_admin_users_and_bots(
@@ -1058,9 +1068,7 @@ class Meta:
10581068
]
10591069

10601070

1061-
def get_realm_emoji_dicts(
1062-
realm: Realm, only_active_emojis: bool = False
1063-
) -> Dict[str, Dict[str, Any]]:
1071+
def get_realm_emoji_dicts(realm: Realm, only_active_emojis: bool = False) -> Dict[str, EmojiInfo]:
10641072
query = RealmEmoji.objects.filter(realm=realm).select_related("author")
10651073
if only_active_emojis:
10661074
query = query.filter(deactivated=False)
@@ -1073,12 +1081,13 @@ def get_realm_emoji_dicts(
10731081
author_id = realm_emoji.author_id
10741082
emoji_url = get_emoji_url(realm_emoji.file_name, realm_emoji.realm_id)
10751083

1076-
emoji_dict = dict(
1084+
emoji_dict: EmojiInfo = dict(
10771085
id=str(realm_emoji.id),
10781086
name=realm_emoji.name,
10791087
source_url=emoji_url,
10801088
deactivated=realm_emoji.deactivated,
10811089
author_id=author_id,
1090+
still_url=None,
10821091
)
10831092

10841093
if realm_emoji.is_animated:
@@ -1095,11 +1104,11 @@ def get_realm_emoji_dicts(
10951104
return d
10961105

10971106

1098-
def get_realm_emoji_uncached(realm: Realm) -> Dict[str, Dict[str, Any]]:
1107+
def get_realm_emoji_uncached(realm: Realm) -> Dict[str, EmojiInfo]:
10991108
return get_realm_emoji_dicts(realm)
11001109

11011110

1102-
def get_active_realm_emoji_uncached(realm: Realm) -> Dict[str, Dict[str, Any]]:
1111+
def get_active_realm_emoji_uncached(realm: Realm) -> Dict[str, EmojiInfo]:
11031112
realm_emojis = get_realm_emoji_dicts(realm, only_active_emojis=True)
11041113
d = {}
11051114
for emoji_id, emoji_dict in realm_emojis.items():

zerver/openapi/zulip.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13931,8 +13931,9 @@ components:
1393113931
emoji's image can be found.
1393213932
still_url:
1393313933
type: string
13934+
nullable: true
1393413935
description: |
13935-
Only present when the emoji's image is animated.
13936+
Only non-null when the emoji's image is animated.
1393613937

1393713938
The path relative to the organization's URL where a still
1393813939
(not animated) version of the emoji can be found. (This is
@@ -13942,7 +13943,9 @@ components:
1394213943
where continuously animating it would be a bad user experience
1394313944
(E.g. because it would be distracting).
1394413945

13945-
**Changes**: New in Zulip 5.0 (feature level 97).
13946+
**Changes**: New in Zulip 5.0 (added as optional field in
13947+
feature level 97 and then made mandatory, but nullable, in
13948+
feature level 113).
1394613949
deactivated:
1394713950
type: boolean
1394813951
description: |

0 commit comments

Comments
 (0)