Skip to content

Commit

Permalink
Merge pull request #4869 from thelounge/tsUpdate
Browse files Browse the repository at this point in the history
Ts update
  • Loading branch information
MaxLeiter committed May 5, 2024
2 parents cbab10f + 3259ac5 commit 74563ef
Show file tree
Hide file tree
Showing 43 changed files with 386 additions and 328 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Expand Up @@ -93,6 +93,7 @@ const tsRules = defineConfig({
// note you must disable the base rule as it can report incorrect errors
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"],
"@typescript-eslint/no-redundant-type-constituents": "off",
},
}).rules;

Expand Down
11 changes: 6 additions & 5 deletions client/components/Chat.vue
Expand Up @@ -136,6 +136,7 @@ import ListIgnored from "./Special/ListIgnored.vue";
import {defineComponent, PropType, ref, computed, watch, nextTick, onMounted, Component} from "vue";
import type {ClientNetwork, ClientChan} from "../js/types";
import {useStore} from "../js/store";
import {SpecialChanType, ChanType} from "../../shared/types/chan";
export default defineComponent({
name: "Chat",
Expand All @@ -161,13 +162,13 @@ export default defineComponent({
const specialComponent = computed(() => {
switch (props.channel.special) {
case "list_bans":
case SpecialChanType.BANLIST:
return ListBans as Component;
case "list_invites":
case SpecialChanType.INVITELIST:
return ListInvites as Component;
case "list_channels":
case SpecialChanType.CHANNELLIST:
return ListChannels as Component;
case "list_ignored":
case SpecialChanType.IGNORELIST:
return ListIgnored as Component;
}
Expand All @@ -194,7 +195,7 @@ export default defineComponent({
};
const editTopic = () => {
if (props.channel.type === "channel") {
if (props.channel.type === ChanType.CHANNEL) {
props.channel.editTopic = true;
}
};
Expand Down
10 changes: 4 additions & 6 deletions client/components/ChatInput.vue
Expand Up @@ -56,13 +56,14 @@
import Mousetrap from "mousetrap";
import {wrapCursor} from "undate";
import autocompletion from "../js/autocompletion";
import commands from "../js/commands/index";
import {commands} from "../js/commands/index";
import socket from "../js/socket";
import upload from "../js/upload";
import eventbus from "../js/eventbus";
import {watch, defineComponent, nextTick, onMounted, PropType, ref, onUnmounted} from "vue";
import type {ClientNetwork, ClientChan} from "../js/types";
import {useStore} from "../js/store";
import {ChanType} from "../../shared/types/chan";
const formattingHotkeys = {
"mod+k": "\x03",
Expand Down Expand Up @@ -130,7 +131,7 @@ export default defineComponent({
};
const getInputPlaceholder = (channel: ClientChan) => {
if (channel.type === "channel" || channel.type === "query") {
if (channel.type === ChanType.CHANNEL || channel.type === ChanType.QUERY) {
return `Write to ${channel.name}`;
}
Expand Down Expand Up @@ -185,10 +186,7 @@ export default defineComponent({
return false;
}
if (
Object.prototype.hasOwnProperty.call(commands, cmd) &&
commands[cmd].input(args)
) {
if (Object.prototype.hasOwnProperty.call(commands, cmd) && commands[cmd](args)) {
return false;
}
}
Expand Down
12 changes: 10 additions & 2 deletions client/components/MessageCondensed.vue
Expand Up @@ -20,6 +20,7 @@
<script lang="ts">
import {computed, defineComponent, PropType, ref} from "vue";
import {condensedTypes} from "../../shared/irc";
import {MessageType} from "../../shared/types/msg";
import {ClientMessage, ClientNetwork} from "../js/types";
import Message from "./Message.vue";
Expand Down Expand Up @@ -57,16 +58,23 @@ export default defineComponent({
for (const message of props.messages) {
// special case since one MODE message can change multiple modes
if (message.type === "mode") {
if (message.type === MessageType.MODE) {
// syntax: +vv-t maybe-some targets
// we want the number of mode changes in the message, so count the
// number of chars other than + and - before the first space
const modeChangesCount = message.text
const text = message.text ? message.text : "";
const modeChangesCount = text
.split(" ")[0]
.split("")
.filter((char) => char !== "+" && char !== "-").length;
obj[message.type] += modeChangesCount;
} else {
if (!message.type) {
/* eslint-disable no-console */
console.log(`empty message type, this should not happen: ${message.id}`);
continue;
}
obj[message.type]++;
}
}
Expand Down
22 changes: 12 additions & 10 deletions client/components/MessageList.vue
Expand Up @@ -59,6 +59,8 @@

<script lang="ts">
import {condensedTypes} from "../../shared/irc";
import {ChanType} from "../../shared/types/chan";
import {MessageType, SharedMsg} from "../../shared/types/msg";
import eventbus from "../js/eventbus";
import clipboard from "../js/clipboard";
import socket from "../js/socket";
Expand All @@ -79,7 +81,6 @@ import {
} from "vue";
import {useStore} from "../js/store";
import {ClientChan, ClientMessage, ClientNetwork, ClientLinkPreview} from "../js/types";
import {SharedMsg} from "../../shared/types/msg";
type CondensedMessageContainer = {
type: "condensed";
Expand All @@ -103,7 +104,7 @@ export default defineComponent({
channel: {type: Object as PropType<ClientChan>, required: true},
focused: Number,
},
setup(props, {emit}) {
setup(props) {
const store = useStore();
const chat = ref<HTMLDivElement | null>(null);
Expand Down Expand Up @@ -177,14 +178,14 @@ export default defineComponent({
});
const condensedMessages = computed(() => {
if (props.channel.type !== "channel" && props.channel.type !== "query") {
if (props.channel.type !== ChanType.CHANNEL && props.channel.type !== ChanType.QUERY) {
return props.channel.messages;
}
// If actions are hidden, just return a message list with them excluded
if (store.state.settings.statusMessages === "hidden") {
return props.channel.messages.filter(
(message) => !condensedTypes.has(message.type)
(message) => !condensedTypes.has(message.type || "")
);
}
Expand All @@ -200,7 +201,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 || !condensedTypes.has(message.type)) {
if (message.self || message.highlight || !condensedTypes.has(message.type || "")) {
lastCondensedContainer = null;
condensed.push(message);
Expand Down Expand Up @@ -242,7 +243,7 @@ export default defineComponent({
});
const shouldDisplayDateMarker = (
message: SharedMsg | ClientMessage | CondensedMessageContainer,
message: SharedMsg | CondensedMessageContainer,
id: number
) => {
const previousMessage = condensedMessages.value[id - 1];
Expand Down Expand Up @@ -270,12 +271,13 @@ export default defineComponent({
return false;
};
const isPreviousSource = (currentMessage: ClientMessage | SharedMsg, id: number) => {
const isPreviousSource = (currentMessage: ClientMessage, id: number) => {
const previousMessage = condensedMessages.value[id - 1];
return !!(
return (
previousMessage &&
currentMessage.type === "message" &&
previousMessage.type === "message" &&
currentMessage.type === MessageType.MESSAGE &&
previousMessage.type === MessageType.MESSAGE &&
currentMessage.from &&
previousMessage.from &&
currentMessage.from.nick === previousMessage.from.nick
);
Expand Down
2 changes: 1 addition & 1 deletion client/components/Windows/NetworkEdit.vue
Expand Up @@ -48,7 +48,7 @@ export default defineComponent({
watch(
() => route.params.uuid,
(newValue) => {
() => {
setNetworkData();
}
);
Expand Down
8 changes: 4 additions & 4 deletions client/js/autocompletion.ts
@@ -1,13 +1,14 @@
import constants from "./constants";

import Mousetrap from "mousetrap";
import {Strategy, Textcomplete, StrategyProps} from "@textcomplete/core";
import {Textcomplete, StrategyProps} from "@textcomplete/core";
import {TextareaEditor} from "@textcomplete/textarea";

import fuzzy from "fuzzy";

import emojiMap from "./helpers/simplemap.json";
import {store} from "./store";
import {ChanType} from "../../shared/types/chan";

export default enableAutocomplete;

Expand Down Expand Up @@ -38,7 +39,6 @@ const nicksStrategy: StrategyProps = {

if (term[0] === "@") {
// TODO: type
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
callback(completeNicks(term.slice(1), true).map((val) => ["@" + val[0], "@" + val[1]]));
} else {
callback(completeNicks(term, true));
Expand Down Expand Up @@ -292,7 +292,7 @@ function rawNicks() {
const otherUser = store.state.activeChannel.channel.name;

// If this is a query, add their name to autocomplete
if (me !== otherUser && store.state.activeChannel.channel.type === "query") {
if (me !== otherUser && store.state.activeChannel.channel.type === ChanType.QUERY) {
return [otherUser, me];
}

Expand Down Expand Up @@ -332,7 +332,7 @@ function completeChans(word: string) {
if (store.state.activeChannel) {
for (const channel of store.state.activeChannel.network.channels) {
// Push all channels that start with the same CHANTYPE
if (channel.type === "channel" && channel.name[0] === word[0]) {
if (channel.type === ChanType.CHANNEL && channel.name[0] === word[0]) {
words.push(channel.name);
}
}
Expand Down
7 changes: 4 additions & 3 deletions client/js/chan.ts
@@ -1,11 +1,12 @@
import {ClientChan, ClientMessage} from "./types";
import {SharedNetworkChan} from "../../shared/types/network";
import {SharedMsg} from "../../shared/types/msg";
import {SharedMsg, MessageType} from "../../shared/types/msg";
import {ChanType} from "../../shared/types/chan";

export function toClientChan(shared: SharedNetworkChan): ClientChan {
const history: string[] = [""].concat(
shared.messages
.filter((m) => m.self && m.text && m.type === "message")
.filter((m) => m.self && m.text && m.type === MessageType.MESSAGE)
// TS is too stupid to see the nil guard on filter... so we monkey patch it
.map((m): string => (m.text ? m.text : ""))
.reverse()
Expand All @@ -21,7 +22,7 @@ export function toClientChan(shared: SharedNetworkChan): ClientChan {
historyLoading: false,
scrolledToBottom: true,
users: [],
usersOutdated: shared.type === "channel" ? true : false,
usersOutdated: shared.type === ChanType.CHANNEL ? true : false,
moreHistoryAvailable: shared.totalMessages > shared.messages.length,
inputHistory: history,
messages: sharedMsgToClientMsg(messages),
Expand Down
6 changes: 2 additions & 4 deletions client/js/commands/collapse.ts
@@ -1,9 +1,9 @@
import socket from "../socket";
import {store} from "../store";

function input() {
export function input(): boolean {
if (!store.state.activeChannel) {
return;
return false;
}

const messageIds: number[] = [];
Expand Down Expand Up @@ -34,5 +34,3 @@ function input() {

return true;
}

export default {input};
6 changes: 2 additions & 4 deletions client/js/commands/expand.ts
@@ -1,9 +1,9 @@
import socket from "../socket";
import {store} from "../store";

function input() {
export function input(): boolean {
if (!store.state.activeChannel) {
return;
return false;
}

const messageIds: number[] = [];
Expand Down Expand Up @@ -34,5 +34,3 @@ function input() {

return true;
}

export default {input};
30 changes: 11 additions & 19 deletions client/js/commands/index.ts
@@ -1,19 +1,11 @@
// Taken from views/index.js

// This creates a version of `require()` in the context of the current
// directory, so we iterate over its content, which is a map statically built by
// Webpack.
// Second argument says it's recursive, third makes sure we only load javascript.
const commands = require.context("./", true, /\.ts$/);

export default commands.keys().reduce<Record<string, unknown>>((acc, path) => {
const command = path.substring(2, path.length - 3);

if (command === "index") {
return acc;
}

acc[command] = commands(path).default;

return acc;
}, {});
import {input as collapse} from "./collapse";
import {input as expand} from "./expand";
import {input as join} from "./join";
import {input as search} from "./search";

export const commands = {
collapse: collapse,
expand: expand,
join: join,
search: search,
};
9 changes: 5 additions & 4 deletions client/js/commands/join.ts
@@ -1,8 +1,9 @@
import socket from "../socket";
import {store} from "../store";
import {switchToChannel} from "../router";
import {ChanType} from "../../../shared/types/chan";

function input(args: string[]) {
export function input(args: string[]): boolean {
if (args.length > 0) {
let channels = args[0];

Expand Down Expand Up @@ -35,7 +36,7 @@ function input(args: string[]) {
return true;
}
}
} else if (store.state.activeChannel?.channel.type === "channel") {
} else if (store.state.activeChannel?.channel.type === ChanType.CHANNEL) {
// If `/join` command is used without any arguments, re-join current channel
socket.emit("input", {
target: store.state.activeChannel.channel.id,
Expand All @@ -44,6 +45,6 @@ function input(args: string[]) {

return true;
}
}

export default {input};
return false;
}
4 changes: 1 addition & 3 deletions client/js/commands/search.ts
@@ -1,7 +1,7 @@
import {store} from "../store";
import {router} from "../router";

function input(args: string[]) {
export function input(args: string[]): boolean {
if (!store.state.settings.searchEnabled) {
return false;
}
Expand All @@ -23,5 +23,3 @@ function input(args: string[]) {

return true;
}

export default {input};

0 comments on commit 74563ef

Please sign in to comment.