summaryrefslogtreecommitdiff
path: root/src/services/note
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-11-04 03:32:20 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-11-04 03:32:20 +0900
commit84db15694d7223d6f46bae6340542b4c24e9bcb3 (patch)
tree1c180a37dfb9433298c6f146418002c6654f48d7 /src/services/note
parent[Client] Improve Emoji management page of admin panel (diff)
downloadsharkey-84db15694d7223d6f46bae6340542b4c24e9bcb3.tar.gz
sharkey-84db15694d7223d6f46bae6340542b4c24e9bcb3.tar.bz2
sharkey-84db15694d7223d6f46bae6340542b4c24e9bcb3.zip
Do not send needless emojis in note
投稿作成時に含まれている絵文字を保存しておくように SEE: https://github.com/syuilo/misskey/pull/3085#issuecomment-435608434
Diffstat (limited to 'src/services/note')
-rw-r--r--src/services/note/create.ts18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/services/note/create.ts b/src/services/note/create.ts
index 7e97740edd..ac8bcf034d 100644
--- a/src/services/note/create.ts
+++ b/src/services/note/create.ts
@@ -30,6 +30,7 @@ import { erase, unique } from '../../prelude/array';
import insertNoteUnread from './unread';
import registerInstance from '../register-instance';
import Instance from '../../models/instance';
+import { TextElementEmoji } from '../../mfm/parse/elements/emoji';
type NotificationType = 'reply' | 'renote' | 'quote' | 'mention';
@@ -146,6 +147,8 @@ export default async (user: IUser, data: Option, silent = false) => new Promise<
const tags = extractHashtags(tokens);
+ const emojis = extractEmojis(tokens);
+
const mentionedUsers = await extractMentionedUsers(tokens);
if (data.reply && !user._id.equals(data.reply.userId) && !mentionedUsers.some(u => u._id.equals(data.reply.userId))) {
@@ -160,7 +163,7 @@ export default async (user: IUser, data: Option, silent = false) => new Promise<
});
}
- const note = await insertNote(user, data, tags, mentionedUsers);
+ const note = await insertNote(user, data, tags, emojis, mentionedUsers);
res(note);
@@ -371,7 +374,7 @@ async function publish(user: IUser, note: INote, noteObj: any, reply: INote, ren
publishToUserLists(note, noteObj);
}
-async function insertNote(user: IUser, data: Option, tags: string[], mentionedUsers: IUser[]) {
+async function insertNote(user: IUser, data: Option, tags: string[], emojis: string[], mentionedUsers: IUser[]) {
const insert: any = {
createdAt: data.createdAt,
fileIds: data.files ? data.files.map(file => file._id) : [],
@@ -382,6 +385,7 @@ async function insertNote(user: IUser, data: Option, tags: string[], mentionedUs
cw: data.cw == null ? null : data.cw,
tags,
tagsLower: tags.map(tag => tag.toLowerCase()),
+ emojis,
userId: user._id,
viaMobile: data.viaMobile,
geo: data.geo || null,
@@ -449,6 +453,16 @@ function extractHashtags(tokens: ReturnType<typeof parse>): string[] {
return unique(hashtags);
}
+function extractEmojis(tokens: ReturnType<typeof parse>): string[] {
+ // Extract emojis
+ const emojis = tokens
+ .filter(t => t.type == 'emoji')
+ .map(t => (t as TextElementEmoji).emoji)
+ .filter(emoji => emoji.length <= 100);
+
+ return unique(emojis);
+}
+
function index(note: INote) {
if (note.text == null || config.elasticsearch == null) return;