Skip to content

Commit

Permalink
feat: local-only antenna
Browse files Browse the repository at this point in the history
  • Loading branch information
syuilo authored and kanarikanaru committed Nov 2, 2023
1 parent fad65b3 commit 45cb968
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 8 deletions.
16 changes: 16 additions & 0 deletions packages/backend/migration/1697436246389-antenna-localOnly.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: syuilo and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/

export class AntennaLocalOnly1697436246389 {
name = 'AntennaLocalOnly1697436246389'

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "antenna" ADD "localOnly" boolean NOT NULL DEFAULT false`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "antenna" DROP COLUMN "localOnly"`);
}
}
2 changes: 2 additions & 0 deletions packages/backend/src/core/AntennaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ export class AntennaService implements OnApplicationShutdown {
if (note.visibility === 'specified') return false;
if (note.visibility === 'followers') return false;

if (antenna.localOnly && noteUser.host != null) return false;

if (!antenna.withReplies && note.replyId != null) return false;

if (antenna.src === 'home') {
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/core/entities/AntennaEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class AntennaEntityService {
userListId: antenna.userListId,
users: antenna.users,
caseSensitive: antenna.caseSensitive,
localOnly: antenna.localOnly,
notify: antenna.notify,
withReplies: antenna.withReplies,
withFile: antenna.withFile,
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/models/Antenna.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,9 @@ export class MiAntenna {
default: true,
})
public isActive: boolean;

@Column('boolean', {
default: false,
})
public localOnly: boolean;
}
5 changes: 5 additions & 0 deletions packages/backend/src/models/json-schema/antenna.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export const packedAntennaSchema = {
optional: false, nullable: false,
default: false,
},
localOnly: {
type: 'boolean',
optional: false, nullable: false,
default: false,
},
notify: {
type: 'boolean',
optional: false, nullable: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class ExportAntennasProcessorService {
return this.utilityService.getFullApAccount(u.username, u.host); // acct
}) : null,
caseSensitive: antenna.caseSensitive,
localOnly: antenna.localOnly,
withReplies: antenna.withReplies,
withFile: antenna.withFile,
notify: antenna.notify,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const validate = new Ajv().compile({
type: 'string',
} },
caseSensitive: { type: 'boolean' },
localOnly: { type: 'boolean' },
withReplies: { type: 'boolean' },
withFile: { type: 'boolean' },
notify: { type: 'boolean' },
Expand Down Expand Up @@ -87,6 +88,7 @@ export class ImportAntennasProcessorService {
excludeKeywords: antenna.excludeKeywords,
users: (antenna.src === 'list' && antenna.userListAccts !== null ? antenna.userListAccts : antenna.users).filter(Boolean),
caseSensitive: antenna.caseSensitive,
localOnly: antenna.localOnly,
withReplies: antenna.withReplies,
withFile: antenna.withFile,
notify: antenna.notify,
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/server/api/endpoints/antennas/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const paramDef = {
type: 'string',
} },
caseSensitive: { type: 'boolean' },
localOnly: { type: 'boolean' },
withReplies: { type: 'boolean' },
withFile: { type: 'boolean' },
notify: { type: 'boolean' },
Expand Down Expand Up @@ -123,6 +124,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
excludeKeywords: ps.excludeKeywords,
users: ps.users,
caseSensitive: ps.caseSensitive,
localOnly: ps.localOnly,
withReplies: ps.withReplies,
withFile: ps.withFile,
notify: ps.notify,
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/server/api/endpoints/antennas/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const paramDef = {
type: 'string',
} },
caseSensitive: { type: 'boolean' },
localOnly: { type: 'boolean' },
withReplies: { type: 'boolean' },
withFile: { type: 'boolean' },
notify: { type: 'boolean' },
Expand Down Expand Up @@ -116,6 +117,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
excludeKeywords: ps.excludeKeywords,
users: ps.users,
caseSensitive: ps.caseSensitive,
localOnly: ps.localOnly,
withReplies: ps.withReplies,
withFile: ps.withFile,
notify: ps.notify,
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/test/e2e/move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ describe('Account Move', () => {
excludeKeywords: [],
users: [],
caseSensitive: false,
localOnly: false,
withReplies: false,
withFile: false,
notify: false,
Expand Down Expand Up @@ -431,6 +432,7 @@ describe('Account Move', () => {
excludeKeywords: [],
users: [eve.id],
caseSensitive: false,
localOnly: false,
withReplies: false,
withFile: false,
notify: false,
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/src/pages/my-antennas/create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import XAntenna from './editor.vue';
import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { useRouter } from '@/router.js';
import { antennasCache } from '@/cache';
import { antennasCache } from '@/cache.js';
const router = useRouter();
Expand All @@ -27,6 +27,7 @@ let draft = $ref({
excludeKeywords: [],
withReplies: false,
caseSensitive: false,
localOnly: false,
withFile: false,
notify: false,
});
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend/src/pages/my-antennas/editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #label>{{ i18n.ts.antennaExcludeKeywords }}</template>
<template #caption>{{ i18n.ts.antennaKeywordsDescription }}</template>
</MkTextarea>
<MkSwitch v-model="localOnly">{{ i18n.ts.localOnly }}</MkSwitch>
<MkSwitch v-model="caseSensitive">{{ i18n.ts.caseSensitive }}</MkSwitch>
<MkSwitch v-model="withFile">{{ i18n.ts.withFileAntenna }}</MkSwitch>
<MkSwitch v-model="notify">{{ i18n.ts.notifyAntenna }}</MkSwitch>
Expand Down Expand Up @@ -75,6 +76,7 @@ let users: string = $ref(props.antenna.users.join('\n'));
let keywords: string = $ref(props.antenna.keywords.map(x => x.join(' ')).join('\n'));
let excludeKeywords: string = $ref(props.antenna.excludeKeywords.map(x => x.join(' ')).join('\n'));
let caseSensitive: boolean = $ref(props.antenna.caseSensitive);
let localOnly: boolean = $ref(props.antenna.localOnly);
let withReplies: boolean = $ref(props.antenna.withReplies);
let withFile: boolean = $ref(props.antenna.withFile);
let notify: boolean = $ref(props.antenna.notify);
Expand All @@ -95,6 +97,7 @@ async function saveAntenna() {
withFile,
notify,
caseSensitive,
localOnly,
users: users.trim().split('\n').map(x => x.trim()),
keywords: keywords.trim().split('\n').map(x => x.trim().split(' ')),
excludeKeywords: excludeKeywords.trim().split('\n').map(x => x.trim().split(' ')),
Expand Down
15 changes: 8 additions & 7 deletions packages/misskey-js/etc/misskey-js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Antenna = {
userGroupId: ID | null;
users: string[];
caseSensitive: boolean;
localOnly: boolean;
notify: boolean;
withReplies: boolean;
withFile: boolean;
Expand Down Expand Up @@ -1381,10 +1382,6 @@ export type Endpoints = {
req: TODO;
res: TODO;
};
'i/get-word-muted-notes-count': {
req: TODO;
res: TODO;
};
'i/import-following': {
req: TODO;
res: TODO;
Expand Down Expand Up @@ -2452,6 +2449,7 @@ type LiteInstanceMetadata = {
url: string;
imageUrl: string;
}[];
notesPerOneAd: number;
translatorAvailable: boolean;
serverRules: string[];
};
Expand Down Expand Up @@ -2758,6 +2756,9 @@ type Notification_2 = {
invitation: UserGroup;
user: User;
userId: User['id'];
} | {
type: 'achievementEarned';
achievement: string;
} | {
type: 'app';
header?: string | null;
Expand All @@ -2768,7 +2769,7 @@ type Notification_2 = {
});

// @public (undocumented)
export const notificationTypes: readonly ["note", "follow", "mention", "reply", "renote", "quote", "reaction", "pollVote", "pollEnded", "receiveFollowRequest", "followRequestAccepted", "groupInvited", "app"];
export const notificationTypes: readonly ["note", "follow", "mention", "reply", "renote", "quote", "reaction", "pollVote", "pollEnded", "receiveFollowRequest", "followRequestAccepted", "groupInvited", "app", "achievementEarned"];

// @public (undocumented)
type OriginType = 'combined' | 'local' | 'remote';
Expand Down Expand Up @@ -2982,9 +2983,9 @@ type UserSorting = '+follower' | '-follower' | '+createdAt' | '-createdAt' | '+u
//
// src/api.types.ts:16:32 - (ae-forgotten-export) The symbol "TODO" needs to be exported by the entry point index.d.ts
// src/api.types.ts:18:25 - (ae-forgotten-export) The symbol "NoParams" needs to be exported by the entry point index.d.ts
// src/api.types.ts:631:18 - (ae-forgotten-export) The symbol "ShowUserReq" needs to be exported by the entry point index.d.ts
// src/api.types.ts:630:18 - (ae-forgotten-export) The symbol "ShowUserReq" needs to be exported by the entry point index.d.ts
// src/entities.ts:107:2 - (ae-forgotten-export) The symbol "notificationTypes_2" needs to be exported by the entry point index.d.ts
// src/entities.ts:596:2 - (ae-forgotten-export) The symbol "ModerationLogPayloads" needs to be exported by the entry point index.d.ts
// src/entities.ts:601:2 - (ae-forgotten-export) The symbol "ModerationLogPayloads" needs to be exported by the entry point index.d.ts
// src/streaming.types.ts:33:4 - (ae-forgotten-export) The symbol "FIXME" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)
Expand Down
1 change: 1 addition & 0 deletions packages/misskey-js/src/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ export type Antenna = {
userGroupId: ID | null; // TODO
users: string[]; // TODO
caseSensitive: boolean;
localOnly: boolean;
notify: boolean;
withReplies: boolean;
withFile: boolean;
Expand Down

0 comments on commit 45cb968

Please sign in to comment.