Fix timeline event name

Add error for not supported timeline type
This commit is contained in:
kPherox 2019-04-30 14:39:00 +09:00
parent 51826ecaab
commit 654b6942c3
No known key found for this signature in database
GPG Key ID: C04751C2BFA2F62D
2 changed files with 25 additions and 20 deletions

View File

@ -69,12 +69,11 @@ export default class Auth {
) )
ipcMain.once("new-account-auth", (event: Event, code: string, instance: string) => { ipcMain.once("new-account-auth", (event: Event, code: string, instance: string) => {
let redirectUri = useURLScheme ? this.redirectUri : undefined this.auth(event, code, instance, appData.clientId, appData.clientSecret, appData.redirectUri)
this.auth(event, code, instance, appData.clientId, appData.clientSecret, redirectUri)
}) })
} }
private static async auth(event: Event, code: string, instance: string, clientId: string, clientSecret: string, redirectUri?: string) { private static async auth(event: Event, code: string, instance: string, clientId: string, clientSecret: string, redirectUri: string) {
let tokenData: Partial<{ accessToken: string }> let tokenData: Partial<{ accessToken: string }>
try { try {
tokenData = await Mastodon.fetchAccessToken(clientId, clientSecret, code, "https://" + instance, redirectUri) tokenData = await Mastodon.fetchAccessToken(clientId, clientSecret, code, "https://" + instance, redirectUri)

View File

@ -7,6 +7,16 @@ import { Status, Response } from 'megalodon'
import Client from './Client' import Client from './Client'
export default class Timeline { export default class Timeline {
private static readonly endpoints: Readonly<{
[key: string]: string
}> = {
home: "/timelines/home",
notify: "/timelines/notifications",
dm: "/conversations",
local: "/timelines/public?local=true",
fediverse: "/timelines/public",
}
public static ready() { public static ready() {
ipcMain.on('no-auth-timeline', async (event: Event, name: string) => { ipcMain.on('no-auth-timeline', async (event: Event, name: string) => {
const client = Client.getNoAuthClient(name) const client = Client.getNoAuthClient(name)
@ -18,26 +28,22 @@ export default class Timeline {
} }
}) })
ipcMain.on('timeline', async (event: Event, name: string, type: string) => { ipcMain.on('timeline', async (event: Event, name: string, type: string) => {
const client = Client.getAuthClient(name) // 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]
try { try {
let url: string = "" const client = Client.getAuthClient(name)
//home/notify/dm/local/fediverse/integrated/localPlus
//integratedはまだ。dmはAPI構造が違う。notifyはmax_idとかのためにヘッダー取らないといけない。
if(type=="home"){
url="/timelines/home"
}else if(type=="notify"){
url="/timelines/notifications"
}else if(type=="dm"){
url="/conversations"
}else if(type=="local"){
url="/timelines/public?local=true"
}else if(type=="fediverse"){
url="/timelines/public"
}
let res: Response<[Status]> = await client.get<[Status]>(url) let res: Response<[Status]> = await client.get<[Status]>(url)
event.sender.send(`timeline-${name}-no-auth`, res.data) event.sender.send(`timeline-${name}-${type}`, res.data)
} catch (error) { } catch (error) {
event.sender.send(`timeline-${name}-no-auth`, [], error) console.log(error)
event.sender.send(`timeline-${name}-${type}`, [], error)
} }
}) })
} }