enhance(server): Improve user block (#7640)

* enhance(server): Improve user block

* Update CHANGELOG.md

* ユーザーリスト対応

* 相手から見れなくなるように

* Update 1629004542760-chart-reindex.ts

2365761ba5 (commitcomment-54919821)

* update test

* add test

* add todos

* Update 1629004542760-chart-reindex.ts
This commit is contained in:
syuilo 2021-08-17 21:48:59 +09:00 committed by GitHub
parent 7ebdd4739a
commit 7015df37e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 394 additions and 30 deletions

View file

@ -8,7 +8,7 @@ import channels from './channels';
import { EventEmitter } from 'events';
import { User } from '../../../models/entities/user';
import { Channel as ChannelModel } from '../../../models/entities/channel';
import { Users, Followings, Mutings, UserProfiles, ChannelFollowings } from '../../../models';
import { Users, Followings, Mutings, UserProfiles, ChannelFollowings, Blockings } from '../../../models';
import { ApiError } from '../error';
import { AccessToken } from '../../../models/entities/access-token';
import { UserProfile } from '../../../models/entities/user-profile';
@ -24,6 +24,7 @@ export default class Connection {
public userProfile?: UserProfile;
public following: Set<User['id']> = new Set();
public muting: Set<User['id']> = new Set();
public blocking: Set<User['id']> = new Set(); // "被"blocking
public followingChannels: Set<ChannelModel['id']> = new Set();
public token?: AccessToken;
private wsConnection: websocket.connection;
@ -52,6 +53,7 @@ export default class Connection {
if (this.user) {
this.updateFollowing();
this.updateMuting();
this.updateBlocking();
this.updateFollowingChannels();
this.updateUserProfile();
@ -80,6 +82,8 @@ export default class Connection {
this.muting.delete(body.id);
break;
// TODO: block events
case 'followChannel':
this.followingChannels.add(body.id);
break;
@ -375,6 +379,18 @@ export default class Connection {
this.muting = new Set<string>(mutings.map(x => x.muteeId));
}
@autobind
private async updateBlocking() { // ここでいうBlockingは被Blockingの意
const blockings = await Blockings.find({
where: {
blockeeId: this.user!.id
},
select: ['blockerId']
});
this.blocking = new Set<string>(blockings.map(x => x.blockerId));
}
@autobind
private async updateFollowingChannels() {
const followings = await ChannelFollowings.find({