Add error handling to get timeline

Revert to async get
Fix freeze when invalid domain
This commit is contained in:
kPherox 2019-04-25 14:21:21 +09:00
parent d47aaf66c1
commit 8f3edf76e6
No known key found for this signature in database
GPG Key ID: C04751C2BFA2F62D
2 changed files with 24 additions and 21 deletions

View File

@ -68,7 +68,8 @@ type DeleteListener = (e: Event, id: number) => void
type Instance = string
type Timeline = {
name: string
statuses?: Map<number, Status>
statuses: Map<number, Status>
error?: Error
}
type Timelines = Timeline[]
type UpdateListener = (e: Event, status: Status) => void
@ -107,35 +108,36 @@ export default class AddColumn extends Vue {
}
public addTL() {
let timeline: Timeline = { name: this.instance }
let timeline: Timeline = { name: this.instance, statuses: new Map() }
this.showInput = false
this.instance = ""
this.pubTL.push(timeline)
// TL
this.loadTL(timeline)
ipcRenderer.once(`timeline-${timeline.name}-no-auth`, (e: Event, statuses: Status[], error?: Error) => {
timeline.error = error
if (error === undefined) {
this.loadTL(timeline, statuses)
}
this.$forceUpdate()
})
ipcRenderer.send("no-auth-timeline", timeline.name)
}
public loadTL(timeline: Timeline, statuses: Status[]) {
timeline.statuses = new Map(
statuses.map((status): [number, Status] => [status.id, status])
)
// streaming
this.subscribeStreaming(timeline)
}
public loadTL(timeline: Timeline) {
let statuses: Status[] = ipcRenderer.sendSync(
"no-auth-timeline",
timeline.name
)
timeline.statuses = new Map(
statuses.map((status): [number, Status] => [status.id, status])
)
}
public async subscribeStreaming(timeline: Timeline) {
// update
let updateListener = (_: Event, status: Status) => {
if (timeline.statuses === undefined) {
timeline.statuses = new Map()
}
timeline.statuses.set(status.id, status)
this.$forceUpdate()
}
@ -147,9 +149,6 @@ export default class AddColumn extends Vue {
// delete
let deleteListener = (_: Event, id: number) => {
if (timeline.statuses === undefined) {
timeline.statuses = new Map()
}
timeline.statuses.delete(id)
this.$forceUpdate()
}

View File

@ -11,8 +11,12 @@ export default class Timeline {
public static ready() {
ipcMain.on('no-auth-timeline', async (event: Event, name: string) => {
const client = Client.getNoAuthClient(name)
let res: Response<[Status]> = await client.get<[Status]>('/timelines/public?local=true')
event.returnValue = res.data
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)
}
})
}
}