mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-04 22:40:29 +03:00
move t and handleEdit
This commit is contained in:
parent
2d66641167
commit
5d3033aa96
1 changed files with 13 additions and 31 deletions
|
|
@ -435,6 +435,7 @@ export function RoomTimeline({
|
||||||
accessibleTagColors,
|
accessibleTagColors,
|
||||||
}: RoomTimelineProps) {
|
}: RoomTimelineProps) {
|
||||||
const mx = useMatrixClient();
|
const mx = useMatrixClient();
|
||||||
|
const { t } = useTranslation();
|
||||||
const useAuthentication = useMediaAuthentication();
|
const useAuthentication = useMediaAuthentication();
|
||||||
const [hideActivity] = useSetting(settingsAtom, 'hideActivity');
|
const [hideActivity] = useSetting(settingsAtom, 'hideActivity');
|
||||||
const [messageLayout] = useSetting(settingsAtom, 'messageLayout');
|
const [messageLayout] = useSetting(settingsAtom, 'messageLayout');
|
||||||
|
|
@ -592,15 +593,8 @@ export function RoomTimeline({
|
||||||
room,
|
room,
|
||||||
useCallback(
|
useCallback(
|
||||||
(mEvt: MatrixEvent) => {
|
(mEvt: MatrixEvent) => {
|
||||||
// if user is at bottom of timeline
|
|
||||||
// keep paginating timeline and conditionally mark as read
|
|
||||||
// otherwise we update timeline without paginating
|
|
||||||
// so timeline can be updated with evt like: edits, reactions etc
|
|
||||||
if (atBottomRef.current) {
|
if (atBottomRef.current) {
|
||||||
if (document.hasFocus() && (!unreadInfo || mEvt.getSender() === mx.getUserId())) {
|
if (document.hasFocus() && (!unreadInfo || mEvt.getSender() === mx.getUserId())) {
|
||||||
// Check if the document is in focus (user is actively viewing the app),
|
|
||||||
// and either there are no unread messages or the latest message is from the current user.
|
|
||||||
// If either condition is met, trigger the markAsRead function to send a read receipt.
|
|
||||||
requestAnimationFrame(() => markAsRead(mx, mEvt.getRoomId()!, hideActivity));
|
requestAnimationFrame(() => markAsRead(mx, mEvt.getRoomId()!, hideActivity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -668,13 +662,11 @@ export function RoomTimeline({
|
||||||
}, [room, liveTimelineLinked])
|
}, [room, liveTimelineLinked])
|
||||||
);
|
);
|
||||||
|
|
||||||
// Stay at bottom when room editor resize
|
|
||||||
useResizeObserver(
|
useResizeObserver(
|
||||||
useMemo(() => {
|
useMemo(() => {
|
||||||
let mounted = false;
|
let mounted = false;
|
||||||
return (entries) => {
|
return (entries) => {
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
// skip initial mounting call
|
|
||||||
mounted = true;
|
mounted = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -742,8 +734,6 @@ export function RoomTimeline({
|
||||||
if (inFocus && atBottomRef.current) {
|
if (inFocus && atBottomRef.current) {
|
||||||
if (unreadInfo?.inLiveTimeline) {
|
if (unreadInfo?.inLiveTimeline) {
|
||||||
handleOpenEvent(unreadInfo.readUptoEventId, false, (scrolled) => {
|
handleOpenEvent(unreadInfo.readUptoEventId, false, (scrolled) => {
|
||||||
// the unread event is already in view
|
|
||||||
// so, try mark as read;
|
|
||||||
if (!scrolled) {
|
if (!scrolled) {
|
||||||
tryAutoMarkAsRead();
|
tryAutoMarkAsRead();
|
||||||
}
|
}
|
||||||
|
|
@ -757,7 +747,6 @@ export function RoomTimeline({
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle up arrow edit
|
|
||||||
useKeyDown(
|
useKeyDown(
|
||||||
window,
|
window,
|
||||||
useCallback(
|
useCallback(
|
||||||
|
|
@ -788,7 +777,6 @@ export function RoomTimeline({
|
||||||
}
|
}
|
||||||
}, [eventId, loadEventTimeline]);
|
}, [eventId, loadEventTimeline]);
|
||||||
|
|
||||||
// Scroll to bottom on initial timeline load
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
const scrollEl = scrollRef.current;
|
const scrollEl = scrollRef.current;
|
||||||
if (scrollEl) {
|
if (scrollEl) {
|
||||||
|
|
@ -796,8 +784,6 @@ export function RoomTimeline({
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// if live timeline is linked and unreadInfo change
|
|
||||||
// Scroll to last read message
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
const { readUptoEventId, inLiveTimeline, scrollTo } = unreadInfo ?? {};
|
const { readUptoEventId, inLiveTimeline, scrollTo } = unreadInfo ?? {};
|
||||||
if (readUptoEventId && inLiveTimeline && scrollTo) {
|
if (readUptoEventId && inLiveTimeline && scrollTo) {
|
||||||
|
|
@ -815,7 +801,6 @@ export function RoomTimeline({
|
||||||
}
|
}
|
||||||
}, [room, unreadInfo, scrollToItem]);
|
}, [room, unreadInfo, scrollToItem]);
|
||||||
|
|
||||||
// scroll to focused message
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (focusItem && focusItem.scrollTo) {
|
if (focusItem && focusItem.scrollTo) {
|
||||||
scrollToItem(focusItem.index, {
|
scrollToItem(focusItem.index, {
|
||||||
|
|
@ -834,7 +819,6 @@ export function RoomTimeline({
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}, [alive, focusItem, scrollToItem]);
|
}, [alive, focusItem, scrollToItem]);
|
||||||
|
|
||||||
// scroll to bottom of timeline
|
|
||||||
const scrollToBottomCount = scrollToBottomRef.current.count;
|
const scrollToBottomCount = scrollToBottomRef.current.count;
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (scrollToBottomCount > 0) {
|
if (scrollToBottomCount > 0) {
|
||||||
|
|
@ -844,14 +828,24 @@ export function RoomTimeline({
|
||||||
}
|
}
|
||||||
}, [scrollToBottomCount]);
|
}, [scrollToBottomCount]);
|
||||||
|
|
||||||
// Remove unreadInfo on mark as read
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!unread) {
|
if (!unread) {
|
||||||
setUnreadInfo(undefined);
|
setUnreadInfo(undefined);
|
||||||
}
|
}
|
||||||
}, [unread]);
|
}, [unread]);
|
||||||
|
|
||||||
// scroll out of view msg editor in view.
|
const handleEdit = useCallback(
|
||||||
|
(editEvtId?: string) => {
|
||||||
|
if (editEvtId) {
|
||||||
|
setEditId(editEvtId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setEditId(undefined);
|
||||||
|
ReactEditor.focus(editor);
|
||||||
|
},
|
||||||
|
[editor]
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (editId) {
|
if (editId) {
|
||||||
const editMsgElement =
|
const editMsgElement =
|
||||||
|
|
@ -982,18 +976,6 @@ export function RoomTimeline({
|
||||||
},
|
},
|
||||||
[mx, room]
|
[mx, room]
|
||||||
);
|
);
|
||||||
const handleEdit = useCallback(
|
|
||||||
(editEvtId?: string) => {
|
|
||||||
if (editEvtId) {
|
|
||||||
setEditId(editEvtId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setEditId(undefined);
|
|
||||||
ReactEditor.focus(editor);
|
|
||||||
},
|
|
||||||
[editor]
|
|
||||||
);
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
const renderMatrixEvent = useMatrixEventRenderer<
|
const renderMatrixEvent = useMatrixEventRenderer<
|
||||||
[string, MatrixEvent, number, EventTimelineSet, boolean]
|
[string, MatrixEvent, number, EventTimelineSet, boolean]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue