Move condensedTypes to shared/

This decouples the rest of the server from the client
This commit is contained in:
Reto Brunner 2023-01-29 23:16:55 +01:00
parent 6f13735a7f
commit b7540b5827
8 changed files with 34 additions and 39 deletions

View File

@ -19,7 +19,7 @@
<script lang="ts">
import {computed, defineComponent, PropType, ref} from "vue";
import constants from "../js/constants";
import {condensedTypes} from "../../shared/irc";
import {ClientMessage, ClientNetwork} from "../js/types";
import Message from "./Message.vue";
@ -51,7 +51,7 @@ export default defineComponent({
const condensedText = computed(() => {
const obj: Record<string, number> = {};
constants.condensedTypes.forEach((type) => {
condensedTypes.forEach((type) => {
obj[type] = 0;
});
@ -75,7 +75,7 @@ export default defineComponent({
obj.part += obj.quit;
const strings: string[] = [];
constants.condensedTypes.forEach((type) => {
condensedTypes.forEach((type) => {
if (obj[type]) {
switch (type) {
case "chghost":

View File

@ -58,7 +58,7 @@
</template>
<script lang="ts">
import constants from "../js/constants";
import {condensedTypes} from "../../shared/irc";
import eventbus from "../js/eventbus";
import clipboard from "../js/clipboard";
import socket from "../js/socket";
@ -184,7 +184,7 @@ export default defineComponent({
// If actions are hidden, just return a message list with them excluded
if (store.state.settings.statusMessages === "hidden") {
return props.channel.messages.filter(
(message) => !constants.condensedTypes.has(message.type)
(message) => !condensedTypes.has(message.type)
);
}
@ -200,11 +200,7 @@ export default defineComponent({
for (const message of props.channel.messages) {
// If this message is not condensable, or its an action affecting our user,
// then just append the message to container and be done with it
if (
message.self ||
message.highlight ||
!constants.condensedTypes.has(message.type)
) {
if (message.self || message.highlight || !condensedTypes.has(message.type)) {
lastCondensedContainer = null;
condensed.push(message);

View File

@ -17,18 +17,6 @@ const colorCodeMap = [
["15", "Light Grey"],
];
const condensedTypes = new Set([
"away",
"back",
"chghost",
"join",
"kick",
"mode",
"nick",
"part",
"quit",
]);
const timeFormats = {
msgDefault: "HH:mm",
msgWithSeconds: "HH:mm:ss",
@ -39,7 +27,6 @@ const timeFormats = {
export default {
colorCodeMap,
commands: [] as string[],
condensedTypes,
timeFormats,
// Same value as media query in CSS that forces sidebars to become overlays
mobileViewportPixels: 768,

View File

@ -9,7 +9,7 @@ import log from "./log";
import Chan, {Channel, ChanType} from "./models/chan";
import Msg, {MessageType, UserInMessage} from "./models/msg";
import Config from "./config";
import constants from "../client/js/constants";
import {condensedTypes} from "../shared/irc";
import inputs from "./plugins/inputs";
import PublicClient from "./plugins/packages/publicClient";
@ -569,7 +569,7 @@ class Client {
startIndex--;
// Do not count condensed messages towards the 100 messages
if (constants.condensedTypes.has(chan.messages[i].type)) {
if (condensedTypes.has(chan.messages[i].type)) {
continue;
}

View File

@ -5,7 +5,6 @@
"../shared/"
] /* Specifies a list of glob patterns that match files to be included in compilation. If no 'files' or 'include' property is present in a tsconfig.json, the compiler defaults to including all files in the containing directory and subdirectories except those specified by 'exclude'. Requires TypeScript version 2.0 or later. */,
"files": [
"../client/js/constants.ts",
"../babel.config.cjs",
"../defaults/config.js",
"../package.json",

View File

@ -4,3 +4,15 @@ const matchFormatting =
export function cleanIrcMessage(message: string) {
return message.replace(matchFormatting, "").trim();
}
export const condensedTypes = new Set([
"away",
"back",
"chghost",
"join",
"kick",
"mode",
"nick",
"part",
"quit",
]);

View File

@ -18,19 +18,6 @@ describe("client-side constants", function () {
});
});
describe(".condensedTypes", function () {
it("should be a non-empty array", function () {
expect(constants.condensedTypes).to.be.an.instanceof(Set).that.is.not.empty;
});
it("should only contain ASCII strings", function () {
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'type' implicitly has an 'any' type.
constants.condensedTypes.forEach((type) => {
expect(type).to.be.a("string").that.does.match(/^\w+$/);
});
});
});
describe(".timeFormats", function () {
it("should be objects of strings", function () {
expect(constants.timeFormats.msgDefault).to.be.an("string").that.is.not.empty;

14
test/shared/irc.ts Normal file
View File

@ -0,0 +1,14 @@
import {expect} from "chai";
import {condensedTypes} from "../../shared/irc";
describe(".condensedTypes", function () {
it("should be a non-empty array", function () {
expect(condensedTypes).to.be.an.instanceof(Set).that.is.not.empty;
});
it("should only contain ASCII strings", function () {
condensedTypes.forEach((type) => {
expect(type).to.be.a("string").that.does.match(/^\w+$/);
});
});
});