summaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/activitypub.ts31
-rw-r--r--src/server/api/endpoints/notes/polls/vote.ts17
2 files changed, 48 insertions, 0 deletions
diff --git a/src/server/activitypub.ts b/src/server/activitypub.ts
index 9adc3dd943..ac8d3d4e26 100644
--- a/src/server/activitypub.ts
+++ b/src/server/activitypub.ts
@@ -16,6 +16,7 @@ import Outbox, { packActivity } from './activitypub/outbox';
import Followers from './activitypub/followers';
import Following from './activitypub/following';
import Featured from './activitypub/featured';
+import renderQuestion from '../remote/activitypub/renderer/question';
// Init router
const router = new Router();
@@ -110,6 +111,36 @@ router.get('/notes/:note/activity', async ctx => {
setResponseType(ctx);
});
+// question
+router.get('/questions/:question', async (ctx, next) => {
+ if (!ObjectID.isValid(ctx.params.question)) {
+ ctx.status = 404;
+ return;
+ }
+
+ const poll = await Note.findOne({
+ _id: new ObjectID(ctx.params.question),
+ visibility: { $in: ['public', 'home'] },
+ localOnly: { $ne: true },
+ poll: {
+ $exists: true,
+ $ne: null
+ },
+ });
+
+ if (poll === null) {
+ ctx.status = 404;
+ return;
+ }
+
+ const user = await User.findOne({
+ _id: poll.userId
+ });
+
+ ctx.body = pack(await renderQuestion(user as ILocalUser, poll));
+ setResponseType(ctx);
+});
+
// outbox
router.get('/users/:user/outbox', Outbox);
diff --git a/src/server/api/endpoints/notes/polls/vote.ts b/src/server/api/endpoints/notes/polls/vote.ts
index 8de0eb420e..f99fb099c7 100644
--- a/src/server/api/endpoints/notes/polls/vote.ts
+++ b/src/server/api/endpoints/notes/polls/vote.ts
@@ -6,6 +6,8 @@ import watch from '../../../../../services/note/watch';
import { publishNoteStream } from '../../../../../stream';
import notify from '../../../../../notify';
import define from '../../../define';
+import createNote from '../../../../../services/note/create';
+import User from '../../../../../models/user';
export const meta = {
desc: {
@@ -114,4 +116,19 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
if (user.settings.autoWatch !== false) {
watch(user._id, note);
}
+
+ // リモート投票の場合リプライ送信
+ if (note._user.host != null) {
+ const pollOwner = await User.findOne({
+ _id: note.userId
+ });
+
+ createNote(user, {
+ createdAt: new Date(),
+ text: ps.choice.toString(),
+ reply: note,
+ visibility: 'specified',
+ visibleUsers: [ pollOwner ],
+ });
+ }
}));