From da6ceefe346ff52c1c40a990a7407bf3d731e438 Mon Sep 17 00:00:00 2001 From: Cutls Date: Sun, 28 Apr 2019 22:47:11 +0900 Subject: [PATCH] Add: WIP: Timeline (rend/main) --- package-lock.json | 41 ++---- src/components/AddColumn/PublicTimeline.vue | 1 - src/components/AddColumn/UserTimeline.vue | 135 ++++++++++++++++++-- src/main/Application.ts | 1 - src/main/Auth.ts | 2 + src/main/Client.ts | 17 ++- src/main/Timeline.ts | 23 ++++ 7 files changed, 172 insertions(+), 48 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5ddf7a3c..c57c4ea6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5431,8 +5431,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -5453,14 +5452,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -5475,20 +5472,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -5605,8 +5599,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -5618,7 +5611,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -5633,7 +5625,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -5641,14 +5632,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -5667,7 +5656,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -5748,8 +5736,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -5761,7 +5748,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -5847,8 +5833,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -5884,7 +5869,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -5904,7 +5888,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -5948,14 +5931,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, diff --git a/src/components/AddColumn/PublicTimeline.vue b/src/components/AddColumn/PublicTimeline.vue index 6dd79759..40922722 100644 --- a/src/components/AddColumn/PublicTimeline.vue +++ b/src/components/AddColumn/PublicTimeline.vue @@ -14,7 +14,6 @@
{{value.name}} -
+
+
+
+ {{value.name}}/{{value.type}} + +
+
@@ -62,4 +163,12 @@ label { display: none; } } +#timelines { + display: flex; + width: 100%; +} +.tl { + height: 100%; + flex-grow: 4; +} \ No newline at end of file diff --git a/src/main/Application.ts b/src/main/Application.ts index 4a5ac1c1..06d177ad 100644 --- a/src/main/Application.ts +++ b/src/main/Application.ts @@ -30,7 +30,6 @@ export default class Application { private constructor() { this.isDarkMode = systemPreferences.isDarkMode() - app.on('window-all-closed', () => this.onWindowAllClosed()) app.on('ready', () => this.onReady()) app.on('activate', () => this.onActivated()) diff --git a/src/main/Auth.ts b/src/main/Auth.ts index 3ad403df..82e4baf8 100644 --- a/src/main/Auth.ts +++ b/src/main/Auth.ts @@ -9,6 +9,7 @@ interface AccountDoc { _id?: string domain: string acct: string + full: string avatar: string avatarStatic: string accessToken: string @@ -101,6 +102,7 @@ export default class Auth { let docs: AccountDoc = { domain: instance, acct: you.acct, + full: you.acct+"@"+instance, avatar: you.avatar, avatarStatic: you.avatar_static, accessToken: tokenData.accessToken, diff --git a/src/main/Client.ts b/src/main/Client.ts index 3c34f0a1..341d174f 100644 --- a/src/main/Client.ts +++ b/src/main/Client.ts @@ -1,6 +1,7 @@ - +import { app } from "electron" import Mastodon from 'megalodon' - +import Datastore from "nedb" +import { join } from "path" type Protocol = 'http' | 'websocket' export default class Clients { @@ -17,7 +18,17 @@ export default class Clients { if (!clients.has(username)) { // usernameからドメインをとトークンをデータベースから取得してクライアントを作る - //this.setAuthClient(protocol, username, this.createAuthClient(protocol, domain, accessToken)) + let db = new Datastore({ + filename: join(app.getPath("userData"), "account.db"), + autoload: true + }) + db.find({ full: username }, function(err: any, docs: { domain: string; accessToken: string; }){ + if (err) { + console.log(err) + } else { + Clients.setAuthClient(protocol, username, Clients.createAuthClient(protocol, docs.domain, docs.accessToken)) + } + }); } return clients.get(username)! diff --git a/src/main/Timeline.ts b/src/main/Timeline.ts index ebb42719..6e80ba51 100644 --- a/src/main/Timeline.ts +++ b/src/main/Timeline.ts @@ -17,5 +17,28 @@ export default class Timeline { event.sender.send(`timeline-${name}-no-auth`, [], error) } }) + ipcMain.on('timeline', async (event: Event, name: string, type: string) => { + const client = Client.getAuthClient(name) + 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" + } + let res: Response<[Status]> = await client.get<[Status]>(url) + event.sender.send(`timeline-${name}-no-auth`, res.data) + } catch (error) { + event.sender.send(`timeline-${name}-no-auth`, [], error) + } + }) } } \ No newline at end of file