diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-09-18 06:29:47 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-09-18 06:29:47 +0900 |
| commit | 1f2ebce8ed749d7e81e999944fc8a22ff39b87b7 (patch) | |
| tree | 4f008a9546f9657c7fc4758f852778e02566437a /src/models | |
| parent | Clean up: Remove unused import (diff) | |
| download | sharkey-1f2ebce8ed749d7e81e999944fc8a22ff39b87b7.tar.gz sharkey-1f2ebce8ed749d7e81e999944fc8a22ff39b87b7.tar.bz2 sharkey-1f2ebce8ed749d7e81e999944fc8a22ff39b87b7.zip | |
Resolve #1302
Diffstat (limited to 'src/models')
| -rw-r--r-- | src/models/user.ts | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/models/user.ts b/src/models/user.ts index 64197c91c2..b595fa8d71 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -35,6 +35,28 @@ User.createIndex('uri', { sparse: true, unique: true }); export default User; +// 後方互換性のため +User.findOne({ + pinnedNoteId: { $exists: true } +}).then(async x => { + if (x == null) return; + + const users = await User.find({ + pinnedNoteId: { $exists: true } + }); + + users.forEach(u => { + User.update({ _id: u._id }, { + $set: { + pinnedNoteIds: [(u as any).pinnedNoteId] + }, + $unset: { + pinnedNoteId: '' + } + }); + }); +}); + type IUserBase = { _id: mongo.ObjectID; createdAt: Date; @@ -53,7 +75,7 @@ type IUserBase = { wallpaperUrl?: string; data: any; description: string; - pinnedNoteId: mongo.ObjectID; + pinnedNoteIds: mongo.ObjectID[]; /** * 凍結されているか否か @@ -464,11 +486,11 @@ export const pack = ( } if (opts.detail) { - if (_user.pinnedNoteId) { - // Populate pinned note - _user.pinnedNote = packNote(_user.pinnedNoteId, meId, { + if (_user.pinnedNoteIds) { + // Populate pinned notes + _user.pinnedNotes = Promise.all(_user.pinnedNoteIds.map((id: mongo.ObjectId) => packNote(id, meId, { detail: true - }); + }))); } if (meId && !meId.equals(_user.id)) { |