redo emoji
ci/woodpecker/push/base Pipeline was successful Details

stripwan
gapodo 2023-11-21 01:58:05 +01:00
parent 5daff6117c
commit 5b3a208f16
8 changed files with 188 additions and 208 deletions

View File

@ -9,7 +9,6 @@
<meta name="og:description" content="The TeaSpeak Web client is a in the browser running client for the VoIP communication software TeaSpeak." /> <meta name="og:description" content="The TeaSpeak Web client is a in the browser running client for the VoIP communication software TeaSpeak." />
<meta name="og:url" content="https://web.teaspeak.de/"> <meta name="og:url" content="https://web.teaspeak.de/">
<% /* TODO: Put in an appropriate image <meta name="og:image" content="https://www.whatsapp.com/img/whatsapp-promo.png"> */ %>
<% /* Using an absolute path here since the manifest.json works only with such. */ %> <% /* Using an absolute path here since the manifest.json works only with such. */ %>
<% /* <link rel="manifest" href="/manifest.json"> */ %> <% /* <link rel="manifest" href="/manifest.json"> */ %>
@ -27,19 +26,6 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="format-detection" content="telephone=no"> <meta name="format-detection" content="telephone=no">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script defer async src="https://www.googletagmanager.com/gtag/js?id=UA-113151733-4"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'UA-113151733-4');
</script>
<link rel="preload" as="image" href="<%= require("./images/initial-sequence.gif") %>"> <link rel="preload" as="image" href="<%= require("./images/initial-sequence.gif") %>">
<link rel="preload" as="image" href="<%= require("./images/bowl.png") %>"> <link rel="preload" as="image" href="<%= require("./images/bowl.png") %>">
<% /* We don't preload the bowl since it's only a div background */ %> <% /* We don't preload the bowl since it's only a div background */ %>

35
package-lock.json generated
View File

@ -2834,6 +2834,7 @@
"version": "7.10.3", "version": "7.10.3",
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.10.3.tgz", "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.10.3.tgz",
"integrity": "sha512-RzGO0RLSdokm9Ipe/YD+7ww8X2Ro79qiXZF3HU9ljrM+qnJmH1Vqth+hbiQZy761LnMJTMitHDuKVYTk3k4dLw==", "integrity": "sha512-RzGO0RLSdokm9Ipe/YD+7ww8X2Ro79qiXZF3HU9ljrM+qnJmH1Vqth+hbiQZy761LnMJTMitHDuKVYTk3k4dLw==",
"dev": true,
"requires": { "requires": {
"regenerator-runtime": "^0.13.4" "regenerator-runtime": "^0.13.4"
} }
@ -3037,6 +3038,16 @@
"integrity": "sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==", "integrity": "sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==",
"dev": true "dev": true
}, },
"@emoji-mart/data": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@emoji-mart/data/-/data-1.1.2.tgz",
"integrity": "sha512-1HP8BxD2azjqWJvxIaWAMyTySeZY0Osr83ukYjltPVkNXeJvTz7yDrPLBtnrD5uqJ3tg4CcLuuBW09wahqL/fg=="
},
"@emoji-mart/react": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@emoji-mart/react/-/react-1.1.1.tgz",
"integrity": "sha512-NMlFNeWgv1//uPsvLxvGQoIerPuVdXwK/EUek8OOkJ6wVOWPUizRBJU0hDqWZCOROVpfBgCemaC3m6jDOXi03g=="
},
"@google-cloud/common": { "@google-cloud/common": {
"version": "2.4.0", "version": "2.4.0",
"resolved": "https://registry.npmjs.org/@google-cloud/common/-/common-2.4.0.tgz", "resolved": "https://registry.npmjs.org/@google-cloud/common/-/common-2.4.0.tgz",
@ -4970,15 +4981,6 @@
"integrity": "sha512-nv+GSx77ZtXiJzwKdsASqi+YQ5Z7vwHsTP0JY2SiQgjGckkBRKZnk8nIM+7oUZ1VCtuTz0+By4qVR7fqzp/Dfg==", "integrity": "sha512-nv+GSx77ZtXiJzwKdsASqi+YQ5Z7vwHsTP0JY2SiQgjGckkBRKZnk8nIM+7oUZ1VCtuTz0+By4qVR7fqzp/Dfg==",
"dev": true "dev": true
}, },
"@types/emoji-mart": {
"version": "3.0.12",
"resolved": "https://registry.npmjs.org/@types/emoji-mart/-/emoji-mart-3.0.12.tgz",
"integrity": "sha512-ff8xM0+98PhhX15xjDseOWGDz413QvCK6D+yes88u0GJ7DoH3qR5AdMI9CbYA7/jE25WxSvX2SsGnI8Mw1Wbkw==",
"dev": true,
"requires": {
"@types/react": "*"
}
},
"@types/emscripten": { "@types/emscripten": {
"version": "1.39.10", "version": "1.39.10",
"resolved": "https://registry.npmjs.org/@types/emscripten/-/emscripten-1.39.10.tgz", "resolved": "https://registry.npmjs.org/@types/emscripten/-/emscripten-1.39.10.tgz",
@ -9915,13 +9917,9 @@
} }
}, },
"emoji-mart": { "emoji-mart": {
"version": "3.0.1", "version": "5.5.2",
"resolved": "https://registry.npmjs.org/emoji-mart/-/emoji-mart-3.0.1.tgz", "resolved": "https://registry.npmjs.org/emoji-mart/-/emoji-mart-5.5.2.tgz",
"integrity": "sha512-sxpmMKxqLvcscu6mFn9ITHeZNkGzIvD0BSNFE/LJESPbCA8s1jM6bCDPjWbV31xHq7JXaxgpHxLB54RCbBZSlg==", "integrity": "sha512-Sqc/nso4cjxhOwWJsp9xkVm8OF5c+mJLZJFoFfzRuKO+yWiN7K8c96xmtughYb0d/fZ8UC6cLIQ/p4BR6Pv3/A=="
"requires": {
"@babel/runtime": "^7.0.0",
"prop-types": "^15.6.0"
}
}, },
"emoji-regex": { "emoji-regex": {
"version": "9.2.2", "version": "9.2.2",
@ -19527,7 +19525,8 @@
"regenerator-runtime": { "regenerator-runtime": {
"version": "0.13.5", "version": "0.13.5",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz",
"integrity": "sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA==" "integrity": "sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA==",
"dev": true
}, },
"regenerator-transform": { "regenerator-transform": {
"version": "0.14.5", "version": "0.14.5",
@ -23899,4 +23898,4 @@
} }
} }
} }
} }

View File

