Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
feat: メディアタイムラインを輸入 (MisskeyIO#103)
Browse files Browse the repository at this point in the history
* メディアタイムラインの実装

* refactor(stream): ストリーミングにwithFilesオプションを実装

---------

Co-authored-by: tar_bin <[email protected]>
  • Loading branch information
nafu-at and tar-bin committed Jul 24, 2023
1 parent cc45f95 commit 0532444
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2012,6 +2012,7 @@ export interface Locale {
"_timelines": {
"home": string;
"local": string;
"media": string;
"social": string;
"global": string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class GlobalTimelineChannel extends Channel {
public static shouldShare = true;
public static requireCredential = false;
private withReplies: boolean;
private withFiles: boolean;

constructor(
private metaService: MetaService,
Expand All @@ -33,6 +34,7 @@ class GlobalTimelineChannel extends Channel {
if (!policies.gtlAvailable) return;

this.withReplies = params.withReplies as boolean;
this.withFiles = params.withFiles as boolean;

// Subscribe events
this.subscriber.on('notesStream', this.onNote);
Expand All @@ -43,6 +45,9 @@ class GlobalTimelineChannel extends Channel {
if (note.visibility !== 'public') return;
if (note.channelId != null) return;

// ファイルを含まない投稿は除外
if (this.withFiles && (note.files === undefined || note.files.length === 0)) return;

// リプライなら再pack
if (note.replyId != null) {
note.reply = await this.noteEntityService.pack(note.replyId, this.user, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class HomeTimelineChannel extends Channel {
public static shouldShare = true;
public static requireCredential = true;
private withReplies: boolean;
private withFiles: boolean;

constructor(
private noteEntityService: NoteEntityService,
Expand All @@ -26,6 +27,7 @@ class HomeTimelineChannel extends Channel {
@bindThis
public async init(params: any) {
this.withReplies = params.withReplies as boolean;
this.withFiles = params.withFiles as boolean;

this.subscriber.on('notesStream', this.onNote);
}
Expand All @@ -42,6 +44,9 @@ class HomeTimelineChannel extends Channel {
// Ignore notes from instances the user has muted
if (isInstanceMuted(note, new Set<string>(this.userProfile!.mutedInstances ?? []))) return;

// ファイルを含まない投稿は除外
if (this.withFiles && (note.files === undefined || note.files.length === 0)) return;

if (['followers', 'specified'].includes(note.visibility)) {
note = await this.noteEntityService.pack(note.id, this.user!, {
detail: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class HybridTimelineChannel extends Channel {
public static shouldShare = true;
public static requireCredential = true;
private withReplies: boolean;
private withFiles: boolean;

constructor(
private metaService: MetaService,
Expand All @@ -33,6 +34,7 @@ class HybridTimelineChannel extends Channel {
if (!policies.ltlAvailable) return;

this.withReplies = params.withReplies as boolean;
this.withFiles = params.withFiles as boolean;

// Subscribe events
this.subscriber.on('notesStream', this.onNote);
Expand All @@ -51,6 +53,9 @@ class HybridTimelineChannel extends Channel {
(note.channelId != null && this.followingChannels.has(note.channelId))
)) return;

// ファイルを含まない投稿は除外
if (this.withFiles && (note.files === undefined || note.files.length === 0)) return;

if (['followers', 'specified'].includes(note.visibility)) {
note = await this.noteEntityService.pack(note.id, this.user!, {
detail: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class LocalTimelineChannel extends Channel {
public static shouldShare = true;
public static requireCredential = false;
private withReplies: boolean;
private withFiles: boolean;

constructor(
private metaService: MetaService,
Expand All @@ -32,6 +33,7 @@ class LocalTimelineChannel extends Channel {
if (!policies.ltlAvailable) return;

this.withReplies = params.withReplies as boolean;
this.withFiles = params.withFiles as boolean;

// Subscribe events
this.subscriber.on('notesStream', this.onNote);
Expand All @@ -43,6 +45,9 @@ class LocalTimelineChannel extends Channel {
if (note.visibility !== 'public') return;
if (note.channelId != null && !this.followingChannels.has(note.channelId)) return;

// ファイルを含まない投稿は除外
if (this.withFiles && (note.files === undefined || note.files.length === 0)) return;

// リプライなら再pack
if (note.replyId != null) {
note.reply = await this.noteEntityService.pack(note.replyId, this.user, {
Expand Down
9 changes: 7 additions & 2 deletions packages/frontend/src/components/MkTimeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ if (props.src === 'antenna') {
});
connection.on('note', prepend);
} else if (props.src === 'media') {
endpoint = 'notes/media-timeline';
connection = stream.useChannel('mediaTimeline', {
endpoint = 'notes/local-timeline';
query = {
withFiles: true,
withReplies: defaultStore.state.showTimelineReplies,
};
connection = stream.useChannel('hybridTimeline', {
withFiles: true,
withReplies: defaultStore.state.showTimelineReplies,
});
connection.on('note', prepend);
Expand Down

0 comments on commit 0532444

Please sign in to comment.