summaryrefslogtreecommitdiff
path: root/src/models
diff options
context:
space:
mode:
Diffstat (limited to 'src/models')
-rw-r--r--src/models/entities/note-reaction.ts2
-rw-r--r--src/models/repositories/note.ts68
2 files changed, 51 insertions, 19 deletions
diff --git a/src/models/entities/note-reaction.ts b/src/models/entities/note-reaction.ts
index 995748760c..ed38450bb2 100644
--- a/src/models/entities/note-reaction.ts
+++ b/src/models/entities/note-reaction.ts
@@ -36,7 +36,7 @@ export class NoteReaction {
public note: Note | null;
@Column('varchar', {
- length: 130
+ length: 260
})
public reaction: string;
}
diff --git a/src/models/repositories/note.ts b/src/models/repositories/note.ts
index 2aad5c0fa3..d29a48b7ec 100644
--- a/src/models/repositories/note.ts
+++ b/src/models/repositories/note.ts
@@ -5,9 +5,11 @@ import { Emojis, Users, PollVotes, DriveFiles, NoteReactions, Followings, Polls
import { ensure } from '../../prelude/ensure';
import { SchemaType } from '../../misc/schema';
import { awaitAll } from '../../prelude/await-all';
-import { convertLegacyReaction, convertLegacyReactions } from '../../misc/reaction-lib';
+import { convertLegacyReaction, convertLegacyReactions, decodeReaction } from '../../misc/reaction-lib';
import { toString } from '../../mfm/toString';
import { parse } from '../../mfm/parse';
+import { Emoji } from '../entities/emoji';
+import { concat } from '../../prelude/array';
export type PackedNote = SchemaType<typeof packedNoteSchema>;
@@ -129,31 +131,61 @@ export class NoteRepository extends Repository<Note> {
};
}
+ /**
+ * 添付用emojisを解決する
+ * @param emojiNames Note等に添付されたカスタム絵文字名 (:は含めない)
+ * @param noteUserHost Noteのホスト
+ * @param reactionNames Note等にリアクションされたカスタム絵文字名 (:は含めない)
+ */
async function populateEmojis(emojiNames: string[], noteUserHost: string | null, reactionNames: string[]) {
- const where = [] as {}[];
+ let all = [] as {
+ name: string,
+ url: string
+ }[];
+ // カスタム絵文字
if (emojiNames?.length > 0) {
- where.push({
- name: In(emojiNames),
- host: noteUserHost
- });
+ const tmp = await Emojis.find({
+ where: {
+ name: In(emojiNames),
+ host: noteUserHost
+ },
+ select: ['name', 'host', 'url']
+ }).then(emojis => emojis.map((emoji: Emoji) => {
+ return {
+ name: emoji.name,
+ url: emoji.url,
+ };
+ }));
+
+ all = concat([all, tmp]);
}
- reactionNames = reactionNames?.filter(x => x.match(/^:[^:]+:$/)).map(x => x.replace(/:/g, ''));
+ const customReactions = reactionNames?.map(x => decodeReaction(x)).filter(x => x.name);
- if (reactionNames?.length > 0) {
- where.push({
- name: In(reactionNames),
- host: null
- });
- }
+ if (customReactions?.length > 0) {
+ const where = [] as {}[];
- if (where.length === 0) return [];
+ for (const customReaction of customReactions) {
+ where.push({
+ name: customReaction.name,
+ host: customReaction.host
+ });
+ }
- return Emojis.find({
- where,
- select: ['name', 'host', 'url', 'aliases']
- });
+ const tmp = await Emojis.find({
+ where,
+ select: ['name', 'host', 'url']
+ }).then(emojis => emojis.map((emoji: Emoji) => {
+ return {
+ name: `${emoji.name}@${emoji.host || '.'}`, // @host付きでローカルは.
+ url: emoji.url,
+ };
+ }));
+ all = concat([all, tmp]);
+ }
+
+ return all;
}
async function populateMyReaction() {