Skip to content

Commit 841406d

Browse files
committed
Merge branch 'develop'
2 parents 61a8a96 + e42f344 commit 841406d

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/constants/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export const APP_STATUS_STORAGE_KEY = 'WEB_CHAT_APP_STATUS' as const
200200
*/
201201
export const MAX_AVATAR_SIZE = 5120 as const
202202

203-
export const SYNC_HISTORY_MAX_DAYS = 30 as const
203+
export const SYNC_HISTORY_MAX_DAYS = 90 as const
204204

205205
/**
206206
* https://lgrahl.de/articles/demystifying-webrtc-dc-size-limit.html

src/domain/ChatRoom.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,13 @@ const ChatRoomDomain = Remesh.domain({
358358
impl: ({ get }, { peerId, lastMessageTime }: { peerId: string; lastMessageTime: number }) => {
359359
const self = get(SelfUserQuery())
360360

361-
const historyMessages = get(messageListDomain.query.ListQuery()).filter(
362-
(message) =>
361+
const historyMessages = get(messageListDomain.query.ListQuery()).filter((message) => {
362+
return (
363363
message.type === MessageType.Normal &&
364364
message.sendTime > lastMessageTime &&
365-
message.sendTime - Date.now() <= SYNC_HISTORY_MAX_DAYS * 24 * 60 * 60 * 1000
366-
)
365+
message.sendTime >= Date.now() - SYNC_HISTORY_MAX_DAYS * 24 * 60 * 60 * 1000
366+
)
367+
})
367368

368369
/**
369370
* Message chunking to ensure that each message does not exceed WEB_RTC_MAX_MESSAGE_SIZE

src/hooks/useDraggable.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { clamp, isInRange } from '@/utils'
2-
import { useCallback, useLayoutEffect, useRef, useState } from 'react'
2+
import { startTransition, useCallback, useLayoutEffect, useRef, useState } from 'react'
33

44
export interface DargOptions {
55
initX: number
@@ -14,8 +14,8 @@ const useDraggable = (options: DargOptions) => {
1414
const { initX, initY, maxX = 0, minX = 0, maxY = 0, minY = 0 } = options
1515

1616
const mousePosition = useRef({ x: 0, y: 0 })
17-
18-
const [position, setPosition] = useState({ x: clamp(initX, minX, maxX), y: clamp(initY, minY, maxY) })
17+
const positionRef = useRef({ x: clamp(initX, minX, maxX), y: clamp(initY, minY, maxY) })
18+
const [position, setPosition] = useState(positionRef.current)
1919

2020
useLayoutEffect(() => {
2121
const newPosition = { x: clamp(initX, minX, maxX), y: clamp(initY, minY, maxY) }
@@ -30,12 +30,13 @@ const useDraggable = (options: DargOptions) => {
3030
(e: MouseEvent) => {
3131
if (isMove.current) {
3232
const { clientX, clientY } = e
33+
const prev = positionRef.current
3334
const delta = {
34-
x: position.x + clientX - mousePosition.current.x,
35-
y: position.y + clientY - mousePosition.current.y
35+
x: prev.x + clientX - mousePosition.current.x,
36+
y: prev.y + clientY - mousePosition.current.y
3637
}
3738

38-
const hasChanged = delta.x !== position.x || delta.y !== position.y
39+
const hasChanged = delta.x !== prev.x || delta.y !== prev.y
3940

4041
if (isInRange(delta.x, minX, maxX)) {
4142
mousePosition.current.x = clientX
@@ -44,15 +45,14 @@ const useDraggable = (options: DargOptions) => {
4445
mousePosition.current.y = clientY
4546
}
4647
if (hasChanged) {
47-
setPosition(() => {
48-
const x = clamp(delta.x, minX, maxX)
49-
const y = clamp(delta.y, minY, maxY)
50-
return { x, y }
51-
})
48+
const x = clamp(delta.x, minX, maxX)
49+
const y = clamp(delta.y, minY, maxY)
50+
positionRef.current = { x, y }
51+
setPosition({ x, y })
5252
}
5353
}
5454
},
55-
[minX, maxX, minY, maxY, position]
55+
[minX, maxX, minY, maxY]
5656
)
5757

5858
const handleEnd = useCallback(() => {

0 commit comments

Comments
 (0)