This commit is contained in:
cutls 2023-02-08 09:23:13 +09:00
parent 8a0e88dcc2
commit 055e8827bd
3 changed files with 11 additions and 7 deletions

View file

@ -38,7 +38,7 @@ export default class Misskey implements MegalodonInterface {
this.proxyConfig = proxyConfig
}
public baseUrlToHost(baseUrl: string): string {
private baseUrlToHost(baseUrl: string): string {
return baseUrl.replace('https://', '')
}

View file

@ -14,7 +14,7 @@ import MisskeyAPI from './api_client'
export default class WebSocket extends EventEmitter implements WebSocketInterface {
public url: string
public channel: 'user' | 'localTimeline' | 'hybridTimeline' | 'globalTimeline' | 'conversation' | 'list'
public parser: Parser
public parser: any
public headers: { [key: string]: string }
public proxyConfig: ProxyConfig | false = false
public listId: string | null = null
@ -74,6 +74,10 @@ export default class WebSocket extends EventEmitter implements WebSocketInterfac
this._startWebSocketConnection()
}
private baseUrlToHost(baseUrl: string): string {
return baseUrl.replace('https://', '')
}
/**
* Reset connection and start new websocket connection.
*/
@ -282,13 +286,13 @@ export default class WebSocket extends EventEmitter implements WebSocketInterfac
*/
private _setupParser() {
this.parser.on('update', (note: MisskeyAPI.Entity.Note) => {
this.emit('update', MisskeyAPI.Converter.note(note))
this.emit('update', MisskeyAPI.Converter.note(note, this.baseUrlToHost(this.url)))
})
this.parser.on('notification', (notification: MisskeyAPI.Entity.Notification) => {
this.emit('notification', MisskeyAPI.Converter.notification(notification))
this.emit('notification', MisskeyAPI.Converter.notification(notification, this.baseUrlToHost(this.url)))
})
this.parser.on('conversation', (note: MisskeyAPI.Entity.Note) => {
this.emit('conversation', MisskeyAPI.Converter.noteToConversation(note))
this.emit('conversation', MisskeyAPI.Converter.noteToConversation(note, this.baseUrlToHost(this.url)))
})
this.parser.on('error', (err: Error) => {
this.emit('parser-error', err)

View file

@ -198,7 +198,7 @@ describe('api_client', () => {
replyId: null,
renoteId: null
}
const megalodonStatus = MisskeyAPI.Converter.note(note)
const megalodonStatus = MisskeyAPI.Converter.note(note, user.host || 'misskey.io')
expect(megalodonStatus.plain_content).toEqual(plainContent)
expect(megalodonStatus.content).toEqual(content)
})
@ -222,7 +222,7 @@ describe('api_client', () => {
replyId: null,
renoteId: null
}
const megalodonStatus = MisskeyAPI.Converter.note(note)
const megalodonStatus = MisskeyAPI.Converter.note(note, user.host || 'misskey.io')
expect(megalodonStatus.plain_content).toEqual(plainContent)
expect(megalodonStatus.content).toEqual(content)
})