Remove comments
This commit is contained in:
parent
1d90f7588b
commit
89eb1334fc
2 changed files with 2 additions and 60 deletions
|
@ -202,9 +202,7 @@ function EmojiBoard({ onSelect, searchRef }) {
|
||||||
setAvailableEmojis([]);
|
setAvailableEmojis([]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Retrieve the packs for the new room
|
|
||||||
// Remove packs that aren't marked as emoji packs
|
|
||||||
// Remove packs without emojis
|
|
||||||
const packs = getRelevantPacks(
|
const packs = getRelevantPacks(
|
||||||
initMatrix.matrixClient.getRoom(selectedRoomId),
|
initMatrix.matrixClient.getRoom(selectedRoomId),
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,26 +1,8 @@
|
||||||
import { emojis } from './emoji';
|
import { emojis } from './emoji';
|
||||||
|
|
||||||
// Custom emoji are stored in one of three places:
|
// https://github.com/Sorunome/matrix-doc/blob/soru/emotes/proposals/2545-emotes.md
|
||||||
// - User emojis, which are stored in account data
|
|
||||||
// - Room emojis, which are stored in state events in a room
|
|
||||||
// - Emoji packs, which are rooms of emojis referenced in the account data or in a room's
|
|
||||||
// cannonical space
|
|
||||||
//
|
|
||||||
// Emojis and packs referenced from within a user's account data should be available
|
|
||||||
// globally, while emojis and packs in rooms and spaces should only be available within
|
|
||||||
// those spaces and rooms
|
|
||||||
|
|
||||||
class ImagePack {
|
class ImagePack {
|
||||||
// Convert a raw image pack into a more maliable format
|
|
||||||
//
|
|
||||||
// Takes an image pack as per MSC 2545 (e.g. as in the Matrix spec), and converts it to a
|
|
||||||
// format used here, while filling in defaults.
|
|
||||||
//
|
|
||||||
// The room argument is the room the pack exists in, which is used as a fallback for
|
|
||||||
// missing properties
|
|
||||||
//
|
|
||||||
// Returns `null` if the rawPack is not a properly formatted image pack, although there
|
|
||||||
// is still a fair amount of tolerance for malformed packs.
|
|
||||||
static parsePack(rawPack, room) {
|
static parsePack(rawPack, room) {
|
||||||
if (typeof rawPack.images === 'undefined') {
|
if (typeof rawPack.images === 'undefined') {
|
||||||
return null;
|
return null;
|
||||||
|
@ -59,23 +41,15 @@ class ImagePack {
|
||||||
this.images = images;
|
this.images = images;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Produce a list of emoji in this image pack
|
|
||||||
getEmojis() {
|
getEmojis() {
|
||||||
return this.images.filter((i) => i.usage.indexOf('emoticon') !== -1);
|
return this.images.filter((i) => i.usage.indexOf('emoticon') !== -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Produce a list of stickers in this image pack
|
|
||||||
getStickers() {
|
getStickers() {
|
||||||
return this.images.filter((i) => i.usage.indexOf('sticker') !== -1);
|
return this.images.filter((i) => i.usage.indexOf('sticker') !== -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve a list of user emojis
|
|
||||||
//
|
|
||||||
// Result is an ImagePack, or null if the user hasn't set up or has deleted their personal
|
|
||||||
// image pack.
|
|
||||||
//
|
|
||||||
// Accepts a reference to a matrix client as the only argument
|
|
||||||
function getUserImagePack(mx) {
|
function getUserImagePack(mx) {
|
||||||
const accountDataEmoji = mx.getAccountData('im.ponies.user_emotes');
|
const accountDataEmoji = mx.getAccountData('im.ponies.user_emotes');
|
||||||
if (!accountDataEmoji) {
|
if (!accountDataEmoji) {
|
||||||
|
@ -87,10 +61,6 @@ function getUserImagePack(mx) {
|
||||||
return userImagePack;
|
return userImagePack;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Produces a list of all of the emoji packs in a room
|
|
||||||
//
|
|
||||||
// Returns a list of `ImagePack`s. This does not include packs in spaces that contain
|
|
||||||
// this room.
|
|
||||||
function getPacksInRoom(room) {
|
function getPacksInRoom(room) {
|
||||||
const packs = room.currentState.getStateEvents('im.ponies.room_emotes');
|
const packs = room.currentState.getStateEvents('im.ponies.room_emotes');
|
||||||
|
|
||||||
|
@ -99,17 +69,6 @@ function getPacksInRoom(room) {
|
||||||
.filter((p) => p !== null);
|
.filter((p) => p !== null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Produce a list of all image packs which should be shown for a given room
|
|
||||||
//
|
|
||||||
// This includes packs in that room, the user's personal images, and will eventually
|
|
||||||
// include the user's enabled global image packs and space-level packs.
|
|
||||||
//
|
|
||||||
// This differs from getPacksInRoom, as the former only returns packs that are directly in
|
|
||||||
// a room, whereas this function returns all packs which should be shown to the user while
|
|
||||||
// they are in this room.
|
|
||||||
//
|
|
||||||
// Packs will be returned in the order that shortcode conflicts should be resolved, with
|
|
||||||
// higher priority packs coming first.
|
|
||||||
function getRelevantPacks(room) {
|
function getRelevantPacks(room) {
|
||||||
return [].concat(
|
return [].concat(
|
||||||
getUserImagePack(room.client) ?? [],
|
getUserImagePack(room.client) ?? [],
|
||||||
|
@ -117,14 +76,6 @@ function getRelevantPacks(room) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns all user+room emojis and all standard unicode emojis
|
|
||||||
//
|
|
||||||
// Accepts a reference to a matrix client as the only argument
|
|
||||||
//
|
|
||||||
// Result is a map from shortcode to the corresponding emoji. If two emoji share a
|
|
||||||
// shortcode, only one will be presented, with priority given to custom emoji.
|
|
||||||
//
|
|
||||||
// Will eventually be expanded to include all emojis revelant to a room and the user
|
|
||||||
function getShortcodeToEmoji(room) {
|
function getShortcodeToEmoji(room) {
|
||||||
const allEmoji = new Map();
|
const allEmoji = new Map();
|
||||||
|
|
||||||
|
@ -159,13 +110,6 @@ function getShortcodeToCustomEmoji(room) {
|
||||||
return allEmoji;
|
return allEmoji;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Produces a special list of emoji specifically for auto-completion
|
|
||||||
//
|
|
||||||
// This list contains each emoji once, with all emoji being deduplicated by shortcode.
|
|
||||||
// However, the order of the standard emoji will have been preserved, and alternate
|
|
||||||
// shortcodes for the standard emoji will not be considered.
|
|
||||||
//
|
|
||||||
// Standard emoji are guaranteed to be earlier in the list than custom emoji
|
|
||||||
function getEmojiForCompletion(room) {
|
function getEmojiForCompletion(room) {
|
||||||
const allEmoji = new Map();
|
const allEmoji = new Map();
|
||||||
getRelevantPacks(room).reverse()
|
getRelevantPacks(room).reverse()
|
||||||
|
|
Loading…
Reference in a new issue