diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2020-08-18 22:44:21 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-18 22:44:21 +0900 |
| commit | 9855405b8989713b81709fc1700e2ead97423467 (patch) | |
| tree | 54254d2159378d1903e962f0fb37c799bb0f4464 /src/server/api/stream | |
| parent | Sign (request-target) Fix #6652 (#6656) (diff) | |
| download | sharkey-9855405b8989713b81709fc1700e2ead97423467.tar.gz sharkey-9855405b8989713b81709fc1700e2ead97423467.tar.bz2 sharkey-9855405b8989713b81709fc1700e2ead97423467.zip | |
Channel (#6621)
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wop
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* add notes
* wip
* wip
* wip
* wip
* sound
* wip
* add kick_gaba2
* wip
Diffstat (limited to 'src/server/api/stream')
| -rw-r--r-- | src/server/api/stream/channel.ts | 4 | ||||
| -rw-r--r-- | src/server/api/stream/channels/channel.ts | 49 | ||||
| -rw-r--r-- | src/server/api/stream/channels/global-timeline.ts | 1 | ||||
| -rw-r--r-- | src/server/api/stream/channels/home-timeline.ts | 8 | ||||
| -rw-r--r-- | src/server/api/stream/channels/hybrid-timeline.ts | 12 | ||||
| -rw-r--r-- | src/server/api/stream/channels/index.ts | 2 | ||||
| -rw-r--r-- | src/server/api/stream/channels/local-timeline.ts | 1 | ||||
| -rw-r--r-- | src/server/api/stream/index.ts | 21 |
8 files changed, 91 insertions, 7 deletions
diff --git a/src/server/api/stream/channel.ts b/src/server/api/stream/channel.ts index 82a95ad3d7..9b7c31e7bb 100644 --- a/src/server/api/stream/channel.ts +++ b/src/server/api/stream/channel.ts @@ -27,6 +27,10 @@ export default abstract class Channel { return this.connection.muting; } + protected get followingChannels() { + return this.connection.followingChannels; + } + protected get subscriber() { return this.connection.subscriber; } diff --git a/src/server/api/stream/channels/channel.ts b/src/server/api/stream/channels/channel.ts new file mode 100644 index 0000000000..c24b3db937 --- /dev/null +++ b/src/server/api/stream/channels/channel.ts @@ -0,0 +1,49 @@ +import autobind from 'autobind-decorator'; +import Channel from '../channel'; +import { Notes } from '../../../../models'; +import { isMutedUserRelated } from '../../../../misc/is-muted-user-related'; +import { PackedNote } from '../../../../models/repositories/note'; + +export default class extends Channel { + public readonly chName = 'channel'; + public static shouldShare = false; + public static requireCredential = false; + private channelId: string; + + @autobind + public async init(params: any) { + this.channelId = params.channelId as string; + + // Subscribe stream + this.subscriber.on('notesStream', this.onNote); + } + + @autobind + private async onNote(note: PackedNote) { + if (note.channelId !== this.channelId) return; + + // リプライなら再pack + if (note.replyId != null) { + note.reply = await Notes.pack(note.replyId, this.user, { + detail: true + }); + } + // Renoteなら再pack + if (note.renoteId != null) { + note.renote = await Notes.pack(note.renoteId, this.user, { + detail: true + }); + } + + // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する + if (isMutedUserRelated(note, this.muting)) return; + + this.send('note', note); + } + + @autobind + public dispose() { + // Unsubscribe events + this.subscriber.off('notesStream', this.onNote); + } +} diff --git a/src/server/api/stream/channels/global-timeline.ts b/src/server/api/stream/channels/global-timeline.ts index d530907d8d..8c97e67226 100644 --- a/src/server/api/stream/channels/global-timeline.ts +++ b/src/server/api/stream/channels/global-timeline.ts @@ -25,6 +25,7 @@ export default class extends Channel { @autobind private async onNote(note: PackedNote) { if (note.visibility !== 'public') return; + if (note.channelId != null) return; // リプライなら再pack if (note.replyId != null) { diff --git a/src/server/api/stream/channels/home-timeline.ts b/src/server/api/stream/channels/home-timeline.ts index caf4ccf5e9..15fe7fa6f0 100644 --- a/src/server/api/stream/channels/home-timeline.ts +++ b/src/server/api/stream/channels/home-timeline.ts @@ -18,8 +18,12 @@ export default class extends Channel { @autobind private async onNote(note: PackedNote) { - // その投稿のユーザーをフォローしていなかったら弾く - if (this.user!.id !== note.userId && !this.following.includes(note.userId)) return; + if (note.channelId) { + if (!this.followingChannels.includes(note.channelId)) return; + } else { + // その投稿のユーザーをフォローしていなかったら弾く + if ((this.user!.id !== note.userId) && !this.following.includes(note.userId)) return; + } if (['followers', 'specified'].includes(note.visibility)) { note = await Notes.pack(note.id, this.user!, { diff --git a/src/server/api/stream/channels/hybrid-timeline.ts b/src/server/api/stream/channels/hybrid-timeline.ts index 1aec98aa72..4dc5f01a32 100644 --- a/src/server/api/stream/channels/hybrid-timeline.ts +++ b/src/server/api/stream/channels/hybrid-timeline.ts @@ -23,11 +23,15 @@ export default class extends Channel { @autobind private async onNote(note: PackedNote) { - // 自分自身の投稿 または その投稿のユーザーをフォローしている または 全体公開のローカルの投稿 の場合だけ + // チャンネルの投稿ではなく、自分自身の投稿 または + // チャンネルの投稿ではなく、その投稿のユーザーをフォローしている または + // チャンネルの投稿ではなく、全体公開のローカルの投稿 または + // フォローしているチャンネルの投稿 の場合だけ if (!( - this.user!.id === note.userId || - this.following.includes(note.userId) || - ((note.user as PackedUser).host == null && note.visibility === 'public') + (note.channelId == null && this.user!.id === note.userId) || + (note.channelId == null && this.following.includes(note.userId)) || + (note.channelId == null && ((note.user as PackedUser).host == null && note.visibility === 'public')) || + (note.channelId != null && this.followingChannels.includes(note.channelId)) )) return; if (['followers', 'specified'].includes(note.visibility)) { diff --git a/src/server/api/stream/channels/index.ts b/src/server/api/stream/channels/index.ts index 6efad078c6..1841573043 100644 --- a/src/server/api/stream/channels/index.ts +++ b/src/server/api/stream/channels/index.ts @@ -11,6 +11,7 @@ import messaging from './messaging'; import messagingIndex from './messaging-index'; import drive from './drive'; import hashtag from './hashtag'; +import channel from './channel'; import admin from './admin'; import gamesReversi from './games/reversi'; import gamesReversiGame from './games/reversi-game'; @@ -29,6 +30,7 @@ export default { messagingIndex, drive, hashtag, + channel, admin, gamesReversi, gamesReversiGame diff --git a/src/server/api/stream/channels/local-timeline.ts b/src/server/api/stream/channels/local-timeline.ts index 6426ccc23f..baeae86603 100644 --- a/src/server/api/stream/channels/local-timeline.ts +++ b/src/server/api/stream/channels/local-timeline.ts @@ -27,6 +27,7 @@ export default class extends Channel { private async onNote(note: PackedNote) { if ((note.user as PackedUser).host !== null) return; if (note.visibility !== 'public') return; + if (note.channelId != null && !this.followingChannels.includes(note.channelId)) return; // リプライなら再pack if (note.replyId != null) { diff --git a/src/server/api/stream/index.ts b/src/server/api/stream/index.ts index bebf88a7cd..d420c6e794 100644 --- a/src/server/api/stream/index.ts +++ b/src/server/api/stream/index.ts @@ -7,7 +7,8 @@ import Channel from './channel'; import channels from './channels'; import { EventEmitter } from 'events'; import { User } from '../../../models/entities/user'; -import { Users, Followings, Mutings, UserProfiles } from '../../../models'; +import { Channel as ChannelModel } from '../../../models/entities/channel'; +import { Users, Followings, Mutings, UserProfiles, ChannelFollowings } from '../../../models'; import { ApiError } from '../error'; import { AccessToken } from '../../../models/entities/access-token'; import { UserProfile } from '../../../models/entities/user-profile'; @@ -20,6 +21,7 @@ export default class Connection { public userProfile?: UserProfile; public following: User['id'][] = []; public muting: User['id'][] = []; + public followingChannels: ChannelModel['id'][] = []; public token?: AccessToken; private wsConnection: websocket.connection; public subscriber: EventEmitter; @@ -27,6 +29,7 @@ export default class Connection { private subscribingNotes: any = {}; private followingClock: NodeJS.Timer; private mutingClock: NodeJS.Timer; + private followingChannelsClock: NodeJS.Timer; private userProfileClock: NodeJS.Timer; constructor( @@ -53,6 +56,9 @@ export default class Connection { this.updateMuting(); this.mutingClock = setInterval(this.updateMuting, 5000); + this.updateFollowingChannels(); + this.followingChannelsClock = setInterval(this.updateFollowingChannels, 5000); + this.updateUserProfile(); this.userProfileClock = setInterval(this.updateUserProfile, 5000); } @@ -269,6 +275,18 @@ export default class Connection { } @autobind + private async updateFollowingChannels() { + const followings = await ChannelFollowings.find({ + where: { + followerId: this.user!.id + }, + select: ['followeeId'] + }); + + this.followingChannels = followings.map(x => x.followeeId); + } + + @autobind private async updateUserProfile() { this.userProfile = await UserProfiles.findOne({ userId: this.user!.id @@ -286,6 +304,7 @@ export default class Connection { if (this.followingClock) clearInterval(this.followingClock); if (this.mutingClock) clearInterval(this.mutingClock); + if (this.followingChannelsClock) clearInterval(this.followingChannelsClock); if (this.userProfileClock) clearInterval(this.userProfileClock); } } |