Resolve #1302
This commit is contained in:
		
							parent
							
								
									fcea9dacb7
								
							
						
					
					
						commit
						1f2ebce8ed
					
				
					 5 changed files with 46 additions and 12 deletions
				
			
		| 
						 | 
					@ -6,7 +6,7 @@
 | 
				
			||||||
		<main>
 | 
							<main>
 | 
				
			||||||
			<div class="main">
 | 
								<div class="main">
 | 
				
			||||||
				<x-header :user="user"/>
 | 
									<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"/>
 | 
									<x-timeline class="timeline" ref="tl" :user="user"/>
 | 
				
			||||||
			</div>
 | 
								</div>
 | 
				
			||||||
			<div class="side">
 | 
								<div class="side">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
<template>
 | 
					<template>
 | 
				
			||||||
<div class="root home">
 | 
					<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">
 | 
						<section class="recent-notes">
 | 
				
			||||||
		<h2>%fa:R comments%%i18n:@recent-notes%</h2>
 | 
							<h2>%fa:R comments%%i18n:@recent-notes%</h2>
 | 
				
			||||||
		<div>
 | 
							<div>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -101,15 +101,15 @@ props:
 | 
				
			||||||
      ja-JP: "投稿の数"
 | 
					      ja-JP: "投稿の数"
 | 
				
			||||||
      en-US: "The number of the notes of this user"
 | 
					      en-US: "The number of the notes of this user"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinnedNote:
 | 
					  pinnedNotes:
 | 
				
			||||||
    type: "entity(Note)"
 | 
					    type: "entity(Note)[]"
 | 
				
			||||||
    optional: true
 | 
					    optional: true
 | 
				
			||||||
    desc:
 | 
					    desc:
 | 
				
			||||||
      ja-JP: "ピン留めされた投稿"
 | 
					      ja-JP: "ピン留めされた投稿"
 | 
				
			||||||
      en-US: "The pinned note of this user"
 | 
					      en-US: "The pinned note of this user"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinnedNoteId:
 | 
					  pinnedNoteIds:
 | 
				
			||||||
    type: "id(Note)"
 | 
					    type: "id(Note)[]"
 | 
				
			||||||
    optional: true
 | 
					    optional: true
 | 
				
			||||||
    desc:
 | 
					    desc:
 | 
				
			||||||
      ja-JP: "ピン留めされた投稿のID"
 | 
					      ja-JP: "ピン留めされた投稿のID"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,6 +35,28 @@ User.createIndex('uri', { sparse: true, unique: true });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default User;
 | 
					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 = {
 | 
					type IUserBase = {
 | 
				
			||||||
	_id: mongo.ObjectID;
 | 
						_id: mongo.ObjectID;
 | 
				
			||||||
	createdAt: Date;
 | 
						createdAt: Date;
 | 
				
			||||||
| 
						 | 
					@ -53,7 +75,7 @@ type IUserBase = {
 | 
				
			||||||
	wallpaperUrl?: string;
 | 
						wallpaperUrl?: string;
 | 
				
			||||||
	data: any;
 | 
						data: any;
 | 
				
			||||||
	description: string;
 | 
						description: string;
 | 
				
			||||||
	pinnedNoteId: mongo.ObjectID;
 | 
						pinnedNoteIds: mongo.ObjectID[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * 凍結されているか否か
 | 
						 * 凍結されているか否か
 | 
				
			||||||
| 
						 | 
					@ -464,11 +486,11 @@ export const pack = (
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (opts.detail) {
 | 
						if (opts.detail) {
 | 
				
			||||||
		if (_user.pinnedNoteId) {
 | 
							if (_user.pinnedNoteIds) {
 | 
				
			||||||
			// Populate pinned note
 | 
								// Populate pinned notes
 | 
				
			||||||
			_user.pinnedNote = packNote(_user.pinnedNoteId, meId, {
 | 
								_user.pinnedNotes = Promise.all(_user.pinnedNoteIds.map((id: mongo.ObjectId) => packNote(id, meId, {
 | 
				
			||||||
				detail: true
 | 
									detail: true
 | 
				
			||||||
			});
 | 
								})));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (meId && !meId.equals(_user.id)) {
 | 
							if (meId && !meId.equals(_user.id)) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,9 +21,21 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
 | 
				
			||||||
		return rej('note not found');
 | 
							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, {
 | 
						await User.update(user._id, {
 | 
				
			||||||
		$set: {
 | 
							$set: {
 | 
				
			||||||
			pinnedNoteId: note._id
 | 
								pinnedNoteIds: pinnedNoteIds
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue