Don't clobber sort order

This commit is contained in:
Jack Kingsman
2026-04-02 18:40:25 -07:00
parent af40cc3c8e
commit 1e7dc6af46
3 changed files with 11 additions and 2 deletions

View File

@@ -508,6 +508,7 @@ export function App() {
health,
favorites,
messages: sortedMessages,
preSorted: activeContactIsRoom,
messagesLoading,
loadingOlder,
hasOlderMessages,

View File

@@ -44,6 +44,7 @@ interface ConversationPaneProps {
notificationsPermission: NotificationPermission | 'unsupported';
favorites: Favorite[];
messages: Message[];
preSorted?: boolean;
messagesLoading: boolean;
loadingOlder: boolean;
hasOlderMessages: boolean;
@@ -114,6 +115,7 @@ export function ConversationPane({
notificationsPermission,
favorites,
messages,
preSorted,
messagesLoading,
loadingOlder,
hasOlderMessages,
@@ -275,6 +277,7 @@ export function ConversationPane({
<MessageList
key={activeConversation.id}
messages={messages}
preSorted={preSorted}
contacts={contacts}
channels={channels}
loading={messagesLoading}

View File

@@ -47,6 +47,7 @@ interface MessageListProps {
loadingNewer?: boolean;
onLoadNewer?: () => void;
onJumpToBottom?: () => void;
preSorted?: boolean;
}
// URL regex for linkifying plain text
@@ -283,6 +284,7 @@ export function MessageList({
loadingNewer = false,
onLoadNewer,
onJumpToBottom,
preSorted = false,
}: MessageListProps) {
const listRef = useRef<HTMLDivElement>(null);
const prevMessagesLengthRef = useRef<number>(0);
@@ -486,8 +488,11 @@ export function MessageList({
// Note: Deduplication is handled by useConversationMessages.observeMessage()
// and the database UNIQUE constraint on (type, conversation_key, text, sender_timestamp)
const sortedMessages = useMemo(
() => [...messages].sort((a, b) => a.received_at - b.received_at || a.id - b.id),
[messages]
() =>
preSorted
? messages
: [...messages].sort((a, b) => a.received_at - b.received_at || a.id - b.id),
[messages, preSorted]
);
const unreadMarkerIndex = useMemo(() => {
if (unreadMarkerLastReadAt === undefined) {