2019-04-24 01:07:20 +09:00
|
|
|
import {
|
2019-04-24 19:31:06 +09:00
|
|
|
ipcMain,
|
|
|
|
Event
|
2019-04-24 01:07:20 +09:00
|
|
|
} from 'electron'
|
2019-04-24 05:30:16 +09:00
|
|
|
import { Status, Response } from 'megalodon'
|
2019-04-24 03:40:04 +09:00
|
|
|
|
2019-04-24 03:58:06 +09:00
|
|
|
import Client from './Client'
|
|
|
|
|
2019-04-24 01:07:20 +09:00
|
|
|
export default class Timeline {
|
2019-04-30 14:39:00 +09:00
|
|
|
private static readonly endpoints: Readonly<{
|
|
|
|
[key: string]: string
|
|
|
|
}> = {
|
|
|
|
home: "/timelines/home",
|
|
|
|
notify: "/timelines/notifications",
|
|
|
|
dm: "/conversations",
|
|
|
|
local: "/timelines/public?local=true",
|
|
|
|
fediverse: "/timelines/public",
|
|
|
|
}
|
|
|
|
|
2019-04-24 03:40:04 +09:00
|
|
|
public static ready() {
|
2019-04-24 05:30:16 +09:00
|
|
|
ipcMain.on('no-auth-timeline', async (event: Event, name: string) => {
|
|
|
|
const client = Client.getNoAuthClient(name)
|
2019-04-25 14:21:21 +09:00
|
|
|
try {
|
|
|
|
let res: Response<[Status]> = await client.get<[Status]>('/timelines/public?local=true')
|
|
|
|
event.sender.send(`timeline-${name}-no-auth`, res.data)
|
|
|
|
} catch (error) {
|
|
|
|
event.sender.send(`timeline-${name}-no-auth`, [], error)
|
|
|
|
}
|
2019-04-24 03:40:04 +09:00
|
|
|
})
|
2019-04-28 22:47:11 +09:00
|
|
|
ipcMain.on('timeline', async (event: Event, name: string, type: string) => {
|
2019-04-30 14:39:00 +09:00
|
|
|
// home/notify/dm/local/fediverse/integrated/localPlus
|
|
|
|
// integratedはまだ。dmはAPI構造が違う。notifyはmax_idとかのためにヘッダー取らないといけない。
|
|
|
|
// integratedはレンダラープロセス側でそれぞれ取得させる形で、ここでは考慮しないのがいいのかな
|
|
|
|
if (!(type in this.endpoints)) {
|
|
|
|
event.sender.send(`timeline-${name}-${type}`, [], new Error("Not supported type"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let url = this.endpoints[type]
|
2019-04-28 22:47:11 +09:00
|
|
|
try {
|
2019-04-30 14:39:00 +09:00
|
|
|
const client = Client.getAuthClient(name)
|
2019-04-28 22:47:11 +09:00
|
|
|
let res: Response<[Status]> = await client.get<[Status]>(url)
|
2019-04-30 14:39:00 +09:00
|
|
|
event.sender.send(`timeline-${name}-${type}`, res.data)
|
2019-04-28 22:47:11 +09:00
|
|
|
} catch (error) {
|
2019-04-30 14:39:00 +09:00
|
|
|
console.log(error)
|
|
|
|
event.sender.send(`timeline-${name}-${type}`, [], error)
|
2019-04-28 22:47:11 +09:00
|
|
|
}
|
|
|
|
})
|
2019-04-24 01:07:20 +09:00
|
|
|
}
|
|
|
|
}
|