From 391205cb346d8c258b1345c3dae22fe3a4ccbdff Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sat, 12 Sep 2020 14:51:03 +0200 Subject: [PATCH] resturctured the project a bit --- shared/fix-imports.ts | 18 +++ shared/js/ConnectionHandler.ts | 10 +- shared/js/connection/CommandHandler.ts | 6 +- shared/js/connection/ConnectionBase.ts | 2 +- .../connection/ServerConnectionDeclaration.ts | 1 - shared/js/file/LocalAvatars.ts | 2 +- shared/js/{ui/channel.ts => tree/Channel.ts} | 10 +- .../js/{ui/view.tsx => tree/ChannelTree.tsx} | 8 +- .../TreeEntry.ts => tree/ChannelTreeEntry.ts} | 0 shared/js/{ui/client.ts => tree/Client.ts} | 8 +- shared/js/{ui/server.ts => tree/Server.ts} | 8 +- shared/js/ui/elements/NetGraph.ts | 2 - shared/js/ui/frames/chat.ts | 1 - shared/js/ui/frames/chat_frame.ts | 6 +- shared/js/ui/frames/side/ConversationUI.tsx | 14 +- .../frames/side/PrivateConversationManager.ts | 2 +- shared/js/ui/frames/side/chat_helper.ts | 151 ------------------ shared/js/ui/frames/side/client_info.ts | 8 +- shared/js/ui/frames/side/music_info.ts | 3 +- shared/js/ui/htmltags.ts | 4 +- shared/js/ui/modal/ModalAvatarList.ts | 2 +- shared/js/ui/modal/ModalBotMenue.ts | 0 shared/js/ui/modal/ModalChangeLatency.ts | 2 +- shared/js/ui/modal/ModalChangeVolume.ts | 2 +- shared/js/ui/modal/ModalChangeVolumeNew.tsx | 2 +- shared/js/ui/modal/ModalChannelInfo.ts | 2 +- shared/js/ui/modal/ModalClientInfo.ts | 2 +- shared/js/ui/modal/ModalCreateChannel.ts | 2 +- shared/js/ui/modal/ModalGroupAssignment.ts | 2 +- shared/js/ui/modal/ModalInvite.ts | 2 +- shared/js/ui/modal/ModalMusicManage.ts | 2 +- shared/js/ui/modal/ModalNewcomer.tsx | 1 - shared/js/ui/modal/ModalServerEdit.ts | 2 +- shared/js/ui/modal/ModalServerInfo.ts | 2 +- .../js/ui/modal/ModalServerInfoBandwidth.ts | 2 +- .../ui/react-elements/TimestampRenderer.tsx | 4 +- shared/js/ui/tree/Channel.tsx | 2 +- shared/js/ui/tree/Client.tsx | 2 +- shared/js/ui/tree/Server.tsx | 2 +- shared/js/ui/tree/TreeEntry.tsx | 2 +- shared/js/ui/tree/View.tsx | 8 +- shared/js/utils/DateUtils.ts | 114 +++++++++++++ shared/js/utils/TimeUtils.ts | 23 +++ shared/js/workers/WorkerOwner.ts | 14 +- shared/js/workers/pow/index.ts | 1 - shared/js/workers/tsconfig_worker_pow.json | 14 -- 46 files changed, 225 insertions(+), 252 deletions(-) create mode 100644 shared/fix-imports.ts rename shared/js/{ui/channel.ts => tree/Channel.ts} (99%) rename shared/js/{ui/view.tsx => tree/ChannelTree.tsx} (99%) rename shared/js/{ui/TreeEntry.ts => tree/ChannelTreeEntry.ts} (100%) rename shared/js/{ui/client.ts => tree/Client.ts} (99%) rename shared/js/{ui/server.ts => tree/Server.ts} (98%) delete mode 100644 shared/js/ui/frames/side/chat_helper.ts delete mode 100644 shared/js/ui/modal/ModalBotMenue.ts create mode 100644 shared/js/utils/DateUtils.ts create mode 100644 shared/js/utils/TimeUtils.ts delete mode 100644 shared/js/workers/tsconfig_worker_pow.json diff --git a/shared/fix-imports.ts b/shared/fix-imports.ts new file mode 100644 index 00000000..be9b2e7c --- /dev/null +++ b/shared/fix-imports.ts @@ -0,0 +1,18 @@ +import * as path from "path"; +import * as fs from "fs-extra"; + + +async function processFile(file: string) { + +} + +async function processDirectory(directory: string) { + const files = await fs.readdir(directory); + for(const file of files) { + console.log(file); + } +} + +processDirectory(path.join(__dirname, "js")).catch(error => { + console.error(error); +}); \ No newline at end of file diff --git a/shared/js/ConnectionHandler.ts b/shared/js/ConnectionHandler.ts index e560e0c6..c0057d06 100644 --- a/shared/js/ConnectionHandler.ts +++ b/shared/js/ConnectionHandler.ts @@ -1,19 +1,15 @@ -import {ChannelTree} from "tc-shared/ui/view"; import {AbstractServerConnection} from "tc-shared/connection/ConnectionBase"; import {PermissionManager} from "tc-shared/permission/PermissionManager"; import {GroupManager} from "tc-shared/permission/GroupManager"; import {ServerSettings, Settings, settings, StaticSettings} from "tc-shared/settings"; import {Sound, SoundManager} from "tc-shared/sound/Sounds"; -import {LocalClientEntry} from "tc-shared/ui/client"; import {ConnectionProfile} from "tc-shared/profiles/ConnectionProfile"; -import {ServerAddress} from "tc-shared/ui/server"; import * as log from "tc-shared/log"; import {LogCategory, logError, logInfo, logWarn} from "tc-shared/log"; import {createErrorModal, createInfoModal, createInputModal, Modal} from "tc-shared/ui/elements/Modal"; import {hashPassword} from "tc-shared/utils/helpers"; import {HandshakeHandler} from "tc-shared/connection/HandshakeHandler"; import * as htmltags from "./ui/htmltags"; -import {ChannelEntry} from "tc-shared/ui/channel"; import {FilterMode, InputStartResult, InputState} from "tc-shared/voice/RecorderBase"; import {CommandResult} from "tc-shared/connection/ServerConnectionDeclaration"; import {defaultRecorder, RecorderProfile} from "tc-shared/voice/RecorderProfile"; @@ -24,7 +20,6 @@ import {connection_log, Regex} from "tc-shared/ui/modal/ModalConnect"; import {formatMessage} from "tc-shared/ui/frames/chat"; import {spawnAvatarUpload} from "tc-shared/ui/modal/ModalAvatar"; import * as dns from "tc-backend/dns"; -import * as top_menu from "tc-shared/ui/frames/MenuBar"; import {EventHandler, Registry} from "tc-shared/events"; import {FileManager} from "tc-shared/file/FileManager"; import {FileTransferState, TransferProvider} from "tc-shared/file/Transfer"; @@ -40,6 +35,9 @@ import {getServerConnectionFactory} from "tc-shared/connection/ConnectionFactory import {WhisperSession} from "tc-shared/voice/VoiceWhisper"; import {spawnEchoTestModal} from "tc-shared/ui/modal/echo-test/Controller"; import {ServerFeature, ServerFeatures} from "tc-shared/connection/ServerFeatures"; +import {ChannelTree} from "tc-shared/tree/ChannelTree"; +import {LocalClientEntry} from "tc-shared/tree/Client"; +import {ServerAddress} from "tc-shared/tree/Server"; export enum InputHardwareState { MISSING, @@ -794,7 +792,7 @@ export class ConnectionHandler { } private _last_record_error_popup: number = 0; - update_voice_status(targetChannel?: ChannelEntry) { + update_voice_status() { this.updateVoiceStatus(); return; } diff --git a/shared/js/connection/CommandHandler.ts b/shared/js/connection/CommandHandler.ts index 52fecfa9..5b28e0d6 100644 --- a/shared/js/connection/CommandHandler.ts +++ b/shared/js/connection/CommandHandler.ts @@ -11,8 +11,8 @@ import { LocalClientEntry, MusicClientEntry, SongInfo -} from "tc-shared/ui/client"; -import {ChannelEntry} from "tc-shared/ui/channel"; +} from "tc-shared/tree/Client"; +import {ChannelEntry} from "tc-shared/tree/Channel"; import {ConnectionHandler, ConnectionState, DisconnectReason, ViewReasonId} from "tc-shared/ConnectionHandler"; import {formatMessage} from "tc-shared/ui/frames/chat"; import {server_connections} from "tc-shared/ui/frames/connection_handlers"; @@ -606,7 +606,7 @@ export class ConnectionCommandHandler extends AbstractCommandHandler { tree.moveClient(client, channel_to); if(self) { - this.connection_handler.update_voice_status(channel_to); + this.connection_handler.update_voice_status(); for(const entry of client.channelTree.clientsByChannel(channelFrom)) { entry.getVoiceClient()?.abortReplay(); diff --git a/shared/js/connection/ConnectionBase.ts b/shared/js/connection/ConnectionBase.ts index 3e5a1ad8..c32f3af2 100644 --- a/shared/js/connection/ConnectionBase.ts +++ b/shared/js/connection/ConnectionBase.ts @@ -1,7 +1,7 @@ import {CommandHelper} from "tc-shared/connection/CommandHelper"; import {HandshakeHandler} from "tc-shared/connection/HandshakeHandler"; import {CommandResult} from "tc-shared/connection/ServerConnectionDeclaration"; -import {ServerAddress} from "tc-shared/ui/server"; +import {ServerAddress} from "tc-shared/tree/Server"; import {ConnectionHandler, ConnectionState} from "tc-shared/ConnectionHandler"; import {AbstractCommandHandlerBoss} from "tc-shared/connection/AbstractCommandHandler"; import {Registry} from "tc-shared/events"; diff --git a/shared/js/connection/ServerConnectionDeclaration.ts b/shared/js/connection/ServerConnectionDeclaration.ts index f92c7c65..b98bc0ca 100644 --- a/shared/js/connection/ServerConnectionDeclaration.ts +++ b/shared/js/connection/ServerConnectionDeclaration.ts @@ -1,5 +1,4 @@ import {LaterPromise} from "tc-shared/utils/LaterPromise"; -import {ErrorCode} from "./ErrorCode"; export class CommandResult { success: boolean; diff --git a/shared/js/file/LocalAvatars.ts b/shared/js/file/LocalAvatars.ts index 783748c2..e4e84b5a 100644 --- a/shared/js/file/LocalAvatars.ts +++ b/shared/js/file/LocalAvatars.ts @@ -15,7 +15,7 @@ import { } from "tc-shared/file/Transfer"; import {CommandResult} from "tc-shared/connection/ServerConnectionDeclaration"; import {server_connections} from "tc-shared/ui/frames/connection_handlers"; -import {ClientEntry} from "tc-shared/ui/client"; +import {ClientEntry} from "tc-shared/tree/Client"; import {tr} from "tc-shared/i18n/localize"; import { AbstractAvatarManager, diff --git a/shared/js/ui/channel.ts b/shared/js/tree/Channel.ts similarity index 99% rename from shared/js/ui/channel.ts rename to shared/js/tree/Channel.ts index 7a7b0cd3..dca4d08d 100644 --- a/shared/js/ui/channel.ts +++ b/shared/js/tree/Channel.ts @@ -1,5 +1,5 @@ -import {ChannelTree} from "tc-shared/ui/view"; -import {ClientEntry, ClientEvents} from "tc-shared/ui/client"; +import {ChannelTree} from "./ChannelTree"; +import {ClientEntry, ClientEvents} from "./Client"; import * as log from "tc-shared/log"; import {LogCategory, LogType} from "tc-shared/log"; import {PermissionType} from "tc-shared/permission/PermissionType"; @@ -9,7 +9,7 @@ import {MenuEntryType} from "tc-shared/ui/elements/ContextMenu"; import {Sound} from "tc-shared/sound/Sounds"; import {createErrorModal, createInfoModal, createInputModal} from "tc-shared/ui/elements/Modal"; import {CommandResult} from "tc-shared/connection/ServerConnectionDeclaration"; -import * as htmltags from "./htmltags"; +import * as htmltags from "../ui/htmltags"; import {hashPassword} from "tc-shared/utils/helpers"; import {openChannelInfo} from "tc-shared/ui/modal/ModalChannelInfo"; import {createChannelModal} from "tc-shared/ui/modal/ModalCreateChannel"; @@ -17,8 +17,8 @@ import {formatMessage} from "tc-shared/ui/frames/chat"; import * as React from "react"; import {Registry} from "tc-shared/events"; -import {ChannelTreeEntry, ChannelTreeEntryEvents} from "tc-shared/ui/TreeEntry"; -import {ChannelEntryView as ChannelEntryView} from "./tree/Channel"; +import {ChannelTreeEntry, ChannelTreeEntryEvents} from "./ChannelTreeEntry"; +import {ChannelEntryView as ChannelEntryView} from "../ui/tree/Channel"; import {spawnFileTransferModal} from "tc-shared/ui/modal/transfer/ModalFileTransfer"; import {ViewReasonId} from "tc-shared/ConnectionHandler"; import {EventChannelData} from "tc-shared/ui/frames/log/Definitions"; diff --git a/shared/js/ui/view.tsx b/shared/js/tree/ChannelTree.tsx similarity index 99% rename from shared/js/ui/view.tsx rename to shared/js/tree/ChannelTree.tsx index 95e7b961..d6218c1c 100644 --- a/shared/js/ui/view.tsx +++ b/shared/js/tree/ChannelTree.tsx @@ -7,9 +7,10 @@ import {PermissionType} from "tc-shared/permission/PermissionType"; import {KeyCode, SpecialKey} from "tc-shared/PPTListener"; import {Sound} from "tc-shared/sound/Sounds"; import {Group} from "tc-shared/permission/GroupManager"; -import {ServerAddress, ServerEntry} from "tc-shared/ui/server"; -import {ChannelEntry, ChannelProperties, ChannelSubscribeMode} from "tc-shared/ui/channel"; -import {ClientEntry, LocalClientEntry, MusicClientEntry} from "tc-shared/ui/client"; +import {ServerAddress, ServerEntry} from "./Server"; +import {ChannelEntry, ChannelProperties, ChannelSubscribeMode} from "./Channel"; +import {ClientEntry, LocalClientEntry, MusicClientEntry} from "./Client"; +import {ChannelTreeEntry} from "./ChannelTreeEntry"; import {ConnectionHandler, ViewReasonId} from "tc-shared/ConnectionHandler"; import {createChannelModal} from "tc-shared/ui/modal/ModalCreateChannel"; import {Registry} from "tc-shared/events"; @@ -19,7 +20,6 @@ import * as React from "react"; import * as ppt from "tc-backend/ppt"; import {batch_updates, BatchUpdateType, flush_batched_updates} from "tc-shared/ui/react-elements/ReactComponentBase"; -import {ChannelTreeEntry} from "tc-shared/ui/TreeEntry"; import {createInputModal} from "tc-shared/ui/elements/Modal"; import {spawnBanClient} from "tc-shared/ui/modal/ModalBanClient"; import {formatMessage} from "tc-shared/ui/frames/chat"; diff --git a/shared/js/ui/TreeEntry.ts b/shared/js/tree/ChannelTreeEntry.ts similarity index 100% rename from shared/js/ui/TreeEntry.ts rename to shared/js/tree/ChannelTreeEntry.ts diff --git a/shared/js/ui/client.ts b/shared/js/tree/Client.ts similarity index 99% rename from shared/js/ui/client.ts rename to shared/js/tree/Client.ts index 3b8abc3e..46fb7d4a 100644 --- a/shared/js/ui/client.ts +++ b/shared/js/tree/Client.ts @@ -1,6 +1,6 @@ import * as contextmenu from "tc-shared/ui/elements/ContextMenu"; import {Registry} from "tc-shared/events"; -import {ChannelTree} from "tc-shared/ui/view"; +import {ChannelTree} from "./ChannelTree"; import * as log from "tc-shared/log"; import {LogCategory, logInfo, LogType} from "tc-shared/log"; import {Settings, settings} from "tc-shared/settings"; @@ -10,7 +10,7 @@ import PermissionType from "tc-shared/permission/PermissionType"; import {createErrorModal, createInputModal} from "tc-shared/ui/elements/Modal"; import * as htmltags from "tc-shared/ui/htmltags"; import {CommandResult, PlaylistSong} from "tc-shared/connection/ServerConnectionDeclaration"; -import {ChannelEntry} from "tc-shared/ui/channel"; +import {ChannelEntry} from "./Channel"; import {ConnectionHandler, ViewReasonId} from "tc-shared/ConnectionHandler"; import {createServerGroupAssignmentModal} from "tc-shared/ui/modal/ModalGroupAssignment"; import {openClientInfo} from "tc-shared/ui/modal/ModalClientInfo"; @@ -19,9 +19,9 @@ import {spawnChangeLatency} from "tc-shared/ui/modal/ModalChangeLatency"; import {formatMessage} from "tc-shared/ui/frames/chat"; import {spawnYesNo} from "tc-shared/ui/modal/ModalYesNo"; import * as hex from "tc-shared/crypto/hex"; -import {ClientEntry as ClientEntryView} from "./tree/Client"; +import {ClientEntry as ClientEntryView} from "../ui/tree/Client"; import * as React from "react"; -import {ChannelTreeEntry, ChannelTreeEntryEvents} from "tc-shared/ui/TreeEntry"; +import {ChannelTreeEntry, ChannelTreeEntryEvents} from "./ChannelTreeEntry"; import {spawnClientVolumeChange, spawnMusicBotVolumeChange} from "tc-shared/ui/modal/ModalChangeVolumeNew"; import {spawnPermissionEditorModal} from "tc-shared/ui/modal/permission/ModalPermissionEditor"; import {EventClient, EventType} from "tc-shared/ui/frames/log/Definitions"; diff --git a/shared/js/ui/server.ts b/shared/js/tree/Server.ts similarity index 98% rename from shared/js/ui/server.ts rename to shared/js/tree/Server.ts index ecda1623..64b8866a 100644 --- a/shared/js/ui/server.ts +++ b/shared/js/tree/Server.ts @@ -1,4 +1,4 @@ -import {ChannelTree} from "tc-shared/ui/view"; +import {ChannelTree} from "./ChannelTree"; import {Settings, settings} from "tc-shared/settings"; import * as contextmenu from "tc-shared/ui/elements/ContextMenu"; import * as log from "tc-shared/log"; @@ -12,12 +12,12 @@ import {spawnIconSelect} from "tc-shared/ui/modal/ModalIconSelect"; import {spawnAvatarList} from "tc-shared/ui/modal/ModalAvatarList"; import {server_connections} from "tc-shared/ui/frames/connection_handlers"; import {connection_log} from "tc-shared/ui/modal/ModalConnect"; -import * as top_menu from "./frames/MenuBar"; +import * as top_menu from "../ui/frames/MenuBar"; import {control_bar_instance} from "tc-shared/ui/frames/control-bar"; -import { ServerEntry as ServerEntryView } from "./tree/Server"; +import { ServerEntry as ServerEntryView } from "../ui/tree/Server"; import * as React from "react"; import {Registry} from "tc-shared/events"; -import {ChannelTreeEntry, ChannelTreeEntryEvents} from "tc-shared/ui/TreeEntry"; +import {ChannelTreeEntry, ChannelTreeEntryEvents} from "./ChannelTreeEntry"; export class ServerProperties { virtualserver_host: string = ""; diff --git a/shared/js/ui/elements/NetGraph.ts b/shared/js/ui/elements/NetGraph.ts index 6f713191..778746f8 100644 --- a/shared/js/ui/elements/NetGraph.ts +++ b/shared/js/ui/elements/NetGraph.ts @@ -88,8 +88,6 @@ export class Graph { }; private _max_space = 1.12; private _max_gap = 5; - private _listener_mouse_move; - private _listener_mouse_out; private _animate_loop; _time_span: TimeSpan = { diff --git a/shared/js/ui/frames/chat.ts b/shared/js/ui/frames/chat.ts index f369f919..46df4137 100644 --- a/shared/js/ui/frames/chat.ts +++ b/shared/js/ui/frames/chat.ts @@ -10,7 +10,6 @@ export enum ChatType { CLIENT } -declare const xbbcode: any; export function htmlEscape(message: string) : string[] { const div = document.createElement('div'); div.innerText = message; diff --git a/shared/js/ui/frames/chat_frame.ts b/shared/js/ui/frames/chat_frame.ts index 8ae13565..954e2198 100644 --- a/shared/js/ui/frames/chat_frame.ts +++ b/shared/js/ui/frames/chat_frame.ts @@ -1,8 +1,8 @@ /* the bar on the right with the chats (Channel & Client) */ -import {ClientEntry, MusicClientEntry} from "tc-shared/ui/client"; +import {ClientEntry, MusicClientEntry} from "tc-shared/tree/Client"; import {ConnectionHandler} from "tc-shared/ConnectionHandler"; -import {ChannelEntry} from "tc-shared/ui/channel"; -import {ServerEntry} from "tc-shared/ui/server"; +import {ChannelEntry} from "tc-shared/tree/Channel"; +import {ServerEntry} from "tc-shared/tree/Server"; import {openMusicManage} from "tc-shared/ui/modal/ModalMusicManage"; import {formatMessage} from "tc-shared/ui/frames/chat"; import {ClientInfo} from "tc-shared/ui/frames/side/client_info"; diff --git a/shared/js/ui/frames/side/ConversationUI.tsx b/shared/js/ui/frames/side/ConversationUI.tsx index eb2a6f97..559d1027 100644 --- a/shared/js/ui/frames/side/ConversationUI.tsx +++ b/shared/js/ui/frames/side/ConversationUI.tsx @@ -3,7 +3,6 @@ import {EventHandler, ReactEventHandler, Registry} from "tc-shared/events"; import {ChatBox} from "tc-shared/ui/frames/side/ChatBox"; import {Ref, useEffect, useRef, useState} from "react"; import {AvatarRenderer} from "tc-shared/ui/react-elements/Avatar"; -import {format} from "tc-shared/ui/frames/side/chat_helper"; import {Translatable} from "tc-shared/ui/react-elements/i18n"; import {LoadingDots} from "tc-shared/ui/react-elements/LoadingDots"; import {Countdown} from "tc-shared/ui/react-elements/Countdown"; @@ -22,6 +21,7 @@ import { import {TimestampRenderer} from "tc-shared/ui/react-elements/TimestampRenderer"; import {BBCodeRenderer} from "tc-shared/text/bbcode"; import {getGlobalAvatarManagerFactory} from "tc-shared/file/Avatars"; +import {ColloquialFormat, date_format, format_date_general, formatDayTime} from "tc-shared/utils/DateUtils"; const cssStyle = require("./ConversationUI.scss"); @@ -86,18 +86,18 @@ const ChatEventMessageRenderer = React.memo((props: { const TimestampEntry = (props: { timestamp: Date, refDiv: React.Ref }) => { - const diff = format.date.date_format(props.timestamp, new Date()); + const diff = date_format(props.timestamp, new Date()); let formatted; let update: boolean; - if(diff == format.date.ColloquialFormat.YESTERDAY) { + if(diff == ColloquialFormat.YESTERDAY) { formatted = Yesterday; update = true; - } else if(diff == format.date.ColloquialFormat.TODAY) { + } else if(diff == ColloquialFormat.TODAY) { formatted = Today; update = true; - } else if(diff == format.date.ColloquialFormat.GENERAL) { - formatted = <>{format.date.format_date_general(props.timestamp, false)}; + } else if(diff == ColloquialFormat.GENERAL) { + formatted = <>{format_date_general(props.timestamp, false)}; update = false; } @@ -194,7 +194,7 @@ const ChatEventLocalUserSwitchRenderer = (props: { event: ChatEventLocalUserSwit {props.event.mode === "join" ? You joined at : You left at}   - {format.date.formatDayTime(new Date(props.timestamp))} + {formatDayTime(new Date(props.timestamp))}
diff --git a/shared/js/ui/frames/side/PrivateConversationManager.ts b/shared/js/ui/frames/side/PrivateConversationManager.ts index 7027509f..2f423ca5 100644 --- a/shared/js/ui/frames/side/PrivateConversationManager.ts +++ b/shared/js/ui/frames/side/PrivateConversationManager.ts @@ -1,4 +1,4 @@ -import {ClientEntry} from "tc-shared/ui/client"; +import {ClientEntry} from "tc-shared/tree/Client"; import {ConnectionHandler, ConnectionState} from "tc-shared/ConnectionHandler"; import {EventHandler, Registry} from "tc-shared/events"; import { diff --git a/shared/js/ui/frames/side/chat_helper.ts b/shared/js/ui/frames/side/chat_helper.ts deleted file mode 100644 index 821f839f..00000000 --- a/shared/js/ui/frames/side/chat_helper.ts +++ /dev/null @@ -1,151 +0,0 @@ -import * as log from "tc-shared/log"; -import {LogCategory} from "tc-shared/log"; -import {Settings, settings} from "tc-shared/settings"; - -const escapeBBCode = (text: string) => text.replace(/([\[\]])/g, "\\$1"); - -export namespace helpers { - export namespace date { - export function same_day(a: number | Date, b: number | Date) { - a = a instanceof Date ? a : new Date(a); - b = b instanceof Date ? b : new Date(b); - - if(a.getDate() !== b.getDate()) - return false; - if(a.getMonth() !== b.getMonth()) - return false; - return a.getFullYear() === b.getFullYear(); - } - } -} - -export namespace format { - export namespace date { - export enum ColloquialFormat { - YESTERDAY, - TODAY, - GENERAL - } - - function dateEqual(a: Date, b: Date) { - return a.getUTCFullYear() === b.getUTCFullYear() && - a.getUTCMonth() === b.getUTCMonth() && - a.getUTCDate() === b.getUTCDate(); - } - - export function date_format(date: Date, now: Date, ignore_settings?: boolean) : ColloquialFormat { - if(!ignore_settings && !settings.static_global(Settings.KEY_CHAT_COLLOQUIAL_TIMESTAMPS)) - return ColloquialFormat.GENERAL; - - if(dateEqual(date, now)) - return ColloquialFormat.TODAY; - - date = new Date(date.getTime()); - date.setDate(date.getDate() + 1); - - if(dateEqual(date, now)) - return ColloquialFormat.YESTERDAY; - - return ColloquialFormat.GENERAL; - } - - export function formatDayTime(date: Date) { - return ("0" + date.getHours()).substr(-2) + ":" + ("0" + date.getMinutes()).substr(-2); - } - - export function format_date_general(date: Date, hours?: boolean) : string { - return ('00' + date.getDate()).substr(-2) + "." - + ('00' + date.getMonth()).substr(-2) + "." - + date.getFullYear() + - (typeof(hours) === "undefined" || hours ? " at " - + ('00' + date.getHours()).substr(-2) + ":" - + ('00' + date.getMinutes()).substr(-2) - : ""); - } - - export function format_date_colloquial(date: Date, current_timestamp: Date) : { result: string; format: ColloquialFormat } { - const format = date_format(date, current_timestamp); - if(format == ColloquialFormat.GENERAL) { - return { - result: format_date_general(date), - format: format - }; - } else { - let hrs = date.getHours(); - let time = "AM"; - if(hrs > 12) { - hrs -= 12; - time = "PM"; - } - return { - result: (format == ColloquialFormat.YESTERDAY ? tr("Yesterday at") : tr("Today at")) + " " + ("0" + hrs).substr(-2) + ":" + ("0" + date.getMinutes()).substr(-2) + " " + time, - format: format - }; - } - } - - export function format_chat_time(date: Date) : { - result: string, - next_update: number /* in MS */ - } { - const timestamp = date.getTime(); - const current_timestamp = new Date(); - - const result = { - result: "", - next_update: 0 - }; - - if(settings.static_global(Settings.KEY_CHAT_FIXED_TIMESTAMPS)) { - const format = format_date_colloquial(date, current_timestamp); - result.result = format.result; - result.next_update = 0; /* TODO: Update on day change? */ - } else { - const delta = current_timestamp.getTime() - timestamp; - if(delta < 2000) { - result.result = "now"; - result.next_update = 2500 - delta; /* update after two seconds */ - } else if(delta < 30000) { /* 30 seconds */ - result.result = Math.floor(delta / 1000) + " " + tr("seconds ago"); - result.next_update = 1000; /* update every second */ - } else if(delta < 30 * 60 * 1000) { /* 30 minutes */ - if(delta < 120 * 1000) - result.result = tr("one minute ago"); - else - result.result = Math.floor(delta / (1000 * 60)) + " " + tr("minutes ago"); - result.next_update = 60000; /* updater after a minute */ - } else { - result.result = format_date_colloquial(date, current_timestamp).result; - result.next_update = 0; /* TODO: Update on day change? */ - } - } - - return result; - } - } - export namespace time { - export function format_online_time(secs: number) : string { - let years = Math.floor(secs / (60 * 60 * 24 * 365)); - let days = Math.floor(secs / (60 * 60 * 24)) % 365; - let hours = Math.floor(secs / (60 * 60)) % 24; - let minutes = Math.floor(secs / 60) % 60; - let seconds = Math.floor(secs % 60); - - let result = ""; - if(years > 0) - result += years + " " + tr("years") + " "; - if(years > 0 || days > 0) - result += days + " " + tr("days") + " "; - if(years > 0 || days > 0 || hours > 0) - result += hours + " " + tr("hours") + " "; - if(years > 0 || days > 0 || hours > 0 || minutes > 0) - result += minutes + " " + tr("minutes") + " "; - if(years > 0 || days > 0 || hours > 0 || minutes > 0 || seconds > 0) - result += seconds + " " + tr("seconds") + " "; - else - result = tr("now") + " "; - - return result.substr(0, result.length - 1); - } - } -} \ No newline at end of file diff --git a/shared/js/ui/frames/side/client_info.ts b/shared/js/ui/frames/side/client_info.ts index f5704057..c18c9851 100644 --- a/shared/js/ui/frames/side/client_info.ts +++ b/shared/js/ui/frames/side/client_info.ts @@ -1,11 +1,11 @@ import {GroupManager} from "tc-shared/permission/GroupManager"; import {Frame, FrameContent} from "tc-shared/ui/frames/chat_frame"; -import {ClientEntry, LocalClientEntry} from "tc-shared/ui/client"; import {openClientInfo} from "tc-shared/ui/modal/ModalClientInfo"; import * as htmltags from "tc-shared/ui/htmltags"; import * as image_preview from "../image_preview"; -import {format} from "tc-shared/ui/frames/side/chat_helper"; import * as i18nc from "tc-shared/i18n/country"; +import {ClientEntry, LocalClientEntry} from "tc-shared/tree/Client"; +import {format_online_time} from "tc-shared/utils/TimeUtils"; export class ClientInfo { readonly handle: Frame; @@ -94,7 +94,7 @@ export class ClientInfo { /* updating the info fields */ { const online_time = this._html_tag.find(".client-online-time"); - online_time.text(format.time.format_online_time(client ? client.calculateOnlineTime() : 0)); + online_time.text(format_online_time(client ? client.calculateOnlineTime() : 0)); if(this._online_time_updater) { clearInterval(this._online_time_updater); this._online_time_updater = 0; @@ -109,7 +109,7 @@ export class ClientInfo { } if(client.currentChannel()) /* If he has no channel then he might be disconnected */ - online_time.text(format.time.format_online_time(client.calculateOnlineTime())); + online_time.text(format_online_time(client.calculateOnlineTime())); else { online_time.text(online_time.text() + tr(" (left view)")); clearInterval(this._online_time_updater); diff --git a/shared/js/ui/frames/side/music_info.ts b/shared/js/ui/frames/side/music_info.ts index bbac4647..aaff3ca9 100644 --- a/shared/js/ui/frames/side/music_info.ts +++ b/shared/js/ui/frames/side/music_info.ts @@ -1,5 +1,4 @@ import {Frame, FrameContent} from "tc-shared/ui/frames/chat_frame"; -import {ClientEvents, MusicClientEntry, MusicClientPlayerState, SongInfo} from "tc-shared/ui/client"; import {LogCategory} from "tc-shared/log"; import {CommandResult, PlaylistSong} from "tc-shared/connection/ServerConnectionDeclaration"; import {createErrorModal, createInputModal} from "tc-shared/ui/elements/Modal"; @@ -7,7 +6,7 @@ import * as log from "tc-shared/log"; import * as image_preview from "../image_preview"; import {Registry} from "tc-shared/events"; import {ErrorCode} from "tc-shared/connection/ErrorCode"; -import {VoicePlayerState} from "tc-shared/voice/VoicePlayer"; +import {ClientEvents, MusicClientEntry, SongInfo} from "tc-shared/tree/Client"; export interface MusicSidebarEvents { "open": {}, /* triggers when frame should be shown */ diff --git a/shared/js/ui/htmltags.ts b/shared/js/ui/htmltags.ts index 76a4373e..37d2c19d 100644 --- a/shared/js/ui/htmltags.ts +++ b/shared/js/ui/htmltags.ts @@ -1,7 +1,7 @@ import * as log from "tc-shared/log"; import {LogCategory} from "tc-shared/log"; -import {ChannelEntry} from "tc-shared/ui/channel"; -import {ClientEntry} from "tc-shared/ui/client"; +import {ChannelEntry} from "tc-shared/tree/Channel"; +import {ClientEntry} from "tc-shared/tree/Client"; import {htmlEscape} from "tc-shared/ui/frames/chat"; import {server_connections} from "tc-shared/ui/frames/connection_handlers"; import {guid} from "tc-shared/crypto/uid"; diff --git a/shared/js/ui/modal/ModalAvatarList.ts b/shared/js/ui/modal/ModalAvatarList.ts index d63a6957..ab1ba0d1 100644 --- a/shared/js/ui/modal/ModalAvatarList.ts +++ b/shared/js/ui/modal/ModalAvatarList.ts @@ -3,7 +3,7 @@ import {LogCategory} from "tc-shared/log"; import {ConnectionHandler} from "tc-shared/ConnectionHandler"; import {base64_encode_ab} from "tc-shared/utils/buffers"; import {spawnYesNo} from "tc-shared/ui/modal/ModalYesNo"; -import {ClientEntry} from "tc-shared/ui/client"; +import {ClientEntry} from "tc-shared/tree/Client"; import * as log from "tc-shared/log"; import * as moment from "moment"; diff --git a/shared/js/ui/modal/ModalBotMenue.ts b/shared/js/ui/modal/ModalBotMenue.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/shared/js/ui/modal/ModalChangeLatency.ts b/shared/js/ui/modal/ModalChangeLatency.ts index 6619e9ea..ad969efc 100644 --- a/shared/js/ui/modal/ModalChangeLatency.ts +++ b/shared/js/ui/modal/ModalChangeLatency.ts @@ -1,5 +1,5 @@ import {createModal, Modal} from "tc-shared/ui/elements/Modal"; -import {ClientEntry} from "tc-shared/ui/client"; +import {ClientEntry} from "tc-shared/tree/Client"; import {Slider, sliderfy} from "tc-shared/ui/elements/Slider"; import * as htmltags from "tc-shared/ui/htmltags"; import {VoicePlayerLatencySettings} from "tc-shared/voice/VoicePlayer"; diff --git a/shared/js/ui/modal/ModalChangeVolume.ts b/shared/js/ui/modal/ModalChangeVolume.ts index 8271705e..4c234cc7 100644 --- a/shared/js/ui/modal/ModalChangeVolume.ts +++ b/shared/js/ui/modal/ModalChangeVolume.ts @@ -2,7 +2,7 @@ import {sliderfy} from "tc-shared/ui/elements/Slider"; import {createModal, Modal} from "tc-shared/ui/elements/Modal"; -import {ClientEntry} from "tc-shared/ui/client"; +import {ClientEntry} from "tc-shared/tree/Client"; import * as htmltags from "tc-shared/ui/htmltags"; let modal: Modal; diff --git a/shared/js/ui/modal/ModalChangeVolumeNew.tsx b/shared/js/ui/modal/ModalChangeVolumeNew.tsx index 2568662e..e7f3bef6 100644 --- a/shared/js/ui/modal/ModalChangeVolumeNew.tsx +++ b/shared/js/ui/modal/ModalChangeVolumeNew.tsx @@ -4,7 +4,7 @@ import {Slider} from "tc-shared/ui/react-elements/Slider"; import {Button} from "tc-shared/ui/react-elements/Button"; import {Translatable} from "tc-shared/ui/react-elements/i18n"; import {EventHandler, ReactEventHandler, Registry} from "tc-shared/events"; -import {ClientEntry, MusicClientEntry} from "tc-shared/ui/client"; +import {ClientEntry, MusicClientEntry} from "tc-shared/tree/Client"; import {InternalModal} from "tc-shared/ui/react-elements/internal-modal/Controller"; const cssStyle = require("./ModalChangeVolume.scss"); diff --git a/shared/js/ui/modal/ModalChannelInfo.ts b/shared/js/ui/modal/ModalChannelInfo.ts index 7433eea0..c38c73c0 100644 --- a/shared/js/ui/modal/ModalChannelInfo.ts +++ b/shared/js/ui/modal/ModalChannelInfo.ts @@ -1,5 +1,5 @@ import {createInfoModal, createModal, Modal} from "tc-shared/ui/elements/Modal"; -import {ChannelEntry} from "tc-shared/ui/channel"; +import {ChannelEntry} from "tc-shared/tree/Channel"; import {copy_to_clipboard} from "tc-shared/utils/helpers"; import * as tooltip from "tc-shared/ui/elements/Tooltip"; import {formatMessage} from "tc-shared/ui/frames/chat"; diff --git a/shared/js/ui/modal/ModalClientInfo.ts b/shared/js/ui/modal/ModalClientInfo.ts index d6f4d600..e846f98b 100644 --- a/shared/js/ui/modal/ModalClientInfo.ts +++ b/shared/js/ui/modal/ModalClientInfo.ts @@ -1,4 +1,4 @@ -import {ClientConnectionInfo, ClientEntry} from "tc-shared/ui/client"; +import {ClientConnectionInfo, ClientEntry} from "tc-shared/tree/Client"; import PermissionType from "tc-shared/permission/PermissionType"; import {createInfoModal, createModal, Modal} from "tc-shared/ui/elements/Modal"; import {copy_to_clipboard} from "tc-shared/utils/helpers"; diff --git a/shared/js/ui/modal/ModalCreateChannel.ts b/shared/js/ui/modal/ModalCreateChannel.ts index a5be35d3..55f0b990 100644 --- a/shared/js/ui/modal/ModalCreateChannel.ts +++ b/shared/js/ui/modal/ModalCreateChannel.ts @@ -1,6 +1,6 @@ import PermissionType from "tc-shared/permission/PermissionType"; import {ConnectionHandler} from "tc-shared/ConnectionHandler"; -import {ChannelEntry, ChannelProperties} from "tc-shared/ui/channel"; +import {ChannelEntry, ChannelProperties} from "tc-shared/tree/Channel"; import {PermissionManager, PermissionValue} from "tc-shared/permission/PermissionManager"; import {LogCategory} from "tc-shared/log"; import {createModal} from "tc-shared/ui/elements/Modal"; diff --git a/shared/js/ui/modal/ModalGroupAssignment.ts b/shared/js/ui/modal/ModalGroupAssignment.ts index 91d79693..eefdc442 100644 --- a/shared/js/ui/modal/ModalGroupAssignment.ts +++ b/shared/js/ui/modal/ModalGroupAssignment.ts @@ -1,7 +1,7 @@ import {LogCategory} from "tc-shared/log"; import {createModal, Modal} from "tc-shared/ui/elements/Modal"; import * as log from "tc-shared/log"; -import {ClientEntry} from "tc-shared/ui/client"; +import {ClientEntry} from "tc-shared/tree/Client"; import {GroupManager, GroupType} from "tc-shared/permission/GroupManager"; import PermissionType from "tc-shared/permission/PermissionType"; diff --git a/shared/js/ui/modal/ModalInvite.ts b/shared/js/ui/modal/ModalInvite.ts index 43f77623..da93a99c 100644 --- a/shared/js/ui/modal/ModalInvite.ts +++ b/shared/js/ui/modal/ModalInvite.ts @@ -1,7 +1,7 @@ import {settings, Settings} from "tc-shared/settings"; import {createModal, Modal} from "tc-shared/ui/elements/Modal"; import {ConnectionHandler} from "tc-shared/ConnectionHandler"; -import {ServerAddress} from "tc-shared/ui/server"; +import {ServerAddress} from "tc-shared/tree/Server"; type URLGeneratorSettings = { flag_direct: boolean, diff --git a/shared/js/ui/modal/ModalMusicManage.ts b/shared/js/ui/modal/ModalMusicManage.ts index 13672018..a2bae37f 100644 --- a/shared/js/ui/modal/ModalMusicManage.ts +++ b/shared/js/ui/modal/ModalMusicManage.ts @@ -1,6 +1,6 @@ import {createErrorModal, createModal} from "tc-shared/ui/elements/Modal"; import {ConnectionHandler} from "tc-shared/ConnectionHandler"; -import {MusicClientEntry} from "tc-shared/ui/client"; +import {MusicClientEntry} from "tc-shared/tree/Client"; import {Registry} from "tc-shared/events"; import {CommandResult} from "tc-shared/connection/ServerConnectionDeclaration"; import {LogCategory} from "tc-shared/log"; diff --git a/shared/js/ui/modal/ModalNewcomer.tsx b/shared/js/ui/modal/ModalNewcomer.tsx index 70e587d7..e8d7fe54 100644 --- a/shared/js/ui/modal/ModalNewcomer.tsx +++ b/shared/js/ui/modal/ModalNewcomer.tsx @@ -2,7 +2,6 @@ import {createModal, Modal} from "tc-shared/ui/elements/Modal"; import {tra} from "tc-shared/i18n/localize"; import {Registry} from "tc-shared/events"; import {modal_settings} from "tc-shared/ui/modal/ModalSettings"; -import {profiles} from "tc-shared/profiles/ConnectionProfile"; import {spawnYesNo} from "tc-shared/ui/modal/ModalYesNo"; import {initialize_audio_microphone_controller, MicrophoneSettingsEvents} from "tc-shared/ui/modal/settings/Microphone"; import {MicrophoneSettings} from "tc-shared/ui/modal/settings/MicrophoneRenderer"; diff --git a/shared/js/ui/modal/ModalServerEdit.ts b/shared/js/ui/modal/ModalServerEdit.ts index bcac98b1..330e5a88 100644 --- a/shared/js/ui/modal/ModalServerEdit.ts +++ b/shared/js/ui/modal/ModalServerEdit.ts @@ -1,4 +1,4 @@ -import {ServerEntry, ServerProperties} from "tc-shared/ui/server"; +import {ServerEntry, ServerProperties} from "tc-shared/tree/Server"; import {createModal, Modal} from "tc-shared/ui/elements/Modal"; import PermissionType from "tc-shared/permission/PermissionType"; import {GroupManager} from "tc-shared/permission/GroupManager"; diff --git a/shared/js/ui/modal/ModalServerInfo.ts b/shared/js/ui/modal/ModalServerInfo.ts index 4898d24d..831e6261 100644 --- a/shared/js/ui/modal/ModalServerInfo.ts +++ b/shared/js/ui/modal/ModalServerInfo.ts @@ -3,7 +3,7 @@ import { RequestInfoStatus, ServerBandwidthInfoUpdateCallback } from "tc-shared/ui/modal/ModalServerInfoBandwidth"; -import {ServerEntry} from "tc-shared/ui/server"; +import {ServerEntry} from "tc-shared/tree/Server"; import {CommandResult} from "tc-shared/connection/ServerConnectionDeclaration"; import {createErrorModal, createModal, Modal} from "tc-shared/ui/elements/Modal"; import {LogCategory} from "tc-shared/log"; diff --git a/shared/js/ui/modal/ModalServerInfoBandwidth.ts b/shared/js/ui/modal/ModalServerInfoBandwidth.ts index d2bca777..abb8ba72 100644 --- a/shared/js/ui/modal/ModalServerInfoBandwidth.ts +++ b/shared/js/ui/modal/ModalServerInfoBandwidth.ts @@ -1,4 +1,4 @@ -import {ServerConnectionInfo, ServerEntry} from "tc-shared/ui/server"; +import {ServerConnectionInfo, ServerEntry} from "tc-shared/tree/Server"; import {createModal, Modal} from "tc-shared/ui/elements/Modal"; import {CommandResult} from "tc-shared/connection/ServerConnectionDeclaration"; import {Graph} from "tc-shared/ui/elements/NetGraph"; diff --git a/shared/js/ui/react-elements/TimestampRenderer.tsx b/shared/js/ui/react-elements/TimestampRenderer.tsx index 24fe9819..d511a215 100644 --- a/shared/js/ui/react-elements/TimestampRenderer.tsx +++ b/shared/js/ui/react-elements/TimestampRenderer.tsx @@ -1,9 +1,9 @@ -import {format} from "tc-shared/ui/frames/side/chat_helper"; import {useEffect, useState} from "react"; import * as React from "react"; +import {format_chat_time} from "tc-shared/utils/DateUtils"; export const TimestampRenderer = (props: { timestamp: number }) => { - const time = format.date.format_chat_time(new Date(props.timestamp)); + const time = format_chat_time(new Date(props.timestamp)); const [ revision, setRevision ] = useState(0); useEffect(() => { diff --git a/shared/js/ui/tree/Channel.tsx b/shared/js/ui/tree/Channel.tsx index 3e312f2d..2d30d870 100644 --- a/shared/js/ui/tree/Channel.tsx +++ b/shared/js/ui/tree/Channel.tsx @@ -4,7 +4,7 @@ import { ReactComponentBase } from "tc-shared/ui/react-elements/ReactComponentBase"; import * as React from "react"; -import {ChannelEntry as ChannelEntryController, ChannelEvents, ChannelProperties} from "../channel"; +import {ChannelEntry as ChannelEntryController, ChannelEvents, ChannelProperties} from "../../tree/Channel"; import {LocalIconRenderer} from "tc-shared/ui/react-elements/Icon"; import {EventHandler, ReactEventHandler} from "tc-shared/events"; import {Settings, settings} from "tc-shared/settings"; diff --git a/shared/js/ui/tree/Client.tsx b/shared/js/ui/tree/Client.tsx index 89e11d07..97a1e54e 100644 --- a/shared/js/ui/tree/Client.tsx +++ b/shared/js/ui/tree/Client.tsx @@ -11,7 +11,7 @@ import { ClientType, LocalClientEntry, MusicClientEntry -} from "../client"; +} from "../../tree/Client"; import {EventHandler, ReactEventHandler} from "tc-shared/events"; import {Group, GroupEvents} from "tc-shared/permission/GroupManager"; import {Settings, settings} from "tc-shared/settings"; diff --git a/shared/js/ui/tree/Server.tsx b/shared/js/ui/tree/Server.tsx index 6468c349..b5aa511e 100644 --- a/shared/js/ui/tree/Server.tsx +++ b/shared/js/ui/tree/Server.tsx @@ -3,7 +3,7 @@ import { BatchUpdateType, ReactComponentBase } from "tc-shared/ui/react-elements/ReactComponentBase"; -import {ServerEntry as ServerEntryController, ServerEvents} from "../server"; +import {ServerEntry as ServerEntryController, ServerEvents} from "../../tree/Server"; import * as React from "react"; import {LocalIconRenderer} from "tc-shared/ui/react-elements/Icon"; import {EventHandler, ReactEventHandler} from "tc-shared/events"; diff --git a/shared/js/ui/tree/TreeEntry.tsx b/shared/js/ui/tree/TreeEntry.tsx index efa596e1..cb753a29 100644 --- a/shared/js/ui/tree/TreeEntry.tsx +++ b/shared/js/ui/tree/TreeEntry.tsx @@ -1,5 +1,5 @@ import {ReactComponentBase} from "tc-shared/ui/react-elements/ReactComponentBase"; -import {ChannelTreeEntry, ChannelTreeEntryEvents} from "tc-shared/ui/TreeEntry"; +import {ChannelTreeEntry, ChannelTreeEntryEvents} from "tc-shared/tree/ChannelTreeEntry"; import * as React from "react"; import {EventHandler, ReactEventHandler} from "tc-shared/events"; diff --git a/shared/js/ui/tree/View.tsx b/shared/js/ui/tree/View.tsx index 9b55705d..68efe9ad 100644 --- a/shared/js/ui/tree/View.tsx +++ b/shared/js/ui/tree/View.tsx @@ -3,7 +3,7 @@ import { BatchUpdateType, ReactComponentBase } from "tc-shared/ui/react-elements/ReactComponentBase"; -import {ChannelTree, ChannelTreeEvents} from "tc-shared/ui/view"; +import {ChannelTree, ChannelTreeEvents} from "tc-shared/tree/ChannelTree"; import ResizeObserver from 'resize-observer-polyfill'; import * as React from "react"; @@ -14,9 +14,9 @@ import {ChannelEntryView as ChannelEntryView} from "./Channel"; import {ServerEntry as ServerEntryView} from "./Server"; import {ClientEntry as ClientEntryView} from "./Client"; -import {ChannelEntry, ChannelEvents} from "tc-shared/ui/channel"; -import {ServerEntry} from "tc-shared/ui/server"; -import {ClientEntry, ClientType} from "tc-shared/ui/client"; +import {ChannelEntry, ChannelEvents} from "tc-shared/tree/Channel"; +import {ServerEntry} from "tc-shared/tree/server"; +import {ClientEntry, ClientType} from "tc-shared/tree/Client"; import * as log from "tc-shared/log"; import {LogCategory} from "tc-shared/log"; import {ConnectionEvents} from "tc-shared/ConnectionHandler"; diff --git a/shared/js/utils/DateUtils.ts b/shared/js/utils/DateUtils.ts new file mode 100644 index 00000000..ba4749e8 --- /dev/null +++ b/shared/js/utils/DateUtils.ts @@ -0,0 +1,114 @@ +import {Settings, settings} from "tc-shared/settings"; + +export enum ColloquialFormat { + YESTERDAY, + TODAY, + GENERAL +} + +function dateEqual(a: Date, b: Date) { + return a.getUTCFullYear() === b.getUTCFullYear() && + a.getUTCMonth() === b.getUTCMonth() && + a.getUTCDate() === b.getUTCDate(); +} + +export function same_day(a: number | Date, b: number | Date) { + a = a instanceof Date ? a : new Date(a); + b = b instanceof Date ? b : new Date(b); + + if(a.getDate() !== b.getDate()) + return false; + if(a.getMonth() !== b.getMonth()) + return false; + return a.getFullYear() === b.getFullYear(); +} + +export function date_format(date: Date, now: Date, ignore_settings?: boolean) : ColloquialFormat { + if(!ignore_settings && !settings.static_global(Settings.KEY_CHAT_COLLOQUIAL_TIMESTAMPS)) + return ColloquialFormat.GENERAL; + + if(dateEqual(date, now)) + return ColloquialFormat.TODAY; + + date = new Date(date.getTime()); + date.setDate(date.getDate() + 1); + + if(dateEqual(date, now)) + return ColloquialFormat.YESTERDAY; + + return ColloquialFormat.GENERAL; +} + +export function formatDayTime(date: Date) { + return ("0" + date.getHours()).substr(-2) + ":" + ("0" + date.getMinutes()).substr(-2); +} + +export function format_date_general(date: Date, hours?: boolean) : string { + return ('00' + date.getDate()).substr(-2) + "." + + ('00' + date.getMonth()).substr(-2) + "." + + date.getFullYear() + + (typeof(hours) === "undefined" || hours ? " at " + + ('00' + date.getHours()).substr(-2) + ":" + + ('00' + date.getMinutes()).substr(-2) + : ""); +} + +export function format_date_colloquial(date: Date, current_timestamp: Date) : { result: string; format: ColloquialFormat } { + const format = date_format(date, current_timestamp); + if(format == ColloquialFormat.GENERAL) { + return { + result: format_date_general(date), + format: format + }; + } else { + let hrs = date.getHours(); + let time = "AM"; + if(hrs > 12) { + hrs -= 12; + time = "PM"; + } + return { + result: (format == ColloquialFormat.YESTERDAY ? tr("Yesterday at") : tr("Today at")) + " " + ("0" + hrs).substr(-2) + ":" + ("0" + date.getMinutes()).substr(-2) + " " + time, + format: format + }; + } +} + +export function format_chat_time(date: Date) : { + result: string, + next_update: number /* in MS */ +} { + const timestamp = date.getTime(); + const current_timestamp = new Date(); + + const result = { + result: "", + next_update: 0 + }; + + if(settings.static_global(Settings.KEY_CHAT_FIXED_TIMESTAMPS)) { + const format = format_date_colloquial(date, current_timestamp); + result.result = format.result; + result.next_update = 0; /* TODO: Update on day change? */ + } else { + const delta = current_timestamp.getTime() - timestamp; + if(delta < 2000) { + result.result = "now"; + result.next_update = 2500 - delta; /* update after two seconds */ + } else if(delta < 30000) { /* 30 seconds */ + result.result = Math.floor(delta / 1000) + " " + tr("seconds ago"); + result.next_update = 1000; /* update every second */ + } else if(delta < 30 * 60 * 1000) { /* 30 minutes */ + if(delta < 120 * 1000) + result.result = tr("one minute ago"); + else + result.result = Math.floor(delta / (1000 * 60)) + " " + tr("minutes ago"); + result.next_update = 60000; /* updater after a minute */ + } else { + result.result = format_date_colloquial(date, current_timestamp).result; + result.next_update = 0; /* TODO: Update on day change? */ + } + } + + return result; +} \ No newline at end of file diff --git a/shared/js/utils/TimeUtils.ts b/shared/js/utils/TimeUtils.ts new file mode 100644 index 00000000..eac81a00 --- /dev/null +++ b/shared/js/utils/TimeUtils.ts @@ -0,0 +1,23 @@ +export function format_online_time(secs: number) : string { + let years = Math.floor(secs / (60 * 60 * 24 * 365)); + let days = Math.floor(secs / (60 * 60 * 24)) % 365; + let hours = Math.floor(secs / (60 * 60)) % 24; + let minutes = Math.floor(secs / 60) % 60; + let seconds = Math.floor(secs % 60); + + let result = ""; + if(years > 0) + result += years + " " + tr("years") + " "; + if(years > 0 || days > 0) + result += days + " " + tr("days") + " "; + if(years > 0 || days > 0 || hours > 0) + result += hours + " " + tr("hours") + " "; + if(years > 0 || days > 0 || hours > 0 || minutes > 0) + result += minutes + " " + tr("minutes") + " "; + if(years > 0 || days > 0 || hours > 0 || minutes > 0 || seconds > 0) + result += seconds + " " + tr("seconds") + " "; + else + result = tr("now") + " "; + + return result.substr(0, result.length - 1); +} \ No newline at end of file diff --git a/shared/js/workers/WorkerOwner.ts b/shared/js/workers/WorkerOwner.ts index 2f5f0199..ce1d63b9 100644 --- a/shared/js/workers/WorkerOwner.ts +++ b/shared/js/workers/WorkerOwner.ts @@ -1,18 +1,10 @@ -import * as log from "../log"; -import {LogCategory, logDebug, logWarn} from "../log"; -import {WorkerMessage, WorkerMessageCommand, WorkerMessageNotify} from "./Protocol"; -import {CommandResponseType, ExecuteResult, GenericCommandMapping, GenericCommands, GenericNotify} from "./Definitions"; +import {LogCategory, logDebug} from "../log"; +import {WorkerMessage} from "./Protocol"; +import {GenericCommandMapping, GenericCommands, GenericNotify} from "./Definitions"; import {tr} from "../i18n/localize"; import {Registry} from "../events"; import {WorkerCommunication} from "tc-shared/workers/Worker"; -type PendingCommand = { - timeout?: any, - - timestampSend: number, - callbackResolve: (_: ExecuteResult) => void; -} - export interface WorkerEvents { notify_worker_died: {} } diff --git a/shared/js/workers/pow/index.ts b/shared/js/workers/pow/index.ts index 262b9490..4b3dfc8b 100644 --- a/shared/js/workers/pow/index.ts +++ b/shared/js/workers/pow/index.ts @@ -2,7 +2,6 @@ declare function postMessage(message: any): void; const prefix = "[POWWorker] "; -let initialized = false; let memory: WebAssembly.Memory; let memory_u8: Uint8Array; let wasm_object: WebAssembly.WebAssemblyInstantiatedSource; diff --git a/shared/js/workers/tsconfig_worker_pow.json b/shared/js/workers/tsconfig_worker_pow.json deleted file mode 100644 index 4ba50fbb..00000000 --- a/shared/js/workers/tsconfig_worker_pow.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "compilerOptions": { - "module": "none", - "target": "es6", - "sourceMap": true, - "outFile": "WorkerPOW.js" - }, - "include": [ - "../../types/*.d.ts" - ], - "files": [ - "pow/POWWorker.ts" - ] -} \ No newline at end of file