Fix #2321
This commit is contained in:
		
							parent
							
								
									d9a1cd082c
								
							
						
					
					
						commit
						6ac92ac4b8
					
				
					 2 changed files with 75 additions and 61 deletions
				
			
		| 
						 | 
					@ -162,6 +162,66 @@ export async function deleteNote(note: string | mongo.ObjectID | INote) {
 | 
				
			||||||
	console.log(`Note: deleted ${n._id}`);
 | 
						console.log(`Note: deleted ${n._id}`);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const hideNote = async (packedNote: any, meId: mongo.ObjectID) => {
 | 
				
			||||||
 | 
						let hide = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// visibility が private かつ投稿者のIDが自分のIDではなかったら非表示
 | 
				
			||||||
 | 
						if (packedNote.visibility == 'private' && (meId == null || !meId.equals(packedNote.userId))) {
 | 
				
			||||||
 | 
							hide = true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// visibility が specified かつ自分が指定されていなかったら非表示
 | 
				
			||||||
 | 
						if (packedNote.visibility == 'specified') {
 | 
				
			||||||
 | 
							if (meId == null) {
 | 
				
			||||||
 | 
								hide = true;
 | 
				
			||||||
 | 
							} else if (meId.equals(packedNote.userId)) {
 | 
				
			||||||
 | 
								hide = false;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								// 指定されているかどうか
 | 
				
			||||||
 | 
								const specified = packedNote.visibleUserIds.some((id: mongo.ObjectID) => id.equals(meId));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (specified) {
 | 
				
			||||||
 | 
									hide = false;
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									hide = true;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// visibility が followers かつ自分が投稿者のフォロワーでなかったら非表示
 | 
				
			||||||
 | 
						if (packedNote.visibility == 'followers') {
 | 
				
			||||||
 | 
							if (meId == null) {
 | 
				
			||||||
 | 
								hide = true;
 | 
				
			||||||
 | 
							} else if (meId.equals(packedNote.userId)) {
 | 
				
			||||||
 | 
								hide = false;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								// フォロワーかどうか
 | 
				
			||||||
 | 
								const following = await Following.findOne({
 | 
				
			||||||
 | 
									followeeId: packedNote.userId,
 | 
				
			||||||
 | 
									followerId: meId
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (following == null) {
 | 
				
			||||||
 | 
									hide = true;
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									hide = false;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (hide) {
 | 
				
			||||||
 | 
							packedNote.fileIds = [];
 | 
				
			||||||
 | 
							packedNote.files = [];
 | 
				
			||||||
 | 
							packedNote.text = null;
 | 
				
			||||||
 | 
							packedNote.poll = null;
 | 
				
			||||||
 | 
							packedNote.cw = null;
 | 
				
			||||||
 | 
							packedNote.tags = [];
 | 
				
			||||||
 | 
							packedNote.tagsLower = [];
 | 
				
			||||||
 | 
							packedNote.geo = null;
 | 
				
			||||||
 | 
							packedNote.isHidden = true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Pack a note for API response
 | 
					 * Pack a note for API response
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					@ -174,11 +234,13 @@ export const pack = async (
 | 
				
			||||||
	note: string | mongo.ObjectID | INote,
 | 
						note: string | mongo.ObjectID | INote,
 | 
				
			||||||
	me?: string | mongo.ObjectID | IUser,
 | 
						me?: string | mongo.ObjectID | IUser,
 | 
				
			||||||
	options?: {
 | 
						options?: {
 | 
				
			||||||
		detail: boolean
 | 
							detail?: boolean;
 | 
				
			||||||
 | 
							skipHide?: boolean;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
) => {
 | 
					) => {
 | 
				
			||||||
	const opts = Object.assign({
 | 
						const opts = Object.assign({
 | 
				
			||||||
		detail: true
 | 
							detail: true,
 | 
				
			||||||
 | 
							skipHide: false
 | 
				
			||||||
	}, options);
 | 
						}, options);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Me
 | 
						// Me
 | 
				
			||||||
| 
						 | 
					@ -207,52 +269,6 @@ export const pack = async (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!_note) throw `invalid note arg ${note}`;
 | 
						if (!_note) throw `invalid note arg ${note}`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	let hide = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// visibility が private かつ投稿者のIDが自分のIDではなかったら非表示
 | 
					 | 
				
			||||||
	if (_note.visibility == 'private' && (meId == null || !meId.equals(_note.userId))) {
 | 
					 | 
				
			||||||
		hide = true;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// visibility が specified かつ自分が指定されていなかったら非表示
 | 
					 | 
				
			||||||
	if (_note.visibility == 'specified') {
 | 
					 | 
				
			||||||
		if (meId == null) {
 | 
					 | 
				
			||||||
			hide = true;
 | 
					 | 
				
			||||||
		} else if (meId.equals(_note.userId)) {
 | 
					 | 
				
			||||||
			hide = false;
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			// 指定されているかどうか
 | 
					 | 
				
			||||||
			const specified = _note.visibleUserIds.some((id: mongo.ObjectID) => id.equals(meId));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (specified) {
 | 
					 | 
				
			||||||
				hide = false;
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				hide = true;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// visibility が followers かつ自分が投稿者のフォロワーでなかったら非表示
 | 
					 | 
				
			||||||
	if (_note.visibility == 'followers') {
 | 
					 | 
				
			||||||
		if (meId == null) {
 | 
					 | 
				
			||||||
			hide = true;
 | 
					 | 
				
			||||||
		} else if (meId.equals(_note.userId)) {
 | 
					 | 
				
			||||||
			hide = false;
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			// フォロワーかどうか
 | 
					 | 
				
			||||||
			const following = await Following.findOne({
 | 
					 | 
				
			||||||
				followeeId: _note.userId,
 | 
					 | 
				
			||||||
				followerId: meId
 | 
					 | 
				
			||||||
			});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (following == null) {
 | 
					 | 
				
			||||||
				hide = true;
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				hide = false;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	const id = _note._id;
 | 
						const id = _note._id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Rename _id to id
 | 
						// Rename _id to id
 | 
				
			||||||
| 
						 | 
					@ -274,7 +290,7 @@ export const pack = async (
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Populate files
 | 
						// Populate files
 | 
				
			||||||
	_note.files = hide ? [] : Promise.all(_note.fileIds.map((fileId: mongo.ObjectID) =>
 | 
						_note.files = Promise.all(_note.fileIds.map((fileId: mongo.ObjectID) =>
 | 
				
			||||||
		packFile(fileId)
 | 
							packFile(fileId)
 | 
				
			||||||
	));
 | 
						));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -304,7 +320,7 @@ export const pack = async (
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Poll
 | 
							// Poll
 | 
				
			||||||
		if (meId && _note.poll && !hide) {
 | 
							if (meId && _note.poll) {
 | 
				
			||||||
			_note.poll = (async poll => {
 | 
								_note.poll = (async poll => {
 | 
				
			||||||
				const vote = await PollVote
 | 
									const vote = await PollVote
 | 
				
			||||||
					.findOne({
 | 
										.findOne({
 | 
				
			||||||
| 
						 | 
					@ -349,15 +365,8 @@ export const pack = async (
 | 
				
			||||||
		_note.text = _note.text.replace(/な/g, 'にゃ').replace(/ナ/g, 'ニャ').replace(/ナ/g, 'ニャ');
 | 
							_note.text = _note.text.replace(/な/g, 'にゃ').replace(/ナ/g, 'ニャ').replace(/ナ/g, 'ニャ');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (hide) {
 | 
						if (!opts.skipHide) {
 | 
				
			||||||
		_note.fileIds = [];
 | 
							await hideNote(_note, meId);
 | 
				
			||||||
		_note.text = null;
 | 
					 | 
				
			||||||
		_note.poll = null;
 | 
					 | 
				
			||||||
		_note.cw = null;
 | 
					 | 
				
			||||||
		_note.tags = [];
 | 
					 | 
				
			||||||
		_note.tagsLower = [];
 | 
					 | 
				
			||||||
		_note.geo = null;
 | 
					 | 
				
			||||||
		_note.isHidden = true;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return _note;
 | 
						return _note;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -447,6 +447,11 @@ async function publishToUserLists(note: INote, noteObj: any) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function publishToFollowers(note: INote, noteObj: any, user: IUser, noteActivity: any) {
 | 
					async function publishToFollowers(note: INote, noteObj: any, user: IUser, noteActivity: any) {
 | 
				
			||||||
 | 
						const detailPackedNote = await pack(note, null, {
 | 
				
			||||||
 | 
							detail: true,
 | 
				
			||||||
 | 
							skipHide: true
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const followers = await Following.find({
 | 
						const followers = await Following.find({
 | 
				
			||||||
		followeeId: note.userId
 | 
							followeeId: note.userId
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
| 
						 | 
					@ -465,10 +470,10 @@ async function publishToFollowers(note: INote, noteObj: any, user: IUser, noteAc
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// Publish event to followers stream
 | 
								// Publish event to followers stream
 | 
				
			||||||
			publishUserStream(following.followerId, 'note', noteObj);
 | 
								publishUserStream(following.followerId, 'note', detailPackedNote);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (isRemoteUser(user) || note.visibility != 'public') {
 | 
								if (isRemoteUser(user) || note.visibility != 'public') {
 | 
				
			||||||
				publishHybridTimelineStream(following.followerId, noteObj);
 | 
									publishHybridTimelineStream(following.followerId, detailPackedNote);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			// フォロワーがリモートユーザーかつ投稿者がローカルユーザーなら投稿を配信
 | 
								// フォロワーがリモートユーザーかつ投稿者がローカルユーザーなら投稿を配信
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue