2016-12-28 22:49:51 +00:00
|
|
|
import * as websocket from 'websocket';
|
|
|
|
import * as redis from 'redis';
|
2017-06-12 17:12:30 +00:00
|
|
|
import read from '../common/read-messaging-message';
|
2018-03-29 11:32:18 +00:00
|
|
|
import { ParsedUrlQuery } from 'querystring';
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2018-03-07 02:40:40 +00:00
|
|
|
export default function(request: websocket.request, connection: websocket.connection, subscriber: redis.RedisClient, user: any): void {
|
2018-03-29 11:32:18 +00:00
|
|
|
const q = request.resourceURL.query as ParsedUrlQuery;
|
|
|
|
const otherparty = q.otherparty as string;
|
2016-12-28 22:49:51 +00:00
|
|
|
|
|
|
|
// Subscribe messaging stream
|
|
|
|
subscriber.subscribe(`misskey:messaging-stream:${user._id}-${otherparty}`);
|
|
|
|
subscriber.on('message', (_, data) => {
|
|
|
|
connection.send(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
connection.on('message', async (data) => {
|
|
|
|
const msg = JSON.parse(data.utf8Data);
|
|
|
|
|
|
|
|
switch (msg.type) {
|
|
|
|
case 'read':
|
2017-06-12 17:12:30 +00:00
|
|
|
if (!msg.id) return;
|
|
|
|
read(user._id, otherparty, msg.id);
|
2016-12-28 22:49:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|