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:
parent
7ebdd4739a
commit
7015df37e3
42 changed files with 394 additions and 30 deletions
|
|
@ -6,7 +6,7 @@ import renderBlock from '../../remote/activitypub/renderer/block';
|
|||
import { deliver } from '../../queue';
|
||||
import renderReject from '../../remote/activitypub/renderer/reject';
|
||||
import { User } from '../../models/entities/user';
|
||||
import { Blockings, Users, FollowRequests, Followings } from '../../models';
|
||||
import { Blockings, Users, FollowRequests, Followings, UserListJoinings, UserLists } from '../../models';
|
||||
import { perUserFollowingChart } from '../chart';
|
||||
import { genId } from '@/misc/gen-id';
|
||||
|
||||
|
|
@ -15,7 +15,8 @@ export default async function(blocker: User, blockee: User) {
|
|||
cancelRequest(blocker, blockee),
|
||||
cancelRequest(blockee, blocker),
|
||||
unFollow(blocker, blockee),
|
||||
unFollow(blockee, blocker)
|
||||
unFollow(blockee, blocker),
|
||||
removeFromList(blockee, blocker),
|
||||
]);
|
||||
|
||||
await Blockings.insert({
|
||||
|
|
@ -112,3 +113,16 @@ async function unFollow(follower: User, followee: User) {
|
|||
deliver(follower, content, followee.inbox);
|
||||
}
|
||||
}
|
||||
|
||||
async function removeFromList(listOwner: User, user: User) {
|
||||
const userLists = await UserLists.find({
|
||||
userId: listOwner.id,
|
||||
});
|
||||
|
||||
for (const userList of userLists) {
|
||||
await UserListJoinings.delete({
|
||||
userListId: userList.id,
|
||||
userId: user.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import { extractMentions } from '@/misc/extract-mentions';
|
|||
import { extractCustomEmojisFromMfm } from '@/misc/extract-custom-emojis-from-mfm';
|
||||
import { extractHashtags } from '@/misc/extract-hashtags';
|
||||
import { Note, IMentionedRemoteUsers } from '../../models/entities/note';
|
||||
import { Mutings, Users, NoteWatchings, Notes, Instances, UserProfiles, Antennas, Followings, MutedNotes, Channels, ChannelFollowings } from '../../models';
|
||||
import { Mutings, Users, NoteWatchings, Notes, Instances, UserProfiles, Antennas, Followings, MutedNotes, Channels, ChannelFollowings, Blockings } from '../../models';
|
||||
import { DriveFile } from '../../models/entities/drive-file';
|
||||
import { App } from '../../models/entities/app';
|
||||
import { Not, getConnection, In } from 'typeorm';
|
||||
|
|
@ -265,8 +265,10 @@ export default async (user: { id: User['id']; username: User['username']; host:
|
|||
.andWhere(`following.followeeId = :userId`, { userId: note.userId })
|
||||
.getMany()
|
||||
.then(async followings => {
|
||||
const blockings = await Blockings.find({ blockerId: user.id }); // TODO: キャッシュしたい
|
||||
const followers = followings.map(f => f.followerId);
|
||||
for (const antenna of (await getAntennas())) {
|
||||
if (blockings.some(blocking => blocking.blockeeId === antenna.userId)) continue; // この処理は checkHitAntenna 内でやるようにしてもいいかも
|
||||
checkHitAntenna(antenna, note, user, followers).then(hit => {
|
||||
if (hit) {
|
||||
addNoteToAntenna(antenna, note, user);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { publishNoteStream } from '../../stream';
|
||||
import { User } from '../../../models/entities/user';
|
||||
import { Note } from '../../../models/entities/note';
|
||||
import { PollVotes, NoteWatchings, Polls } from '../../../models';
|
||||
import { PollVotes, NoteWatchings, Polls, Blockings } from '../../../models';
|
||||
import { Not } from 'typeorm';
|
||||
import { genId } from '@/misc/gen-id';
|
||||
import { createNotification } from '../../create-notification';
|
||||
|
|
@ -14,6 +14,17 @@ export default async function(user: User, note: Note, choice: number) {
|
|||
// Check whether is valid choice
|
||||
if (poll.choices[choice] == null) throw new Error('invalid choice param');
|
||||
|
||||
// Check blocking
|
||||
if (note.userId !== user.id) {
|
||||
const block = await Blockings.findOne({
|
||||
blockerId: note.userId,
|
||||
blockeeId: user.id,
|
||||
});
|
||||
if (block) {
|
||||
throw new Error('blocked');
|
||||
}
|
||||
}
|
||||
|
||||
// if already voted
|
||||
const exist = await PollVotes.find({
|
||||
noteId: note.id,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { renderActivity } from '../../../remote/activitypub/renderer';
|
|||
import { toDbReaction, decodeReaction } from '@/misc/reaction-lib';
|
||||
import { User, IRemoteUser } from '../../../models/entities/user';
|
||||
import { Note } from '../../../models/entities/note';
|
||||
import { NoteReactions, Users, NoteWatchings, Notes, Emojis } from '../../../models';
|
||||
import { NoteReactions, Users, NoteWatchings, Notes, Emojis, Blockings } from '../../../models';
|
||||
import { Not } from 'typeorm';
|
||||
import { perUserReactionsChart } from '../../chart';
|
||||
import { genId } from '@/misc/gen-id';
|
||||
|
|
@ -16,6 +16,17 @@ import { NoteReaction } from '../../../models/entities/note-reaction';
|
|||
import { IdentifiableError } from '@/misc/identifiable-error';
|
||||
|
||||
export default async (user: { id: User['id']; host: User['host']; }, note: Note, reaction?: string) => {
|
||||
// Check blocking
|
||||
if (note.userId !== user.id) {
|
||||
const block = await Blockings.findOne({
|
||||
blockerId: note.userId,
|
||||
blockeeId: user.id,
|
||||
});
|
||||
if (block) {
|
||||
throw new IdentifiableError('e70412a4-7197-4726-8e74-f3e0deb92aa7');
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: cache
|
||||
reaction = await toDbReaction(reaction, user.host);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue