chore: delete world time

This commit is contained in:
molvqingtai 2024-11-03 08:52:21 +08:00
parent 7c4f65573c
commit 99aed36c00
5 changed files with 8 additions and 23 deletions

View file

@ -58,7 +58,7 @@ const MessageItem: FC<MessageItemProps> = (props) => {
<div className="overflow-hidden"> <div className="overflow-hidden">
<div className="grid grid-cols-[1fr_auto] items-center gap-x-2 leading-none"> <div className="grid grid-cols-[1fr_auto] items-center gap-x-2 leading-none">
<div className="truncate text-sm font-semibold text-slate-600 dark:text-slate-50">{props.data.username}</div> <div className="truncate text-sm font-semibold text-slate-600 dark:text-slate-50">{props.data.username}</div>
<FormatDate className="text-xs text-slate-400 dark:text-slate-100" date={props.data.receiveTime}></FormatDate> <FormatDate className="text-xs text-slate-400 dark:text-slate-100" date={props.data.sendTime}></FormatDate>
</div> </div>
<div> <div>
<div className="pb-2"> <div className="pb-2">

View file

@ -26,7 +26,7 @@ const Main: FC = () => {
} }
return message return message
}) })
.toSorted((a, b) => a.worldTime - b.worldTime) .toSorted((a, b) => a.sendTime - b.sendTime)
const handleLikeChange = (messageId: string) => { const handleLikeChange = (messageId: string) => {
send(roomDomain.command.SendLikeMessageCommand(messageId)) send(roomDomain.command.SendLikeMessageCommand(messageId))

View file

@ -53,7 +53,6 @@ const generateMessage = async (userInfo: UserInfo): Promise<Message> => {
body: mockTextList.shift()!, body: mockTextList.shift()!,
sendTime: Date.now(), sendTime: Date.now(),
receiveTime: Date.now(), receiveTime: Date.now(),
worldTime: Date.now(),
type: MessageType.Normal, type: MessageType.Normal,
userId, userId,
username, username,

View file

@ -26,7 +26,6 @@ export interface NormalMessage extends MessageUser {
body: string body: string
sendTime: number sendTime: number
receiveTime: number receiveTime: number
worldTime: number
likeUsers: MessageUser[] likeUsers: MessageUser[]
hateUsers: MessageUser[] hateUsers: MessageUser[]
atUsers: AtUser[] atUsers: AtUser[]
@ -38,7 +37,6 @@ export interface PromptMessage extends MessageUser {
body: string body: string
sendTime: number sendTime: number
receiveTime: number receiveTime: number
worldTime: number
} }
export type Message = NormalMessage | PromptMessage export type Message = NormalMessage | PromptMessage

View file

@ -26,14 +26,12 @@ export interface SyncUserMessage extends MessageUser {
peerId: string peerId: string
joinTime: number joinTime: number
sendTime: number sendTime: number
worldTime: number
lastMessageTime: number lastMessageTime: number
} }
export interface SyncHistoryMessage extends MessageUser { export interface SyncHistoryMessage extends MessageUser {
type: SendType.SyncHistory type: SendType.SyncHistory
sendTime: number sendTime: number
worldTime: number
id: string id: string
messages: NormalMessage[] messages: NormalMessage[]
} }
@ -41,14 +39,12 @@ export interface SyncHistoryMessage extends MessageUser {
export interface LikeMessage extends MessageUser { export interface LikeMessage extends MessageUser {
type: SendType.Like type: SendType.Like
sendTime: number sendTime: number
worldTime: number
id: string id: string
} }
export interface HateMessage extends MessageUser { export interface HateMessage extends MessageUser {
type: SendType.Hate type: SendType.Hate
sendTime: number sendTime: number
worldTime: number
id: string id: string
} }
@ -57,7 +53,6 @@ export interface TextMessage extends MessageUser {
id: string id: string
body: string body: string
sendTime: number sendTime: number
worldTime: number
atUsers: AtUser[] atUsers: AtUser[]
} }
@ -114,7 +109,7 @@ const RoomDomain = Remesh.domain({
return ( return (
get(messageListDomain.query.ListQuery()) get(messageListDomain.query.ListQuery())
.filter((message) => message.type === MessageType.Normal) .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`, body: `"${username}" joined the chat`,
type: MessageType.Prompt, type: MessageType.Prompt,
sendTime: Date.now(), sendTime: Date.now(),
receiveTime: Date.now(), receiveTime: Date.now()
worldTime: Date.now()
}), }),
JoinStatusModule.command.SetFinishedCommand(), JoinStatusModule.command.SetFinishedCommand(),
JoinRoomEvent(peerRoom.roomId) JoinRoomEvent(peerRoom.roomId)
@ -163,8 +157,7 @@ const RoomDomain = Remesh.domain({
body: `"${username}" left the chat`, body: `"${username}" left the chat`,
type: MessageType.Prompt, type: MessageType.Prompt,
sendTime: Date.now(), sendTime: Date.now(),
receiveTime: Date.now(), receiveTime: Date.now()
worldTime: Date.now()
}), }),
UpdateUserListCommand({ UpdateUserListCommand({
type: 'delete', type: 'delete',
@ -186,7 +179,6 @@ const RoomDomain = Remesh.domain({
id: nanoid(), id: nanoid(),
type: SendType.Text, type: SendType.Text,
sendTime: Date.now(), sendTime: Date.now(),
worldTime: Date.now(),
body: typeof message === 'string' ? message : message.body, body: typeof message === 'string' ? message : message.body,
atUsers: typeof message === 'string' ? [] : message.atUsers atUsers: typeof message === 'string' ? [] : message.atUsers
} }
@ -215,7 +207,6 @@ const RoomDomain = Remesh.domain({
...self, ...self,
id: messageId, id: messageId,
sendTime: Date.now(), sendTime: Date.now(),
worldTime: Date.now(),
type: SendType.Like type: SendType.Like
} }
const listMessage: NormalMessage = { const listMessage: NormalMessage = {
@ -237,7 +228,6 @@ const RoomDomain = Remesh.domain({
...self, ...self,
id: messageId, id: messageId,
sendTime: Date.now(), sendTime: Date.now(),
worldTime: Date.now(),
type: SendType.Hate type: SendType.Hate
} }
const listMessage: NormalMessage = { const listMessage: NormalMessage = {
@ -259,7 +249,6 @@ const RoomDomain = Remesh.domain({
...self, ...self,
id: nanoid(), id: nanoid(),
sendTime: Date.now(), sendTime: Date.now(),
worldTime: Date.now(),
lastMessageTime, lastMessageTime,
type: SendType.SyncUser type: SendType.SyncUser
} }
@ -297,8 +286,8 @@ const RoomDomain = Remesh.domain({
const historyMessages = get(messageListDomain.query.ListQuery()).filter( const historyMessages = get(messageListDomain.query.ListQuery()).filter(
(message) => (message) =>
message.type === MessageType.Normal && message.type === MessageType.Normal &&
message.worldTime > lastMessageTime && message.sendTime > lastMessageTime &&
message.worldTime - Date.now() <= SYNC_HISTORY_MAX_DAYS * 24 * 60 * 60 * 1000 message.sendTime - Date.now() <= SYNC_HISTORY_MAX_DAYS * 24 * 60 * 60 * 1000
) )
/** /**
@ -310,7 +299,6 @@ const RoomDomain = Remesh.domain({
...self, ...self,
id: nanoid(), id: nanoid(),
sendTime: Date.now(), sendTime: Date.now(),
worldTime: Date.now(),
type: SendType.SyncHistory, type: SendType.SyncHistory,
messages: [cur as NormalMessage] messages: [cur as NormalMessage]
} }
@ -487,6 +475,7 @@ const RoomDomain = Remesh.domain({
return of( return of(
messageListDomain.command.UpdateItemCommand({ messageListDomain.command.UpdateItemCommand({
..._message, ..._message,
receiveTime: Date.now(),
[type]: desert( [type]: desert(
_message[type], _message[type],
{ {
@ -529,7 +518,6 @@ const RoomDomain = Remesh.domain({
body: `"${user.username}" left the chat`, body: `"${user.username}" left the chat`,
type: MessageType.Prompt, type: MessageType.Prompt,
sendTime: Date.now(), sendTime: Date.now(),
worldTime: Date.now(),
receiveTime: Date.now() receiveTime: Date.now()
}), }),
OnLeaveRoomEvent(peerId) OnLeaveRoomEvent(peerId)