diff --git a/public/res/ic/outlined/message-unread.svg b/public/res/ic/outlined/message-unread.svg new file mode 100644 index 0000000..fc5e9ff --- /dev/null +++ b/public/res/ic/outlined/message-unread.svg @@ -0,0 +1,15 @@ + + + + diff --git a/public/res/ic/outlined/message.svg b/public/res/ic/outlined/message.svg new file mode 100644 index 0000000..d36e9a3 --- /dev/null +++ b/public/res/ic/outlined/message.svg @@ -0,0 +1,12 @@ + + + + diff --git a/src/app/molecules/room-options/RoomOptions.jsx b/src/app/molecules/room-options/RoomOptions.jsx index 734f93b..85b2b5a 100644 --- a/src/app/molecules/room-options/RoomOptions.jsx +++ b/src/app/molecules/room-options/RoomOptions.jsx @@ -6,6 +6,7 @@ import { twemojify } from '../../../util/twemojify'; import initMatrix from '../../../client/initMatrix'; import { openInviteUser } from '../../../client/action/navigation'; import * as roomActions from '../../../client/action/room'; +import { markAsRead } from '../../../client/action/notifications'; import { MenuHeader, MenuItem } from '../../atoms/context-menu/ContextMenu'; import RoomNotification from '../room-notification/RoomNotification'; @@ -20,10 +21,8 @@ function RoomOptions({ roomId, afterOptionSelect }) { const canInvite = room?.canInvite(mx.getUserId()); const handleMarkAsRead = () => { + markAsRead(roomId); afterOptionSelect(); - if (!room) return; - const events = room.getLiveTimeline().getEvents(); - mx.sendReadReceipt(events[events.length - 1]); }; const handleInviteClick = () => { diff --git a/src/app/organisms/room/Room.jsx b/src/app/organisms/room/Room.jsx index 015fb68..7c199be 100644 --- a/src/app/organisms/room/Room.jsx +++ b/src/app/organisms/room/Room.jsx @@ -26,7 +26,7 @@ function Room() { roomInfo.roomTimeline?.removeInternalListeners(); if (mx.getRoom(rId)) { setRoomInfo({ - roomTimeline: new RoomTimeline(rId, initMatrix.notifications), + roomTimeline: new RoomTimeline(rId), eventId: eId ?? null, }); } else { diff --git a/src/app/organisms/room/RoomViewContent.jsx b/src/app/organisms/room/RoomViewContent.jsx index e3f2aba..dd77e98 100644 --- a/src/app/organisms/room/RoomViewContent.jsx +++ b/src/app/organisms/room/RoomViewContent.jsx @@ -14,6 +14,7 @@ import cons from '../../../client/state/cons'; import navigation from '../../../client/state/navigation'; import { openProfileViewer } from '../../../client/action/navigation'; import { diffMinutes, isInSameDay, Throttle } from '../../../util/common'; +import { markAsRead } from '../../../client/action/notifications'; import Divider from '../../atoms/divider/Divider'; import ScrollView from '../../atoms/scroll/ScrollView'; @@ -253,7 +254,7 @@ function useHandleScroll( ); roomTimeline.emit(cons.events.roomTimeline.AT_BOTTOM, isAtBottom); if (isAtBottom && readUptoEvtStore.getItem()) { - requestAnimationFrame(() => roomTimeline.markAllAsRead()); + requestAnimationFrame(() => markAsRead(roomTimeline.roomId)); } }); autoPaginate(); @@ -263,7 +264,7 @@ function useHandleScroll( const timelineScroll = timelineScrollRef.current; const limit = eventLimitRef.current; if (readUptoEvtStore.getItem()) { - requestAnimationFrame(() => roomTimeline.markAllAsRead()); + requestAnimationFrame(() => markAsRead(roomTimeline.roomId)); } if (roomTimeline.isServingLiveTimeline()) { limit.setFrom(roomTimeline.timeline.length - limit.maxEvents); @@ -286,7 +287,7 @@ function useEventArrive(roomTimeline, readUptoEvtStore, timelineScrollRef, event const limit = eventLimitRef.current; const trySendReadReceipt = (event) => { if (myUserId === event.getSender()) { - requestAnimationFrame(() => roomTimeline.markAllAsRead()); + requestAnimationFrame(() => markAsRead(roomTimeline.roomId)); return; } const readUpToEvent = readUptoEvtStore.getItem(); @@ -295,7 +296,7 @@ function useEventArrive(roomTimeline, readUptoEvtStore, timelineScrollRef, event if (isUnread === false) { if (document.visibilityState === 'visible' && timelineScroll.bottom < 16) { - requestAnimationFrame(() => roomTimeline.markAllAsRead()); + requestAnimationFrame(() => markAsRead(roomTimeline.roomId)); } else { readUptoEvtStore.setItem(roomTimeline.findEventByIdInTimelineSet(readUpToId)); } @@ -305,7 +306,7 @@ function useEventArrive(roomTimeline, readUptoEvtStore, timelineScrollRef, event const { timeline } = roomTimeline; const unreadMsgIsLast = timeline[timeline.length - 2].getId() === readUpToId; if (unreadMsgIsLast) { - requestAnimationFrame(() => roomTimeline.markAllAsRead()); + requestAnimationFrame(() => markAsRead(roomTimeline.roomId)); } }; @@ -399,7 +400,7 @@ function RoomViewContent({ eventId, roomTimeline }) { if (timelineScroll.bottom < 16 && !roomTimeline.canPaginateForward()) { const readUpToId = roomTimeline.getReadUpToEventId(); if (readUptoEvtStore.getItem()?.getId() === readUpToId || readUpToId === null) { - requestAnimationFrame(() => roomTimeline.markAllAsRead()); + requestAnimationFrame(() => markAsRead(roomTimeline.roomId)); } } jumpToItemIndex = -1; diff --git a/src/app/organisms/room/RoomViewFloating.jsx b/src/app/organisms/room/RoomViewFloating.jsx index 1bec52d..e65e854 100644 --- a/src/app/organisms/room/RoomViewFloating.jsx +++ b/src/app/organisms/room/RoomViewFloating.jsx @@ -5,11 +5,13 @@ import './RoomViewFloating.scss'; import initMatrix from '../../../client/initMatrix'; import cons from '../../../client/state/cons'; +import { markAsRead } from '../../../client/action/notifications'; import Text from '../../atoms/text/Text'; import Button from '../../atoms/button/Button'; import IconButton from '../../atoms/button/IconButton'; +import MessageUnreadIC from '../../../../public/res/ic/outlined/message-unread.svg'; import ChevronBottomIC from '../../../../public/res/ic/outlined/chevron-bottom.svg'; import TickMarkIC from '../../../../public/res/ic/outlined/tick-mark.svg'; @@ -23,7 +25,7 @@ function useJumpToEvent(roomTimeline) { }; const cancelJumpToEvent = () => { - roomTimeline.markAllAsRead(); + markAsRead(roomTimeline.roomId); setEventId(null); }; @@ -36,11 +38,12 @@ function useJumpToEvent(roomTimeline) { setEventId(readEventId); } + const { notifications } = initMatrix; const handleMarkAsRead = () => setEventId(null); - roomTimeline.on(cons.events.roomTimeline.MARKED_AS_READ, handleMarkAsRead); + notifications.on(cons.events.notifications.FULL_READ, handleMarkAsRead); return () => { - roomTimeline.removeListener(cons.events.roomTimeline.MARKED_AS_READ, handleMarkAsRead); + notifications.removeListener(cons.events.notifications.FULL_READ, handleMarkAsRead); setEventId(null); }; }, [roomTimeline]); @@ -96,17 +99,12 @@ function RoomViewFloating({ return ( <>