emoji: Disable support for letting users switch emojisets.

Due to copyright issues with potentially displaying Apple emojisets on
non-apple devices, as well as iamcal dropping support for the emojione
emojiset (see https://github.com/iamcal/emoji-data/pull/142), we are
dropping (perhaps temporarily) support for allowing users to switch
emojisets in Zulip.

This commit just hides the feature from the user but leaves most of
the infrastructure in place so that in the future if we decide to
re-enable the support we will not need to redo the infrastructure work
(some JS-side code is deleted, mostly because we'll want to re-add the
feature using the do_settings_change infrastructure anyway).

The most likely emoji set to add is the legacy "blobs" Google emoji
set, since it seems popular with some users.

Tweaked by tabbott to remove some additional JS code and update the
changelog.
This commit is contained in:
Harshit Bansal 2018-07-20 12:58:32 +05:30 committed by Tim Abbott
parent 1cfe7f6494
commit 9057e543ac
7 changed files with 71 additions and 44 deletions

View File

@ -66,6 +66,9 @@ Zulip 1.9; it is generally updated in bursts.
thousands of users and hundreds of bot users.
- Optimized production release tarballs to save about 40MB of size.
- Upgraded to the latest version of the Google emoji set.
- Dropped, at least for now, support for user-configured alternative
emoji sets. This was largely motivated by
[EmojiOne requesting removal from the emoji-data project](https://github.com/iamcal/emoji-data/pull/142)
- Removed the "Delete streams" administration page; one can delete
streams directly on "Manage streams".
- Removed support code for the (long-deprecated) legacy desktop app.

View File

@ -111,6 +111,7 @@ function setup_settings_label() {
left_side_userlist: i18n.t("User list on left sidebar in narrow windows"),
night_mode: i18n.t("Night mode"),
twenty_four_hour_time: i18n.t("24-hour time (17:00 instead of 5:00 PM)"),
translate_emoji_to_text: i18n.t("Translate emoji to text (Convert 😃 to <code>:smile:</code>)"),
translate_emoticons: i18n.t("Translate emoticons (convert <code>:)</code> to 😃 in messages)"),
};
}

View File

@ -33,7 +33,9 @@ exports.set_up = function () {
$("#display-settings-status").hide();
$("#user_timezone").val(page_params.timezone);
$(".emojiset_choice[value=" + page_params.emojiset + "]").prop("checked", true);
// $(".emojiset_choice[value=" + page_params.emojiset + "]").prop("checked", true);
$("#translate_emoji_to_text").prop('checked', page_params.emojiset === "text");
$("#default_language_modal [data-dismiss]").click(function () {
overlays.close_modal('default_language_modal');
@ -107,22 +109,15 @@ exports.set_up = function () {
change_display_setting(data, '#time-settings-status');
});
$(".emojiset_choice").click(function () {
var emojiset = $(this).val();
$("#translate_emoji_to_text").change(function () {
var data = {};
data.emojiset = JSON.stringify(emojiset);
var spinner = $("#emoji-settings-status").expectOne();
loading.make_indicator(spinner, {text: settings_ui.strings.saving });
channel.patch({
url: '/json/settings/display',
data: data,
success: function () {
},
error: function (xhr) {
ui_report.error(settings_ui.strings.failure, xhr, $('#emoji-settings-status').expectOne());
},
});
var is_checked = $("#translate_emoji_to_text").is(":checked");
if (is_checked) {
data.emojiset = JSON.stringify("text");
} else {
data.emojiset = JSON.stringify("google");
}
change_display_setting(data, '#emoji-settings-status');
});
$("#translate_emoticons").change(function () {
@ -134,25 +129,8 @@ exports.set_up = function () {
};
exports.report_emojiset_change = function () {
// TODO: Clean up how this works so we can use
// change_display_setting. The challenge is that we don't want to
// report success before the server_events request returns that
// causes the actual sprite sheet to change. The current
// implementation is wrong, though, in that it displays the UI
// update in all active browser windows.
function emoji_success() {
if ($("#emoji-settings-status").length) {
loading.destroy_indicator($("#emojiset_spinner"));
$("#emojiset_select").val(page_params.emojiset);
ui_report.success(i18n.t("Emojiset changed successfully!"),
$('#emoji-settings-status').expectOne());
var spinner = $("#emoji-settings-status").expectOne();
settings_ui.display_checkmark(spinner);
}
}
// This function still has full support for multiple emojiset options.
if (page_params.emojiset === 'text') {
emoji_success();
return;
}
@ -160,7 +138,6 @@ exports.report_emojiset_change = function () {
sprite.onload = function () {
var sprite_css_href = "/static/generated/emoji/" + page_params.emojiset + "_sprite.css";
$("#emoji-spritesheet").attr('href', sprite_css_href);
emoji_success();
};
sprite.src = "/static/generated/emoji/sheet_" + page_params.emojiset + "_64.png";
};
@ -169,9 +146,9 @@ exports.update_page = function () {
$("#twenty_four_hour_time").prop('checked', page_params.twenty_four_hour_time);
$("#left_side_userlist").prop('checked', page_params.left_side_userlist);
$("#default_language_name").text(page_params.default_language_name);
$("#translate_emoji_to_text").prop('checked', page_params.emojiset === "text");
$("#translate_emoticons").prop('checked', page_params.translate_emoticons);
$("#night_mode").prop('checked', page_params.night_mode);
// TODO: Set emojiset selector here.
// Longer term, we'll want to automate this function
};

View File

@ -72,9 +72,10 @@
</div>
<div id="user-emoji-settings">
<h3 class="inline-block light">Emoji style</h3>
<h3 class="inline-block light">Emoji settings</h3>
<div class="alert-notification" id="emoji-settings-status"></div>
{{#if false}}
<div class="input-group">
<div class="emojiset_choices grey-box">
{{#each page_params.emojiset_choices }}
@ -95,6 +96,12 @@
{{/each}}
</div>
</div>
{{/if}}
{{partial "settings_checkbox"
"setting_name" "translate_emoji_to_text"
"is_checked" false
"label" settings_label.translate_emoji_to_text}}
{{partial "settings_checkbox"
"setting_name" "translate_emoticons"

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from django.db import migrations, models
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
def change_emojiset_choice(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
UserProfile = apps.get_model('zerver', 'UserProfile')
UserProfile.objects.exclude(emojiset__in=['google', 'text']).update(emojiset='google')
class Migration(migrations.Migration):
dependencies = [
('zerver', '0180_usermessage_add_active_mobile_push_notification'),
]
operations = [
migrations.RunPython(
change_emojiset_choice,
reverse_code=migrations.RunPython.noop),
migrations.AlterField(
model_name='userprofile',
name='emojiset',
field=models.CharField(choices=[('google', 'Google'), ('text', 'Plain text')], default='google', max_length=20),
),
]

View File

@ -771,15 +771,9 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
timezone = models.CharField(max_length=40, default=u'') # type: str
# Emojisets
APPLE_EMOJISET = u'apple'
EMOJIONE_EMOJISET = u'emojione'
GOOGLE_EMOJISET = u'google'
TWITTER_EMOJISET = u'twitter'
TEXT_EMOJISET = u'text'
EMOJISET_CHOICES = ((GOOGLE_EMOJISET, "Google"),
(APPLE_EMOJISET, "Apple"),
(TWITTER_EMOJISET, "Twitter"),
(EMOJIONE_EMOJISET, "EmojiOne"),
(TEXT_EMOJISET, "Plain text"))
emojiset = models.CharField(default=GOOGLE_EMOJISET, choices=EMOJISET_CHOICES, max_length=20) # type: str

View File

@ -225,7 +225,7 @@ class ChangeSettingsTest(ZulipTestCase):
test_changes = dict(
default_language = 'de',
emojiset = 'apple',
emojiset = 'google',
timezone = 'US/Mountain',
) # type: Dict[str, Any]
@ -260,6 +260,26 @@ class ChangeSettingsTest(ZulipTestCase):
for setting in user_settings:
self.do_test_change_user_display_setting(setting)
def do_change_emojiset(self, emojiset: str) -> HttpResponse:
email = self.example_email('hamlet')
self.login(email)
data = {'emojiset': ujson.dumps(emojiset)}
result = self.client_patch("/json/settings/display", data)
return result
def test_emojiset(self) -> None:
"""Test banned emojisets are not accepted."""
banned_emojisets = ['apple', 'emojione', 'twitter']
valid_emojisets = ['google', 'text']
for emojiset in banned_emojisets:
result = self.do_change_emojiset(emojiset)
self.assert_json_error(result, "Invalid emojiset '%s'" % (emojiset))
for emojiset in valid_emojisets:
result = self.do_change_emojiset(emojiset)
self.assert_json_success(result)
class UserChangesTest(ZulipTestCase):
def test_update_api_key(self) -> None: