Skip to content

Commit

Permalink
Feat: HTLとSTLをローカルのみに絞り込む機能
Browse files Browse the repository at this point in the history
  • Loading branch information
tai-cha authored and kanarikanaru committed Mar 2, 2024
1 parent 9b308e0 commit 04e57c4
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const meta = {
bothWithRepliesAndWithFiles: {
message: 'Specifying both withReplies and withFiles is not supported',
code: 'BOTH_WITH_REPLIES_AND_WITH_FILES',
id: 'dfaa3eb7-8002-4cb7-bcc4-1095df46656f'
id: 'dfaa3eb7-8002-4cb7-bcc4-1095df46656f',
},
},
} as const;
Expand All @@ -67,6 +67,7 @@ export const paramDef = {
withFiles: { type: 'boolean', default: false },
withRenotes: { type: 'boolean', default: true },
withReplies: { type: 'boolean', default: false },
onlyLocal: { type: 'boolean', default: false },
},
required: [],
} as const;
Expand Down Expand Up @@ -113,6 +114,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
withReplies: ps.withReplies,
onlyLocal: ps.onlyLocal,
}, me);

process.nextTick(() => {
Expand Down Expand Up @@ -152,6 +154,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
useDbFallback: serverSettings.enableFanoutTimelineDbFallback,
alwaysIncludeMyNotes: true,
excludePureRenotes: !ps.withRenotes,
noteFilter: (note) => {
if (ps.onlyLocal && note.user && note.user.host !== null ) {
return false;
}
return true;
},
dbFallback: async (untilId, sinceId, limit) => await this.getFromDb({
untilId,
sinceId,
Expand All @@ -161,6 +169,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
withReplies: ps.withReplies,
onlyLocal: ps.onlyLocal,
}, me),
});

Expand All @@ -181,6 +190,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
includeLocalRenotes: boolean,
withFiles: boolean,
withReplies: boolean,
onlyLocal: boolean,
}, me: MiLocalUser) {
const followees = await this.userFollowingService.getFollowees(me.id);
const followingChannels = await this.channelFollowingsRepository.find({
Expand Down Expand Up @@ -267,6 +277,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (ps.withFiles) {
query.andWhere('note.fileIds != \'{}\'');
}

if (ps.onlyLocal) {
query.andWhere('note.userHost IS NULL');
}
//#endregion

return await query.limit(ps.limit).getMany();
Expand Down
13 changes: 12 additions & 1 deletion packages/backend/src/server/api/endpoints/notes/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const paramDef = {
includeLocalRenotes: { type: 'boolean', default: true },
withFiles: { type: 'boolean', default: false },
withRenotes: { type: 'boolean', default: true },
onlyLocal: { type: 'boolean', default: false },
},
required: [],
} as const;
Expand Down Expand Up @@ -87,6 +88,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
withRenotes: ps.withRenotes,
onlyLocal: ps.onlyLocal,
}, me);

process.nextTick(() => {
Expand Down Expand Up @@ -117,6 +119,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (!Object.hasOwn(followings, note.reply.userId)) return false;
}

if (ps.onlyLocal && note.user && note.user.host !== null ) {
return false;
}

return true;
},
dbFallback: async (untilId, sinceId, limit) => await this.getFromDb({
Expand All @@ -128,6 +134,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
withRenotes: ps.withRenotes,
onlyLocal: ps.onlyLocal,
}, me),
});

Expand All @@ -139,7 +146,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
});
}

private async getFromDb(ps: { untilId: string | null; sinceId: string | null; limit: number; includeMyRenotes: boolean; includeRenotedMyNotes: boolean; includeLocalRenotes: boolean; withFiles: boolean; withRenotes: boolean; }, me: MiLocalUser) {
private async getFromDb(ps: { untilId: string | null; sinceId: string | null; limit: number; includeMyRenotes: boolean; includeRenotedMyNotes: boolean; includeLocalRenotes: boolean; withFiles: boolean; withRenotes: boolean; onlyLocal: boolean; }, me: MiLocalUser) {
const followees = await this.userFollowingService.getFollowees(me.id);
const followingChannels = await this.channelFollowingsRepository.find({
where: {
Expand Down Expand Up @@ -241,6 +248,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (ps.withRenotes === false) {
query.andWhere('note.renoteId IS NULL');
}

if (ps.onlyLocal) {
query.andWhere('note.userHost IS NULL');
}
//#endregion

return await query.limit(ps.limit).getMany();
Expand Down
9 changes: 8 additions & 1 deletion packages/frontend/src/components/MkTimeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ const props = withDefaults(defineProps<{
withRenotes?: boolean;
withReplies?: boolean;
onlyFiles?: boolean;
onlyLocal?: boolean;
}>(), {
withRenotes: true,
withReplies: false,
onlyFiles: false,
onlyLocal: false,
});

const emit = defineEmits<{
Expand All @@ -61,6 +63,7 @@ type TimelineQueryType = {
listId?: string,
channelId?: string,
roleId?: string
onlyLocal?: boolean,
}

const prComponent = shallowRef<InstanceType<typeof MkPullToRefresh>>();
Expand All @@ -71,6 +74,8 @@ let tlNotesCount = 0;
function prepend(note) {
if (tlComponent.value == null) return;

if (props.onlyLocal === true && note.user.host !== null) return;

tlNotesCount++;

if (instance.notesPerOneAd > 0 && tlNotesCount % instance.notesPerOneAd === 0) {
Expand Down Expand Up @@ -172,6 +177,7 @@ function updatePaginationQuery() {
query = {
withRenotes: props.withRenotes,
withFiles: props.onlyFiles ? true : undefined,
onlyLocal: props.onlyLocal ? true : undefined,
};
} else if (props.src === 'local') {
endpoint = 'notes/local-timeline';
Expand All @@ -186,6 +192,7 @@ function updatePaginationQuery() {
withRenotes: props.withRenotes,
withReplies: props.withReplies,
withFiles: props.onlyFiles ? true : undefined,
onlyLocal: props.onlyLocal ? true : undefined,
};
} else if (props.src === 'global') {
endpoint = 'notes/global-timeline';
Expand Down Expand Up @@ -245,7 +252,7 @@ function refreshEndpointAndChannel() {

// デッキのリストカラムでwithRenotesを変更した場合に自動的に更新されるようにさせる
// IDが切り替わったら切り替え先のTLを表示させたい
watch(() => [props.list, props.antenna, props.channel, props.role, props.withRenotes], refreshEndpointAndChannel);
watch(() => [props.list, props.antenna, props.channel, props.role, props.withRenotes, props.onlyLocal], refreshEndpointAndChannel);

// 初回表示用
refreshEndpointAndChannel();
Expand Down
12 changes: 11 additions & 1 deletion packages/frontend/src/pages/timeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SPDX-License-Identifier: AGPL-3.0-only
:withRenotes="withRenotes"
:withReplies="withReplies"
:onlyFiles="onlyFiles"
:onlyLocal="onlyLocal"
:sound="true"
@queue="queueUpdated"
/>
Expand Down Expand Up @@ -116,6 +117,11 @@ const withSensitive = computed<boolean>({
set: (x) => saveTlFilter('withSensitive', x),
});

const onlyLocal = computed<boolean>({
get: () => defaultStore.reactiveState.tl.value.filter.onlyLocal,
set: (x) => saveTlFilter('onlyLocal', x),
});

watch(src, () => {
queue.value = 0;
});
Expand Down Expand Up @@ -264,7 +270,11 @@ const headerActions = computed(() => {
text: i18n.ts.fileAttachedOnly,
ref: onlyFiles,
disabled: src.value === 'local' || src.value === 'social' ? withReplies : false,
}], ev.currentTarget ?? ev.target);
}, src.value === 'home' || src.value === 'social' ? {
type: 'switch',
text: i18n.ts.localOnly,
ref: onlyLocal,
} : undefined,], ev.currentTarget ?? ev.target);
},
},
];
Expand Down
5 changes: 3 additions & 2 deletions packages/frontend/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export const defaultStore = markRaw(new Storage('base', {
withRenotes: true,
withSensitive: true,
onlyFiles: false,
onlyLocal: false,
},
},
},
Expand Down Expand Up @@ -431,10 +432,10 @@ export const defaultStore = markRaw(new Storage('base', {
sfxVolume: 1,
},
},
hemisphere: {
hemisphere: {
where: 'device',
default: hemisphere as 'N' | 'S',
},
},
enableHorizontalSwipe: {
where: 'device',
default: false,
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/src/ui/deck/deck-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type Column = {
withRenotes?: boolean;
withReplies?: boolean;
onlyFiles?: boolean;
onlyLocal?: boolean;
};

export const deckStore = markRaw(new Storage('deck', {
Expand Down
16 changes: 14 additions & 2 deletions packages/frontend/src/ui/deck/tl-column.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkTimeline
v-else-if="column.tl"
ref="timeline"
:key="column.tl + withRenotes + withReplies + onlyFiles"
:key="column.tl + withRenotes + withReplies + onlyFiles + onlyLocal"
:src="column.tl"
:withRenotes="withRenotes"
:withReplies="withReplies"
:onlyFiles="onlyFiles"
:onlyLocal="onlyLocal"
/>
</XColumn>
</template>
Expand Down Expand Up @@ -55,6 +56,7 @@ const isGlobalTimelineAvailable = (($i == null && instance.policies.gtlAvailable
const withRenotes = ref(props.column.withRenotes ?? true);
const withReplies = ref(props.column.withReplies ?? false);
const onlyFiles = ref(props.column.onlyFiles ?? false);
const onlyLocal = ref(props.column.onlyLocal ?? false);

watch(withRenotes, v => {
updateColumn(props.column.id, {
Expand All @@ -74,6 +76,12 @@ watch(onlyFiles, v => {
});
});

watch(onlyLocal, v => {
updateColumn(props.column.id, {
onlyLocal: v,
});
});

onMounted(() => {
if (props.column.tl == null) {
setType();
Expand Down Expand Up @@ -126,7 +134,11 @@ const menu = [{
text: i18n.ts.fileAttachedOnly,
ref: onlyFiles,
disabled: props.column.tl === 'local' || props.column.tl === 'social' ? withReplies : false,
}];
}, props.column.tl === 'home' || props.column.tl === 'social' ? {
type: 'switch',
text: i18n.ts.localOnly,
ref: onlyLocal,
} : undefined];
</script>

<style lang="scss" module>
Expand Down
4 changes: 4 additions & 0 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20805,6 +20805,8 @@ export type operations = {
withRenotes?: boolean;
/** @default false */
withReplies?: boolean;
/** @default false */
onlyLocal?: boolean;
};
};
};
Expand Down Expand Up @@ -21773,6 +21775,8 @@ export type operations = {
withFiles?: boolean;
/** @default true */
withRenotes?: boolean;
/** @default false */
onlyLocal?: boolean;
};
};
};
Expand Down

0 comments on commit 04e57c4

Please sign in to comment.