Skip to content

Commit

Permalink
Revert "被ブロックをタイムラインで隠すように (#1979)"
Browse files Browse the repository at this point in the history
This reverts commit e299b7b.
  • Loading branch information
fs5m8 committed Nov 10, 2022
1 parent f2d6f2a commit 3de1369
Show file tree
Hide file tree
Showing 25 changed files with 5 additions and 106 deletions.
15 changes: 0 additions & 15 deletions src/misc/is-blocker-user-related.ts

This file was deleted.

27 changes: 2 additions & 25 deletions src/server/api/common/generate-block-query.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
import { User } from '../../../models/entities/user';
import { Blockings } from '../../../models';
import { Brackets, SelectQueryBuilder } from 'typeorm';
import { SelectQueryBuilder } from 'typeorm';

// ここでいうBlockedは被Blockedの意
export function generateBlockedUserQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }) {
const blockingQuery = Blockings.createQueryBuilder('blocking')
.select('blocking.blockerId')
.where('blocking.blockeeId = :blockeeId', { blockeeId: me.id });

// 投稿の作者にブロックされていない かつ
// 投稿の返信先の作者にブロックされていない かつ
// 投稿の引用元の作者にブロックされていない
q
.andWhere(`note.userId NOT IN (${ blockingQuery.getQuery() })`)
.andWhere(new Brackets(qb => { qb
.where(`note.replyUserId IS NULL`)
.orWhere(`note.replyUserId NOT IN (${ blockingQuery.getQuery() })`);
}))
.andWhere(new Brackets(qb => { qb
.where(`note.renoteUserId IS NULL`)
.orWhere(`note.renoteUserId NOT IN (${ blockingQuery.getQuery() })`);
}));

q.setParameters(blockingQuery.getParameters());
}

