Skip to content

Commit

Permalink
enhance: ハッシュタグをリアルタイムで更新するように
Browse files Browse the repository at this point in the history
  • Loading branch information
Esurio committed Sep 13, 2024
1 parent 212368d commit 8f1f680
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
) {
super(meta, paramDef, async (ps, me) => {
const hashtags = await this.hashtagsRepository.createQueryBuilder('tag')
.where('tag.name like :q', { q: sqlLikeEscape(ps.query.toLowerCase()) + '%' })
.where('tag.name ILIKE :q', { q: sqlLikeEscape(ps.query.toLowerCase()) + '%' })
.orderBy('tag.mentionedLocalUsersCount', 'DESC')
.groupBy('tag.id')
.limit(ps.limit)
Expand Down
2 changes: 1 addition & 1 deletion packages/cherrypick-js/etc/cherrypick-js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ export type Channels = {
};
hashtag: {
params: {
q?: string;
q?: string[][];
};
events: {
note: (payload: Note) => void;
Expand Down
2 changes: 1 addition & 1 deletion packages/cherrypick-js/src/streaming.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export type Channels = {
};
hashtag: {
params: {
q?: string;
q?: string[][];
};
events: {
note: (payload: Note) => void;
Expand Down
55 changes: 54 additions & 1 deletion packages/frontend/src/pages/tag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>

<script lang="ts" setup>
import { computed, ref } from 'vue';
import { computed, onMounted, onUnmounted, ref } from 'vue';
import MkNotes from '@/components/MkNotes.vue';
import MkButton from '@/components/MkButton.vue';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { i18n } from '@/i18n.js';
import { $i } from '@/account.js';
import { defaultStore } from '@/store.js';
import * as os from '@/os.js';
import { useStream } from '@/stream';
import * as Misskey from 'cherrypick-js';
import { globalEvents } from '@/events';
const props = defineProps<{
tag: string;
Expand All @@ -42,6 +45,52 @@ const pagination = {
};
const notes = ref<InstanceType<typeof MkNotes>>();
//#region ChannelConnection
let connection: Misskey.ChannelConnection | null = null;
const stream = useStream();
function connectChannel() {
connection = stream.useChannel('hashtag', {
q: [[props.tag]],
});
connection?.on('note', note => {
notes.value?.pagingComponent?.prepend(note);
});
}
function disconnectChannel() {
if (connection) connection.dispose();
}
function refreshChannel() {
if (!defaultStore.state.disableStreamingTimeline) {
disconnectChannel();
connectChannel();
}
}
onMounted(() => {
globalEvents.on('reloadTimeline',() => reloadTimeline());
});
onUnmounted(() => {
disconnectChannel();
});
refreshChannel();
function reloadTimeline() {
return new Promise<void>((res) => {
if (notes.value == null) return;
notes.value.pagingComponent?.reload().then(() => {
res();
});
});
}
//#endregion
async function post() {
defaultStore.set('postFormHashtags', props.tag);
defaultStore.set('postFormWithHashtags', true);
Expand All @@ -59,6 +108,10 @@ definePageMetadata(() => ({
title: props.tag,
icon: 'ti ti-hash',
}));
defineExpose({
reloadTimeline,
});
</script>

<style lang="scss" module>
Expand Down

0 comments on commit 8f1f680

Please sign in to comment.