diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-09-17 09:00:20 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-09-17 09:00:20 +0900 |
| commit | 109738ccb9ef8c203685e6f4bc31986ac2a17046 (patch) | |
| tree | f91e8bb9c9ec445a10b018a934c88ebbdfeb8db1 /src/server/api/stream | |
| parent | 8.44.1 (diff) | |
| download | sharkey-109738ccb9ef8c203685e6f4bc31986ac2a17046.tar.gz sharkey-109738ccb9ef8c203685e6f4bc31986ac2a17046.tar.bz2 sharkey-109738ccb9ef8c203685e6f4bc31986ac2a17046.zip | |
ハッシュタグタイムラインを実装
Diffstat (limited to 'src/server/api/stream')
| -rw-r--r-- | src/server/api/stream/hashtag.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/server/api/stream/hashtag.ts b/src/server/api/stream/hashtag.ts new file mode 100644 index 0000000000..db2806e796 --- /dev/null +++ b/src/server/api/stream/hashtag.ts @@ -0,0 +1,48 @@ +import * as websocket from 'websocket'; +import Xev from 'xev'; + +import { IUser } from '../../../models/user'; +import Mute from '../../../models/mute'; +import { pack } from '../../../models/note'; + +export default async function( + request: websocket.request, + connection: websocket.connection, + subscriber: Xev, + user?: IUser +) { + const mute = user ? await Mute.find({ muterId: user._id }) : null; + const mutedUserIds = mute ? mute.map(m => m.muteeId.toString()) : []; + + const q: Array<string[]> = JSON.parse((request.resourceURL.query as any).q); + + // Subscribe stream + subscriber.on('hashtag', async note => { + const matched = q.some(tags => tags.every(tag => note.tags.map((t: string) => t.toLowerCase()).includes(tag.toLowerCase()))); + if (!matched) return; + + // Renoteなら再pack + if (note.renoteId != null) { + note.renote = await pack(note.renoteId, user, { + detail: true + }); + } + + //#region 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する + if (mutedUserIds.indexOf(note.userId) != -1) { + return; + } + if (note.reply != null && mutedUserIds.indexOf(note.reply.userId) != -1) { + return; + } + if (note.renote != null && mutedUserIds.indexOf(note.renote.userId) != -1) { + return; + } + //#endregion + + connection.send(JSON.stringify({ + type: 'note', + body: note + })); + }); +} |