This commit is contained in:
syuilo 2018-09-18 06:29:47 +09:00
parent fcea9dacb7
commit 1f2ebce8ed
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
5 changed files with 46 additions and 12 deletions

View file

@ -6,7 +6,7 @@
<main>
<div class="main">
<x-header :user="user"/>
<mk-note-detail v-if="user.pinnedNote" :note="user.pinnedNote" :compact="true"/>
<mk-note-detail v-for="n in user.pinnedNotes" :key="n.id" :note="n" :compact="true"/>
<x-timeline class="timeline" ref="tl" :user="user"/>
</div>
<div class="side">

View file

@ -1,6 +1,6 @@
<template>
<div class="root home">
<mk-note-detail v-if="user.pinnedNote" :note="user.pinnedNote" :compact="true"/>
<mk-note-detail v-for="n in user.pinnedNotes" :key="n.id" :note="n" :compact="true"/>
<section class="recent-notes">
<h2>%fa:R comments%%i18n:@recent-notes%</h2>
<div>

View file

@ -101,15 +101,15 @@ props:
ja-JP: "投稿の数"
en-US: "The number of the notes of this user"
pinnedNote:
type: "entity(Note)"
pinnedNotes:
type: "entity(Note)[]"
optional: true
desc:
ja-JP: "ピン留めされた投稿"
en-US: "The pinned note of this user"
pinnedNoteId:
type: "id(Note)"
pinnedNoteIds:
type: "id(Note)[]"
optional: true
desc:
ja-JP: "ピン留めされた投稿のID"

View file

@ -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)) {

View file

@ -21,9 +21,21 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
return rej('note not found');
}
const pinnedNoteIds = user.pinnedNoteIds || [];
if (pinnedNoteIds.some(id => id.equals(note._id))) {
return rej('already exists');
}
pinnedNoteIds.unshift(note._id);
if (pinnedNoteIds.length > 5) {
pinnedNoteIds.pop();
}
await User.update(user._id, {
$set: {
pinnedNoteId: note._id
pinnedNoteIds: pinnedNoteIds
}
});