Skip to content

Commit

Permalink
Add an option for showing notes without hashtags on timelines
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriha-chan committed Nov 7, 2023
1 parent b53d4c1 commit 45604f5
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ enableServiceworker: "Enable Push-Notifications for your Browser"
antennaUsersDescription: "List one username per line"
caseSensitive: "Case sensitive"
withReplies: "Include replies"
withHashtags: "Include notes with hashtags"
connectedTo: "Following account(s) are connected"
notesAndReplies: "Notes and replies"
withFiles: "Including files"
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ enableServiceworker: "ブラウザへのプッシュ通知を有効にする"
antennaUsersDescription: "ユーザー名を改行で区切って指定します"
caseSensitive: "大文字小文字を区別する"
withReplies: "返信を含む"
withHashtags: "ハッシュタグ付きを含む"
connectedTo: "次のアカウントに接続されています"
notesAndReplies: "投稿と返信"
withFiles: "ファイル付き"
Expand Down
1 change: 1 addition & 0 deletions locales/ja-KS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ enableServiceworker: "ブラウザにプッシュ通知が行くようにする"
antennaUsersDescription: "ユーザー名を改行で区切ったってな"
caseSensitive: "大文字と小文字は別もんや"
withReplies: "返信も入れたって"
withHashtags: "ハッシュタグのあるもんも入れたって"
connectedTo: "次のアカウントに繋がっとるで"
notesAndReplies: "投稿と返信"
withFiles: "ファイル付いとる"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const paramDef = {
withFiles: { type: 'boolean', default: false },
withReplies: { type: 'boolean', default: false },
withRenotes: { type: 'boolean', default: true },
withHashtags: { type: 'boolean', default: true },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
Expand Down Expand Up @@ -100,6 +101,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}));
}));
}

if (!ps.withHashtags) {
query.andWhere('note.tags = \'{}\'');
}
//#endregion

const timeline = await query.limit(ps.limit).getMany();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const paramDef = {
withFiles: { type: 'boolean', default: false },
withReplies: { type: 'boolean', default: false },
withRenotes: { type: 'boolean', default: true },
withHashtags: { type: 'boolean', default: true },
},
required: [],
} as const;
Expand Down Expand Up @@ -148,6 +149,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}));
}));
}

if (!ps.withHashtags) {
query.andWhere('note.tags = \'{}\'');
}
//#endregion

const timeline = await query.limit(ps.limit).getMany();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const paramDef = {
withFiles: { type: 'boolean', default: false },
withReplies: { type: 'boolean', default: false },
withRenotes: { type: 'boolean', default: true },
withHashtags: { type: 'boolean', default: true },
fileType: { type: 'array', items: {
type: 'string',
} },
Expand Down Expand Up @@ -121,6 +122,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}));
}));
}

if (!ps.withHashtags) {
query.andWhere('note.tags = \'{}\'');
}
//#endregion

const timeline = await query.limit(ps.limit).getMany();
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/server/api/endpoints/notes/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const paramDef = {
withFiles: { type: 'boolean', default: false },
withReplies: { type: 'boolean', default: false },
withRenotes: { type: 'boolean', default: true },
withHashtags: { type: 'boolean', default: true },
},
required: [],
} as const;
Expand Down Expand Up @@ -137,6 +138,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}));
}));
}

if (!ps.withHashtags) {
query.andWhere('note.tags = \'{}\'');
}
//#endregion

