summaryrefslogtreecommitdiff
path: root/src/remote/activitypub/renderer/question.ts
blob: cf0bf387c8b2a87aac66ea675a5a9f23e6d34929 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import config from '../../../config';
import { ILocalUser } from '../../../models/user';
import { INote } from '../../../models/note';

export default async function renderQuestion(user: ILocalUser, note: INote) {
	const question = {
		type: 'Question',
		id: `${config.url}/questions/${note._id}`,
		actor: `${config.url}/users/${user._id}`,
		content:  note.text || '',
		[note.poll.multiple ? 'anyOf' : 'oneOf']: note.poll.choices.map(c => ({
			name: c.text,
			_misskey_votes: c.votes,
			replies: {
				type: 'Collection',
				totalItems: c.votes
			}
		}))
	};

	return question;
}