@ -24,7 +24,6 @@
"@svgr/webpack": "^5.5.0", "@svgr/webpack": "^5.5.0",
"@types/dompurify": "^2.4.0", "@types/dompurify": "^2.4.0",
"@types/ejs": "^3.1.5", "@types/ejs": "^3.1.5",
"@types/emoji-mart": "^3.0.12",
"@types/emscripten": "^1.39.10", "@types/emscripten": "^1.39.10",
"@types/fs-extra": "^8.1.5", "@types/fs-extra": "^8.1.5",
"@types/html-minifier": "^3.5.3", "@types/html-minifier": "^3.5.3",
@ -98,6 +97,8 @@
}, },
"homepage": "https://www.teaspeak.de", "homepage": "https://www.teaspeak.de",
"dependencies": { "dependencies": {
"@emoji-mart/data": "^1.1.2",
"@emoji-mart/react": "^1.1.1",
"@types/crypto-js": "^4.2.1", "@types/crypto-js": "^4.2.1",
"broadcastchannel-polyfill": "^1.0.1", "broadcastchannel-polyfill": "^1.0.1",
"buffer": "^6.0.3", "buffer": "^6.0.3",
@ -105,7 +106,7 @@
"crypto-js": "^4.2.0", "crypto-js": "^4.2.0",
"detect-browser": "^5.3.0", "detect-browser": "^5.3.0",
"dompurify": "^2.4.7", "dompurify": "^2.4.7",
"emoji-mart": "^3.0.1", "emoji-mart": "^5.5.2",
"emoji-regex": "^9.2.2", "emoji-regex": "^9.2.2",
"highlight.js": "^10.7.3", "highlight.js": "^10.7.3",
"ip-regex": "^4.3.0", "ip-regex": "^4.3.0",

BIN
shared/img/smiley.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -1,14 +1,14 @@
import * as loader from "tc-loader"; import * as loader from "tc-loader";
import {Stage} from "tc-loader"; import { Stage } from "tc-loader";
import {ignorePromise, WritableKeys} from "tc-shared/proto"; import { ignorePromise, WritableKeys } from "tc-shared/proto";
import {LogCategory, logDebug, logError, logInfo, logTrace, logWarn} from "tc-shared/log"; import { LogCategory, logDebug, logError, logInfo, logTrace, logWarn } from "tc-shared/log";
import {guid} from "tc-shared/crypto/uid"; import { guid } from "tc-shared/crypto/uid";
import {Registry} from "tc-events"; import { Registry } from "tc-events";
import {server_connections} from "tc-shared/ConnectionManager"; import { server_connections } from "tc-shared/ConnectionManager";
import {defaultConnectProfile, findConnectProfile} from "tc-shared/profiles/ConnectionProfile"; import { defaultConnectProfile, findConnectProfile } from "tc-shared/profiles/ConnectionProfile";
import {ConnectionState} from "tc-shared/ConnectionHandler"; import { ConnectionState } from "tc-shared/ConnectionHandler";
import * as _ from "lodash"; import * as _ from "lodash";
import {getStorageAdapter} from "tc-shared/StorageAdapter"; import { getStorageAdapter } from "tc-shared/StorageAdapter";
type BookmarkBase = { type BookmarkBase = {
readonly uniqueId: string, readonly uniqueId: string,
@ -64,9 +64,9 @@ export class BookmarkManager {
async loadBookmarks() { async loadBookmarks() {
const bookmarksJson = await getStorageAdapter().get(kStorageKey); const bookmarksJson = await getStorageAdapter().get(kStorageKey);
if(typeof bookmarksJson !== "string") { if (typeof bookmarksJson !== "string") {
const oldBookmarksJson = await getStorageAdapter().get("bookmarks"); const oldBookmarksJson = await getStorageAdapter().get("bookmarks");
if(typeof oldBookmarksJson === "string") { if (typeof oldBookmarksJson === "string") {
logDebug(LogCategory.BOOKMARKS, tr("Found no new bookmarks but found old bookmarks. Trying to import.")); logDebug(LogCategory.BOOKMARKS, tr("Found no new bookmarks but found old bookmarks. Trying to import."));
try { try {
this.importOldBookmarks(oldBookmarksJson); this.importOldBookmarks(oldBookmarksJson);
@ -83,7 +83,7 @@ export class BookmarkManager {
} else { } else {
try { try {
const storageData = JSON.parse(bookmarksJson); const storageData = JSON.parse(bookmarksJson);
if(storageData.version !== 2) { if (storageData.version !== 2) {
throw tr("bookmark storage has an invalid version"); throw tr("bookmark storage has an invalid version");
} }
@ -99,7 +99,7 @@ export class BookmarkManager {
} }
} }
if(!this.defaultBookmarkCreated && this.registeredBookmarks.length === 0) { if (!this.defaultBookmarkCreated && this.registeredBookmarks.length === 0) {
this.defaultBookmarkCreated = true; this.defaultBookmarkCreated = true;
logDebug(LogCategory.BOOKMARKS, tr("No bookmarks found. Registering default bookmark.")); logDebug(LogCategory.BOOKMARKS, tr("No bookmarks found. Registering default bookmark."));
@ -107,12 +107,12 @@ export class BookmarkManager {
connectOnStartup: false, connectOnStartup: false,
connectProfile: "default", connectProfile: "default",
displayName: "Official TeaSpeak - Test server", displayName: "Our LanPart<",
parentEntry: undefined, parentEntry: undefined,
previousEntry: undefined, previousEntry: undefined,
serverAddress: "ts.teaspeak.de", serverAddress: "tea.lp.kle.li",
serverPasswordHash: undefined, serverPasswordHash: undefined,
defaultChannel: undefined, defaultChannel: undefined,
@ -123,21 +123,21 @@ export class BookmarkManager {
private importOldBookmarks(jsonData: string) { private importOldBookmarks(jsonData: string) {
const data = JSON.parse(jsonData); const data = JSON.parse(jsonData);
if(typeof data?.root_bookmark !== "object") { if (typeof data?.root_bookmark !== "object") {
throw tr("missing root bookmark"); throw tr("missing root bookmark");
} }
if(!Array.isArray(data?.root_bookmark?.content)) { if (!Array.isArray(data?.root_bookmark?.content)) {
throw tr("Missing root bookmarks content"); throw tr("Missing root bookmarks content");
} }
const registerBookmarks = (parentEntry: string, previousEntry: string, entry: any) : string | undefined => { const registerBookmarks = (parentEntry: string, previousEntry: string, entry: any): string | undefined => {
if(typeof entry.display_name !== "string") { if (typeof entry.display_name !== "string") {
logWarn(LogCategory.BOOKMARKS, tr("Missing display_name in old bookmark entry. Skipping entry.")); logWarn(LogCategory.BOOKMARKS, tr("Missing display_name in old bookmark entry. Skipping entry."));
return undefined; return undefined;
} }
if("content" in entry) { if ("content" in entry) {
/* it was a directory */ /* it was a directory */
const directory = this.createDirectory({ const directory = this.createDirectory({
previousEntry, previousEntry,
@ -152,23 +152,23 @@ export class BookmarkManager {
}); });
} else { } else {
/* it was a normal entry */ /* it was a normal entry */
if(typeof entry.connect_profile !== "string") { if (typeof entry.connect_profile !== "string") {
logWarn(LogCategory.BOOKMARKS, tr("Missing connect_profile in old bookmark entry. Skipping entry.")); logWarn(LogCategory.BOOKMARKS, tr("Missing connect_profile in old bookmark entry. Skipping entry."));
return undefined; return undefined;
} }
if(typeof entry.server_properties?.server_address !== "string") { if (typeof entry.server_properties?.server_address !== "string") {
logWarn(LogCategory.BOOKMARKS, tr("Missing server_address in old bookmark entry. Skipping entry.")); logWarn(LogCategory.BOOKMARKS, tr("Missing server_address in old bookmark entry. Skipping entry."));
return undefined; return undefined;
} }
if(typeof entry.server_properties?.server_port !== "number") { if (typeof entry.server_properties?.server_port !== "number") {
logWarn(LogCategory.BOOKMARKS, tr("Missing server_port in old bookmark entry. Skipping entry.")); logWarn(LogCategory.BOOKMARKS, tr("Missing server_port in old bookmark entry. Skipping entry."));
return undefined; return undefined;
} }
let serverAddress; let serverAddress;
if(entry.server_properties.server_address.indexOf(":") !== -1) { if (entry.server_properties.server_address.indexOf(":") !== -1) {
serverAddress = `[${entry.server_properties.server_address}]`; serverAddress = `[${entry.server_properties.server_address}]`;
} else { } else {
serverAddress = entry.server_properties.server_address; serverAddress = entry.server_properties.server_address;
@ -209,23 +209,23 @@ export class BookmarkManager {
})); }));
} }
getRegisteredBookmarks() : BookmarkEntry[] { getRegisteredBookmarks(): BookmarkEntry[] {
return this.registeredBookmarks; return this.registeredBookmarks;
} }
getOrderedRegisteredBookmarks() : OrderedBookmarkEntry[] { getOrderedRegisteredBookmarks(): OrderedBookmarkEntry[] {
const unorderedBookmarks = this.registeredBookmarks.slice(0); const unorderedBookmarks = this.registeredBookmarks.slice(0);
const orderedBookmarks: OrderedBookmarkEntry[] = []; const orderedBookmarks: OrderedBookmarkEntry[] = [];
const orderTreeLayer = (entries: BookmarkEntry[]): BookmarkEntry[] => { const orderTreeLayer = (entries: BookmarkEntry[]): BookmarkEntry[] => {
if(entries.length === 0) { if (entries.length === 0) {
return []; return [];
} }
const result = []; const result = [];
while(entries.length > 0) { while (entries.length > 0) {
let head = entries.find(entry => !entry.previousEntry) || entries[0]; let head = entries.find(entry => !entry.previousEntry) || entries[0];
while(head) { while (head) {
result.push(head); result.push(head);
entries.remove(head); entries.remove(head);
head = entries.find(entry => entry.previousEntry === head.uniqueId); head = entries.find(entry => entry.previousEntry === head.uniqueId);
@ -240,7 +240,7 @@ export class BookmarkManager {
children.forEach(child => unorderedBookmarks.remove(child)); children.forEach(child => unorderedBookmarks.remove(child));
const childCount = children.length; const childCount = children.length;
for(const entry of orderTreeLayer(children)) { for (const entry of orderTreeLayer(children)) {
let orderedEntry: OrderedBookmarkEntry = { let orderedEntry: OrderedBookmarkEntry = {
entry: entry, entry: entry,
depth: depth, depth: depth,
@ -264,11 +264,11 @@ export class BookmarkManager {
return orderedBookmarks; return orderedBookmarks;
} }
findBookmark(uniqueId: string) : BookmarkEntry | undefined { findBookmark(uniqueId: string): BookmarkEntry | undefined {
return this.registeredBookmarks.find(entry => entry.uniqueId === uniqueId); return this.registeredBookmarks.find(entry => entry.uniqueId === uniqueId);
} }
createBookmark(properties: Pick<BookmarkInfo, WritableKeys<BookmarkInfo>>) : BookmarkInfo { createBookmark(properties: Pick<BookmarkInfo, WritableKeys<BookmarkInfo>>): BookmarkInfo {
this.validateHangInPoint(properties); this.validateHangInPoint(properties);
const bookmark = Object.assign(properties, { const bookmark = Object.assign(properties, {
uniqueId: guid(), uniqueId: guid(),
@ -284,7 +284,7 @@ export class BookmarkManager {
this.doEditBookmark(uniqueId, newValues); this.doEditBookmark(uniqueId, newValues);
} }
createDirectory(properties: Pick<BookmarkInfo, WritableKeys<BookmarkDirectory>>) : BookmarkDirectory { createDirectory(properties: Pick<BookmarkInfo, WritableKeys<BookmarkDirectory>>): BookmarkDirectory {
this.validateHangInPoint(properties); this.validateHangInPoint(properties);
const bookmark = Object.assign(properties, { const bookmark = Object.assign(properties, {
uniqueId: guid(), uniqueId: guid(),
@ -300,20 +300,20 @@ export class BookmarkManager {
this.doEditBookmark(uniqueId, newValues); this.doEditBookmark(uniqueId, newValues);
} }
directoryContents(uniqueId: string) : BookmarkEntry[] { directoryContents(uniqueId: string): BookmarkEntry[] {
return this.registeredBookmarks.filter(bookmark => bookmark.parentEntry === uniqueId); return this.registeredBookmarks.filter(bookmark => bookmark.parentEntry === uniqueId);
} }
deleteEntry(uniqueId: string) { deleteEntry(uniqueId: string) {
const index = this.registeredBookmarks.findIndex(entry => entry.uniqueId === uniqueId); const index = this.registeredBookmarks.findIndex(entry => entry.uniqueId === uniqueId);
if(index === -1) { if (index === -1) {
return; return;
} }
const [ entry ] = this.registeredBookmarks.splice(index, 1); const [entry] = this.registeredBookmarks.splice(index, 1);
const children = [], pendingChildren = [ entry ]; const children = [], pendingChildren = [entry];
while(pendingChildren[0]) { while (pendingChildren[0]) {
const child = pendingChildren.pop_front(); const child = pendingChildren.pop_front();
children.push(child); children.push(child);
@ -329,12 +329,12 @@ export class BookmarkManager {
executeConnect(uniqueId: string, newTab: boolean) { executeConnect(uniqueId: string, newTab: boolean) {
const bookmark = this.findBookmark(uniqueId); const bookmark = this.findBookmark(uniqueId);
if(!bookmark || bookmark.type !== "entry") { if (!bookmark || bookmark.type !== "entry") {
return; return;
} }
const connection = newTab ? server_connections.spawnConnectionHandler() : server_connections.getActiveConnectionHandler(); const connection = newTab ? server_connections.spawnConnectionHandler() : server_connections.getActiveConnectionHandler();
if(!connection) { if (!connection) {
return; return;
} }
@ -360,12 +360,12 @@ export class BookmarkManager {
executeAutoConnect() { executeAutoConnect() {
let newTab = server_connections.getActiveConnectionHandler().connection_state !== ConnectionState.UNCONNECTED; let newTab = server_connections.getActiveConnectionHandler().connection_state !== ConnectionState.UNCONNECTED;
for(const entry of this.getOrderedRegisteredBookmarks()) { for (const entry of this.getOrderedRegisteredBookmarks()) {
if(entry.entry.type !== "entry") { if (entry.entry.type !== "entry") {
continue; continue;
} }
if(!entry.entry.connectOnStartup) { if (!entry.entry.connectOnStartup) {
continue; continue;
} }
@ -374,14 +374,14 @@ export class BookmarkManager {
} }
} }
exportBookmarks() : string { exportBookmarks(): string {
return JSON.stringify({ return JSON.stringify({
version: 1, version: 1,
bookmarks: this.registeredBookmarks bookmarks: this.registeredBookmarks
}); });
} }
importBookmarks(filePayload: string) : number { importBookmarks(filePayload: string): number {
let data; let data;
try { try {
data = JSON.parse(filePayload) data = JSON.parse(filePayload)
@ -389,26 +389,26 @@ export class BookmarkManager {
throw tr("failed to parse bookmarks"); throw tr("failed to parse bookmarks");
} }
if(data?.version !== 1) { if (data?.version !== 1) {
throw tr("supplied data contains invalid version"); throw tr("supplied data contains invalid version");
} }
const newBookmarks = data.bookmarks as BookmarkEntry[]; const newBookmarks = data.bookmarks as BookmarkEntry[];
if(!Array.isArray(newBookmarks)) { if (!Array.isArray(newBookmarks)) {
throw tr("missing bookmarks"); throw tr("missing bookmarks");
} }
/* TODO: Validate integrity? */ /* TODO: Validate integrity? */
for(const knownBookmark of this.registeredBookmarks) { for (const knownBookmark of this.registeredBookmarks) {
const index = newBookmarks.findIndex(entry => entry.uniqueId === knownBookmark.uniqueId); const index = newBookmarks.findIndex(entry => entry.uniqueId === knownBookmark.uniqueId);
if(index === -1) { if (index === -1) {
continue; continue;
} }
newBookmarks.splice(index, 1); newBookmarks.splice(index, 1);
} }
if(newBookmarks.length === 0) { if (newBookmarks.length === 0) {
return; return;
} }
@ -420,26 +420,26 @@ export class BookmarkManager {
private doEditBookmark(uniqueId: string, newValues: any) { private doEditBookmark(uniqueId: string, newValues: any) {
const bookmarkInfo = this.findBookmark(uniqueId); const bookmarkInfo = this.findBookmark(uniqueId);
if(!bookmarkInfo) { if (!bookmarkInfo) {
return; return;
} }
const originalProperties = _.cloneDeep(bookmarkInfo); const originalProperties = _.cloneDeep(bookmarkInfo);
for(const key of Object.keys(newValues)) { for (const key of Object.keys(newValues)) {
bookmarkInfo[key] = newValues[key]; bookmarkInfo[key] = newValues[key];
} }
this.validateHangInPoint(bookmarkInfo); this.validateHangInPoint(bookmarkInfo);
const editedKeys = []; const editedKeys = [];
for(const key of Object.keys(newValues)) { for (const key of Object.keys(newValues)) {
if(_.isEqual(bookmarkInfo[key], originalProperties[key])) { if (_.isEqual(bookmarkInfo[key], originalProperties[key])) {
continue; continue;
} }
editedKeys.push(key); editedKeys.push(key);
} }
if(editedKeys.length === 0) { if (editedKeys.length === 0) {
return; return;
} }
@ -448,12 +448,12 @@ export class BookmarkManager {
} }
private validateHangInPoint(entry: Partial<BookmarkBase>) { private validateHangInPoint(entry: Partial<BookmarkBase>) {
if(entry.previousEntry) { if (entry.previousEntry) {
const previousEntry = this.findBookmark(entry.previousEntry); const previousEntry = this.findBookmark(entry.previousEntry);
if(!previousEntry) { if (!previousEntry) {
logError(LogCategory.BOOKMARKS, tr("New bookmark previous entry does not exists. Clearing it.")); logError(LogCategory.BOOKMARKS, tr("New bookmark previous entry does not exists. Clearing it."));
entry.previousEntry = undefined; entry.previousEntry = undefined;
} else if(previousEntry.parentEntry !== entry.parentEntry) { } else if (previousEntry.parentEntry !== entry.parentEntry) {
logWarn(LogCategory.BOOKMARKS, tr("Previous entries parent does not match our entries parent. Updating our parent from %s to %s"), entry.parentEntry, previousEntry.parentEntry); logWarn(LogCategory.BOOKMARKS, tr("Previous entries parent does not match our entries parent. Updating our parent from %s to %s"), entry.parentEntry, previousEntry.parentEntry);
entry.parentEntry = previousEntry.parentEntry; entry.parentEntry = previousEntry.parentEntry;
} }
@ -461,13 +461,13 @@ export class BookmarkManager {
const openList = this.registeredBookmarks.filter(e1 => e1.parentEntry === entry.parentEntry); const openList = this.registeredBookmarks.filter(e1 => e1.parentEntry === entry.parentEntry);
let currentEntry = entry; let currentEntry = entry;
while(true) { while (true) {
if(!currentEntry.previousEntry) { if (!currentEntry.previousEntry) {
break; break;
} }
const previousEntry = openList.find(entry => entry.uniqueId === currentEntry.previousEntry); const previousEntry = openList.find(entry => entry.uniqueId === currentEntry.previousEntry);
if(!previousEntry) { if (!previousEntry) {
logError(LogCategory.BOOKMARKS, tr("Found circular dependency within the previous entry or one of the previous entries does not exists. Clearing out previous entry.")); logError(LogCategory.BOOKMARKS, tr("Found circular dependency within the previous entry or one of the previous entries does not exists. Clearing out previous entry."));
entry.previousEntry = undefined; entry.previousEntry = undefined;
break; break;
@ -478,22 +478,22 @@ export class BookmarkManager {
} }
} }
if(entry.parentEntry) { if (entry.parentEntry) {
const parentEntry = this.findBookmark(entry.parentEntry); const parentEntry = this.findBookmark(entry.parentEntry);
if(!parentEntry) { if (!parentEntry) {
logError(LogCategory.BOOKMARKS, tr("Missing parent entry %s. Clearing it."), entry.parentEntry); logError(LogCategory.BOOKMARKS, tr("Missing parent entry %s. Clearing it."), entry.parentEntry);
entry.parentEntry = undefined; entry.parentEntry = undefined;
} }
const openList = this.registeredBookmarks.slice(); const openList = this.registeredBookmarks.slice();
let currentEntry = entry; let currentEntry = entry;
while(true) { while (true) {
if(!currentEntry.parentEntry) { if (!currentEntry.parentEntry) {
break; break;
} }
const parentEntry = openList.find(entry => entry.uniqueId === currentEntry.parentEntry); const parentEntry = openList.find(entry => entry.uniqueId === currentEntry.parentEntry);
if(!parentEntry) { if (!parentEntry) {
logError(LogCategory.BOOKMARKS, tr("Found circular dependency within a parent or one of the parents does not exists. Clearing out parent.")); logError(LogCategory.BOOKMARKS, tr("Found circular dependency within a parent or one of the parents does not exists. Clearing out parent."));
entry.parentEntry = undefined; entry.parentEntry = undefined;
break; break;
@ -504,9 +504,9 @@ export class BookmarkManager {
} }
} }
if(entry.previousEntry) { if (entry.previousEntry) {
this.registeredBookmarks.forEach(bookmark => { this.registeredBookmarks.forEach(bookmark => {
if(bookmark.previousEntry === entry.previousEntry && bookmark !== entry) { if (bookmark.previousEntry === entry.previousEntry && bookmark !== entry) {
bookmark.previousEntry = bookmark.uniqueId; bookmark.previousEntry = bookmark.uniqueId;
} }
}); });

View File

@ -364,7 +364,7 @@ export class Settings {
static readonly KEY_I18N_DEFAULT_REPOSITORY: ValuedRegistryKey<string> = { static readonly KEY_I18N_DEFAULT_REPOSITORY: ValuedRegistryKey<string> = {
key: "i18n.default_repository", key: "i18n.default_repository",
valueType: "string", valueType: "string",
defaultValue: "https://web.teaspeak.de/i18n/" defaultValue: "i18n/"
}; };
/* Default client states */ /* Default client states */

View File

@ -1,25 +1,25 @@
import {Registry} from "tc-shared/events"; import { Registry } from "tc-shared/events";
import { import {
ConnectUiEvents, ConnectUiEvents,
ConnectUiVariables, ConnectUiVariables,
} from "tc-shared/ui/modal/connect/Definitions"; } from "tc-shared/ui/modal/connect/Definitions";
import {LogCategory, logError, logWarn} from "tc-shared/log"; import { LogCategory, logError, logWarn } from "tc-shared/log";
import { import {
availableConnectProfiles, availableConnectProfiles,
ConnectionProfile, ConnectionProfile,
defaultConnectProfile, defaultConnectProfile,
findConnectProfile findConnectProfile
} from "tc-shared/profiles/ConnectionProfile"; } from "tc-shared/profiles/ConnectionProfile";
import {Settings, settings} from "tc-shared/settings"; import { Settings, settings } from "tc-shared/settings";
import {connectionHistory, ConnectionHistoryEntry} from "tc-shared/connectionlog/History"; import { connectionHistory, ConnectionHistoryEntry } from "tc-shared/connectionlog/History";
import {createErrorModal} from "tc-shared/ui/elements/Modal"; import { createErrorModal } from "tc-shared/ui/elements/Modal";
import {ConnectionHandler} from "tc-shared/ConnectionHandler"; import { ConnectionHandler } from "tc-shared/ConnectionHandler";
import {server_connections} from "tc-shared/ConnectionManager"; import { server_connections } from "tc-shared/ConnectionManager";
import {parseServerAddress} from "tc-shared/tree/Server"; import { parseServerAddress } from "tc-shared/tree/Server";
import {spawnSettingsModal} from "tc-shared/ui/modal/ModalSettings"; import { spawnSettingsModal } from "tc-shared/ui/modal/ModalSettings";
import {UiVariableProvider} from "tc-shared/ui/utils/Variable"; import { UiVariableProvider } from "tc-shared/ui/utils/Variable";
import {createIpcUiVariableProvider} from "tc-shared/ui/utils/IpcVariable"; import { createIpcUiVariableProvider } from "tc-shared/ui/utils/IpcVariable";
import {spawnModal} from "tc-shared/ui/react-elements/modal"; import { spawnModal } from "tc-shared/ui/react-elements/modal";
import ipRegex from "ip-regex"; import ipRegex from "ip-regex";
const kRegexDomain = /^(localhost|((([a-zA-Z0-9_-]{0,63}\.){0,253})?[a-zA-Z0-9_-]{0,63}\.[a-zA-Z]{2,64}))$/i; const kRegexDomain = /^(localhost|((([a-zA-Z0-9_-]{0,63}\.){0,253})?[a-zA-Z0-9_-]{0,63}\.[a-zA-Z]{2,64}))$/i;
@ -61,7 +61,8 @@ class ConnectController {
private validateNickname: boolean; private validateNickname: boolean;
private validateAddress: boolean; private validateAddress: boolean;
constructor(uiVariables: UiVariableProvider<ConnectUiVariables>) {7 constructor(uiVariables: UiVariableProvider<ConnectUiVariables>) {
7
this.uiEvents = new Registry<ConnectUiEvents>(); this.uiEvents = new Registry<ConnectUiEvents>();
this.uiEvents.enableDebug("modal-connect"); this.uiEvents.enableDebug("modal-connect");
@ -71,7 +72,7 @@ class ConnectController {
this.validateNickname = false; this.validateNickname = false;
this.validateAddress = false; this.validateAddress = false;
this.defaultAddress = "ts.teaspeak.de"; this.defaultAddress = "tea.lp.kle.li";
this.historyShown = settings.getValue(Settings.KEY_CONNECT_SHOW_HISTORY); this.historyShown = settings.getValue(Settings.KEY_CONNECT_SHOW_HISTORY);
this.currentAddress = settings.getValue(Settings.KEY_CONNECT_ADDRESS); this.currentAddress = settings.getValue(Settings.KEY_CONNECT_ADDRESS);
@ -109,11 +110,11 @@ class ConnectController {
})); }));
this.uiVariables.setVariableProvider("server_address_valid", () => { this.uiVariables.setVariableProvider("server_address_valid", () => {
if(this.validateAddress) { if (this.validateAddress) {
const address = this.currentAddress || this.defaultAddress || ""; const address = this.currentAddress || this.defaultAddress || "";
const parsedAddress = parseServerAddress(address); const parsedAddress = parseServerAddress(address);
if(parsedAddress) { if (parsedAddress) {
kRegexDomain.lastIndex = 0; kRegexDomain.lastIndex = 0;
return kRegexDomain.test(parsedAddress.host) || ipRegex({ exact: true }).test(parsedAddress.host); return kRegexDomain.test(parsedAddress.host) || ipRegex({ exact: true }).test(parsedAddress.host);
} else { } else {
@ -125,7 +126,7 @@ class ConnectController {
}); });
this.uiVariables.setVariableEditor("server_address", newValue => { this.uiVariables.setVariableEditor("server_address", newValue => {
if(this.currentAddress === newValue.currentAddress) { if (this.currentAddress === newValue.currentAddress) {
return false; return false;
} }
@ -139,7 +140,7 @@ class ConnectController {
})); }));
this.uiVariables.setVariableProvider("nickname_valid", () => { this.uiVariables.setVariableProvider("nickname_valid", () => {
if(this.validateNickname) { if (this.validateNickname) {
const nickname = this.currentNickname || this.currentProfile?.connectUsername() || ""; const nickname = this.currentNickname || this.currentProfile?.connectUsername() || "";
return nickname.length >= 3 && nickname.length <= 30; return nickname.length >= 3 && nickname.length <= 30;
} else { } else {
@ -148,7 +149,7 @@ class ConnectController {
}); });
this.uiVariables.setVariableEditor("nickname", newValue => { this.uiVariables.setVariableEditor("nickname", newValue => {
if(this.currentNickname === newValue.currentNickname) { if (this.currentNickname === newValue.currentNickname) {
return false; return false;
} }
@ -166,7 +167,7 @@ class ConnectController {
})); }));
this.uiVariables.setVariableEditor("password", newValue => { this.uiVariables.setVariableEditor("password", newValue => {
if(this.currentPassword === newValue.password) { if (this.currentPassword === newValue.password) {
return false; return false;
} }
@ -179,7 +180,7 @@ class ConnectController {
this.uiVariables.setVariableProvider("historyShown", () => this.historyShown); this.uiVariables.setVariableProvider("historyShown", () => this.historyShown);
this.uiVariables.setVariableEditor("historyShown", newValue => { this.uiVariables.setVariableEditor("historyShown", newValue => {
if(this.historyShown === newValue) { if (this.historyShown === newValue) {
return false; return false;
} }
@ -188,8 +189,8 @@ class ConnectController {
return true; return true;
}); });
this.uiVariables.setVariableProvider("history",async () => { this.uiVariables.setVariableProvider("history", async () => {
if(!this.history) { if (!this.history) {
this.history = await connectionHistory.lastConnectedServers(10); this.history = await connectionHistory.lastConnectedServers(10);
} }
@ -237,7 +238,7 @@ class ConnectController {
this.uiVariables.setVariableEditor("profiles", newValue => { this.uiVariables.setVariableEditor("profiles", newValue => {
const profile = findConnectProfile(newValue.selected); const profile = findConnectProfile(newValue.selected);
if(!profile) { if (!profile) {
createErrorModal(tr("Invalid profile"), tr("Target connect profile is missing.")).open(); createErrorModal(tr("Invalid profile"), tr("Target connect profile is missing.")).open();
return false; return false;
} }
@ -252,16 +253,16 @@ class ConnectController {
this.uiVariables.destroy(); this.uiVariables.destroy();
} }
generateConnectParameters() : ConnectParameters | undefined { generateConnectParameters(): ConnectParameters | undefined {
if(!this.uiVariables.getVariableSync("nickname_valid", undefined, true)) { if (!this.uiVariables.getVariableSync("nickname_valid", undefined, true)) {
return undefined; return undefined;
} }
if(!this.uiVariables.getVariableSync("server_address_valid", undefined, true)) { if (!this.uiVariables.getVariableSync("server_address_valid", undefined, true)) {
return undefined; return undefined;
} }
if(!this.uiVariables.getVariableSync("profile_valid", undefined, true)) { if (!this.uiVariables.getVariableSync("profile_valid", undefined, true)) {
return undefined; return undefined;
} }
@ -279,7 +280,7 @@ class ConnectController {
} }
setSelectedHistoryId(id: number | -1) { setSelectedHistoryId(id: number | -1) {
if(this.selectedHistoryId === id) { if (this.selectedHistoryId === id) {
return; return;
} }
@ -287,7 +288,7 @@ class ConnectController {
this.uiVariables.sendVariable("history"); this.uiVariables.sendVariable("history");
const historyEntry = this.history?.find(entry => entry.id === id); const historyEntry = this.history?.find(entry => entry.id === id);
if(!historyEntry) { return; } if (!historyEntry) { return; }
this.currentAddress = historyEntry.targetAddress; this.currentAddress = historyEntry.targetAddress;
this.currentNickname = historyEntry.nickname; this.currentNickname = historyEntry.nickname;
@ -300,12 +301,12 @@ class ConnectController {
} }
setSelectedAddress(address: string | undefined, validate: boolean, updateUi: boolean) { setSelectedAddress(address: string | undefined, validate: boolean, updateUi: boolean) {
if(this.currentAddress !== address) { if (this.currentAddress !== address) {
this.currentAddress = address; this.currentAddress = address;
settings.setValue(Settings.KEY_CONNECT_ADDRESS, address); settings.setValue(Settings.KEY_CONNECT_ADDRESS, address);
this.setSelectedHistoryId(-1); this.setSelectedHistoryId(-1);
if(updateUi) { if (updateUi) {
this.uiVariables.sendVariable("server_address"); this.uiVariables.sendVariable("server_address");
} }
} }
@ -315,7 +316,7 @@ class ConnectController {
} }
setSelectedProfile(profile: ConnectionProfile | undefined) { setSelectedProfile(profile: ConnectionProfile | undefined) {
if(this.currentProfile === profile) { if (this.currentProfile === profile) {
return; return;
} }
@ -347,11 +348,11 @@ export function spawnConnectModalNew(options: ConnectModalOptions) {
const variableProvider = createIpcUiVariableProvider(); const variableProvider = createIpcUiVariableProvider();
const controller = new ConnectController(variableProvider); const controller = new ConnectController(variableProvider);
if(typeof options.selectedAddress === "string") { if (typeof options.selectedAddress === "string") {
controller.setSelectedAddress(options.selectedAddress, false, true); controller.setSelectedAddress(options.selectedAddress, false, true);
} }
if(typeof options.selectedProfile === "object") { if (typeof options.selectedProfile === "object") {
controller.setSelectedProfile(options.selectedProfile); controller.setSelectedProfile(options.selectedProfile);
} }
@ -363,7 +364,7 @@ export function spawnConnectModalNew(options: ConnectModalOptions) {
controller.uiEvents.on("action_connect", event => { controller.uiEvents.on("action_connect", event => {
const parameters = controller.generateConnectParameters(); const parameters = controller.generateConnectParameters();
if(!parameters) { if (!parameters) {
/* invalid parameters detected */ /* invalid parameters detected */
return; return;
} }
@ -371,14 +372,14 @@ export function spawnConnectModalNew(options: ConnectModalOptions) {
modal.destroy(); modal.destroy();
let connection: ConnectionHandler; let connection: ConnectionHandler;
if(event.newTab) { if (event.newTab) {
connection = server_connections.spawnConnectionHandler(); connection = server_connections.spawnConnectionHandler();
server_connections.setActiveConnectionHandler(connection); server_connections.setActiveConnectionHandler(connection);
} else { } else {
connection = server_connections.getActiveConnectionHandler(); connection = server_connections.getActiveConnectionHandler();
} }
if(!connection) { if (!connection) {
return; return;
} }

View File

@ -1,14 +1,16 @@
import * as React from "react"; import * as React from "react";
import {useEffect, useRef, useState} from "react"; import { useEffect, useRef, useState } from "react";
import {Registry} from "tc-shared/events"; import { Registry } from "tc-shared/events";
import { settings, Settings } from "tc-shared/settings";
import { Translatable } from "tc-shared/ui/react-elements/i18n";
import Picker from '@emoji-mart/react'
import data from '@emoji-mart/data'
import { Emoji, init } from "emoji-mart";
init({ data })
import '!style-loader!css-loader!emoji-mart/css/emoji-mart.css'
import {Picker, emojiIndex} from 'emoji-mart'
import {settings, Settings} from "tc-shared/settings";
import {Translatable} from "tc-shared/ui/react-elements/i18n";
import {getTwenmojiHashFromNativeEmoji} from "tc-shared/text/bbcode/EmojiUtil";
import {BaseEmoji} from "emoji-mart";
import {useGlobalSetting} from "tc-shared/ui/react-elements/Helper";
const cssStyle = require("./ChatBox.scss"); const cssStyle = require("./ChatBox.scss");
@ -28,34 +30,26 @@ interface ChatBoxEvents {
} }
const LastUsedEmoji = () => { const LastUsedEmoji = () => {
const settingValue = useGlobalSetting(Settings.KEY_CHAT_LAST_USED_EMOJI); return <img key={"fallback"} alt={""} src={"img/smiley.png"} />;
const lastEmoji: BaseEmoji = (emojiIndex.emojis[settingValue] || emojiIndex.emojis["joy"]) as any;
if(!lastEmoji?.native) {
return <img key={"fallback"} alt={""} src={"img/smiley-smile.svg"} />;
}
return (
<img draggable={false} src={"https://twemoji.maxcdn.com/v/12.1.2/72x72/" + getTwenmojiHashFromNativeEmoji(lastEmoji.native) + ".png"} alt={lastEmoji.native} className={cssStyle.emoji} />
)
} }
const EmojiButton = (props: { events: Registry<ChatBoxEvents> }) => { const EmojiButton = (props: { events: Registry<ChatBoxEvents> }) => {
const [ shown, setShown ] = useState(false); const [shown, setShown] = useState(false);
const [ enabled, setEnabled ] = useState(false); const [enabled, setEnabled] = useState(false);
const refContainer = useRef(); const refContainer = useRef();
useEffect(() => { useEffect(() => {
if(!shown) { if (!shown) {
return; return;
} }
const clickListener = (event: MouseEvent) => { const clickListener = (event: MouseEvent) => {
let target = event.target as HTMLElement; let target = event.target as HTMLElement;
while(target && target !== refContainer.current) while (target && target !== refContainer.current)
target = target.parentElement; target = target.parentElement;
if(target === refContainer.current && target) if (target === refContainer.current && target)
return; return;
setShown(false); setShown(false);
@ -76,22 +70,21 @@ const EmojiButton = (props: { events: Registry<ChatBoxEvents> }) => {
<div className={cssStyle.picker} style={{ display: shown ? undefined : "none" }}> <div className={cssStyle.picker} style={{ display: shown ? undefined : "none" }}>
{!shown ? undefined : {!shown ? undefined :
<Picker <Picker
data={data}
key={"picker"} key={"picker"}
set={"twitter"} set={"native"}
theme={"light"} noCountryFlags={true}
showPreview={true} showPreview={true}
title={""} title={""}
showSkinTones={true} skinTonePosition={"none"}
useButton={false}
native={false}
onSelect={(emoji: any) => { onEmojiSelect={(emoji: any) => {
if(enabled) { if (enabled) {
settings.setValue(Settings.KEY_CHAT_LAST_USED_EMOJI, emoji.id as string);
props.events.fire("action_insert_text", { text: emoji.native, focus: true }); props.events.fire("action_insert_text", { text: emoji.native, focus: true });
} }
}} }}
/> />
} }
</div> </div>
</div> </div>
@ -101,27 +94,27 @@ const EmojiButton = (props: { events: Registry<ChatBoxEvents> }) => {
const pasteTextTransformElement = document.createElement("div"); const pasteTextTransformElement = document.createElement("div");
const nodeToText = (element: Node) => { const nodeToText = (element: Node) => {
if(element instanceof Text) { if (element instanceof Text) {
return element.textContent; return element.textContent;
} else if(element instanceof HTMLElement) { } else if (element instanceof HTMLElement) {
if(element instanceof HTMLImageElement) { if (element instanceof HTMLImageElement) {
return element.alt || element.title; return element.alt || element.title;
} else if(element instanceof HTMLBRElement) { } else if (element instanceof HTMLBRElement) {
return '\n'; return '\n';
} else if(element instanceof HTMLAnchorElement) { } else if (element instanceof HTMLAnchorElement) {
const content = [...element.childNodes].map(nodeToText).join(""); const content = [...element.childNodes].map(nodeToText).join("");
if(element.href) { if (element.href) {
if(settings.getValue(Settings.KEY_CHAT_ENABLE_MARKDOWN)) { if (settings.getValue(Settings.KEY_CHAT_ENABLE_MARKDOWN)) {
if(content && element.title) { if (content && element.title) {
return `[${content}](${element.href} "${element.title}")`; return `[${content}](${element.href} "${element.title}")`;
} else if(content) { } else if (content) {
return `[${content}](${element.href})`; return `[${content}](${element.href})`;
} else { } else {
return `[${element.href}](${element.href})`; return `[${element.href}](${element.href})`;
} }
} else if(settings.getValue(Settings.KEY_CHAT_ENABLE_BBCODE)) { } else if (settings.getValue(Settings.KEY_CHAT_ENABLE_BBCODE)) {
if(content) { if (content) {
return `[url=${element.href}]${content}"[/url]`; return `[url=${element.href}]${content}"[/url]`;
} else { } else {
return `[url]${element.href}"[/url]`; return `[url]${element.href}"[/url]`;
@ -134,11 +127,11 @@ const nodeToText = (element: Node) => {
} }
} }
if(element.children.length > 0) { if (element.children.length > 0) {
return [...element.childNodes].map(nodeToText).join(""); return [...element.childNodes].map(nodeToText).join("");
} }
return typeof(element.innerText) === "string" ? element.innerText : ""; return typeof (element.innerText) === "string" ? element.innerText : "";
} else { } else {
return ""; return "";
} }
@ -146,19 +139,19 @@ const nodeToText = (element: Node) => {
const htmlEscape = (message: string) => { const htmlEscape = (message: string) => {
pasteTextTransformElement.innerText = message; pasteTextTransformElement.innerText = message;
message = pasteTextTransformElement.innerHTML; message = pasteTextTransformElement.innerHTML;
return message.replace(/ /g, '&nbsp;'); return message.replace(/ /g, '&nbsp;');
}; };
const TextInput = (props: { events: Registry<ChatBoxEvents>, enabled?: boolean, placeholder?: string }) => { const TextInput = (props: { events: Registry<ChatBoxEvents>, enabled?: boolean, placeholder?: string }) => {
const [ enabled, setEnabled ] = useState(!!props.enabled); const [enabled, setEnabled] = useState(!!props.enabled);
const [ historyIndex, setHistoryIndex ] = useState(-1); const [historyIndex, setHistoryIndex] = useState(-1);
const history = useRef([]); const history = useRef([]);
const refInput = useRef<HTMLInputElement>(); const refInput = useRef<HTMLInputElement>();
const typingTimeout = useRef(undefined); const typingTimeout = useRef(undefined);
const triggerTyping = () => { const triggerTyping = () => {
if(typeof typingTimeout.current === "number") if (typeof typingTimeout.current === "number")
return; return;
props.events.fire("notify_typing"); props.events.fire("notify_typing");
@ -182,7 +175,7 @@ const TextInput = (props: { events: Registry<ChatBoxEvents>, enabled?: boolean,
event.preventDefault(); event.preventDefault();
const clipboard = event.clipboardData || (window as any).clipboardData; const clipboard = event.clipboardData || (window as any).clipboardData;
if(!clipboard) return; if (!clipboard) return;
const rawText = clipboard.getData('text/plain'); const rawText = clipboard.getData('text/plain');
const selection = window.getSelection(); const selection = window.getSelection();
@ -191,7 +184,7 @@ const TextInput = (props: { events: Registry<ChatBoxEvents>, enabled?: boolean,
} }
let htmlXML = clipboard.getData('text/html'); let htmlXML = clipboard.getData('text/html');
if(!htmlXML) { if (!htmlXML) {
pasteTextTransformElement.textContent = rawText; pasteTextTransformElement.textContent = rawText;
htmlXML = pasteTextTransformElement.innerHTML; htmlXML = pasteTextTransformElement.innerHTML;
} }
@ -235,33 +228,33 @@ const TextInput = (props: { events: Registry<ChatBoxEvents>, enabled?: boolean,
triggerTyping(); triggerTyping();
const inputEmpty = refInput.current.innerText.trim().length === 0; const inputEmpty = refInput.current.innerText.trim().length === 0;
if(event.key === "Enter" && !event.shiftKey) { if (event.key === "Enter" && !event.shiftKey) {
if(inputEmpty) { if (inputEmpty) {
return; return;
} }
const text = refInput.current.innerText; const text = refInput.current.innerText;
props.events.fire("action_submit_message", { message: text }); props.events.fire("action_submit_message", { message: text });
history.current.push(text); history.current.push(text);
while(history.current.length > 10) { while (history.current.length > 10) {
history.current.pop_front(); history.current.pop_front();
} }
refInput.current.innerText = ""; refInput.current.innerText = "";
setHistoryIndex(-1); setHistoryIndex(-1);
event.preventDefault(); event.preventDefault();
} else if(event.key === "ArrowUp") { } else if (event.key === "ArrowUp") {
const inputOriginal = history.current[historyIndex] === refInput.current.innerText; const inputOriginal = history.current[historyIndex] === refInput.current.innerText;
if(inputEmpty && (historyIndex === -1 || !inputOriginal)) { if (inputEmpty && (historyIndex === -1 || !inputOriginal)) {
setHistory(history.current.length - 1); setHistory(history.current.length - 1);
event.preventDefault(); event.preventDefault();
} else if(historyIndex > 0 && inputOriginal) { } else if (historyIndex > 0 && inputOriginal) {
setHistory(historyIndex - 1); setHistory(historyIndex - 1);
event.preventDefault(); event.preventDefault();
} }
} else if(event.key === "ArrowDown") { } else if (event.key === "ArrowDown") {
if(history.current[historyIndex] === refInput.current.innerText) { if (history.current[historyIndex] === refInput.current.innerText) {
if(historyIndex < history.current.length - 1) { if (historyIndex < history.current.length - 1) {
setHistory(historyIndex + 1); setHistory(historyIndex + 1);
} else { } else {
setHistory(-1); setHistory(-1);
@ -273,7 +266,7 @@ const TextInput = (props: { events: Registry<ChatBoxEvents>, enabled?: boolean,
props.events.reactUse("action_request_focus", () => refInput.current?.focus()); props.events.reactUse("action_request_focus", () => refInput.current?.focus());
props.events.reactUse("notify_typing", () => { props.events.reactUse("notify_typing", () => {
if(typeof typingTimeout.current === "number") { if (typeof typingTimeout.current === "number") {
return; return;
} }
@ -281,15 +274,15 @@ const TextInput = (props: { events: Registry<ChatBoxEvents>, enabled?: boolean,
}); });
props.events.reactUse("action_insert_text", event => { props.events.reactUse("action_insert_text", event => {
refInput.current.innerHTML = refInput.current.innerHTML + event.text; refInput.current.innerHTML = refInput.current.innerHTML + event.text;
if(event.focus) { if (event.focus) {
refInput.current.focus(); refInput.current.focus();
} }
}); });
props.events.reactUse("action_set_enabled", event => { props.events.reactUse("action_set_enabled", event => {
setEnabled(event.enabled); setEnabled(event.enabled);
if(!event.enabled) { if (!event.enabled) {
const text = refInput.current.innerText; const text = refInput.current.innerText;
if(text.trim().length !== 0) if (text.trim().length !== 0)
history.current.push(text); history.current.push(text);
refInput.current.innerText = ""; refInput.current.innerText = "";
} }
@ -324,17 +317,17 @@ export interface ChatBoxState {
} }
const MarkdownFormatHelper = () => { const MarkdownFormatHelper = () => {
const [ visible, setVisible ] = useState(settings.getValue(Settings.KEY_CHAT_ENABLE_MARKDOWN)); const [visible, setVisible] = useState(settings.getValue(Settings.KEY_CHAT_ENABLE_MARKDOWN));
settings.events.reactUse("notify_setting_changed", event => { settings.events.reactUse("notify_setting_changed", event => {
if(event.setting !== Settings.KEY_CHAT_ENABLE_MARKDOWN.key) { if (event.setting !== Settings.KEY_CHAT_ENABLE_MARKDOWN.key) {
return; return;
} }
setVisible(settings.getValue(Settings.KEY_CHAT_ENABLE_MARKDOWN)); setVisible(settings.getValue(Settings.KEY_CHAT_ENABLE_MARKDOWN));
}); });
if(visible) { if (visible) {
return ( return (
<div key={"help"} className={cssStyle.containerHelp}>*italic*, **bold**, ~~strikethrough~~, `code`, <Translatable>and more</Translatable>...</div> <div key={"help"} className={cssStyle.containerHelp}>*italic*, **bold**, ~~strikethrough~~, `code`, <Translatable>and more</Translatable>...</div>
); );
@ -380,7 +373,7 @@ export class ChatBox extends React.Component<ChatBoxProperties, ChatBoxState> {
} }
componentDidUpdate(prevProps: Readonly<ChatBoxProperties>, prevState: Readonly<ChatBoxState>, snapshot?: any): void { componentDidUpdate(prevProps: Readonly<ChatBoxProperties>, prevState: Readonly<ChatBoxState>, snapshot?: any): void {
if(prevState.enabled !== this.state.enabled) { if (prevState.enabled !== this.state.enabled) {
this.events.fire_react("action_set_enabled", { enabled: this.state.enabled }); this.events.fire_react("action_set_enabled", { enabled: this.state.enabled });
} }
} }