summaryrefslogtreecommitdiff
path: root/src/models
diff options
context:
space:
mode:
authorMeiMei <30769358+mei23@users.noreply.github.com>2018-11-02 08:59:40 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2018-11-02 08:59:40 +0900
commit80b5fda292efd70cc749910e3672d50c9a70a72e (patch)
treea8f287c9c60a532112801d084fcb7d5b8c4e3650 /src/models
parentFix bug (diff)
downloadsharkey-80b5fda292efd70cc749910e3672d50c9a70a72e.tar.gz
sharkey-80b5fda292efd70cc749910e3672d50c9a70a72e.tar.bz2
sharkey-80b5fda292efd70cc749910e3672d50c9a70a72e.zip
Remote custom emojis (#3074)
* Remote custom emojis * んほおおおおお
Diffstat (limited to 'src/models')
-rw-r--r--src/models/emoji.ts22
-rw-r--r--src/models/note.ts6
2 files changed, 28 insertions, 0 deletions
diff --git a/src/models/emoji.ts b/src/models/emoji.ts
new file mode 100644
index 0000000000..f0d0b58273
--- /dev/null
+++ b/src/models/emoji.ts
@@ -0,0 +1,22 @@
+import db from '../db/mongodb';
+
+const Emoji = db.get<IEmoji>('emoji');
+
+Emoji.createIndex(['name', 'host'], { unique: true });
+
+export default Emoji;
+
+export type IEmoji = {
+ name: string;
+ host: string;
+ url: string;
+ aliases?: string[];
+ updatedAt?: Date;
+};
+
+export const packEmojis = async (
+ host: string,
+ // MeiTODO: filter
+) => {
+ return await Emoji.find({ host });
+};
diff --git a/src/models/note.ts b/src/models/note.ts
index 09246dea45..684e8c3b1e 100644
--- a/src/models/note.ts
+++ b/src/models/note.ts
@@ -12,6 +12,7 @@ import { packMany as packFileMany, IDriveFile } from './drive-file';
import Favorite from './favorite';
import Following from './following';
import config from '../config';
+import { packEmojis } from './emoji';
const Note = db.get<INote>('notes');
Note.createIndex('uri', { sparse: true, unique: true });
@@ -228,6 +229,11 @@ export const pack = async (
const id = _note._id;
+ // _note._userを消す前か、_note.userを解決した後でないとホストがわからない
+ if (_note._user) {
+ _note.emojis = packEmojis(_note._user.host);
+ }
+
// Rename _id to id
_note.id = _note._id;
delete _note._id;