emoji: Fix sort order of emoji choices.

The previous code for ensuring the sort order of emoji choices was
correct relied on an OrderedDict structure, which isn't guaranteed to
be preserved when passed to the frontend via JSON (in fact, it isn't,
since we converted the way page_params is passed to use
sort_keys=True).  Switch it to a list of dictionaries to correct this.

Fixes #13220.
This commit is contained in:
Ivan Mitev 2019-09-28 02:06:46 +03:00 committed by Tim Abbott
parent 4166c901ef
commit 16c9d63056
3 changed files with 12 additions and 12 deletions

View File

@ -72,18 +72,18 @@
<div class="input-group"> <div class="input-group">
<div class="emojiset_choices grey-box"> <div class="emojiset_choices grey-box">
{{#each page_params.emojiset_choices }} {{#each page_params.emojiset_choices}}
<label> <label>
<input type="radio" class="emojiset_choice" name="emojiset_group" value="{{@key}}" /> <input type="radio" class="emojiset_choice" name="emojiset_group" value="{{this.key}}" />
<span>{{t this }}</span> <span>{{this.text}}</span>
<span class="right"> <span class="right">
{{#if (eq @key "text") }} {{#if (eq this.key "text") }}
<div class="emoji_alt_code">&nbsp;:relaxed:</div> <div class="emoji_alt_code">&nbsp;:relaxed:</div>
{{else}} {{else}}
<img class="emoji" src="/static/generated/emoji/images-{{@key}}-64/1f642.png" /> <img class="emoji" src="/static/generated/emoji/images-{{this.key}}-64/1f642.png" />
<img class="emoji" src="/static/generated/emoji/images-{{@key}}-64/1f44d.png" /> <img class="emoji" src="/static/generated/emoji/images-{{this.key}}-64/1f44d.png" />
<img class="emoji" src="/static/generated/emoji/images-{{@key}}-64/1f680.png" /> <img class="emoji" src="/static/generated/emoji/images-{{this.key}}-64/1f680.png" />
<img class="emoji" src="/static/generated/emoji/images-{{@key}}-64/1f389.png" /> <img class="emoji" src="/static/generated/emoji/images-{{this.key}}-64/1f389.png" />
{{/if}} {{/if}}
</span> </span>
</label> </label>

View File

@ -41,7 +41,7 @@ from zerver.lib.types import Validator, ExtendedValidator, \
from bitfield import BitField from bitfield import BitField
from bitfield.types import BitHandler from bitfield.types import BitHandler
from collections import defaultdict, OrderedDict from collections import defaultdict
from datetime import timedelta from datetime import timedelta
import pylibmc import pylibmc
import re import re
@ -1037,8 +1037,8 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
return allowed_bot_types return allowed_bot_types
@staticmethod @staticmethod
def emojiset_choices() -> Dict[str, str]: def emojiset_choices() -> List[Dict[str, str]]:
return OrderedDict((emojiset[0], emojiset[1]) for emojiset in UserProfile.EMOJISET_CHOICES) return [dict(key=emojiset[0], text=emojiset[1]) for emojiset in UserProfile.EMOJISET_CHOICES]
@staticmethod @staticmethod
def emails_from_ids(user_ids: Sequence[int]) -> Dict[int, str]: def emails_from_ids(user_ids: Sequence[int]) -> Dict[int, str]:

View File

@ -138,7 +138,7 @@ def update_display_settings_backend(
raise JsonableError(_("Invalid timezone '%s'") % (timezone,)) raise JsonableError(_("Invalid timezone '%s'") % (timezone,))
if (emojiset is not None and if (emojiset is not None and
emojiset not in UserProfile.emojiset_choices()): emojiset not in [emojiset_choice['key'] for emojiset_choice in UserProfile.emojiset_choices()]):
raise JsonableError(_("Invalid emojiset '%s'") % (emojiset,)) raise JsonableError(_("Invalid emojiset '%s'") % (emojiset,))
if (demote_inactive_streams is not None and if (demote_inactive_streams is not None and