Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通知は来るミュート #4430

Draft
wants to merge 4 commits into
base: mei-m544
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
},
"devDependencies": {
"@redocly/openapi-core": "1.0.0-beta.120",
"@types/animejs": "3.1.6",
"@types/bcryptjs": "2.4.2",
"@types/cheerio": "0.22.31",
"@types/double-ended-queue": "2.1.2",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/models/mute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface IMute {
muterId: mongo.ObjectID;
muteeId: mongo.ObjectID;
expiresAt?: Date;
allowNotification?: boolean;
}

export const packMany = (
Expand Down
1 change: 1 addition & 0 deletions src/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export async function getMute(muterId: mongo.ObjectId | string, muteeId: mongo.O
return await Mute.findOne({
muterId: transform(muterId),
muteeId: transform(muteeId),
allowNotification: { $ne: true },
$or: [
{ expiresAt: null },
{ expiresAt: { $lt: new Date() }}
Expand Down
15 changes: 13 additions & 2 deletions src/queue/processors/db/export-mute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ export async function exportMute(job: Bull.Job<DbUserJobData>): Promise<string>
muterId: user._id,
});

await new Promise<void>((res, rej) => {
stream.write(`Account address,Hide notifications\n`, err => {
if (err) {
logger.error(err);
rej(err);
} else {
res();
}
});
});

while (true) {
const mutes = await Mute.find({
expiresAt: null,
Expand All @@ -68,8 +79,8 @@ export async function exportMute(job: Bull.Job<DbUserJobData>): Promise<string>
const u = await User.findOne({ _id: mute.muteeId }, { fields: { username: true, host: true } });
if (u == null) continue; // DB blocken ?
const content = getFullApAccount(u.username, u.host);
await new Promise((res, rej) => {
stream.write(content + '\n', err => {
await new Promise<void>((res, rej) => {
stream.write(`${content},${!mute.allowNotification}\n`, err => {
if (err) {
logger.error(err);
rej(err);
Expand Down
7 changes: 4 additions & 3 deletions src/server/api/common/get-hide-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import User, { IUser } from '../../../models/user';
import { unique } from '../../../prelude/array';
import Blocking from '../../../models/blocking';

export async function getHideUserIds(me: IUser | null, includeSilenced = true, includeSuspended = true) {
return await getHideUserIdsById(me ? me._id : null, includeSilenced, includeSuspended);
export async function getHideUserIds(me: IUser | null, includeSilenced = true, includeSuspended = true, allowNotification = false) {
return await getHideUserIdsById(me ? me._id : null, includeSilenced, includeSuspended, allowNotification);
}

export async function getHideUserIdsById(meId?: mongo.ObjectID | null, includeSilenced = true, includeSuspended = true) {
export async function getHideUserIdsById(meId?: mongo.ObjectID | null, includeSilenced = true, includeSuspended = true, allowNotification = false) {
const [deleted, suspended, silenced, muted, blocking, blocked] = await Promise.all([
User.find({
isDeleted: true
Expand Down Expand Up @@ -37,6 +37,7 @@ export async function getHideUserIdsById(meId?: mongo.ObjectID | null, includeSi
{ expiresAt: null },
{ expiresAt: { $gt: new Date() }}
],
...(allowNotification ? { notification: { $ne: true } } : {}),
muterId: meId
}) : [],
meId ? Blocking.find({
Expand Down
2 changes: 1 addition & 1 deletion src/server/api/endpoints/i/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const meta = {
};

export default define(meta, async (ps, user) => {
const hideUserIds = await getHideUserIds(user, false);
const hideUserIds = await getHideUserIds(user, false, true, true);

const query = {
notifieeId: user._id,
Expand Down
14 changes: 12 additions & 2 deletions src/server/api/endpoints/mute/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ export const meta = {
'ja-JP': 'ミュートの期限',
'en-US': 'Expires at'
}
}
},

allowNotification: {
validator: $.optional.boolean,
default: false,
desc: {
'ja-JP': '通知を許可する',
'en-US': 'Allow notifications'
}
},
},

errors: {
Expand Down Expand Up @@ -93,7 +102,8 @@ export default define(meta, async (ps, user) => {
createdAt: new Date(),
muterId: muter._id,
muteeId: mutee._id,
expiresAt: ps.expiresAt ? new Date(ps.expiresAt) : undefined
expiresAt: ps.expiresAt ? new Date(ps.expiresAt) : undefined,
allowNotification: !!ps.allowNotification,
});

publishMutingChanged(muter._id);
Expand Down