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="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>
<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 className="pb-2">

View file

@ -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))

View file

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

View file

@ -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

View file

@ -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)