Commit 2029be03 authored by Valery Sizov's avatar Valery Sizov

Merge branch 'emoji_aliases' into 'master'

Emoji aliases problem

Fixes #3850

See merge request !2064
parents cd97dba2 72b7d1f5
...@@ -43,6 +43,7 @@ v 8.3.0 (unreleased) ...@@ -43,6 +43,7 @@ v 8.3.0 (unreleased)
- Prevent possible XSS attack with award-emoji - Prevent possible XSS attack with award-emoji
- Upgraded Sidekiq to 4.x - Upgraded Sidekiq to 4.x
- Accept COPYING,COPYING.lesser, and licence as license file (Zeger-Jan van de Weg) - Accept COPYING,COPYING.lesser, and licence as license file (Zeger-Jan van de Weg)
- Fix emoji aliases problem
v 8.2.3 v 8.2.3
- Fix application settings cache not expiring after changes (Stan Hu) - Fix application settings cache not expiring after changes (Stan Hu)
......
class @AwardsHandler class @AwardsHandler
constructor: (@post_emoji_url, @noteable_type, @noteable_id) -> constructor: (@post_emoji_url, @noteable_type, @noteable_id, @aliases) ->
addAward: (emoji) -> addAward: (emoji) ->
emoji = @normilizeEmojiName(emoji)
@postEmoji emoji, => @postEmoji emoji, =>
@addAwardToEmojiBar(emoji) @addAwardToEmojiBar(emoji)
addAwardToEmojiBar: (emoji, custom_path = '') -> addAwardToEmojiBar: (emoji, custom_path = '') ->
emoji = @normilizeEmojiName(emoji)
if @exist(emoji) if @exist(emoji)
if @isActive(emoji) if @isActive(emoji)
@decrementCounter(emoji) @decrementCounter(emoji)
...@@ -94,3 +96,6 @@ class @AwardsHandler ...@@ -94,3 +96,6 @@ class @AwardsHandler
$('body, html').animate({ $('body, html').animate({
scrollTop: $('.awards').offset().top - 80 scrollTop: $('.awards').offset().top - 80
}, 200) }, 200)
normilizeEmojiName: (emoji) ->
@aliases[emoji] || emoji
...@@ -377,6 +377,7 @@ class Note < ActiveRecord::Base ...@@ -377,6 +377,7 @@ class Note < ActiveRecord::Base
end end
def award_emoji_name def award_emoji_name
note.match(Gitlab::Markdown::EmojiFilter.emoji_pattern)[1] original_name = note.match(Gitlab::Markdown::EmojiFilter.emoji_pattern)[1]
AwardEmoji.normilize_emoji_name(original_name)
end end
end end
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
post_emoji_url = "#{award_toggle_namespace_project_notes_path(@project.namespace, @project)}" post_emoji_url = "#{award_toggle_namespace_project_notes_path(@project.namespace, @project)}"
noteable_type = "#{votable.class.name.underscore}" noteable_type = "#{votable.class.name.underscore}"
noteable_id = "#{votable.id}" noteable_id = "#{votable.id}"
window.awards_handler = new AwardsHandler(post_emoji_url, noteable_type, noteable_id) aliases = #{AwardEmoji::ALIASES.to_json}
window.awards_handler = new AwardsHandler(post_emoji_url, noteable_type, noteable_id, aliases)
$(".awards-menu li").click (e)-> $(".awards-menu li").click (e)->
emoji = $(this).data("emoji") emoji = $(this).data("emoji")
......
...@@ -6,7 +6,42 @@ class AwardEmoji ...@@ -6,7 +6,42 @@ class AwardEmoji
"ambulance", "anguished", "two_hearts", "wink" "ambulance", "anguished", "two_hearts", "wink"
] ]
ALIASES = {
pout: "rage",
satisfied: "laughing",
hankey: "shit",
poop: "shit",
collision: "boom",
thumbsup: "+1",
thumbsdown: "-1",
punch: "facepunch",
raised_hand: "hand",
running: "runner",
ng_woman: "no_good",
shoe: "mans_shoe",
tshirt: "shirt",
honeybee: "bee",
flipper: "dolphin",
paw_prints: "feet",
waxing_gibbous_moon: "moon",
telephone: "phone",
knife: "hocho",
envelope: "email",
pencil: "memo",
open_book: "book",
sailboat: "boat",
red_car: "car",
lantern: "izakaya_lantern",
uk: "gb",
heavy_exclamation_mark: "exclamation",
squirrel: "shipit"
}.with_indifferent_access
def self.path_to_emoji_image(name) def self.path_to_emoji_image(name)
"emoji/#{Emoji.emoji_filename(name)}.png" "emoji/#{Emoji.emoji_filename(name)}.png"
end end
def self.normilize_emoji_name(name)
ALIASES[name] || name
end
end end
...@@ -159,4 +159,13 @@ describe Note, models: true do ...@@ -159,4 +159,13 @@ describe Note, models: true do
expect(note.editable?).to be_falsy expect(note.editable?).to be_falsy
end end
end end
describe "set_award!" do
let(:issue) { create :issue }
it "converts aliases to actual name" do
note = create :note, note: ":thumbsup:", noteable: issue
expect(note.reload.note).to eq("+1")
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment