diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-02-09 18:28:06 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-02-09 18:28:06 +0900 |
| commit | b7596e357c373b95d681bbf3f0b12683fa467e71 (patch) | |
| tree | 6179246c6eccccf167e6aa1ac0417f73be889548 /src | |
| parent | wip (diff) | |
| download | sharkey-b7596e357c373b95d681bbf3f0b12683fa467e71.tar.gz sharkey-b7596e357c373b95d681bbf3f0b12683fa467e71.tar.bz2 sharkey-b7596e357c373b95d681bbf3f0b12683fa467e71.zip | |
wip
Diffstat (limited to 'src')
| -rw-r--r-- | src/tsconfig.json | 4 | ||||
| -rw-r--r-- | src/web/app/common/mios.ts | 35 | ||||
| -rw-r--r-- | src/web/app/common/mixins.ts | 40 | ||||
| -rw-r--r-- | src/web/app/common/tags/time.vue | 56 | ||||
| -rw-r--r-- | src/web/app/init.ts | 24 |
5 files changed, 76 insertions, 83 deletions
diff --git a/src/tsconfig.json b/src/tsconfig.json index 36600eed2b..d88432d243 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -12,7 +12,9 @@ "target": "es2017", "module": "commonjs", "removeComments": false, - "noLib": false + "noLib": false, + "strict": true, + "strictNullChecks": false }, "compileOnSave": false, "include": [ diff --git a/src/web/app/common/mios.ts b/src/web/app/common/mios.ts index 6ee42ea8a7..b947e0743c 100644 --- a/src/web/app/common/mios.ts +++ b/src/web/app/common/mios.ts @@ -4,6 +4,10 @@ import signout from './scripts/signout'; import Progress from './scripts/loading'; import HomeStreamManager from './scripts/streaming/home-stream-manager'; import api from './scripts/api'; +import DriveStreamManager from './scripts/streaming/drive-stream-manager'; +import ServerStreamManager from './scripts/streaming/server-stream-manager'; +import RequestsStreamManager from './scripts/streaming/requests-stream-manager'; +import MessagingIndexStreamManager from './scripts/streaming/messaging-index-stream-manager'; //#region environment variables declare const _VERSION_: string; @@ -51,6 +55,16 @@ export default class MiOS extends EventEmitter { public stream: HomeStreamManager; /** + * Connection managers + */ + public streams: { + driveStream: DriveStreamManager; + serverStream: ServerStreamManager; + requestsStream: RequestsStreamManager; + messagingIndexStream: MessagingIndexStreamManager; + }; + + /** * A registration of service worker */ private swRegistration: ServiceWorkerRegistration = null; @@ -69,6 +83,9 @@ export default class MiOS extends EventEmitter { this.shouldRegisterSw = shouldRegisterSw; + this.streams.serverStream = new ServerStreamManager(); + this.streams.requestsStream = new RequestsStreamManager(); + //#region BIND this.log = this.log.bind(this); this.logInfo = this.logInfo.bind(this); @@ -79,6 +96,15 @@ export default class MiOS extends EventEmitter { this.getMeta = this.getMeta.bind(this); this.registerSw = this.registerSw.bind(this); //#endregion + + this.once('signedin', () => { + // Init home stream manager + this.stream = new HomeStreamManager(this.i); + + // Init other stream manager + this.streams.driveStream = new DriveStreamManager(this.i); + this.streams.messagingIndexStream = new MessagingIndexStreamManager(this.i); + }); } public log(...args) { @@ -139,8 +165,8 @@ export default class MiOS extends EventEmitter { // When failure .catch(() => { // Render the error screen - document.body.innerHTML = '<mk-error />'; - riot.mount('*'); + //document.body.innerHTML = '<mk-error />'; + //riot.mount('*'); Progress.done(); }); @@ -173,10 +199,7 @@ export default class MiOS extends EventEmitter { this.i = me; - // Init home stream manager - this.stream = this.isSignedin - ? new HomeStreamManager(this.i) - : null; + this.emit('signedin'); // Finish init callback(); diff --git a/src/web/app/common/mixins.ts b/src/web/app/common/mixins.ts deleted file mode 100644 index e9c3625937..0000000000 --- a/src/web/app/common/mixins.ts +++ /dev/null @@ -1,40 +0,0 @@ -import * as riot from 'riot'; - -import MiOS from './mios'; -import ServerStreamManager from './scripts/streaming/server-stream-manager'; -import RequestsStreamManager from './scripts/streaming/requests-stream-manager'; -import MessagingIndexStreamManager from './scripts/streaming/messaging-index-stream-manager'; -import DriveStreamManager from './scripts/streaming/drive-stream-manager'; - -export default (mios: MiOS) => { - (riot as any).mixin('os', { - mios: mios - }); - - (riot as any).mixin('i', { - init: function() { - this.I = mios.i; - this.SIGNIN = mios.isSignedin; - - if (this.SIGNIN) { - this.on('mount', () => { - mios.i.on('updated', this.update); - }); - this.on('unmount', () => { - mios.i.off('updated', this.update); - }); - } - }, - me: mios.i - }); - - (riot as any).mixin('api', { - api: mios.api - }); - - (riot as any).mixin('stream', { stream: mios.stream }); - (riot as any).mixin('drive-stream', { driveStream: new DriveStreamManager(mios.i) }); - (riot as any).mixin('server-stream', { serverStream: new ServerStreamManager() }); - (riot as any).mixin('requests-stream', { requestsStream: new RequestsStreamManager() }); - (riot as any).mixin('messaging-index-stream', { messagingIndexStream: new MessagingIndexStreamManager(mios.i) }); -}; diff --git a/src/web/app/common/tags/time.vue b/src/web/app/common/tags/time.vue index 0239f5422e..7d165fc006 100644 --- a/src/web/app/common/tags/time.vue +++ b/src/web/app/common/tags/time.vue @@ -7,23 +7,43 @@ </template> <script lang="typescript"> - export default { + import Vue from 'vue'; + + export default Vue.extend({ props: ['time', 'mode'], data() { return { mode: 'relative', - tickId: null + tickId: null, + now: new Date() }; }, + computed: { + absolute() { + return ( + this.time.getFullYear() + '年' + + (this.time.getMonth() + 1) + '月' + + this.time.getDate() + '日' + + ' ' + + this.time.getHours() + '時' + + this.time.getMinutes() + '分'); + }, + relative() { + const ago = (this.now - this.time) / 1000/*ms*/; + return ( + ago >= 31536000 ? '%i18n:common.time.years_ago%' .replace('{}', ~~(ago / 31536000)) : + ago >= 2592000 ? '%i18n:common.time.months_ago%' .replace('{}', ~~(ago / 2592000)) : + ago >= 604800 ? '%i18n:common.time.weeks_ago%' .replace('{}', ~~(ago / 604800)) : + ago >= 86400 ? '%i18n:common.time.days_ago%' .replace('{}', ~~(ago / 86400)) : + ago >= 3600 ? '%i18n:common.time.hours_ago%' .replace('{}', ~~(ago / 3600)) : + ago >= 60 ? '%i18n:common.time.minutes_ago%'.replace('{}', ~~(ago / 60)) : + ago >= 10 ? '%i18n:common.time.seconds_ago%'.replace('{}', ~~(ago % 60)) : + ago >= 0 ? '%i18n:common.time.just_now%' : + ago < 0 ? '%i18n:common.time.future%' : + '%i18n:common.time.unknown%'); + } + }, created() { - this.absolute = - this.time.getFullYear() + '年' + - (this.time.getMonth() + 1) + '月' + - this.time.getDate() + '日' + - ' ' + - this.time.getHours() + '時' + - this.time.getMinutes() + '分'; - if (this.mode == 'relative' || this.mode == 'detail') { this.tick(); this.tickId = setInterval(this.tick, 1000); @@ -36,20 +56,8 @@ }, methods: { tick() { - const now = new Date(); - const ago = (now - this.time) / 1000/*ms*/; - this.relative = - ago >= 31536000 ? '%i18n:common.time.years_ago%' .replace('{}', ~~(ago / 31536000)) : - ago >= 2592000 ? '%i18n:common.time.months_ago%' .replace('{}', ~~(ago / 2592000)) : - ago >= 604800 ? '%i18n:common.time.weeks_ago%' .replace('{}', ~~(ago / 604800)) : - ago >= 86400 ? '%i18n:common.time.days_ago%' .replace('{}', ~~(ago / 86400)) : - ago >= 3600 ? '%i18n:common.time.hours_ago%' .replace('{}', ~~(ago / 3600)) : - ago >= 60 ? '%i18n:common.time.minutes_ago%'.replace('{}', ~~(ago / 60)) : - ago >= 10 ? '%i18n:common.time.seconds_ago%'.replace('{}', ~~(ago % 60)) : - ago >= 0 ? '%i18n:common.time.just_now%' : - ago < 0 ? '%i18n:common.time.future%' : - '%i18n:common.time.unknown%'; + this.now = new Date(); } } - }; + }); </script> diff --git a/src/web/app/init.ts b/src/web/app/init.ts index 62bd6949bb..4b2a3b8689 100644 --- a/src/web/app/init.ts +++ b/src/web/app/init.ts @@ -30,21 +30,21 @@ if (_HOST_ != 'localhost') { document.domain = _HOST_; } -{ // Set lang attr - const html = document.documentElement; - html.setAttribute('lang', _LANG_); -} +//#region Set lang attr +const html = document.documentElement; +html.setAttribute('lang', _LANG_); +//#endregion -{ // Set description meta tag - const head = document.getElementsByTagName('head')[0]; - const meta = document.createElement('meta'); - meta.setAttribute('name', 'description'); - meta.setAttribute('content', '%i18n:common.misskey%'); - head.appendChild(meta); -} +//#region Set description meta tag +const head = document.getElementsByTagName('head')[0]; +const meta = document.createElement('meta'); +meta.setAttribute('name', 'description'); +meta.setAttribute('content', '%i18n:common.misskey%'); +head.appendChild(meta); +//#endregion // Set global configuration -(riot as any).mixin(__CONSTS__); +//(riot as any).mixin(__CONSTS__); // iOSでプライベートモードだとlocalStorageが使えないので既存のメソッドを上書きする try { |