This commit is contained in:
payacom
2026-07-16 20:08:49 +03:30
parent 39b12a0986
commit 58314d0ab5
40 changed files with 986 additions and 535 deletions

View File

@@ -1,5 +1,24 @@
import type { ChatMessage } from "@/components/chat/ChatMessageCard";
function matchesPendingServer(server: ChatMessage, pending: ChatMessage): boolean {
if (String(server.senderId) !== String(pending.senderId)) return false;
if (pending.fileType !== server.fileType) return false;
if (pending.fileType === "location" || (!pending.fileType && !pending.file)) {
return server.content === pending.content;
}
return Boolean(pending.fileType && server.fileType === pending.fileType);
}
export function filterResolvedPendingMessages(
server: ChatMessage[],
pending: ChatMessage[]
): ChatMessage[] {
return pending.filter(
(p) =>
!server.some((s) => s._id === p._id || matchesPendingServer(s, p))
);
}
export function dedupeChatMessages(messages: ChatMessage[]): ChatMessage[] {
const seen = new Set<string>();
const result: ChatMessage[] = [];

View File

@@ -8,8 +8,8 @@ export type MessageGroup =
| { type: "date"; label: string; key: string }
| { type: "message"; message: ChatMessage; key: string };
function dayKey(createdAt?: string | null): string {
const d = parseMessageDate(createdAt);
function dayKey(msg: ChatMessage): string {
const d = parseMessageDate(msg.createdAtIso ?? msg.createdAt);
if (d) return d.toDateString();
return "unknown-day";
}
@@ -21,12 +21,12 @@ export function groupMessagesByDate(messages: ChatMessage[]): MessageGroup[] {
messages.forEach((msg, i) => {
if (!msg) return;
const dk = dayKey(msg.createdAt);
const dk = dayKey(msg);
if (dk !== lastDay) {
lastDay = dk;
groups.push({
type: "date",
label: formatChatDateLabel(msg.createdAt),
label: formatChatDateLabel(msg.createdAtIso ?? msg.createdAt),
key: `date-${dk}`,
});
}

View File

@@ -3,8 +3,8 @@ import { parseMessageDate } from "@/lib/chat/formatMessageTime";
export type BubbleGroupPosition = "single" | "first" | "middle" | "last";
function dayKey(createdAt?: string | null): string {
const d = parseMessageDate(createdAt);
function dayKey(msg: ChatMessage): string {
const d = parseMessageDate(msg.createdAtIso ?? msg.createdAt);
if (d) return d.toDateString();
return "unknown-day";
}
@@ -14,7 +14,7 @@ export function sameSender(a: ChatMessage, b: ChatMessage): boolean {
}
function sameVisualGroup(a: ChatMessage, b: ChatMessage): boolean {
return sameSender(a, b) && dayKey(a.createdAt) === dayKey(b.createdAt);
return sameSender(a, b) && dayKey(a) === dayKey(b);
}
export { sameVisualGroup };