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

disableReaction #4731

Draft
wants to merge 1 commit 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
4 changes: 4 additions & 0 deletions src/client/app/common/views/components/settings/profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<ui-switch v-model="isCat" @change="save(false)">{{ $t('is-cat') }}</ui-switch>
<ui-switch v-model="isBot" @change="save(false)">{{ $t('is-bot') }}</ui-switch>
<ui-switch v-model="alwaysMarkNsfw">{{ $t('@._settings.always-mark-nsfw') }}</ui-switch>
<ui-switch v-model="disableReaction" @change="save(false)">{{ $t('disableReaction') }}</ui-switch>
</div>
</section>

Expand Down Expand Up @@ -184,6 +185,7 @@ export default Vue.extend({
autoAcceptFollowed: false,
avoidSearchIndex: false,
isExplorable: false,
disableReaction: false,
searchableBy: true,
hideFollows: '',
noFederation: false,
Expand Down Expand Up @@ -239,6 +241,7 @@ export default Vue.extend({
this.autoAcceptFollowed = this.$store.state.i.autoAcceptFollowed;
this.avoidSearchIndex = this.$store.state.i.avoidSearchIndex;
this.isExplorable = this.$store.state.i.isExplorable;
this.disableReaction = this.$store.state.i.disableReaction;
this.searchableBy = this.$store.state.i.searchableBy === 'public';
this.hideFollows = this.$store.state.i.hideFollows;
this.noFederation = this.$store.state.i.noFederation;
Expand Down Expand Up @@ -341,6 +344,7 @@ export default Vue.extend({
autoAcceptFollowed: !!this.autoAcceptFollowed,
avoidSearchIndex: !!this.avoidSearchIndex,
isExplorable: !!this.isExplorable,
disableReaction: !!this.disableReaction,
hideFollows: this.hideFollows || '',
searchableBy: this.searchableBy ? 'public' : 'none',
fields,
Expand Down
12 changes: 11 additions & 1 deletion src/misc/reaction-lib.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Emoji from '../models/emoji';
import { emojiRegex, vendorEmojiRegex } from './emoji-regex';
import { toApHost, toDbHost } from './convert-host';
import { IUser } from '../models/user';
import * as mongo from 'mongodb';

const basic10: Record<string, string> = {
'👍': 'like',
Expand Down Expand Up @@ -31,9 +33,17 @@ const normalizeMap: Record<string, string> = {

const REACTION_STAR = '⭐';

export async function toDbReaction(reaction: string | undefined | null, enableEmoji = true, reacterHost?: string | null): Promise<string> {
export async function toDbReaction(reaction: string | undefined | null, enableEmoji = true, reacter?: IUser, reactee?: IUser): Promise<string> {
let reacterHost = reacter?.host;

if (reaction == null) return REACTION_STAR;

// disable reaction from
if (reacter?.disableReaction) return REACTION_STAR;

// disable reaction to
if (reactee?.disableReaction) return REACTION_STAR;

// 既存の文字列リアクションはそのまま
if (Object.values(basic10).includes(reaction)) return reaction;

Expand Down
1 change: 1 addition & 0 deletions src/models/packed-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export type PackedUser = ThinPackedUser & {
refuseFollow?: boolean;
autoAcceptFollowed?: boolean;
isExplorable?: boolean;
disableReaction?: boolean;
searchableBy?: string;
hideFollows?: string;
wallpaperId?: string | null;
Expand Down
6 changes: 6 additions & 0 deletions src/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ type IUserBase = {
*/
isExplorable?: boolean;

/**
* リアクションを無効にするか
*/
disableReaction?: boolean;

searchableBy?: 'public' | 'none' | null;

/**
Expand Down Expand Up @@ -547,6 +552,7 @@ export async function pack(
isExplorable: !!db.isExplorable,
searchableBy: db.searchableBy || 'public',
hideFollows: db.hideFollows || '',
disableReaction: !!db.disableReaction,

wallpaperId: toOidStringOrNull(db.wallpaperId),
wallpaperUrl: sanitizeUrl(db.wallpaperUrl) || null,
Expand Down
8 changes: 8 additions & 0 deletions src/server/api/endpoints/i/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ export const meta = {
}
},

disableReaction: {
validator: $.optional.bool,
desc: {
'ja-JP': 'リアクションを無効にするか'
}
},

searchableBy: {
validator: $.optional.nullable.str.or(['public', 'none']),
desc: {
Expand Down Expand Up @@ -290,6 +297,7 @@ export default define(meta, async (ps, user, app) => {
if (typeof ps.autoAcceptFollowed == 'boolean') updates.autoAcceptFollowed = ps.autoAcceptFollowed;
if (typeof ps.avoidSearchIndex == 'boolean') updates.avoidSearchIndex = ps.avoidSearchIndex;
if (typeof ps.isExplorable == 'boolean') updates.isExplorable = ps.isExplorable;
if (typeof ps.disableReaction == 'boolean') updates.disableReaction = ps.disableReaction;
if (ps.searchableBy !== undefined) updates.searchableBy = ps.searchableBy;
if (ps.hideFollows !== undefined) updates.hideFollows = ps.hideFollows;
if (typeof ps.noFederation == 'boolean') updates.noFederation = ps.noFederation;
Expand Down
5 changes: 3 additions & 2 deletions src/services/note/reaction/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export default async (user: IUser, note: INote, reaction?: string, dislike = fal
}
}

reaction = await toDbReaction(reaction, true, user.host);
const reactee = await User.findOne({ _id: note.userId });

reaction = await toDbReaction(reaction, true, user, reactee);

const inserted = {
_id: new mongo.ObjectID(),
Expand Down Expand Up @@ -94,7 +96,6 @@ export default async (user: IUser, note: INote, reaction?: string, dislike = fal
const dm = new DeliverManager(user, content)

if (isRemoteUser(note._user)) {
const reactee = await User.findOne({ _id: note.userId });
if (isRemoteUser(reactee)) dm.addDirectRecipe(reactee);
}

Expand Down