const timeline = await query.limit(ps.limit).getMany();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class GlobalTimelineChannel extends Channel {
public static requireCredential = false;
private withReplies: boolean;
private withRenotes: boolean;
private withHashtags: boolean;

constructor(
private metaService: MetaService,
Expand All @@ -40,6 +41,7 @@ class GlobalTimelineChannel extends Channel {

this.withReplies = params.withReplies ?? false;
this.withRenotes = params.withRenotes ?? true;
this.withHashtags = params.withHashtags ?? true;

// Subscribe events
this.subscriber.on('notesStream', this.onNote);
Expand Down Expand Up @@ -72,6 +74,8 @@ class GlobalTimelineChannel extends Channel {

if (note.renote && note.text == null && (note.fileIds == null || note.fileIds.length === 0) && !this.withRenotes) return;

if (note.tags && !this.withHashtags) return;

// Ignore notes from instances the user has muted
if (isInstanceMuted(note, new Set<string>(this.userProfile?.mutedInstances ?? []))) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class HomeTimelineChannel extends Channel {
public static requireCredential = true;
private withReplies: boolean;
private withRenotes: boolean;
private withHashtags: boolean;

constructor(
private noteEntityService: NoteEntityService,
Expand All @@ -33,6 +34,7 @@ class HomeTimelineChannel extends Channel {
public async init(params: any) {
this.withReplies = params.withReplies ?? false;
this.withRenotes = params.withRenotes ?? true;
this.withHashtags = params.withHashtags ?? true;

this.subscriber.on('notesStream', this.onNote);
}
Expand Down Expand Up @@ -85,6 +87,8 @@ class HomeTimelineChannel extends Channel {

if (note.renote && note.text == null && (note.fileIds == null || note.fileIds.length === 0) && !this.withRenotes) return;

if (note.tags && !this.withHashtags) return;

// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
if (isUserRelated(note, this.userIdsWhoMeMuting)) return;
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class HybridTimelineChannel extends Channel {
public static requireCredential = true;
private withReplies: boolean;
private withRenotes: boolean;
private withHashtags: boolean;

constructor(
private metaService: MetaService,
Expand All @@ -40,6 +41,7 @@ class HybridTimelineChannel extends Channel {

this.withReplies = params.withReplies ?? false;
this.withRenotes = params.withRenotes ?? true;
this.withHashtags = params.withHashtags ?? true;

// Subscribe events
this.subscriber.on('notesStream', this.onNote);
Expand Down Expand Up @@ -97,6 +99,8 @@ class HybridTimelineChannel extends Channel {

if (note.renote && note.text == null && (note.fileIds == null || note.fileIds.length === 0) && !this.withRenotes) return;

if (note.tags && !this.withHashtags) return;

// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
if (isUserRelated(note, this.userIdsWhoMeMuting)) return;
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class LocalTimelineChannel extends Channel {
public static requireCredential = false;
private withReplies: boolean;
private withRenotes: boolean;
private withHashtags: boolean;

constructor(
private metaService: MetaService,
Expand All @@ -39,6 +40,7 @@ class LocalTimelineChannel extends Channel {

this.withReplies = params.withReplies ?? false;
this.withRenotes = params.withRenotes ?? true;
this.withHashtags = params.withHashtags ?? true;

// Subscribe events
this.subscriber.on('notesStream', this.onNote);
Expand Down Expand Up @@ -72,6 +74,8 @@ class LocalTimelineChannel extends Channel {

if (note.renote && note.text == null && (note.fileIds == null || note.fileIds.length === 0) && !this.withRenotes) return;

if (note.tags && !this.withHashtags) return;

// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
if (isUserRelated(note, this.userIdsWhoMeMuting)) return;
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
Expand Down
10 changes: 10 additions & 0 deletions packages/frontend/src/components/MkTimeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ const props = withDefaults(defineProps<{
sound?: boolean;
withRenotes?: boolean;
withReplies?: boolean;
withHashtags?: boolean;
onlyFiles?: boolean;
}>(), {
withRenotes: true,
withReplies: false,
withHashtags: true;
onlyFiles: false,
});

Expand Down Expand Up @@ -71,11 +73,13 @@ if (props.src === 'antenna') {
query = {
withRenotes: props.withRenotes,
withReplies: props.withReplies,
withHashtags: props.withHashtags,
withFiles: props.onlyFiles ? true : undefined,
};
connection = stream.useChannel('homeTimeline', {
withRenotes: props.withRenotes,
withReplies: props.withReplies,
withHashtags: props.withHashtags,
withFiles: props.onlyFiles ? true : undefined,
});
connection.on('note', prepend);
Expand All @@ -86,11 +90,13 @@ if (props.src === 'antenna') {
query = {
withRenotes: props.withRenotes,
withReplies: props.withReplies,
withHashtags: props.withHashtags,
withFiles: props.onlyFiles ? true : undefined,
};
connection = stream.useChannel('localTimeline', {
withRenotes: props.withRenotes,
withReplies: props.withReplies,
withHashtags: props.withHashtags,
withFiles: props.onlyFiles ? true : undefined,
});
connection.on('note', prepend);
Expand All @@ -99,11 +105,13 @@ if (props.src === 'antenna') {
query = {
withRenotes: props.withRenotes,
withReplies: props.withReplies,
withHashtags: props.withHashtags,
withFiles: props.onlyFiles ? true : undefined,
};
connection = stream.useChannel('hybridTimeline', {
withRenotes: props.withRenotes,
withReplies: props.withReplies,
withHashtags: props.withHashtags,
withFiles: props.onlyFiles ? true : undefined,
});
connection.on('note', prepend);
Expand All @@ -112,11 +120,13 @@ if (props.src === 'antenna') {
query = {
withRenotes: props.withRenotes,
withReplies: props.withReplies,
withHashtags: props.withHashtags,
withFiles: props.onlyFiles ? true : undefined,
};
connection = stream.useChannel('globalTimeline', {
withRenotes: props.withRenotes,
withReplies: props.withReplies,
withHashtags: props.withHashtags,
withFiles: props.onlyFiles ? true : undefined,
});
connection.on('note', prepend);
Expand Down
7 changes: 7 additions & 0 deletions packages/frontend/src/pages/timeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SPDX-License-Identifier: AGPL-3.0-only
:list="src.split(':')[1]"
:withRenotes="withRenotes"
:withReplies="withReplies"
:withHashtags="withHashtags"
:onlyFiles="onlyFiles"
:sound="true"
@queue="queueUpdated"
Expand Down Expand Up @@ -63,6 +64,7 @@ let srcWhenNotSignin = $ref(isLocalTimelineAvailable ? 'local' : 'global');
const src = $computed({ get: () => ($i ? defaultStore.reactiveState.tl.value.src : srcWhenNotSignin), set: (x) => saveSrc(x) });
const withRenotes = $ref(true);
const withReplies = $ref(false);
const withHashtags = $ref(true);
const onlyFiles = $ref(false);

watch($$(src), () => queue = 0);
Expand Down Expand Up @@ -149,6 +151,11 @@ const headerActions = $computed(() => [{
text: i18n.ts.withReplies,
icon: 'ti ti-arrow-back-up',
ref: $$(withReplies),
}, {
type: 'switch',
text: i18n.ts.withHashtags,
icon: 'ti ti-arrow-back-up',
ref: $$(withHashtags),
}, {
type: 'switch',
text: i18n.ts.fileAttachedOnly,
Expand Down

0 comments on commit 45604f5

Please sign in to comment.