Add add-timeline
event
This commit is contained in:
parent
161ebb3f40
commit
e3a1dded3d
|
@ -89,6 +89,7 @@ export default class PublicTimeline extends Vue {
|
||||||
|
|
||||||
public addTL() {
|
public addTL() {
|
||||||
let timeline: Timeline = { name: this.instance, statuses: new Map() }
|
let timeline: Timeline = { name: this.instance, statuses: new Map() }
|
||||||
|
ipcRenderer.send("add-timeline", timeline.name, 'no-auth')
|
||||||
|
|
||||||
this.showInput = false
|
this.showInput = false
|
||||||
this.instance = ""
|
this.instance = ""
|
||||||
|
|
|
@ -1,11 +1,20 @@
|
||||||
import {
|
import {
|
||||||
|
app,
|
||||||
ipcMain,
|
ipcMain,
|
||||||
Event
|
Event
|
||||||
} from 'electron'
|
} from 'electron'
|
||||||
import { Status, Response } from 'megalodon'
|
import { Status, Response } from 'megalodon'
|
||||||
|
import { join } from "path"
|
||||||
|
import Datastore from "nedb"
|
||||||
|
|
||||||
import Client from './Client'
|
import Client from './Client'
|
||||||
|
|
||||||
|
interface TimelineDoc {
|
||||||
|
_id?: string
|
||||||
|
name: string
|
||||||
|
type: string
|
||||||
|
}
|
||||||
|
|
||||||
export default class Timeline {
|
export default class Timeline {
|
||||||
private static readonly endpoints: Readonly<{
|
private static readonly endpoints: Readonly<{
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
|
@ -18,33 +27,67 @@ export default class Timeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ready() {
|
public static ready() {
|
||||||
ipcMain.on('no-auth-timeline', async (event: Event, name: string) => {
|
ipcMain.on('add-timeline', (event: Event, name: string, type: string) => this.onAddTimeline(event, name, type))
|
||||||
const client = Client.getNoAuthClient(name)
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
ipcMain.on('timeline', async (event: Event, name: string, type: string) => {
|
|
||||||
// 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]
|
ipcMain.on('no-auth-timeline', (event: Event, name: string) => this.onNoAuthTimeline(event, name))
|
||||||
try {
|
|
||||||
const client = Client.getAuthClient(name)
|
ipcMain.on('timeline', (event: Event, name: string, type: string) => this.onTimeline(event, name, type))
|
||||||
let res: Response<[Status]> = await client.get<[Status]>(url)
|
}
|
||||||
event.sender.send(`timeline-${name}-${type}`, res.data)
|
|
||||||
} catch (error) {
|
private static async onAddTimeline(event: Event, name: string, type: string) {
|
||||||
console.log(error)
|
if (!(type in this.endpoints) && type !== 'no-auth') {
|
||||||
event.sender.send(`timeline-${name}-${type}`, [], error)
|
event.sender.send(`add-timeline`, {}, new Error("Not supported type"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let db = new Datastore({
|
||||||
|
filename: join(app.getPath("userData"), "timeline.db"),
|
||||||
|
autoload: true
|
||||||
|
})
|
||||||
|
|
||||||
|
let docs: TimelineDoc = {
|
||||||
|
name: name,
|
||||||
|
type: type,
|
||||||
|
}
|
||||||
|
|
||||||
|
db.insert(docs, function (err, newDocs) {
|
||||||
|
if (err) {
|
||||||
|
let error = new Error("You cannot login already logined account.")
|
||||||
|
error.name = "ERROR_YOU_TRY_ANOTHER_ACCOUNT"
|
||||||
|
event.sender.send(`add-timeline`, {}, error)
|
||||||
|
} else {
|
||||||
|
event.sender.send(`add-timeline`, newDocs)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async onNoAuthTimeline(event: Event, name: string) {
|
||||||
|
try {
|
||||||
|
const client = Client.getNoAuthClient(name)
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async onTimeline(event: Event, name: string, type: string) {
|
||||||
|
// 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 {
|
||||||
|
const client = Client.getAuthClient(name)
|
||||||
|
let res: Response<[Status]> = await client.get<[Status]>(url)
|
||||||
|
event.sender.send(`timeline-${name}-${type}`, res.data)
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
event.sender.send(`timeline-${name}-${type}`, [], error)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -14,6 +14,7 @@
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"types": [
|
"types": [
|
||||||
"lodash",
|
"lodash",
|
||||||
|
"nedb",
|
||||||
"webpack-env",
|
"webpack-env",
|
||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user