Refactor (#7394)
* wip * wip * wip * wip * wip * Update define.ts * Update update.ts * Update user.ts * wip * wip * Update request.ts * URL * wip * wip * wip * wip * Update invite.ts * Update create.ts
This commit is contained in:
parent
62cc14c93b
commit
ce340aba7a
109 changed files with 252 additions and 201 deletions
|
|
@ -17,7 +17,7 @@ import { isDuplicateKeyValueError } from '@/misc/is-duplicate-key-value-error';
|
|||
|
||||
const logger = new Logger('following/create');
|
||||
|
||||
export async function insertFollowingDoc(followee: User, follower: User) {
|
||||
export async function insertFollowingDoc(followee: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox'] }, follower: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox'] }) {
|
||||
if (follower.id === followee.id) return;
|
||||
|
||||
let alreadyFollowed = false;
|
||||
|
|
@ -86,7 +86,7 @@ export async function insertFollowingDoc(followee: User, follower: User) {
|
|||
|
||||
// Publish follow event
|
||||
if (Users.isLocalUser(follower)) {
|
||||
Users.pack(followee, follower, {
|
||||
Users.pack(followee.id, follower, {
|
||||
detail: true
|
||||
}).then(packed => {
|
||||
publishUserEvent(follower.id, 'follow', packed);
|
||||
|
|
@ -96,7 +96,7 @@ export async function insertFollowingDoc(followee: User, follower: User) {
|
|||
|
||||
// Publish followed event
|
||||
if (Users.isLocalUser(followee)) {
|
||||
Users.pack(follower, followee).then(packed => publishMainStream(followee.id, 'followed', packed));
|
||||
Users.pack(follower.id, followee).then(packed => publishMainStream(followee.id, 'followed', packed));
|
||||
|
||||
// 通知を作成
|
||||
createNotification(followee.id, 'follow', {
|
||||
|
|
@ -105,7 +105,12 @@ export async function insertFollowingDoc(followee: User, follower: User) {
|
|||
}
|
||||
}
|
||||
|
||||
export default async function(follower: User, followee: User, requestId?: string) {
|
||||
export default async function(_follower: { id: User['id'] }, _followee: { id: User['id'] }, requestId?: string) {
|
||||
const [follower, followee] = await Promise.all([
|
||||
Users.findOneOrFail(_follower.id),
|
||||
Users.findOneOrFail(_followee.id)
|
||||
]);
|
||||
|
||||
// check blocking
|
||||
const [blocking, blocked] = await Promise.all([
|
||||
Blockings.findOne({
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import { instanceChart, perUserFollowingChart } from '../chart';
|
|||
|
||||
const logger = new Logger('following/delete');
|
||||
|
||||
export default async function(follower: User, followee: User, silent = false) {
|
||||
export default async function(follower: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox']; }, followee: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox']; }, silent = false) {
|
||||
const following = await Followings.findOne({
|
||||
followerId: follower.id,
|
||||
followeeId: followee.id
|
||||
|
|
@ -28,7 +28,7 @@ export default async function(follower: User, followee: User, silent = false) {
|
|||
|
||||
// Publish unfollow event
|
||||
if (!silent && Users.isLocalUser(follower)) {
|
||||
Users.pack(followee, follower, {
|
||||
Users.pack(followee.id, follower, {
|
||||
detail: true
|
||||
}).then(packed => {
|
||||
publishUserEvent(follower.id, 'unfollow', packed);
|
||||
|
|
@ -42,7 +42,7 @@ export default async function(follower: User, followee: User, silent = false) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function decrementFollowing(follower: User, followee: User) {
|
||||
export async function decrementFollowing(follower: { id: User['id']; host: User['host']; }, followee: { id: User['id']; host: User['host']; }) {
|
||||
//#region Decrement following count
|
||||
Users.decrement({ id: follower.id }, 'followingCount', 1);
|
||||
//#endregion
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { FollowRequests, Users } from '../../../models';
|
|||
* 指定したユーザー宛てのフォローリクエストをすべて承認
|
||||
* @param user ユーザー
|
||||
*/
|
||||
export default async function(user: User) {
|
||||
export default async function(user: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox']; }) {
|
||||
const requests = await FollowRequests.find({
|
||||
followeeId: user.id
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import { User, ILocalUser } from '../../../models/entities/user';
|
|||
import { FollowRequests, Users } from '../../../models';
|
||||
import { IdentifiableError } from '@/misc/identifiable-error';
|
||||
|
||||
export default async function(followee: User, follower: User) {
|
||||
export default async function(followee: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox']; }, follower: User) {
|
||||
const request = await FollowRequests.findOne({
|
||||
followeeId: followee.id,
|
||||
followerId: follower.id
|
||||
|
|
@ -20,12 +20,12 @@ export default async function(followee: User, follower: User) {
|
|||
|
||||
await insertFollowingDoc(followee, follower);
|
||||
|
||||
if (Users.isRemoteUser(follower)) {
|
||||
const content = renderActivity(renderAccept(renderFollow(follower, followee, request.requestId!), followee as ILocalUser));
|
||||
deliver(followee as ILocalUser, content, follower.inbox);
|
||||
if (Users.isRemoteUser(follower) && Users.isLocalUser(followee)) {
|
||||
const content = renderActivity(renderAccept(renderFollow(follower, followee, request.requestId!), followee));
|
||||
deliver(followee, content, follower.inbox);
|
||||
}
|
||||
|
||||
Users.pack(followee, followee, {
|
||||
Users.pack(followee.id, followee, {
|
||||
detail: true
|
||||
}).then(packed => publishMainStream(followee.id, 'meUpdated', packed));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,13 @@ import { IdentifiableError } from '@/misc/identifiable-error';
|
|||
import { User, ILocalUser } from '../../../models/entities/user';
|
||||
import { Users, FollowRequests } from '../../../models';
|
||||
|
||||
export default async function(followee: User, follower: User) {
|
||||
export default async function(followee: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox'] }, follower: { id: User['id']; host: User['host']; uri: User['host'] }) {
|
||||
if (Users.isRemoteUser(followee)) {
|
||||
const content = renderActivity(renderUndo(renderFollow(follower, followee), follower));
|
||||
deliver(follower as ILocalUser, content, followee.inbox);
|
||||
|
||||
if (Users.isLocalUser(follower)) { // 本来このチェックは不要だけどTSに怒られるので
|
||||
deliver(follower, content, followee.inbox);
|
||||
}
|
||||
}
|
||||
|
||||
const request = await FollowRequests.findOne({
|
||||
|
|
@ -27,7 +30,7 @@ export default async function(followee: User, follower: User) {
|
|||
followerId: follower.id
|
||||
});
|
||||
|
||||
Users.pack(followee, followee, {
|
||||
Users.pack(followee.id, followee, {
|
||||
detail: true
|
||||
}).then(packed => publishMainStream(followee.id, 'meUpdated', packed));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { Blockings, FollowRequests, Users } from '../../../models';
|
|||
import { genId } from '@/misc/gen-id';
|
||||
import { createNotification } from '../../create-notification';
|
||||
|
||||
export default async function(follower: User, followee: User, requestId?: string) {
|
||||
export default async function(follower: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox']; }, followee: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox']; }, requestId?: string) {
|
||||
if (follower.id === followee.id) return;
|
||||
|
||||
// check blocking
|
||||
|
|
@ -43,9 +43,9 @@ export default async function(follower: User, followee: User, requestId?: string
|
|||
|
||||
// Publish receiveRequest event
|
||||
if (Users.isLocalUser(followee)) {
|
||||
Users.pack(follower, followee).then(packed => publishMainStream(followee.id, 'receiveFollowRequest', packed));
|
||||
Users.pack(follower.id, followee).then(packed => publishMainStream(followee.id, 'receiveFollowRequest', packed));
|
||||
|
||||
Users.pack(followee, followee, {
|
||||
Users.pack(followee.id, followee, {
|
||||
detail: true
|
||||
}).then(packed => publishMainStream(followee.id, 'meUpdated', packed));
|
||||
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@ import { User, ILocalUser } from '../../../models/entities/user';
|
|||
import { Users, FollowRequests, Followings } from '../../../models';
|
||||
import { decrementFollowing } from '../delete';
|
||||
|
||||
export default async function(followee: User, follower: User) {
|
||||
if (Users.isRemoteUser(follower)) {
|
||||
export default async function(followee: { id: User['id']; host: User['host']; uri: User['host'] }, follower: User) {
|
||||
if (Users.isRemoteUser(follower) && Users.isLocalUser(followee)) {
|
||||
const request = await FollowRequests.findOne({
|
||||
followeeId: followee.id,
|
||||
followerId: follower.id
|
||||
});
|
||||
|
||||
const content = renderActivity(renderReject(renderFollow(follower, followee, request!.requestId!), followee as ILocalUser));
|
||||
deliver(followee as ILocalUser, content, follower.inbox);
|
||||
const content = renderActivity(renderReject(renderFollow(follower, followee, request!.requestId!), followee));
|
||||
deliver(followee, content, follower.inbox);
|
||||
}
|
||||
|
||||
const request = await FollowRequests.findOne({
|
||||
|
|
@ -37,7 +37,7 @@ export default async function(followee: User, follower: User) {
|
|||
}
|
||||
}
|
||||
|
||||
Users.pack(followee, follower, {
|
||||
Users.pack(followee.id, follower, {
|
||||
detail: true
|
||||
}).then(packed => {
|
||||
publishUserEvent(follower.id, 'unfollow', packed);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue