From 99aed36c00da77c2930f413b73ddbcf71364cca2 Mon Sep 17 00:00:00 2001 From: molvqingtai Date: Sun, 3 Nov 2024 08:52:21 +0800 Subject: [PATCH] chore: delete world time --- src/app/content/components/MessageItem.tsx | 2 +- src/app/content/views/Main/index.tsx | 2 +- src/app/content/views/Setup/index.tsx | 1 - src/domain/MessageList.ts | 2 -- src/domain/Room.ts | 24 ++++++---------------- 5 files changed, 8 insertions(+), 23 deletions(-) diff --git a/src/app/content/components/MessageItem.tsx b/src/app/content/components/MessageItem.tsx index 3b11d4d..ce92931 100644 --- a/src/app/content/components/MessageItem.tsx +++ b/src/app/content/components/MessageItem.tsx @@ -58,7 +58,7 @@ const MessageItem: FC = (props) => {
{props.data.username}
- +
diff --git a/src/app/content/views/Main/index.tsx b/src/app/content/views/Main/index.tsx index bfb6ada..f719116 100644 --- a/src/app/content/views/Main/index.tsx +++ b/src/app/content/views/Main/index.tsx @@ -26,7 +26,7 @@ const Main: FC = () => { } return message }) - .toSorted((a, b) => a.worldTime - b.worldTime) + .toSorted((a, b) => a.sendTime - b.sendTime) const handleLikeChange = (messageId: string) => { send(roomDomain.command.SendLikeMessageCommand(messageId)) diff --git a/src/app/content/views/Setup/index.tsx b/src/app/content/views/Setup/index.tsx index 45a4c43..e738b95 100644 --- a/src/app/content/views/Setup/index.tsx +++ b/src/app/content/views/Setup/index.tsx @@ -53,7 +53,6 @@ const generateMessage = async (userInfo: UserInfo): Promise => { body: mockTextList.shift()!, sendTime: Date.now(), receiveTime: Date.now(), - worldTime: Date.now(), type: MessageType.Normal, userId, username, diff --git a/src/domain/MessageList.ts b/src/domain/MessageList.ts index ef5309f..d97257b 100644 --- a/src/domain/MessageList.ts +++ b/src/domain/MessageList.ts @@ -26,7 +26,6 @@ export interface NormalMessage extends MessageUser { body: string sendTime: number receiveTime: number - worldTime: number likeUsers: MessageUser[] hateUsers: MessageUser[] atUsers: AtUser[] @@ -38,7 +37,6 @@ export interface PromptMessage extends MessageUser { body: string sendTime: number receiveTime: number - worldTime: number } export type Message = NormalMessage | PromptMessage diff --git a/src/domain/Room.ts b/src/domain/Room.ts index eb67834..6a57d53 100644 --- a/src/domain/Room.ts +++ b/src/domain/Room.ts @@ -26,14 +26,12 @@ export interface SyncUserMessage extends MessageUser { peerId: string joinTime: number sendTime: number - worldTime: number lastMessageTime: number } export interface SyncHistoryMessage extends MessageUser { type: SendType.SyncHistory sendTime: number - worldTime: number id: string messages: NormalMessage[] } @@ -41,14 +39,12 @@ export interface SyncHistoryMessage extends MessageUser { export interface LikeMessage extends MessageUser { type: SendType.Like sendTime: number - worldTime: number id: string } export interface HateMessage extends MessageUser { type: SendType.Hate sendTime: number - worldTime: number id: string } @@ -57,7 +53,6 @@ export interface TextMessage extends MessageUser { id: string body: string sendTime: number - worldTime: number atUsers: AtUser[] } @@ -114,7 +109,7 @@ const RoomDomain = Remesh.domain({ return ( get(messageListDomain.query.ListQuery()) .filter((message) => message.type === MessageType.Normal) - .toSorted((a, b) => b.worldTime - a.worldTime)[0]?.worldTime ?? new Date(1970, 1, 1).getTime() + .toSorted((a, b) => b.sendTime - a.sendTime)[0]?.sendTime ?? new Date(1970, 1, 1).getTime() ) } }) @@ -140,8 +135,7 @@ const RoomDomain = Remesh.domain({ body: `"${username}" joined the chat`, type: MessageType.Prompt, sendTime: Date.now(), - receiveTime: Date.now(), - worldTime: Date.now() + receiveTime: Date.now() }), JoinStatusModule.command.SetFinishedCommand(), JoinRoomEvent(peerRoom.roomId) @@ -163,8 +157,7 @@ const RoomDomain = Remesh.domain({ body: `"${username}" left the chat`, type: MessageType.Prompt, sendTime: Date.now(), - receiveTime: Date.now(), - worldTime: Date.now() + receiveTime: Date.now() }), UpdateUserListCommand({ type: 'delete', @@ -186,7 +179,6 @@ const RoomDomain = Remesh.domain({ id: nanoid(), type: SendType.Text, sendTime: Date.now(), - worldTime: Date.now(), body: typeof message === 'string' ? message : message.body, atUsers: typeof message === 'string' ? [] : message.atUsers } @@ -215,7 +207,6 @@ const RoomDomain = Remesh.domain({ ...self, id: messageId, sendTime: Date.now(), - worldTime: Date.now(), type: SendType.Like } const listMessage: NormalMessage = { @@ -237,7 +228,6 @@ const RoomDomain = Remesh.domain({ ...self, id: messageId, sendTime: Date.now(), - worldTime: Date.now(), type: SendType.Hate } const listMessage: NormalMessage = { @@ -259,7 +249,6 @@ const RoomDomain = Remesh.domain({ ...self, id: nanoid(), sendTime: Date.now(), - worldTime: Date.now(), lastMessageTime, type: SendType.SyncUser } @@ -297,8 +286,8 @@ const RoomDomain = Remesh.domain({ const historyMessages = get(messageListDomain.query.ListQuery()).filter( (message) => message.type === MessageType.Normal && - message.worldTime > lastMessageTime && - message.worldTime - Date.now() <= SYNC_HISTORY_MAX_DAYS * 24 * 60 * 60 * 1000 + message.sendTime > lastMessageTime && + message.sendTime - Date.now() <= SYNC_HISTORY_MAX_DAYS * 24 * 60 * 60 * 1000 ) /** @@ -310,7 +299,6 @@ const RoomDomain = Remesh.domain({ ...self, id: nanoid(), sendTime: Date.now(), - worldTime: Date.now(), type: SendType.SyncHistory, messages: [cur as NormalMessage] } @@ -487,6 +475,7 @@ const RoomDomain = Remesh.domain({ return of( messageListDomain.command.UpdateItemCommand({ ..._message, + receiveTime: Date.now(), [type]: desert( _message[type], { @@ -529,7 +518,6 @@ const RoomDomain = Remesh.domain({ body: `"${user.username}" left the chat`, type: MessageType.Prompt, sendTime: Date.now(), - worldTime: Date.now(), receiveTime: Date.now() }), OnLeaveRoomEvent(peerId)