wip
This commit is contained in:
@@ -13,7 +13,7 @@ import Watching from '../../models/post-watching';
|
||||
import serialize from '../../serializers/post';
|
||||
import notify from '../../common/notify';
|
||||
import watch from '../../common/watch-post';
|
||||
import event from '../../event';
|
||||
import { default as event, publishChannelStream } from '../../event';
|
||||
import config from '../../../conf';
|
||||
|
||||
/**
|
||||
@@ -258,6 +258,11 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
||||
// Publish event to myself's stream
|
||||
event(user._id, 'post', postObj);
|
||||
|
||||
// Publish event to channel
|
||||
if (channel) {
|
||||
publishChannelStream(channel._id, 'post', postObj);
|
||||
}
|
||||
|
||||
// Fetch all followers
|
||||
const followers = await Following
|
||||
.find({
|
||||
|
@@ -25,6 +25,10 @@ class MisskeyEvent {
|
||||
this.publish(`messaging-stream:${userId}-${otherpartyId}`, type, typeof value === 'undefined' ? null : value);
|
||||
}
|
||||
|
||||
public publishChannelStream(channelId: ID, type: string, value?: any): void {
|
||||
this.publish(`channel-stream:${channelId}`, type, typeof value === 'undefined' ? null : value);
|
||||
}
|
||||
|
||||
private publish(channel: string, type: string, value?: any): void {
|
||||
const message = value == null ?
|
||||
{ type: type } :
|
||||
@@ -41,3 +45,5 @@ export default ev.publishUserStream.bind(ev);
|
||||
export const publishPostStream = ev.publishPostStream.bind(ev);
|
||||
|
||||
export const publishMessagingStream = ev.publishMessagingStream.bind(ev);
|
||||
|
||||
export const publishChannelStream = ev.publishChannelStream.bind(ev);
|
||||
|
12
src/api/stream/channel.ts
Normal file
12
src/api/stream/channel.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import * as websocket from 'websocket';
|
||||
import * as redis from 'redis';
|
||||
|
||||
export default function(request: websocket.request, connection: websocket.connection, subscriber: redis.RedisClient): void {
|
||||
const channel = request.resourceURL.query.channel;
|
||||
|
||||
// Subscribe channel stream
|
||||
subscriber.subscribe(`misskey:channel-stream:${channel}`);
|
||||
subscriber.on('message', (_, data) => {
|
||||
connection.send(data);
|
||||
});
|
||||
}
|
@@ -9,6 +9,7 @@ import isNativeToken from './common/is-native-token';
|
||||
import homeStream from './stream/home';
|
||||
import messagingStream from './stream/messaging';
|
||||
import serverStream from './stream/server';
|
||||
import channelStream from './stream/channel';
|
||||
|
||||
module.exports = (server: http.Server) => {
|
||||
/**
|
||||
@@ -26,14 +27,6 @@ module.exports = (server: http.Server) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const user = await authenticate(request.resourceURL.query.i);
|
||||
|
||||
if (user == null) {
|
||||
connection.send('authentication-failed');
|
||||
connection.close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Connect to Redis
|
||||
const subscriber = redis.createClient(
|
||||
config.redis.port, config.redis.host);
|
||||
@@ -43,6 +36,19 @@ module.exports = (server: http.Server) => {
|
||||
subscriber.quit();
|
||||
});
|
||||
|
||||
if (request.resourceURL.pathname === '/channel') {
|
||||
channelStream(request, connection, subscriber);
|
||||
return;
|
||||
}
|
||||
|
||||
const user = await authenticate(request.resourceURL.query.i);
|
||||
|
||||
if (user == null) {
|
||||
connection.send('authentication-failed');
|
||||
connection.close();
|
||||
return;
|
||||
}
|
||||
|
||||
const channel =
|
||||
request.resourceURL.pathname === '/' ? homeStream :
|
||||
request.resourceURL.pathname === '/messaging' ? messagingStream :
|
||||
|
Reference in New Issue
Block a user