nanka iroiro

This commit is contained in:
syuilo 2018-04-15 17:53:25 +09:00
parent 0bbe8267b8
commit 10e3411020
5 changed files with 26 additions and 25 deletions

View file

@ -19,12 +19,12 @@ export function createHttp(data) {
} }
export function deliver(user, content, to) { export function deliver(user, content, to) {
return createHttp({ createHttp({
type: 'deliver', type: 'deliver',
user, user,
content, content,
to to
}); }).save();
} }
export default function() { export default function() {

View file

@ -58,11 +58,11 @@ export default async function(follower: IUser, followee: IUser, activity?) {
if (isLocalUser(follower) && isRemoteUser(followee)) { if (isLocalUser(follower) && isRemoteUser(followee)) {
const content = pack(renderFollow(follower, followee)); const content = pack(renderFollow(follower, followee));
deliver(follower, content, followee.inbox).save(); deliver(follower, content, followee.inbox);
} }
if (isRemoteUser(follower) && isLocalUser(followee)) { if (isRemoteUser(follower) && isLocalUser(followee)) {
const content = pack(renderAccept(activity)); const content = pack(renderAccept(activity));
deliver(followee, content, follower.inbox).save(); deliver(followee, content, follower.inbox);
} }
} }

View file

@ -57,6 +57,6 @@ export default async function(follower: IUser, followee: IUser, activity?) {
if (isLocalUser(follower) && isRemoteUser(followee)) { if (isLocalUser(follower) && isRemoteUser(followee)) {
const content = pack(renderUndo(renderFollow(follower, followee))); const content = pack(renderUndo(renderFollow(follower, followee)));
deliver(follower, content, followee.inbox).save(); deliver(follower, content, followee.inbox);
} }
} }

View file

@ -136,12 +136,12 @@ export default async (user: IUser, data: {
// 投稿がリプライかつ投稿者がローカルユーザーかつリプライ先の投稿の投稿者がリモートユーザーなら配送 // 投稿がリプライかつ投稿者がローカルユーザーかつリプライ先の投稿の投稿者がリモートユーザーなら配送
if (data.reply && isLocalUser(user) && isRemoteUser(data.reply._user)) { if (data.reply && isLocalUser(user) && isRemoteUser(data.reply._user)) {
deliver(user, await render(), data.reply._user.inbox).save(); deliver(user, await render(), data.reply._user.inbox);
} }
// 投稿がRenoteかつ投稿者がローカルユーザーかつRenote元の投稿の投稿者がリモートユーザーなら配送 // 投稿がRenoteかつ投稿者がローカルユーザーかつRenote元の投稿の投稿者がリモートユーザーなら配送
if (data.renote && isLocalUser(user) && isRemoteUser(data.renote._user)) { if (data.renote && isLocalUser(user) && isRemoteUser(data.renote._user)) {
deliver(user, await render(), data.renote._user.inbox).save(); deliver(user, await render(), data.renote._user.inbox);
} }
Promise.all(followers.map(async follower => { Promise.all(followers.map(async follower => {
@ -153,7 +153,7 @@ export default async (user: IUser, data: {
} else { } else {
// フォロワーがリモートユーザーかつ投稿者がローカルユーザーなら投稿を配信 // フォロワーがリモートユーザーかつ投稿者がローカルユーザーなら投稿を配信
if (isLocalUser(user)) { if (isLocalUser(user)) {
deliver(user, await render(), follower.inbox).save(); deliver(user, await render(), follower.inbox);
} }
} }
})); }));

View file

@ -9,6 +9,7 @@ import watch from '../watch';
import renderLike from '../../../remote/activitypub/renderer/like'; import renderLike from '../../../remote/activitypub/renderer/like';
import { deliver } from '../../../queue'; import { deliver } from '../../../queue';
import pack from '../../../remote/activitypub/renderer'; import pack from '../../../remote/activitypub/renderer';
import { MongoError } from 'mongodb';
export default async (user: IUser, note: INote, reaction: string) => new Promise(async (res, rej) => { export default async (user: IUser, note: INote, reaction: string) => new Promise(async (res, rej) => {
// Myself // Myself
@ -16,23 +17,23 @@ export default async (user: IUser, note: INote, reaction: string) => new Promise
return rej('cannot react to my note'); return rej('cannot react to my note');
} }
// if already reacted
const exist = await NoteReaction.findOne({
noteId: note._id,
userId: user._id
});
if (exist !== null) {
return rej('already reacted');
}
// Create reaction // Create reaction
await NoteReaction.insert({ try {
createdAt: new Date(), await NoteReaction.insert({
noteId: note._id, createdAt: new Date(),
userId: user._id, noteId: note._id,
reaction userId: user._id,
}); reaction
});
} catch (e) {
// duplicate key error
if (e instanceof MongoError && e.code === 11000) {
return rej('already reacted');
}
console.error(e);
return rej('something happened');
}
res(); res();
@ -86,7 +87,7 @@ export default async (user: IUser, note: INote, reaction: string) => new Promise
// リアクターがローカルユーザーかつリアクション対象がリモートユーザーの投稿なら配送 // リアクターがローカルユーザーかつリアクション対象がリモートユーザーの投稿なら配送
if (isLocalUser(user) && isRemoteUser(note._user)) { if (isLocalUser(user) && isRemoteUser(note._user)) {
const content = pack(renderLike(user, note)); const content = pack(renderLike(user, note));
deliver(user, content, note._user.inbox).save(); deliver(user, content, note._user.inbox);
} }
//#endregion //#endregion
}); });