Skip to content

Commit

Permalink
Renote Visibility Check
Browse files Browse the repository at this point in the history
  • Loading branch information
atsu1125 committed Dec 27, 2023
1 parent a657000 commit 90ebd82
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/client/components/note.vue
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export default defineComponent({
},
canRenote(): boolean {
return ['public', 'home'].includes(this.appearNote.visibility) || this.isMyNote;
return ['public', 'home'].includes(this.appearNote.visibility) || (['followers', 'users'].includes(this.appearNote.visibility) && this.isMyNote);
},
reactionsCount(): number {
Expand Down
15 changes: 15 additions & 0 deletions src/server/api/endpoints/notes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ export const meta = {
code: 'NO_SUCH_CHANNEL',
id: 'b1653923-5453-4edc-b786-7c4f39bb0bbb'
},

cannotRenoteDueToVisibility: {
message: 'You can not Renote due to target visibility.',
code: 'CANNOT_RENOTE_DUE_TO_VISIBILITY',
id: 'be9529e9-fe72-4de0-ae43-0b363c4938af',
},
}
};

Expand Down Expand Up @@ -260,6 +266,15 @@ export default define(meta, async (ps, user) => {
} else if (renote.renoteId && !renote.text && renote.fileIds.length === 0) {
throw new ApiError(meta.errors.cannotReRenote);
}

// Renote visibility Check
if ((renote.visibility === 'followers' || renote.visibility === 'users') && renote.userId !== user.id) {
// 他人のfollowers/users noteはreject
throw new ApiError(meta.errors.cannotRenoteDueToVisibility);
} else if (renote.visibility === 'specified') {
// specified / direct noteはreject
throw new ApiError(meta.errors.cannotRenoteDueToVisibility);
}
}

let reply: Note | undefined;
Expand Down
53 changes: 34 additions & 19 deletions src/services/note/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,29 +144,44 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
data.visibility = 'home';
}

// Renote対象が「ホームまたは全体」以外の公開範囲ならreject
if (data.renote && data.renote.visibility !== 'public' && data.renote.visibility !== 'home' && data.renote.userId !== user.id) {
return rej('Renote target is not public or home');
}

// localOnly と remoteFollowersOnly は共存できない
if (data.localOnly && data.remoteFollowersOnly) {
return rej('You can\'t specify both localOnly and remoteFollowersOnly flags');
}

// Renote対象がpublicではないならhomeにする
if (data.renote && data.renote.visibility !== 'public' && data.visibility === 'public') {
data.visibility = 'home';
}

// Renote対象がfollowersならfollowersにする
if (data.renote && data.renote.visibility === 'followers') {
data.visibility = 'followers';
}

// Renote対象がusersならusersにする
if (data.renote && data.renote.visibility === 'users') {
data.visibility = 'users';
// Renote Visibility Check
if (data.renote) {
switch (data.renote.visibility) {
case 'public':
// public noteは無条件にrenote可能
break;
case 'home':
// home noteはhome以下にrenote可能
if (data.visibility === 'public') {
data.visibility = 'home';
}
break;
case 'followers':
// 他人のfollowers noteはreject
if (data.renote.userId !== user.id) {
throw new Error('Renote target is not public or home');
}
// Renote対象がfollowersならfollowersにする
data.visibility = 'followers';
break;
case 'users':
// 他人のusers noteはreject
if (data.renote.userId !== user.id) {
throw new Error('Renote target is not public or home');
}
// Renote対象がusersならusersにする
data.visibility = 'users';
break;
case 'specified':
// specified / direct noteはreject
throw new Error('Renote target is not public or home');
break;
}
}

// 返信対象がpublicではないならhomeにする
Expand Down Expand Up @@ -415,7 +430,7 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
if (noteActivity === null) {
return;
}

const dm = new DeliverManager(user, noteActivity);

// メンションされたリモートユーザーに配送
Expand Down

0 comments on commit 90ebd82

Please sign in to comment.