added psql query for removal of muted notes

This commit is contained in:
puffaboo 2021-08-26 18:07:02 +01:00
parent ffdbf751df
commit ef5709406c
5 changed files with 30 additions and 2 deletions

View file

@ -62,14 +62,12 @@ export default defineComponent({
async created() {
console.log(this.$i);
this.instanceMutes = this.$i.mutedInstances.join('\n');
},
methods: {
async save() {
let mutes = this.instanceMutes.trim().split('\n');
console.log(mutes);
await os.api('i/update', {
mutedInstances: mutes,
});

View file

@ -0,0 +1,24 @@
import { User } from '@/models/entities/user';
import { UserProfiles } from '@/models/index';
import { SelectQueryBuilder, Brackets } from 'typeorm';
export function generateMutedInstanceQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }) {
const mutingQuery = UserProfiles.createQueryBuilder('user_profile')
.select('user_profile.mutedInstances')
.where('user_profile.userId = :muterId', { muterId: me.id });
q
.andWhere(new Brackets(qb => { qb
.andWhere('note.userHost IS NULL')
.orWhere(`NOT((${ mutingQuery.getQuery() })::jsonb ? note.userHost)`)
}))
.andWhere(new Brackets(qb => { qb
.where(`note.replyUserHost IS NULL`)
.orWhere(`NOT ((${ mutingQuery.getQuery() })::jsonb ? note.replyUserHost)`);
}))
.andWhere(new Brackets(qb => { qb
.where(`note.renoteUserHost IS NULL`)
.orWhere(`NOT ((${ mutingQuery.getQuery() })::jsonb ? note.renoteUserHost)`);
}));
q.setParameters(mutingQuery.getParameters());
}

View file

@ -6,6 +6,7 @@ import { ApiError } from '../../error';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { Notes } from '@/models/index';
import { generateMutedUserQuery } from '../../common/generate-muted-user-query';
import { generateMutedInstanceQuery } from '../../common/generate-muted-instance-query';
import { activeUsersChart } from '@/services/chart/index';
import { generateRepliesQuery } from '../../common/generate-replies-query';
import { generateMutedNoteQuery } from '../../common/generate-muted-note-query';
@ -83,6 +84,7 @@ export default define(meta, async (ps, user) => {
if (user) generateMutedUserQuery(query, user);
if (user) generateMutedNoteQuery(query, user);
if (user) generateBlockedUserQuery(query, user);
if (user) generateMutedInstanceQuery(query, user);
if (ps.withFiles) {
query.andWhere('note.fileIds != \'{}\'');

View file

@ -8,6 +8,7 @@ import { Followings, Notes } from '@/models/index';
import { Brackets } from 'typeorm';
import { generateVisibilityQuery } from '../../common/generate-visibility-query';
import { generateMutedUserQuery } from '../../common/generate-muted-user-query';
import { generateMutedInstanceQuery } from '../../common/generate-muted-instance-query';
import { activeUsersChart } from '@/services/chart/index';
import { generateRepliesQuery } from '../../common/generate-replies-query';
import { generateMutedNoteQuery } from '../../common/generate-muted-note-query';
@ -108,6 +109,7 @@ export default define(meta, async (ps, user) => {
generateRepliesQuery(query, user);
generateVisibilityQuery(query, user);
generateMutedUserQuery(query, user);
generateMutedInstanceQuery(query, user);
generateMutedNoteQuery(query, user);
generateBlockedUserQuery(query, user);

View file

@ -5,6 +5,7 @@ import { makePaginationQuery } from '../../common/make-pagination-query';
import { Notes, Followings } from '@/models/index';
import { generateVisibilityQuery } from '../../common/generate-visibility-query';
import { generateMutedUserQuery } from '../../common/generate-muted-user-query';
import { generateMutedInstanceQuery } from '../../common/generate-muted-instance-query';
import { activeUsersChart } from '@/services/chart/index';
import { Brackets } from 'typeorm';
import { generateRepliesQuery } from '../../common/generate-replies-query';
@ -100,6 +101,7 @@ export default define(meta, async (ps, user) => {
generateRepliesQuery(query, user);
generateVisibilityQuery(query, user);
generateMutedUserQuery(query, user);
generateMutedInstanceQuery(query, user);
generateMutedNoteQuery(query, user);
generateBlockedUserQuery(query, user);