Merge pull request #1548 from h3poteto/iss-1514/status-update-event
refs #1514 Handle status.update event in websocket
This commit is contained in:
commit
fef39ec2b0
|
@ -37,6 +37,10 @@ stream.on('error', (err: Error) => {
|
|||
console.error(err)
|
||||
})
|
||||
|
||||
stream.on('status_update', (status: Entity.Status) => {
|
||||
console.log('updated: ', status.url)
|
||||
})
|
||||
|
||||
stream.on('heartbeat', () => {
|
||||
console.log('thump.')
|
||||
})
|
||||
|
|
|
@ -45,6 +45,10 @@ stream.on('heartbeat', () => {
|
|||
logger.debug('thump.')
|
||||
})
|
||||
|
||||
stream.on('status_update', (status: Entity.Status) => {
|
||||
logger.debug('updated: ', status.url)
|
||||
})
|
||||
|
||||
stream.on('close', () => {
|
||||
logger.debug('close')
|
||||
})
|
||||
|
|
|
@ -248,6 +248,9 @@ export default class WebSocket extends EventEmitter implements WebSocketInterfac
|
|||
this.parser.on('conversation', (conversation: MastodonAPI.Entity.Conversation) => {
|
||||
this.emit('conversation', MastodonAPI.Converter.conversation(conversation))
|
||||
})
|
||||
this.parser.on('status_update', (status: MastodonAPI.Entity.Status) => {
|
||||
this.emit('status_update', MastodonAPI.Converter.status(status))
|
||||
})
|
||||
this.parser.on('error', (err: Error) => {
|
||||
this.emit('parser-error', err)
|
||||
})
|
||||
|
@ -329,6 +332,9 @@ export class Parser extends EventEmitter {
|
|||
case 'delete':
|
||||
this.emit('delete', payload)
|
||||
break
|
||||
case 'status.update':
|
||||
this.emit('status_update', mes as MastodonAPI.Entity.Status)
|
||||
break
|
||||
default:
|
||||
this.emit('error', new Error(`Unknown event has received: ${message}`))
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import { EventEmitter } from 'events'
|
|||
|
||||
import proxyAgent, { ProxyConfig } from '../proxy_config'
|
||||
import { WebSocketInterface } from '../megalodon'
|
||||
import MastodonAPI from './api_client'
|
||||
import PleromaAPI from './api_client'
|
||||
|
||||
/**
|
||||
* WebSocket
|
||||
|
@ -237,17 +237,20 @@ export default class WebSocket extends EventEmitter implements WebSocketInterfac
|
|||
* Set up parser when receive message.
|
||||
*/
|
||||
private _setupParser() {
|
||||
this.parser.on('update', (status: MastodonAPI.Entity.Status) => {
|
||||
this.emit('update', MastodonAPI.Converter.status(status))
|
||||
this.parser.on('update', (status: PleromaAPI.Entity.Status) => {
|
||||
this.emit('update', PleromaAPI.Converter.status(status))
|
||||
})
|
||||
this.parser.on('notification', (notification: MastodonAPI.Entity.Notification) => {
|
||||
this.emit('notification', MastodonAPI.Converter.notification(notification))
|
||||
this.parser.on('notification', (notification: PleromaAPI.Entity.Notification) => {
|
||||
this.emit('notification', PleromaAPI.Converter.notification(notification))
|
||||
})
|
||||
this.parser.on('delete', (id: string) => {
|
||||
this.emit('delete', id)
|
||||
})
|
||||
this.parser.on('conversation', (conversation: MastodonAPI.Entity.Conversation) => {
|
||||
this.emit('conversation', MastodonAPI.Converter.conversation(conversation))
|
||||
this.parser.on('conversation', (conversation: PleromaAPI.Entity.Conversation) => {
|
||||
this.emit('conversation', PleromaAPI.Converter.conversation(conversation))
|
||||
})
|
||||
this.parser.on('status_update', (status: PleromaAPI.Entity.Status) => {
|
||||
this.emit('status_update', PleromaAPI.Converter.status(status))
|
||||
})
|
||||
this.parser.on('error', (err: Error) => {
|
||||
this.emit('parser-error', err)
|
||||
|
@ -319,17 +322,20 @@ export class Parser extends EventEmitter {
|
|||
|
||||
switch (event) {
|
||||
case 'update':
|
||||
this.emit('update', mes as MastodonAPI.Entity.Status)
|
||||
this.emit('update', mes as PleromaAPI.Entity.Status)
|
||||
break
|
||||
case 'notification':
|
||||
this.emit('notification', mes as MastodonAPI.Entity.Notification)
|
||||
this.emit('notification', mes as PleromaAPI.Entity.Notification)
|
||||
break
|
||||
case 'conversation':
|
||||
this.emit('conversation', mes as MastodonAPI.Entity.Conversation)
|
||||
this.emit('conversation', mes as PleromaAPI.Entity.Conversation)
|
||||
break
|
||||
case 'delete':
|
||||
this.emit('delete', payload)
|
||||
break
|
||||
case 'status.update':
|
||||
this.emit('status_update', mes as PleromaAPI.Entity.Status)
|
||||
break
|
||||
default:
|
||||
this.emit('error', new Error(`Unknown event has received: ${message}`))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue