chatuserlist

This commit is contained in:
Reto Brunner 2024-03-01 09:04:30 +01:00
parent 7073584f1c
commit 88c8830a17
3 changed files with 8 additions and 7 deletions

View file

@ -59,7 +59,7 @@
<script lang="ts"> <script lang="ts">
import {filter as fuzzyFilter} from "fuzzy"; import {filter as fuzzyFilter} from "fuzzy";
import {computed, defineComponent, nextTick, PropType, ref} from "vue"; import {computed, defineComponent, nextTick, PropType, ref} from "vue";
import type {UserInMessage} from "../../server/models/msg"; import type {UserInMessage} from "../../shared/types/msg";
import type {ClientChan, ClientUser} from "../js/types"; import type {ClientChan, ClientUser} from "../js/types";
import Username from "./Username.vue"; import Username from "./Username.vue";
@ -104,7 +104,7 @@ export default defineComponent({
const result = filteredUsers.value; const result = filteredUsers.value;
for (const user of result) { for (const user of result) {
const mode = user.original.modes[0] || ""; const mode: string = user.original.modes[0] || "";
if (!groups[mode]) { if (!groups[mode]) {
groups[mode] = []; groups[mode] = [];

View file

@ -2,7 +2,7 @@ import {nextTick} from "vue";
import socket from "../socket"; import socket from "../socket";
import {store} from "../store"; import {store} from "../store";
import {ClientMessage} from "../types"; import {ClientMessage} from "../../../shared/types/msg";
socket.on("more", async (data) => { socket.on("more", async (data) => {
const channel = store.getters.findChannel(data.chan)?.channel; const channel = store.getters.findChannel(data.chan)?.channel;
@ -14,12 +14,15 @@ socket.on("more", async (data) => {
channel.inputHistory = channel.inputHistory.concat( channel.inputHistory = channel.inputHistory.concat(
data.messages data.messages
.filter((m) => m.self && m.text && m.type === "message") .filter((m) => m.self && m.text && m.type === "message")
.map((m) => m.text) // TS is too stupid to see the guard in .filter(), so we monkey patch it
// to please the compiler
.map((m) => (m.text ? m.text : ""))
.reverse() .reverse()
.slice(0, 100 - channel.inputHistory.length) .slice(0, 100 - channel.inputHistory.length)
); );
channel.moreHistoryAvailable = channel.moreHistoryAvailable =
data.totalMessages > channel.messages.length + data.messages.length; data.totalMessages > channel.messages.length + data.messages.length;
// TODO: invalid type cast
channel.messages.unshift(...(data.messages as ClientMessage[])); channel.messages.unshift(...(data.messages as ClientMessage[]));
await nextTick(); await nextTick();

View file

@ -15,9 +15,7 @@ interface LoungeWindow extends Window {
}; };
} }
type ClientUser = SharedUser & { type ClientUser = SharedUser;
//
};
type ClientChan = Omit<SharedChan, "users" | "messages"> & { type ClientChan = Omit<SharedChan, "users" | "messages"> & {
moreHistoryAvailable: boolean; moreHistoryAvailable: boolean;