export function generateBlockQueryForUsers(q: SelectQueryBuilder<any>, me: { id: User['id'] }) {
export function generateBlockQueryForUsers(q: SelectQueryBuilder<any>, me: User) {
const blockingQuery = Blockings.createQueryBuilder('blocking')
.select('blocking.blockeeId')
.where('blocking.blockerId = :blockerId', { blockerId: me.id });
Expand Down
2 changes: 0 additions & 2 deletions src/server/api/endpoints/notes/children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { generateVisibilityQuery } from '../../common/generate-visibility-query'
import { generateMuteQuery } from '../../common/generate-mute-query';
import { Brackets } from 'typeorm';
import { Notes } from '../../../../models';
import { generateBlockedUserQuery } from '../../common/generate-block-query';

export const meta = {
desc: {
Expand Down Expand Up @@ -79,7 +78,6 @@ export default define(meta, async (ps, user) => {

generateVisibilityQuery(query, user);
if (user) generateMuteQuery(query, user);
if (user) generateBlockedUserQuery(query, user);

const notes = await query.take(ps.limit!).getMany();

Expand Down
2 changes: 0 additions & 2 deletions src/server/api/endpoints/notes/featured.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import $ from 'cafy';
import define from '../../define';
import { generateMuteQuery } from '../../common/generate-mute-query';
import { Notes } from '../../../../models';
import { generateBlockedUserQuery } from '../../common/generate-block-query';

export const meta = {
desc: {
Expand Down Expand Up @@ -56,7 +55,6 @@ export default define(meta, async (ps, user) => {
.leftJoinAndSelect('renoteUser.banner', 'renoteUserBanner');

if (user) generateMuteQuery(query, user);
if (user) generateBlockedUserQuery(query, user);

const notes = await query.orderBy('note.score', 'DESC').take(ps.limit!).getMany();

Expand Down
1 change: 0 additions & 1 deletion src/server/api/endpoints/notes/global-timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { makePaginationQuery } from '../../common/make-pagination-query';
import { Notes } from '../../../../models';
import { generateMuteQuery } from '../../common/generate-mute-query';
import { activeUsersChart } from '../../../../services/chart';
import { generateBlockedUserQuery } from '../../common/generate-block-query';

export const meta = {
desc: {
Expand Down
2 changes: 0 additions & 2 deletions src/server/api/endpoints/notes/hybrid-timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Brackets } from 'typeorm';
import { generateVisibilityQuery } from '../../common/generate-visibility-query';
import { generateMuteQuery } from '../../common/generate-mute-query';
import { activeUsersChart } from '../../../../services/chart';
import { generateBlockedUserQuery } from '../../common/generate-block-query';

export const meta = {
desc: {
Expand Down Expand Up @@ -140,7 +139,6 @@ export default define(meta, async (ps, user) => {

generateVisibilityQuery(query, user);
generateMuteQuery(query, user);
generateBlockedUserQuery(query, user);

if (ps.includeMyRenotes === false) {
query.andWhere(new Brackets(qb => {
Expand Down
1 change: 0 additions & 1 deletion src/server/api/endpoints/notes/local-timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { makePaginationQuery } from '../../common/make-pagination-query';
import { generateVisibilityQuery } from '../../common/generate-visibility-query';
import { activeUsersChart } from '../../../../services/chart';
import { Brackets } from 'typeorm';
import { generateBlockedUserQuery } from '../../common/generate-block-query';

export const meta = {
desc: {
Expand Down
2 changes: 0 additions & 2 deletions src/server/api/endpoints/notes/mentions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { generateVisibilityQuery } from '../../common/generate-visibility-query'
import { generateMuteQuery } from '../../common/generate-mute-query';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { Brackets } from 'typeorm';
import { generateBlockedUserQuery } from '../../common/generate-block-query';

export const meta = {
desc: {
Expand Down Expand Up @@ -78,7 +77,6 @@ export default define(meta, async (ps, user) => {

generateVisibilityQuery(query, user);
generateMuteQuery(query, user);
generateBlockedUserQuery(query, user);

if (ps.visibility) {
query.andWhere('note.visibility = :visibility', { visibility: ps.visibility });
Expand Down
2 changes: 0 additions & 2 deletions src/server/api/endpoints/notes/renotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { generateVisibilityQuery } from '../../common/generate-visibility-query'
import { generateMuteQuery } from '../../common/generate-mute-query';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { Notes } from '../../../../models';
import { generateBlockedUserQuery } from '../../common/generate-block-query';

export const meta = {
desc: {
Expand Down Expand Up @@ -83,7 +82,6 @@ export default define(meta, async (ps, user) => {

generateVisibilityQuery(query, user);
if (user) generateMuteQuery(query, user);
if (user) generateBlockedUserQuery(query, user);

const renotes = await query.take(ps.limit!).getMany();

Expand Down
2 changes: 0 additions & 2 deletions src/server/api/endpoints/notes/replies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Notes } from '../../../../models';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { generateVisibilityQuery } from '../../common/generate-visibility-query';
import { generateMuteQuery } from '../../common/generate-mute-query';
import { generateBlockedUserQuery } from '../../common/generate-block-query';

export const meta = {
desc: {
Expand Down Expand Up @@ -74,7 +73,6 @@ export default define(meta, async (ps, user) => {

generateVisibilityQuery(query, user);
if (user) generateMuteQuery(query, user);
if (user) generateBlockedUserQuery(query, user);

const timeline = await query.take(ps.limit!).getMany();

Expand Down
2 changes: 0 additions & 2 deletions src/server/api/endpoints/notes/search-by-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { generateVisibilityQuery } from '../../common/generate-visibility-query'
import { Brackets } from 'typeorm';
import { normalizeTag } from '../../../../misc/normalize-tag';
import { safeForSql } from '../../../../misc/safe-for-sql';
import { generateBlockedUserQuery } from '../../common/generate-block-query';

export const meta = {
desc: {
Expand Down Expand Up @@ -110,7 +109,6 @@ export default define(meta, async (ps, me) => {

generateVisibilityQuery(query, me);
if (me) generateMuteQuery(query, me);
if (me) generateBlockedUserQuery(query, me);

if (ps.tag) {
query.andWhere(`'{"${safeForSql(ps.tag) ? normalizeTag(ps.tag) : 'aichan_kawaii'}"}' <@ note.tags`);
Expand Down
2 changes: 0 additions & 2 deletions src/server/api/endpoints/notes/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { generateVisibilityQuery } from '../../common/generate-visibility-query'
import { generateMuteQuery } from '../../common/generate-mute-query';
import { activeUsersChart } from '../../../../services/chart';
import { Brackets } from 'typeorm';
import { generateBlockedUserQuery } from '../../common/generate-block-query';

export const meta = {
desc: {
Expand Down Expand Up @@ -126,7 +125,6 @@ export default define(meta, async (ps, user) => {

generateVisibilityQuery(query, user);
generateMuteQuery(query, user);
generateBlockedUserQuery(query, user);

if (ps.includeMyRenotes === false) {
query.andWhere(new Brackets(qb => {
Expand Down
1 change: 0 additions & 1 deletion src/server/api/endpoints/users/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ export default define(meta, async (ps, me) => {

generateVisibilityQuery(query, me);
if (me) generateMuteQuery(query, me, user);
// モデレーションの問題があるため被ブロックには対応しない

if (ps.withFiles) {
query.andWhere('note.fileIds != \'{}\'');
Expand Down
3 changes: 1 addition & 2 deletions src/server/api/endpoints/users/recommendation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import $ from 'cafy';
import define from '../../define';
import { Users, Followings } from '../../../../models';
import { generateMuteQueryForUsers } from '../../common/generate-mute-query';
import { generateBlockedUserQuery, generateBlockQueryForUsers } from '../../common/generate-block-query';
import { generateBlockQueryForUsers } from '../../common/generate-block-query';

export const meta = {
desc: {
Expand Down Expand Up @@ -49,7 +49,6 @@ export default define(meta, async (ps, me) => {

generateMuteQueryForUsers(query, me);
generateBlockQueryForUsers(query, me);
generateBlockedUserQuery(query, me);

const followingQuery = Followings.createQueryBuilder('following')
.select('following.followeeId')
Expand Down
4 changes: 0 additions & 4 deletions src/server/api/stream/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ export default abstract class Channel {
return this.connection.muting;
}

protected get blocking() {
return this.connection.blocking;
}

protected get subscriber() {
return this.connection.subscriber;
}
Expand Down
1 change: 0 additions & 1 deletion src/server/api/stream/channels/global-timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Channel from '../channel';
import { fetchMeta } from '../../../../misc/fetch-meta';
import { Notes } from '../../../../models';
import { PackedNote } from '../../../../models/repositories/note';
import { isBlockerUserRelated } from '../../../../misc/is-blocker-user-related';

export default class extends Channel {
public readonly chName = 'globalTimeline';
Expand Down
2 changes: 0 additions & 2 deletions src/server/api/stream/channels/hashtag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Channel from '../channel';
import { Notes } from '../../../../models';
import { PackedNote } from '../../../../models/repositories/note';
import { normalizeTag } from '../../../../misc/normalize-tag';
import { isBlockerUserRelated } from '../../../../misc/is-blocker-user-related';

export default class extends Channel {
public readonly chName = 'hashtag';
Expand Down Expand Up @@ -37,7 +36,6 @@ export default class extends Channel {

// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
if (shouldMuteThisNote(note, this.muting)) return;
if (isBlockerUserRelated(note, this.blocking)) return;

this.send('note', note);
}
Expand Down
2 changes: 0 additions & 2 deletions src/server/api/stream/channels/home-timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
import Channel from '../channel';
import { Notes } from '../../../../models';
import { PackedNote } from '../../../../models/repositories/note';
import { isBlockerUserRelated } from '../../../../misc/is-blocker-user-related';

export default class extends Channel {
public readonly chName = 'homeTimeline';
Expand Down Expand Up @@ -46,7 +45,6 @@ export default class extends Channel {

// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
if (shouldMuteThisNote(note, this.muting)) return;
if (isBlockerUserRelated(note, this.blocking)) return;

this.send('note', note);
}
Expand Down
2 changes: 0 additions & 2 deletions src/server/api/stream/channels/hybrid-timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { fetchMeta } from '../../../../misc/fetch-meta';
import { Notes } from '../../../../models';
import { PackedNote } from '../../../../models/repositories/note';
import { PackedUser } from '../../../../models/repositories/user';
import { isBlockerUserRelated } from '../../../../misc/is-blocker-user-related';

export default class extends Channel {
public readonly chName = 'hybridTimeline';
Expand Down Expand Up @@ -55,7 +54,6 @@ export default class extends Channel {

// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
if (shouldMuteThisNote(note, this.muting)) return;
if (isBlockerUserRelated(note, this.blocking)) return;

this.send('note', note);
}
Expand Down
1 change: 0 additions & 1 deletion src/server/api/stream/channels/local-timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { fetchMeta } from '../../../../misc/fetch-meta';
import { Notes } from '../../../../models';
import { PackedNote } from '../../../../models/repositories/note';
import { PackedUser } from '../../../../models/repositories/user';
import { isBlockerUserRelated } from '../../../../misc/is-blocker-user-related';

export default class extends Channel {
public readonly chName = 'localTimeline';
Expand Down
2 changes: 0 additions & 2 deletions src/server/api/stream/channels/user-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Notes, UserListJoinings, UserLists } from '../../../../models';
import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
import { User } from '../../../../models/entities/user';
import { PackedNote } from '../../../../models/repositories/note';
import { isBlockerUserRelated } from '../../../../misc/is-blocker-user-related';

export default class extends Channel {
public readonly chName = 'userList';
Expand Down Expand Up @@ -75,7 +74,6 @@ export default class extends Channel {

// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
if (shouldMuteThisNote(note, this.muting)) return;
if (isBlockerUserRelated(note, this.blocking)) return;

this.send('note', note);
}
Expand Down
20 changes: 1 addition & 19 deletions src/server/api/stream/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import channels from './channels';
import { EventEmitter } from 'events';
import { User } from '../../../models/entities/user';
import { App } from '../../../models/entities/app';
import { Users, Followings, Mutings, Blockings } from '../../../models';
import { Users, Followings, Mutings } from '../../../models';

/**
* Main stream connection
Expand All @@ -17,7 +17,6 @@ export default class Connection {
public user?: User;
public following: User['id'][] = [];
public muting: User['id'][] = [];
public blocking: User['id'][] = [];
public app: App;
private wsConnection: websocket.connection;
public subscriber: EventEmitter;
Expand All @@ -40,7 +39,6 @@ export default class Connection {
if (this.user) {
this.updateFollowing();
this.updateMuting();
this.updateBlocking();
this.subscriber.on(`serverEvent:${this.user.id}`, this.onServerEvent);
}
}
Expand Down Expand Up @@ -227,10 +225,6 @@ export default class Connection {
this.updateMuting();
}

if (data.type === 'blockingChanged') {
this.updateBlocking();
}

if (data.type === 'terminate') {
this.wsConnection.close();
this.dispose();
Expand Down Expand Up @@ -261,18 +255,6 @@ export default class Connection {
this.muting = 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 = blockings.map(x => x.blockerId);
}

/**
* ストリームが切れたとき
*/
Expand Down
5 changes: 1 addition & 4 deletions src/services/blocking/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { User } from '../../models/entities/user';
import { Blockings, Users, FollowRequests, Followings } from '../../models';
import { perUserFollowingChart } from '../chart';
import { genId } from '../../misc/gen-id';
import { publishBlockingChanged, publishFollowingChanged } from '../server-event';
import { publishFollowingChanged } from '../server-event';

export default async function(blocker: User, blockee: User) {
await Promise.all([
Expand All @@ -30,9 +30,6 @@ export default async function(blocker: User, blockee: User) {
const content = renderActivity(renderBlock(blocker, blockee));
deliver(blocker, content, blockee.inbox);
}

publishBlockingChanged(blocker.id);
if (Users.isLocalUser(blockee)) publishBlockingChanged(blockee.id);
}

async function cancelRequest(follower: User, followee: User) {
Expand Down
4 changes: 0 additions & 4 deletions src/services/blocking/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { deliver } from '../../queue';
import Logger from '../logger';
import { User } from '../../models/entities/user';
import { Blockings, Users } from '../../models';
import { publishBlockingChanged } from '../server-event';

const logger = new Logger('blocking/delete');

Expand All @@ -27,7 +26,4 @@ export default async function(blocker: User, blockee: User) {
const content = renderActivity(renderUndo(renderBlock(blocker, blockee), blocker));
deliver(blocker, content, blockee.inbox);
}

publishBlockingChanged(blocker.id);
if (Users.isLocalUser(blockee)) publishBlockingChanged(blockee.id);
}
Loading

0 comments on commit 3de1369

Please sign in to comment.