Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Add an emoji deny list site setting #20929

Merged
merged 34 commits into from Apr 13, 2023
Merged

Conversation

dbattersby
Copy link
Contributor

This feature will allow sites to define which emoji are not allowed. Emoji in this list should be excluded from the set we show in the core emoji picker used in the composer for posts when emoji are enabled. And they should not be allowed to be chosen to be added to messages or as reactions in chat.

This feature prevents denied emoji from appearing in the following scenarios:

  • topic title and page title
  • private messages (topic title and body)
  • inserting emojis into a chat
  • reacting to chat messages
  • using the emoji picker (composer, user status etc)
  • using search within emoji picker

It also takes into account the various ways that emojis can be accessed, such as:

  • emoji autocomplete suggestions
  • emoji favourites (auto populates when adding to emoji deny list for example)
  • emoji inline translations
  • emoji skintones (ie. for certain hand gestures)

/t/93605/

@github-actions github-actions bot added the chat PRs which include a change to Chat plugin label Apr 3, 2023
@dbattersby
Copy link
Contributor Author

The site setting has no default default values selected in this pr (blank string). This means that adding this feature should not affect any emojis when merged in.

The denied emojis will only kick in once a user adds the emojis via the site settings interface.

app/models/emoji.rb Outdated Show resolved Hide resolved
app/models/emoji.rb Outdated Show resolved Hide resolved
lib/pretty_text.rb Outdated Show resolved Hide resolved
@jjaffeux jjaffeux removed the chat PRs which include a change to Chat plugin label Apr 5, 2023
@github-actions github-actions bot added the chat PRs which include a change to Chat plugin label Apr 7, 2023
@dbattersby
Copy link
Contributor Author

dbattersby commented Apr 10, 2023

Added a new model method at Emoji.denied, which uses the SiteSetting value of emoji_deny_list and returns an array of the denied emojis and their aliases. This is then passed into Ember using the SiteSerializer. Updated all touch points within JS to reference the denied_emoji array for consistency and to simplify the logic.

app/models/emoji.rb Outdated Show resolved Hide resolved
app/models/emoji.rb Outdated Show resolved Hide resolved
@tgxworld
Copy link
Contributor

@dbattersby Code is looking much simpler to me 👍 I do have some concerns about performance and some minor comments but the code looks good to me otherwise.

@dbattersby dbattersby force-pushed the add-emoji-deny-list branch 2 times, most recently from 46c6de8 to 7453538 Compare April 12, 2023 03:59
if denied_emojis.present?
all.reject { |e| denied_emojis.include?(e.name) }
else
all
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're kind of double caching here since Emoji.all is already cached. This ends up adding more data to our cache unnecessarily.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually.... this also means that if the number of denied emojis is low, we also end up double caching alot of the data 🤔

[5] pry(main)> now = Time.zone.now; Emoji.all.reject { |emoji| ["alien", "robot"].include?(emoji.name) }; Time.zone.now - now
=> 0.003174472

Looping through all the emojis add 3ms to each page load though 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange, but I really can't see any difference in the response time between calling .all and all.reject. However Emoji.denied is much faster:

[4] pry(main)> now = Time.zone.now; Emoji.all.reject { |emoji| ["alien", "robot"].include?(emoji.name) }; Time.zone.now - now
=> 0.006026
[5] pry(main)> now = Time.zone.now; Emoji.all; Time.zone.now - now
=> 0.006118
[6] pry(main)> now = Time.zone.now; Emoji.denied; Time.zone.now - now
=> 0.001315
[7] pry(main)> now = Time.zone.now; Emoji.denied; Time.zone.now - now
=> 0.000592

In the above example there are 4 denied emoji in site settings. On the first call the Emoji.denied relies on .aliases which reads from a json file on first try, then subsequent calls will read from the cache. On second request it drops from 1ms to 0.5ms.

My personal opinion is that even at 3ms it is negligible, but I'm open to ideas here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The best solution here might be to remove the Emoji.allowed cache since .all is already cached?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea sorry for the confusion, let's just remove the cache for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think I found a better way for this to prevent the double caching:

  def self.load_allowed
    denied_emojis = denied
    all_emojis = load_standard + load_custom

    if denied_emojis.present?
      all_emojis.reject { |e| denied_emojis.include?(e.name) }
    else
      all_emojis
    end
  end

By using load_standard + load_custom, we can get all the default and custom user emojis. Then remove denied emojis and cache the result.

[1] pry(main)> Emoji.clear_cache
=> {}
[2] pry(main)> now = Time.zone.now; Emoji.all; Time.zone.now - now
  CustomEmoji Load (1.6ms)  SELECT "custom_emojis".* FROM "custom_emojis" ORDER BY "custom_emojis"."name" ASC
=> 0.05434
[3] pry(main)> now = Time.zone.now; Emoji.all; Time.zone.now - now
=> 0.006179
[4] pry(main)> now = Time.zone.now; Emoji.allowed; Time.zone.now - now
  CustomEmoji Load (1.3ms)  SELECT "custom_emojis".* FROM "custom_emojis" ORDER BY "custom_emojis"."name" ASC
=> 0.023715
[5] pry(main)> now = Time.zone.now; Emoji.allowed; Time.zone.now - now
=> 0.006197

Now at just over 2ms on first load then down to 0.6ms when reading from the cache.

Copy link
Contributor

@tgxworld tgxworld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Do remember to squash and update the commit title/description when merging. Thank you!

@dbattersby dbattersby merged commit 967010e into main Apr 13, 2023
13 checks passed
@dbattersby dbattersby deleted the add-emoji-deny-list branch April 13, 2023 07:38
@discoursebot
Copy link

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/support-more-management-to-emoji-reaction-in-chat/249001/14

@discoursebot
Copy link

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/3-1-0-beta4-new-notifications-menu-chat-and-sidebar-improvements-security-fixes-and-more/262044/1

ChadBoschert pushed a commit to apt-crowd/discourse that referenced this pull request Apr 26, 2023
This feature will allow sites to define which emoji are not allowed. Emoji in this list should be excluded from the set we show in the core emoji picker used in the composer for posts when emoji are enabled. And they should not be allowed to be chosen to be added to messages or as reactions in chat.

This feature prevents denied emoji from appearing in the following scenarios:
- topic title and page title
- private messages (topic title and body)
- inserting emojis into a chat
- reacting to chat messages
- using the emoji picker (composer, user status etc)
- using search within emoji picker

It also takes into account the various ways that emojis can be accessed, such as:
- emoji autocomplete suggestions
- emoji favourites (auto populates when adding to emoji deny list for example)
- emoji inline translations
- emoji skintones (ie. for certain hand gestures)
@discoursebot
Copy link

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/trying-to-prevent-some-emojies/272559/2

enduvar pushed a commit to ForgottenWorld/discourse that referenced this pull request Sep 8, 2023
This feature will allow sites to define which emoji are not allowed. Emoji in this list should be excluded from the set we show in the core emoji picker used in the composer for posts when emoji are enabled. And they should not be allowed to be chosen to be added to messages or as reactions in chat.

This feature prevents denied emoji from appearing in the following scenarios:
- topic title and page title
- private messages (topic title and body)
- inserting emojis into a chat
- reacting to chat messages
- using the emoji picker (composer, user status etc)
- using search within emoji picker

It also takes into account the various ways that emojis can be accessed, such as:
- emoji autocomplete suggestions
- emoji favourites (auto populates when adding to emoji deny list for example)
- emoji inline translations
- emoji skintones (ie. for certain hand gestures)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chat PRs which include a change to Chat plugin
4 participants