Fix timeline event name
Add error for not supported timeline type
This commit is contained in:
parent
51826ecaab
commit
654b6942c3
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
try {
|
// integratedはまだ。dmはAPI構造が違う。notifyはmax_idとかのためにヘッダー取らないといけない。
|
||||||
let url: string = ""
|
// integratedはレンダラープロセス側でそれぞれ取得させる形で、ここでは考慮しないのがいいのかな
|
||||||
//home/notify/dm/local/fediverse/integrated/localPlus
|
if (!(type in this.endpoints)) {
|
||||||
//integratedはまだ。dmはAPI構造が違う。notifyはmax_idとかのためにヘッダー取らないといけない。
|
event.sender.send(`timeline-${name}-${type}`, [], new Error("Not supported type"))
|
||||||
if(type=="home"){
|
return
|
||||||
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 url = this.endpoints[type]
|
||||||
|
try {
|
||||||
|
const client = Client.getAuthClient(name)
|
||||||
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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user