Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Subscribe to changes in use conversation hook

Hakan Shehu2ae6f89ade2d
diff --git a/desktop/src/components/messages/message.tsx b/desktop/src/components/messages/message.tsx
index 26fafa16..a5f4db47 100644
--- a/desktop/src/components/messages/message.tsx
+++ b/desktop/src/components/messages/message.tsx
@@ -55,6 +55,10 @@ export const Message = observer(
const canReplyInThread = true;
const nodeWithChildren = buildNodeWithChildren(message, nodes);
+ if (!nodeWithChildren.children || nodeWithChildren.children.length === 0) {
+ return null;
+ }
+
return (
<div
id={`message-${message.id}`}
diff --git a/desktop/src/hooks/use-conversation.tsx b/desktop/src/hooks/use-conversation.tsx
index f4ce24d6..23c3eb3c 100644
--- a/desktop/src/hooks/use-conversation.tsx
+++ b/desktop/src/hooks/use-conversation.tsx
@@ -39,7 +39,30 @@ export const useConversation = (
fetchNodes();
const subscriptionId = eventBus.subscribe((event) => {
- console.log('event', event);
+ if (event.event === 'node_created') {
+ const createdNode = event.payload as Node;
+ if (
+ store.getNode(createdNode.id) ||
+ createdNode.parentId === conversationId
+ ) {
+ store.setNode(createdNode);
+ } else {
+ const parent = store.getNode(createdNode.parentId);
+ if (parent) {
+ store.setNode(createdNode);
+ }
+ }
+ } else if (event.event === 'node_updated') {
+ const updatedNode = event.payload as Node;
+ if (store.getNode(updatedNode.id)) {
+ store.setNode(updatedNode);
+ }
+ } else if (event.event === 'node-deleted') {
+ const deletedNode = event.payload as Node;
+ if (store.getNode(deletedNode.id)) {
+ store.deleteNode(deletedNode.id);
+ }
+ }
});
return () => {
diff --git a/desktop/src/store/conversation.ts b/desktop/src/store/conversation.ts
index e50bd01b..f93c4898 100644
--- a/desktop/src/store/conversation.ts
+++ b/desktop/src/store/conversation.ts
@@ -26,6 +26,10 @@ export class ConversationStore {
});
}
+ public deleteNode(nodeId: string) {
+ delete this.nodes[nodeId];
+ }
+
public setIsLoading(isLoading: boolean) {
this.isLoading = isLoading;
}