Merge commit '88ce59505e
' into kb_migration
This commit is contained in:
commit
04253356cf
4 changed files with 49 additions and 36 deletions
|
@ -565,7 +565,7 @@ GEM
|
||||||
redis (>= 4)
|
redis (>= 4)
|
||||||
redlock (1.3.2)
|
redlock (1.3.2)
|
||||||
redis (>= 3.0.0, < 6.0)
|
redis (>= 3.0.0, < 6.0)
|
||||||
regexp_parser (2.7.0)
|
regexp_parser (2.8.0)
|
||||||
request_store (1.5.1)
|
request_store (1.5.1)
|
||||||
rack (>= 1.4)
|
rack (>= 1.4)
|
||||||
responders (3.1.0)
|
responders (3.1.0)
|
||||||
|
@ -601,7 +601,7 @@ GEM
|
||||||
rspec_chunked (0.6)
|
rspec_chunked (0.6)
|
||||||
rspec_junit_formatter (0.6.0)
|
rspec_junit_formatter (0.6.0)
|
||||||
rspec-core (>= 2, < 4, != 2.12.0)
|
rspec-core (>= 2, < 4, != 2.12.0)
|
||||||
rubocop (1.49.0)
|
rubocop (1.50.2)
|
||||||
json (~> 2.3)
|
json (~> 2.3)
|
||||||
parallel (~> 1.10)
|
parallel (~> 1.10)
|
||||||
parser (>= 3.2.0.0)
|
parser (>= 3.2.0.0)
|
||||||
|
|
|
@ -74,9 +74,9 @@ describe('emoji', () => {
|
||||||
.toEqual('<span class="invisible">😄<br>😴</span><img draggable="false" class="emojione" alt="😇" title=":innocent:" src="/emoji/1f607.svg">');
|
.toEqual('<span class="invisible">😄<br>😴</span><img draggable="false" class="emojione" alt="😇" title=":innocent:" src="/emoji/1f607.svg">');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('skips the textual presentation VS15 character', () => {
|
it('does not emojify emojis with textual presentation VS15 character', () => {
|
||||||
expect(emojify('✴︎')) // This is U+2734 EIGHT POINTED BLACK STAR then U+FE0E VARIATION SELECTOR-15
|
expect(emojify('✴︎')) // This is U+2734 EIGHT POINTED BLACK STAR then U+FE0E VARIATION SELECTOR-15
|
||||||
.toEqual('<img draggable="false" class="emojione" alt="✴" title=":eight_pointed_black_star:" src="/emoji/2734_border.svg">');
|
.toEqual('✴︎');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does an simple emoji properly', () => {
|
it('does an simple emoji properly', () => {
|
||||||
|
|
|
@ -20,13 +20,18 @@ const emojiFilename = (filename) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const emojifyTextNode = (node, customEmojis) => {
|
const emojifyTextNode = (node, customEmojis) => {
|
||||||
|
const VS15 = 0xFE0E;
|
||||||
|
const VS16 = 0xFE0F;
|
||||||
|
|
||||||
let str = node.textContent;
|
let str = node.textContent;
|
||||||
|
|
||||||
const fragment = new DocumentFragment();
|
const fragment = new DocumentFragment();
|
||||||
|
let i = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
let match, i = 0;
|
let match;
|
||||||
|
|
||||||
|
// Skip to the next potential emoji to replace
|
||||||
if (customEmojis === null) {
|
if (customEmojis === null) {
|
||||||
while (i < str.length && !(match = trie.search(str.slice(i)))) {
|
while (i < str.length && !(match = trie.search(str.slice(i)))) {
|
||||||
i += str.codePointAt(i) < 65536 ? 1 : 2;
|
i += str.codePointAt(i) < 65536 ? 1 : 2;
|
||||||
|
@ -37,51 +42,58 @@ const emojifyTextNode = (node, customEmojis) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let rend, replacement = null;
|
// We reached the end of the string, nothing to replace
|
||||||
if (i === str.length) {
|
if (i === str.length) {
|
||||||
break;
|
break;
|
||||||
} else if (str[i] === ':') {
|
}
|
||||||
if (!(() => {
|
|
||||||
rend = str.indexOf(':', i + 1) + 1;
|
let rend, replacement = null;
|
||||||
if (!rend) return false; // no pair of ':'
|
if (str[i] === ':') { // Potentially the start of a custom emoji shortcode
|
||||||
const shortname = str.slice(i, rend);
|
if (!(rend = str.indexOf(':', i + 1) + 1)) {
|
||||||
// now got a replacee as ':shortname:'
|
continue; // no pair of ':'
|
||||||
// if you want additional emoji handler, add statements below which set replacement and return true.
|
}
|
||||||
if (shortname in customEmojis) {
|
|
||||||
const filename = autoPlayGif ? customEmojis[shortname].url : customEmojis[shortname].static_url;
|
const shortname = str.slice(i, rend);
|
||||||
replacement = document.createElement('img');
|
// now got a replacee as ':shortname:'
|
||||||
replacement.setAttribute('draggable', 'false');
|
// if you want additional emoji handler, add statements below which set replacement and return true.
|
||||||
replacement.setAttribute('class', 'emojione custom-emoji');
|
if (shortname in customEmojis) {
|
||||||
replacement.setAttribute('alt', shortname);
|
const filename = autoPlayGif ? customEmojis[shortname].url : customEmojis[shortname].static_url;
|
||||||
replacement.setAttribute('title', shortname);
|
replacement = document.createElement('img');
|
||||||
replacement.setAttribute('src', filename);
|
replacement.setAttribute('draggable', 'false');
|
||||||
replacement.setAttribute('data-original', customEmojis[shortname].url);
|
replacement.setAttribute('class', 'emojione custom-emoji');
|
||||||
replacement.setAttribute('data-static', customEmojis[shortname].static_url);
|
replacement.setAttribute('alt', shortname);
|
||||||
return true;
|
replacement.setAttribute('title', shortname);
|
||||||
}
|
replacement.setAttribute('src', filename);
|
||||||
return false;
|
replacement.setAttribute('data-original', customEmojis[shortname].url);
|
||||||
})()) rend = ++i;
|
replacement.setAttribute('data-static', customEmojis[shortname].static_url);
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
} else { // matched to unicode emoji
|
} else { // matched to unicode emoji
|
||||||
|
rend = i + match.length;
|
||||||
|
|
||||||
|
// If the matched character was followed by VS15 (for selecting text presentation), skip it.
|
||||||
|
if (str.codePointAt(rend - 1) !== VS16 && str.codePointAt(rend) === VS15) {
|
||||||
|
i = rend + 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const { filename, shortCode } = unicodeMapping[match];
|
const { filename, shortCode } = unicodeMapping[match];
|
||||||
const title = shortCode ? `:${shortCode}:` : '';
|
const title = shortCode ? `:${shortCode}:` : '';
|
||||||
|
|
||||||
replacement = document.createElement('img');
|
replacement = document.createElement('img');
|
||||||
replacement.setAttribute('draggable', 'false');
|
replacement.setAttribute('draggable', 'false');
|
||||||
replacement.setAttribute('class', 'emojione');
|
replacement.setAttribute('class', 'emojione');
|
||||||
replacement.setAttribute('alt', match);
|
replacement.setAttribute('alt', match);
|
||||||
replacement.setAttribute('title', title);
|
replacement.setAttribute('title', title);
|
||||||
replacement.setAttribute('src', `${assetHost}/emoji/${emojiFilename(filename)}.svg`);
|
replacement.setAttribute('src', `${assetHost}/emoji/${emojiFilename(filename)}.svg`);
|
||||||
rend = i + match.length;
|
|
||||||
// If the matched character was followed by VS15 (for selecting text presentation), skip it.
|
|
||||||
if (str.codePointAt(rend) === 65038) {
|
|
||||||
rend += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the processed-up-to-now string and the emoji replacement
|
||||||
fragment.append(document.createTextNode(str.slice(0, i)));
|
fragment.append(document.createTextNode(str.slice(0, i)));
|
||||||
if (replacement) {
|
fragment.append(replacement);
|
||||||
fragment.append(replacement);
|
|
||||||
}
|
|
||||||
str = str.slice(rend);
|
str = str.slice(rend);
|
||||||
|
i = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment.append(document.createTextNode(str));
|
fragment.append(document.createTextNode(str));
|
||||||
|
|
|
@ -543,7 +543,7 @@ module Mastodon
|
||||||
if options[:all]
|
if options[:all]
|
||||||
User.pending.find_each(&:approve!)
|
User.pending.find_each(&:approve!)
|
||||||
say('OK', :green)
|
say('OK', :green)
|
||||||
elsif options[:number]
|
elsif options[:number]&.positive?
|
||||||
User.pending.limit(options[:number]).each(&:approve!)
|
User.pending.limit(options[:number]).each(&:approve!)
|
||||||
say('OK', :green)
|
say('OK', :green)
|
||||||
elsif username.present?
|
elsif username.present?
|
||||||
|
@ -557,6 +557,7 @@ module Mastodon
|
||||||
account.user&.approve!
|
account.user&.approve!
|
||||||
say('OK', :green)
|
say('OK', :green)
|
||||||
else
|
else
|
||||||
|
say('Number must be positive', :red) if options[:number]
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue