diff options
| author | Aya Morisawa <AyaMorisawa4869@gmail.com> | 2018-12-20 19:41:04 +0900 |
|---|---|---|
| committer | Aya Morisawa <AyaMorisawa4869@gmail.com> | 2018-12-20 19:42:10 +0900 |
| commit | e9f8897fe28249642d47dd1ecf3e6a76b552ddf5 (patch) | |
| tree | c64445f671f782ae2a08e149400b1297f99e5eae /src/services/note | |
| parent | Fix overlap of birthday label on datepicker (#3697) (diff) | |
| download | sharkey-e9f8897fe28249642d47dd1ecf3e6a76b552ddf5.tar.gz sharkey-e9f8897fe28249642d47dd1ecf3e6a76b552ddf5.tar.bz2 sharkey-e9f8897fe28249642d47dd1ecf3e6a76b552ddf5.zip | |
Refactor MFM
Co-authored-by: syuilo syuilotan@yahoo.co.jp
Diffstat (limited to 'src/services/note')
| -rw-r--r-- | src/services/note/create.ts | 43 |
1 files changed, 3 insertions, 40 deletions
diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 55d5eed146..248c2372f0 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -24,12 +24,13 @@ import isQuote from '../../misc/is-quote'; import notesChart from '../../chart/notes'; import perUserNotesChart from '../../chart/per-user-notes'; -import { erase, unique } from '../../prelude/array'; +import { erase } from '../../prelude/array'; import insertNoteUnread from './unread'; import registerInstance from '../register-instance'; import Instance from '../../models/instance'; -import { Node } from '../../mfm/parser'; import extractMentions from '../../misc/extract-mentions'; +import extractEmojis from '../../misc/extract-emojis'; +import extractHashtags from '../../misc/extract-hashtags'; type NotificationType = 'reply' | 'renote' | 'quote' | 'mention'; @@ -466,44 +467,6 @@ async function insertNote(user: IUser, data: Option, tags: string[], emojis: str } } -function extractHashtags(tokens: ReturnType<typeof parse>): string[] { - const hashtags: string[] = []; - - const extract = (tokens: Node[]) => { - for (const x of tokens.filter(x => x.name === 'hashtag')) { - hashtags.push(x.props.hashtag); - } - for (const x of tokens.filter(x => x.children)) { - extract(x.children); - } - }; - - // Extract hashtags - extract(tokens); - - return unique(hashtags); -} - -export function extractEmojis(tokens: ReturnType<typeof parse>): string[] { - const emojis: string[] = []; - - const extract = (tokens: Node[]) => { - for (const x of tokens.filter(x => x.name === 'emoji')) { - if (x.props.name && x.props.name.length <= 100) { - emojis.push(x.props.name); - } - } - for (const x of tokens.filter(x => x.children)) { - extract(x.children); - } - }; - - // Extract emojis - extract(tokens); - - return unique(emojis); -} - function index(note: INote) { if (note.text == null || config.elasticsearch == null) return; |