From 1eab257ab1af9cfe650acb5089fd154945ae48fb Mon Sep 17 00:00:00 2001 From: Joseph Tseng Date: Sun, 18 Aug 2019 02:07:53 +0800 Subject: [PATCH] 1. Update npm ptt-client version. 2. Modify search method according to new ptt-client. 3. Add reset search condition feature in refresh. --- package-lock.json | 39 +++++++++++++++++++++++++++------------ package.json | 2 +- src/extension.ts | 35 ++++++----------------------------- 3 files changed, 34 insertions(+), 42 deletions(-) diff --git a/package-lock.json b/package-lock.json index ee1ae81..769f35c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,13 @@ { "name": "vscode-ptt", - "version": "0.2.1", + "version": "0.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { "@babel/runtime": { - "version": "7.4.3", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.4.3.tgz", - "integrity": "sha512-9lsJwJLxDh/T3Q3SZszfWOTkk3pHbkmH+3KY+zwIDmsNlxsumuhS2TH3NIpktU4kNvfzy+k3eLT7aTJSPTo0OA==", + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.5.5.tgz", + "integrity": "sha512-28QvEGyQyNkB0/m2B4FU7IEZGK2NUrcMtT6BZEFALTguLk+AUT6ofsHtPk5QyjAdUkpMJ+/Em+quwz4HOt30AQ==", "requires": { "regenerator-runtime": "^0.13.2" } @@ -766,17 +766,32 @@ "dev": true }, "ptt-client": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/ptt-client/-/ptt-client-0.5.2.tgz", - "integrity": "sha512-8z5eGFTOe7hQdzJiR9pATT3ZbIcHGfu2SWnhcuKouFMUIfKvlmeejHvYd7MzdqLjgpJHISONSwwxHac+xYp4lQ==", + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/ptt-client/-/ptt-client-0.8.0.tgz", + "integrity": "sha512-XwNO7b0c5h1UWa7Dq0iZuwEmbfooWjp2UOngoQjb6akBm33dJO7ba1Po3LQxHJ54Tq2prcI5NqQG+GyreiQ6XA==", "requires": { "@babel/runtime": "^7.4.2", - "eventemitter3": "^3.1.0", + "eventemitter3": "^4.0.0", "sleep-promise": "^8.0.1", "terminal.js": "github:kevinptt0323/terminal.js", "uao-js": "^1.0.1", "wcwidth": "^1.0.1", - "ws": "^6.2.1" + "ws": "^7.1.1" + }, + "dependencies": { + "eventemitter3": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.0.tgz", + "integrity": "sha512-qerSRB0p+UDEssxTtm6EDKcE7W4OaoisfIMl4CngyEhjpYglocpNg6UEqCvemdGhosAsg4sO2dXJOdyBifPGCg==" + }, + "ws": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.1.2.tgz", + "integrity": "sha512-gftXq3XI81cJCgkUiAVixA0raD9IVmXqsylCrjRygw4+UOOGzPoxnQ6r/CnVL9i+mDncJo94tSkyrtuuQVBmrg==", + "requires": { + "async-limiter": "^1.0.0" + } + } } }, "punycode": { @@ -798,9 +813,9 @@ "dev": true }, "regenerator-runtime": { - "version": "0.13.2", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.2.tgz", - "integrity": "sha512-S/TQAZJO+D3m9xeN1WTI8dLKBBiRgXBlTJvbWjCThHWZj9EvHK70Ff50/tYj2J/fvBY6JtFVwRuazHN2E7M9BA==" + "version": "0.13.3", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz", + "integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==" }, "request": { "version": "2.88.0", diff --git a/package.json b/package.json index 6b3797e..1daea93 100644 --- a/package.json +++ b/package.json @@ -152,7 +152,7 @@ "dependencies": { "find-free-port": "^2.0.0", "http-proxy": "^1.17.0", - "ptt-client": "^0.5.2", + "ptt-client": "^0.8.0", "ws": "^6.2.1" } } diff --git a/src/extension.ts b/src/extension.ts index e010721..06183f8 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,6 +1,6 @@ import * as vscode from 'vscode'; import PTT from 'ptt-client'; -import key from 'ptt-client/dist/utils/keyboard'; +import key from 'ptt-client/dist/utils/keymap'; (global as any).WebSocket = require('ws'); @@ -122,34 +122,9 @@ async function pickFavorite (): Promise { } } -async function searchArticleByPush(boardname: string, push: number): Promise +function setSearchCondition(type: string, criteria: string): void { - let searchedArticles: ArticleListItem[] = await fillPushArray(boardname, push, 10); - return searchedArticles; -} - -async function fillPushArray(boardname: string, push: number, articleNum: number, offset: number = 0, articles: ArticleListItem[] = []): Promise -{ - if (articles.length > articleNum) - { - return articles; - } - else - { - let articlesStore: ArticleListItem[]; - let lastsn: number; - - articlesStore = await ptt.getArticles(boardname, offset); - lastsn = articlesStore.slice(-1)[0].sn; - - let filteredStore = articlesStore.filter((article) => - { - let pushNumber: string = (article.push === '爆') ? '100' : article.push; - return (Number(pushNumber) >= push); - }); - articles.push(...filteredStore); - return fillPushArray(boardname, push, articleNum, lastsn, articles); - } + ptt.setSearchCondition(type, criteria); } export async function activate(context: vscode.ExtensionContext) { @@ -232,6 +207,7 @@ export async function activate(context: vscode.ExtensionContext) { })); context.subscriptions.push(vscode.commands.registerCommand('ptt.refresh-article', () => { + ptt.resetSearchCondition(); pttProvider.refresh(); })); @@ -264,7 +240,8 @@ export async function activate(context: vscode.ExtensionContext) { } vscode.window.showInformationMessage('開始搜尋'); - let pushArticles: ArticleListItem[] = await searchArticleByPush(board.boardname, Number(push)); + setSearchCondition("push", push); + let pushArticles: ArticleListItem[] = await ptt.getArticles(board.boardname); vscode.window.showInformationMessage('完成搜尋'); store.add(board.boardname, pushArticles);