Files
colanode/packages/ui/src/components/messages/message.tsx

84 lines
2.8 KiB
TypeScript
Raw Normal View History

2024-12-02 00:44:02 +01:00
import { InView } from 'react-intersection-observer';
Web version (#43) * Create client package * Create the UI package * Init web app * Use isomorphic 'ws' for web sockets * File and asset implementations * Use Opfs SAH version of sqlite in browser * Generate Svg sprites for emojis and icons * Include emojis sprite * Improve and refactor assets * More assets improvements * Implement emoji and icons db import as readonly * Improve import paths * Handle concurrency limits for sqlite * Fix event broadcast in web * Pass windowId for subscribe and unsubscribe queries in desktop * Remove asset context * Implement avatar upload/download with the new structure * Improve file handlings * Move the necessary dependencies to client and ui packages * Update packages * Improve open file dialog * Make sure database files are deleted in browser * Improve avatar loading * Improve file loading * Fix some assets * Implement asset caching for offline access * Small fixes and improvements * Use server instead of pre signed urls for file upload/download * Cleanup some client related metadata * Switch Axios with ky * Refactor mutation results * Minor concurrency fix * Refactor web sockets * Improve file uploading * Handle connection close on server * Use stream for downloading the file * Add config options for cors * Update document in all tabs on local change * Include necessary icons for web * Update docker compose * Implement server upgrade required component * Use correct client type and platform in web and desktop * Improve service worker * Improve versioning * Fix an import * Minor fixes * Update some user endpoints * Minor endpoint changes * Enable app badge for desktop * Add error handling in some database operations * Update mutation naming convention * Update query naming convention * Update event and some metadata naming conventions * Update event and job naming conventions in server * Update Github workflow files * Restructure assets directory * Update packages * Upgrade to Zod v4 * Upgrade to react 19 * Upgrade to tailwind v4 * Minor ui improvements * Fix some cursor pointers * Add browser not supported message in web * Enhance server create flow, allow insecure connections and custom api paths * Execute electron-rebuild as postinstall command * Update docker compose
2025-06-11 00:14:17 +02:00
import { LocalMessageNode } from '@colanode/client/types';
import { MessageActions } from '@colanode/ui/components/messages/message-actions';
import { MessageAuthorAvatar } from '@colanode/ui/components/messages/message-author-avatar';
import { MessageAuthorName } from '@colanode/ui/components/messages/message-author-name';
import { MessageContent } from '@colanode/ui/components/messages/message-content';
import { MessageReactionCounts } from '@colanode/ui/components/messages/message-reaction-counts';
import { MessageReference } from '@colanode/ui/components/messages/message-reference';
import { MessageTime } from '@colanode/ui/components/messages/message-time';
import { useRadar } from '@colanode/ui/contexts/radar';
import { useWorkspace } from '@colanode/ui/contexts/workspace';
2024-08-03 19:14:38 +02:00
interface MessageProps {
message: LocalMessageNode;
previousMessage?: LocalMessageNode | null;
2024-08-03 19:14:38 +02:00
}
const shouldDisplayAuthor = (
message: LocalMessageNode,
previousMessage?: LocalMessageNode | null
2024-09-15 16:29:47 +02:00
) => {
if (!previousMessage) {
return true;
}
2024-09-15 16:29:47 +02:00
const previousMessageDate = new Date(previousMessage.createdAt);
const currentMessageDate = new Date(message.createdAt);
2024-09-15 16:29:47 +02:00
if (previousMessageDate.getDate() !== currentMessageDate.getDate()) {
return true;
}
return previousMessage.createdBy !== message.createdBy;
2024-09-15 16:29:47 +02:00
};
2024-08-03 19:14:38 +02:00
export const Message = ({ message, previousMessage }: MessageProps) => {
const workspace = useWorkspace();
const radar = useRadar();
const displayAuthor = shouldDisplayAuthor(message, previousMessage);
2024-09-15 16:29:47 +02:00
2024-08-27 15:20:16 +02:00
return (
<div
id={`message-${message.id}`}
key={`message-${message.id}`}
className={`group flex flex-row px-1 rounded-sm hover:bg-accent ${
displayAuthor ? 'mt-2 first:mt-0' : ''
2024-08-27 15:20:16 +02:00
}`}
>
<div className="mr-2 w-10 pt-1">
2024-11-22 13:40:58 +01:00
{displayAuthor && <MessageAuthorAvatar message={message} />}
2024-08-27 15:20:16 +02:00
</div>
2024-08-03 19:14:38 +02:00
2024-08-27 15:20:16 +02:00
<div className="relative w-full">
2024-11-22 13:40:58 +01:00
{displayAuthor && (
<div className="flex flex-row items-center gap-0.5">
<MessageAuthorName message={message} />
<MessageTime message={message} />
</div>
)}
2024-08-27 15:20:16 +02:00
<InView
rootMargin="50px"
onChange={(inView) => {
2024-10-28 20:35:30 +01:00
if (inView) {
radar.markNodeAsSeen(
workspace.accountId,
workspace.id,
message.id
);
2024-10-28 20:35:30 +01:00
}
2024-08-27 15:20:16 +02:00
}}
>
2024-11-18 13:16:22 +01:00
<MessageActions message={message} />
2025-01-09 11:13:22 +01:00
{message.attributes.referenceId && (
<MessageReference messageId={message.attributes.referenceId} />
)}
<MessageContent message={message} />
<MessageReactionCounts message={message} />
2024-08-27 15:20:16 +02:00
</InView>
2024-08-03 19:14:38 +02:00
</div>
2024-08-27 15:20:16 +02:00
</div>
);
};