Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8ca15422f | ||
| eee419c0d4 |
@@ -104,12 +104,6 @@ export function DialogInput() {
|
|||||||
}, [dialog, editableDivRef]);
|
}, [dialog, editableDivRef]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if(systemAccounts.find((acc) => acc.publicKey == dialog)){
|
|
||||||
/**
|
|
||||||
* У системных аккаунтов нельзя отвечать на сообщения
|
|
||||||
*/
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(replyMessages.inDialogInput && replyMessages.inDialogInput == dialog){
|
if(replyMessages.inDialogInput && replyMessages.inDialogInput == dialog){
|
||||||
setAttachments([{
|
setAttachments([{
|
||||||
type: AttachmentType.MESSAGES,
|
type: AttachmentType.MESSAGES,
|
||||||
@@ -117,10 +111,8 @@ export function DialogInput() {
|
|||||||
blob: JSON.stringify([...replyMessages.messages]),
|
blob: JSON.stringify([...replyMessages.messages]),
|
||||||
preview: ""
|
preview: ""
|
||||||
}]);
|
}]);
|
||||||
if(editableDivRef.current){
|
|
||||||
editableDivRef.current.focus();
|
editableDivRef.current.focus();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}, [dialog, replyMessages]);
|
}, [dialog, replyMessages]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -216,12 +208,6 @@ export function DialogInput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onClickCamera = async () => {
|
const onClickCamera = async () => {
|
||||||
if(systemAccounts.find((acc) => acc.publicKey == dialog)){
|
|
||||||
/**
|
|
||||||
* У системных аккаунтов нельзя вызывать вложения
|
|
||||||
*/
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(avatars.length == 0){
|
if(avatars.length == 0){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -231,10 +217,8 @@ export function DialogInput() {
|
|||||||
type: AttachmentType.AVATAR,
|
type: AttachmentType.AVATAR,
|
||||||
preview: await base64ImageToBlurhash(avatars[0].avatar)
|
preview: await base64ImageToBlurhash(avatars[0].avatar)
|
||||||
}]);
|
}]);
|
||||||
if(editableDivRef.current){
|
|
||||||
editableDivRef.current.focus();
|
editableDivRef.current.focus();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const sendTypeingPacket = () => {
|
const sendTypeingPacket = () => {
|
||||||
let packet = new PacketTyping();
|
let packet = new PacketTyping();
|
||||||
@@ -245,12 +229,6 @@ export function DialogInput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onPaste = async (event: React.ClipboardEvent) => {
|
const onPaste = async (event: React.ClipboardEvent) => {
|
||||||
if(systemAccounts.find((acc) => acc.publicKey == dialog)){
|
|
||||||
/**
|
|
||||||
* У системных аккаунтов нельзя вызывать вложения
|
|
||||||
*/
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(attachments.length >= MAX_ATTACHMENTS_IN_MESSAGE){
|
if(attachments.length >= MAX_ATTACHMENTS_IN_MESSAGE){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -271,9 +249,7 @@ export function DialogInput() {
|
|||||||
preview: await base64ImageToBlurhash(base64Image)
|
preview: await base64ImageToBlurhash(base64Image)
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
if(editableDivRef.current){
|
|
||||||
editableDivRef.current.focus();
|
editableDivRef.current.focus();
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ export function MentionRow(props : MentionRowProps) {
|
|||||||
{props.username == 'all' && <Avatar title="@" variant="filled" color={colors.brandColor}>@</Avatar>}
|
{props.username == 'all' && <Avatar title="@" variant="filled" color={colors.brandColor}>@</Avatar>}
|
||||||
{props.username == 'admin' && <Avatar title="@" variant="filled" color={colors.error}>@</Avatar>}
|
{props.username == 'admin' && <Avatar title="@" variant="filled" color={colors.error}>@</Avatar>}
|
||||||
{props.username != 'all' && props.username != 'admin' && <Avatar
|
{props.username != 'all' && props.username != 'admin' && <Avatar
|
||||||
name={props.title}
|
title={props.title}
|
||||||
variant="light"
|
variant="filled"
|
||||||
color="initials"
|
color="initials"
|
||||||
src={avatars.length > 0 ? avatars[0].avatar : null}
|
src={avatars.length > 0 ? avatars[0].avatar : null}
|
||||||
></Avatar>}
|
></Avatar>}
|
||||||
|
|||||||
@@ -7,12 +7,14 @@ import { MessageSkeleton } from "../MessageSkeleton/MessageSkeleton";
|
|||||||
import { ScrollArea } from "@mantine/core";
|
import { ScrollArea } from "@mantine/core";
|
||||||
import { MESSAGE_AVATAR_NO_RENDER_TIME_DIFF_S, SCROLL_TOP_IN_MESSAGES_TO_VIEW_AFFIX } from "@/app/constants";
|
import { MESSAGE_AVATAR_NO_RENDER_TIME_DIFF_S, SCROLL_TOP_IN_MESSAGES_TO_VIEW_AFFIX } from "@/app/constants";
|
||||||
import { DialogAffix } from "../DialogAffix/DialogAffix";
|
import { DialogAffix } from "../DialogAffix/DialogAffix";
|
||||||
|
import { useReplyMessages } from "@/app/providers/DialogProvider/useReplyMessages";
|
||||||
import { useSetting } from "@/app/providers/SettingsProvider/useSetting";
|
import { useSetting } from "@/app/providers/SettingsProvider/useSetting";
|
||||||
|
|
||||||
export function Messages() {
|
export function Messages() {
|
||||||
const colors = useRosettaColors();
|
const colors = useRosettaColors();
|
||||||
const publicKey = usePublicKey();
|
const publicKey = usePublicKey();
|
||||||
const { messages, dialog, loadMessagesToTop, loading } = useDialog();
|
const { messages, dialog, loadMessagesToTop, loading } = useDialog();
|
||||||
|
const { replyMessages, isSelectionStarted } = useReplyMessages();
|
||||||
|
|
||||||
const viewportRef = useRef<HTMLDivElement | null>(null);
|
const viewportRef = useRef<HTMLDivElement | null>(null);
|
||||||
const lastMessageRef = useRef<HTMLDivElement | null>(null);
|
const lastMessageRef = useRef<HTMLDivElement | null>(null);
|
||||||
@@ -20,7 +22,6 @@ export function Messages() {
|
|||||||
const shouldAutoScrollRef = useRef(true);
|
const shouldAutoScrollRef = useRef(true);
|
||||||
const isFirstRenderRef = useRef(true);
|
const isFirstRenderRef = useRef(true);
|
||||||
const previousScrollHeightRef = useRef(0);
|
const previousScrollHeightRef = useRef(0);
|
||||||
const distanceFromButtomRef = useRef(0);
|
|
||||||
|
|
||||||
const [affix, setAffix] = useState(false);
|
const [affix, setAffix] = useState(false);
|
||||||
const [wallpaper] = useSetting<string>
|
const [wallpaper] = useSetting<string>
|
||||||
@@ -120,10 +121,15 @@ export function Messages() {
|
|||||||
const lastMessage = messages[messages.length - 1];
|
const lastMessage = messages[messages.length - 1];
|
||||||
|
|
||||||
// Скроллим если пользователь внизу или это его собственное сообщение
|
// Скроллим если пользователь внизу или это его собственное сообщение
|
||||||
if ((shouldAutoScrollRef.current || lastMessage.from_me)) {
|
if ((shouldAutoScrollRef.current || lastMessage.from_me) && !affix) {
|
||||||
|
/**
|
||||||
|
* Скролл только если пользователь не читает сейчас старую переписку
|
||||||
|
* (!affix))
|
||||||
|
*/
|
||||||
|
//console.info("Scroll because", shouldAutoScrollRef.current);
|
||||||
scrollToBottom(true);
|
scrollToBottom(true);
|
||||||
}
|
}
|
||||||
}, [messages.length, loading, scrollToBottom]);
|
}, [messages.length, loading, affix, scrollToBottom]);
|
||||||
|
|
||||||
// Восстановление позиции после загрузки старых сообщений
|
// Восстановление позиции после загрузки старых сообщений
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -136,6 +142,12 @@ export function Messages() {
|
|||||||
}
|
}
|
||||||
}, [messages.length]);
|
}, [messages.length]);
|
||||||
|
|
||||||
|
// Скролл при отправке reply сообщения
|
||||||
|
useEffect(() => {
|
||||||
|
if (replyMessages.messages.length === 0 || isSelectionStarted()) return;
|
||||||
|
scrollToBottom(true);
|
||||||
|
}, [replyMessages.messages.length]);
|
||||||
|
|
||||||
const loadMessagesToScrollAreaTop = async () => {
|
const loadMessagesToScrollAreaTop = async () => {
|
||||||
if (!viewportRef.current) return;
|
if (!viewportRef.current) return;
|
||||||
|
|
||||||
@@ -183,7 +195,6 @@ export function Messages() {
|
|||||||
// Показываем/скрываем кнопку "вниз"
|
// Показываем/скрываем кнопку "вниз"
|
||||||
const distanceFromBottom =
|
const distanceFromBottom =
|
||||||
(viewportRef.current.scrollHeight - viewportRef.current.clientHeight) - scroll.y;
|
(viewportRef.current.scrollHeight - viewportRef.current.clientHeight) - scroll.y;
|
||||||
distanceFromButtomRef.current = distanceFromBottom;
|
|
||||||
|
|
||||||
setAffix(distanceFromBottom > SCROLL_TOP_IN_MESSAGES_TO_VIEW_AFFIX);
|
setAffix(distanceFromBottom > SCROLL_TOP_IN_MESSAGES_TO_VIEW_AFFIX);
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user