Минорные исправления

This commit is contained in:
Artem VV 2023-05-19 21:15:28 +07:00
parent f2a6469a55
commit fb6fb58d11
3 changed files with 55 additions and 19 deletions

View file

@ -33,7 +33,25 @@ if (chat.messages.length > 0) {
<div class="col d-flex flex-column" data-chatId={chat.chat.id}>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">{chat.chat.title}</a>
<!-- <p class="navbar-brand">
Чат "{chat.chat.title}" с {
chat.chat.user_in_chat
.map((e) => e.user.fullName ?? e.user.login)
.filter((e) => e !== null)
.join(", ")
}
</p> -->
<div>
<p class="mb-1">Чат "{chat.chat.title}"</p>
<small class="text-muted">
Пользователи: {
chat.chat.user_in_chat
.map((e) => e.user.fullName ?? e.user.login)
.filter((e) => e !== null)
.join(", ")
}
</small>
</div>
</div>
</nav>
<div id="chatHolder" class="flex-grow-1" data-lastMessageAt={lastMessageAt}>
@ -90,7 +108,10 @@ if (chat.messages.length > 0) {
const chatHolder = document.getElementById("chatHolder")!;
const lastMessage = chatHolder.querySelectorAll(`[data-messageId]`).item(chatHolder.childElementCount - 1);
const lastMessageId = lastMessage !== null ? lastMessage.getAttribute("data-messageId") : null;
let lastMessageId = null;
try {
lastMessageId = lastMessage.getAttribute("data-messageId");
} catch (e) {}
for (const message of data.messages) {
if (lastMessageId !== null && message.id === lastMessageId) continue;
@ -112,7 +133,9 @@ if (chat.messages.length > 0) {
try {
const fd = new FormData();
fd.append("chatId", chatId());
try {
fd.append("since", lastMessageAt().toISOString());
} catch (e) {}
const resp = await fetch("/chatapi/getMessages", {
method: "POST",
@ -188,7 +211,7 @@ if (chat.messages.length > 0) {
<style>
#chatHolder {
max-height: calc(100vh - 13rem);
max-height: calc(100vh - 14rem);
overflow: hidden;
overflow-y: scroll;
}

View file

@ -1,4 +1,4 @@
import { PrismaClient, chat, chat_message, users } from "@prisma/client";
import { PrismaClient, chat, chat_message, user_in_chat, users } from "@prisma/client";
import { blake3 } from "@noble/hashes/blake3";
import { bytesToHex as toHex } from "@noble/hashes/utils";
@ -385,7 +385,11 @@ export async function getUserChats(userId: number) {
}
export type CompositeChat = {
chat: chat;
chat: chat & {
user_in_chat: (user_in_chat & {
user: users;
})[];
};
messages: (chat_message & {
user: users;
})[];
@ -396,6 +400,13 @@ export async function getChatMessages(chatId: string, since?: Date): Promise<Com
where: {
id: chatId,
},
include: {
user_in_chat: {
include: {
user: true,
},
},
},
}))!;
const messages = await client.chat_message.findMany({
where: {

View file

@ -59,6 +59,7 @@ const users = await searchUsers({
<div class="card-body">
<h5 class="card-title">{e.fullName}</h5>
<h6 class="card-subtitle mb-2 text-muted">{e.login}</h6>
<div class="d-flex flex-row gap-1">
<a href={`/user/${e.login}`} class="btn btn-primary btn-sm">
Открыть профиль
</a>
@ -75,6 +76,7 @@ const users = await searchUsers({
) : null}
</div>
</div>
</div>
))
}
</div>