From 654b6942c3a94b5f1aaca14a062a2a8d46a4c5ed Mon Sep 17 00:00:00 2001 From: kPherox Date: Tue, 30 Apr 2019 14:39:00 +0900 Subject: [PATCH] Fix timeline event name Add error for not supported timeline type --- src/main/Auth.ts | 5 ++--- src/main/Timeline.ts | 40 +++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/main/Auth.ts b/src/main/Auth.ts index 7baebffb..4909c5be 100644 --- a/src/main/Auth.ts +++ b/src/main/Auth.ts @@ -69,12 +69,11 @@ export default class Auth { ) 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, redirectUri) + this.auth(event, code, instance, appData.clientId, appData.clientSecret, appData.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 }> try { tokenData = await Mastodon.fetchAccessToken(clientId, clientSecret, code, "https://" + instance, redirectUri) diff --git a/src/main/Timeline.ts b/src/main/Timeline.ts index 6e80ba51..d66f85fb 100644 --- a/src/main/Timeline.ts +++ b/src/main/Timeline.ts @@ -7,6 +7,16 @@ import { Status, Response } from 'megalodon' import Client from './Client' 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() { ipcMain.on('no-auth-timeline', async (event: Event, name: string) => { const client = Client.getNoAuthClient(name) @@ -18,26 +28,22 @@ export default class Timeline { } }) 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 { - let url: string = "" - //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" - } + const client = Client.getAuthClient(name) 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) { - event.sender.send(`timeline-${name}-no-auth`, [], error) + console.log(error) + event.sender.send(`timeline-${name}-${type}`, [], error) } }) }