1
0
forked from mirror/misskey

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) {
return createHttp({
createHttp({
type: 'deliver',
user,
content,
to
});
}).save();
}
export default function() {

View File

@ -58,11 +58,11 @@ export default async function(follower: IUser, followee: IUser, activity?) {
if (isLocalUser(follower) && isRemoteUser(followee)) {
const content = pack(renderFollow(follower, followee));
deliver(follower, content, followee.inbox).save();
deliver(follower, content, followee.inbox);
}
if (isRemoteUser(follower) && isLocalUser(followee)) {
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)) {
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)) {
deliver(user, await render(), data.reply._user.inbox).save();
deliver(user, await render(), data.reply._user.inbox);
}
// 投稿がRenoteかつ投稿者がローカルユーザーかつRenote元の投稿の投稿者がリモートユーザーなら配送
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 => {
@ -153,7 +153,7 @@ export default async (user: IUser, data: {
} else {
// フォロワーがリモートユーザーかつ投稿者がローカルユーザーなら投稿を配信
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 { deliver } from '../../../queue';
import pack from '../../../remote/activitypub/renderer';
import { MongoError } from 'mongodb';
export default async (user: IUser, note: INote, reaction: string) => new Promise(async (res, rej) => {
// Myself
@ -16,23 +17,23 @@ export default async (user: IUser, note: INote, reaction: string) => new Promise
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
try {
await NoteReaction.insert({
createdAt: new Date(),
noteId: note._id,
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();
@ -86,7 +87,7 @@ export default async (user: IUser, note: INote, reaction: string) => new Promise
// リアクターがローカルユーザーかつリアクション対象がリモートユーザーの投稿なら配送
if (isLocalUser(user) && isRemoteUser(note._user)) {
const content = pack(renderLike(user, note));
deliver(user, content, note._user.inbox).save();
deliver(user, content, note._user.inbox);
}
//#endregion
});