Fix #1712
This commit is contained in:
		
							parent
							
								
									4d914f5c0a
								
							
						
					
					
						commit
						1472f0b141
					
				
					 5 changed files with 36 additions and 4 deletions
				
			
		| 
						 | 
					@ -48,6 +48,11 @@ export type INote = {
 | 
				
			||||||
	repliesCount: number;
 | 
						repliesCount: number;
 | 
				
			||||||
	reactionCounts: any;
 | 
						reactionCounts: any;
 | 
				
			||||||
	mentions: mongo.ObjectID[];
 | 
						mentions: mongo.ObjectID[];
 | 
				
			||||||
 | 
						mentionedRemoteUsers: Array<{
 | 
				
			||||||
 | 
							uri: string;
 | 
				
			||||||
 | 
							username: string;
 | 
				
			||||||
 | 
							host: string;
 | 
				
			||||||
 | 
						}>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * public ... 公開
 | 
						 * public ... 公開
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
import config from '../../../config';
 | 
					import config from '../../../config';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default tag => ({
 | 
					export default (tag: string) => ({
 | 
				
			||||||
	type: 'Hashtag',
 | 
						type: 'Hashtag',
 | 
				
			||||||
	href: `${config.url}/tags/${encodeURIComponent(tag)}`,
 | 
						href: `${config.url}/tags/${encodeURIComponent(tag)}`,
 | 
				
			||||||
	name: '#' + tag
 | 
						name: '#' + tag
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										9
									
								
								src/remote/activitypub/renderer/mention.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/remote/activitypub/renderer/mention.ts
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,9 @@
 | 
				
			||||||
 | 
					export default (mention: {
 | 
				
			||||||
 | 
						uri: string;
 | 
				
			||||||
 | 
						username: string;
 | 
				
			||||||
 | 
						host: string;
 | 
				
			||||||
 | 
					}) => ({
 | 
				
			||||||
 | 
						type: 'Mention',
 | 
				
			||||||
 | 
						href: mention.uri,
 | 
				
			||||||
 | 
						name: `@${mention.username}@${mention.host}`
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,6 @@
 | 
				
			||||||
import renderDocument from './document';
 | 
					import renderDocument from './document';
 | 
				
			||||||
import renderHashtag from './hashtag';
 | 
					import renderHashtag from './hashtag';
 | 
				
			||||||
 | 
					import renderMention from './mention';
 | 
				
			||||||
import config from '../../../config';
 | 
					import config from '../../../config';
 | 
				
			||||||
import DriveFile from '../../../models/drive-file';
 | 
					import DriveFile from '../../../models/drive-file';
 | 
				
			||||||
import Note, { INote } from '../../../models/note';
 | 
					import Note, { INote } from '../../../models/note';
 | 
				
			||||||
| 
						 | 
					@ -45,6 +46,18 @@ export default async function renderNote(note: INote, dive = true) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const attributedTo = `${config.url}/users/${user._id}`;
 | 
						const attributedTo = `${config.url}/users/${user._id}`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const mentions = note.mentionedRemoteUsers && note.mentionedRemoteUsers.length > 0
 | 
				
			||||||
 | 
							? note.mentionedRemoteUsers.map(x => x.uri)
 | 
				
			||||||
 | 
							: [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const cc = ['public', 'home', 'followers'].includes(note.visibility)
 | 
				
			||||||
 | 
							? [`${attributedTo}/followers`].concat(mentions)
 | 
				
			||||||
 | 
							: [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const hashtagTags = (note.tags || []).map(renderHashtag);
 | 
				
			||||||
 | 
						const mentionTags = (note.mentionedRemoteUsers || []).map(renderMention);
 | 
				
			||||||
 | 
						const tag = hashtagTags.concat(mentionTags)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return {
 | 
						return {
 | 
				
			||||||
		id: `${config.url}/notes/${note._id}`,
 | 
							id: `${config.url}/notes/${note._id}`,
 | 
				
			||||||
		type: 'Note',
 | 
							type: 'Note',
 | 
				
			||||||
| 
						 | 
					@ -52,9 +65,9 @@ export default async function renderNote(note: INote, dive = true) {
 | 
				
			||||||
		content: toHtml(note),
 | 
							content: toHtml(note),
 | 
				
			||||||
		published: note.createdAt.toISOString(),
 | 
							published: note.createdAt.toISOString(),
 | 
				
			||||||
		to: 'https://www.w3.org/ns/activitystreams#Public',
 | 
							to: 'https://www.w3.org/ns/activitystreams#Public',
 | 
				
			||||||
		cc: `${attributedTo}/followers`,
 | 
							cc,
 | 
				
			||||||
		inReplyTo,
 | 
							inReplyTo,
 | 
				
			||||||
		attachment: (await promisedFiles).map(renderDocument),
 | 
							attachment: (await promisedFiles).map(renderDocument),
 | 
				
			||||||
		tag: (note.tags || []).map(renderHashtag)
 | 
							tag
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -329,7 +329,12 @@ export default async (user: IUser, data: {
 | 
				
			||||||
		if (mentionedUsers.length > 0) {
 | 
							if (mentionedUsers.length > 0) {
 | 
				
			||||||
			Note.update({ _id: note._id }, {
 | 
								Note.update({ _id: note._id }, {
 | 
				
			||||||
				$set: {
 | 
									$set: {
 | 
				
			||||||
					mentions: mentionedUsers.map(u => u._id)
 | 
										mentions: mentionedUsers.map(u => u._id),
 | 
				
			||||||
 | 
										mentionedRemoteUsers: mentionedUsers.filter(u => isRemoteUser(u)).map(u => ({
 | 
				
			||||||
 | 
											uri: (u as IRemoteUser).uri,
 | 
				
			||||||
 | 
											username: u.username,
 | 
				
			||||||
 | 
											host: u.host
 | 
				
			||||||
 | 
										}))
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue