From 59af3db87e5ae4d9bae621f0020f90238ae7c7ff Mon Sep 17 00:00:00 2001 From: molvqingtai Date: Tue, 17 Sep 2024 02:48:03 +0800 Subject: [PATCH] fix: message may not exist --- src/domain/MessageList.ts | 3 +++ src/domain/Room.ts | 7 ++++++- src/domain/impls/PeerRoom.ts | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/domain/MessageList.ts b/src/domain/MessageList.ts index 839b65b..6791b27 100644 --- a/src/domain/MessageList.ts +++ b/src/domain/MessageList.ts @@ -37,6 +37,8 @@ const MessageListDomain = Remesh.domain({ const ItemQuery = MessageListModule.query.ItemQuery + const HasItemQuery = MessageListModule.query.HasItemByKeyQuery + const ChangeListEvent = domain.event({ name: 'MessageList.ChangeListEvent', impl: ({ get }) => { @@ -128,6 +130,7 @@ const MessageListDomain = Remesh.domain({ return { query: { + HasItemQuery, ItemQuery, ListQuery }, diff --git a/src/domain/Room.ts b/src/domain/Room.ts index 7a14db0..bd1abaa 100644 --- a/src/domain/Room.ts +++ b/src/domain/Room.ts @@ -155,7 +155,6 @@ const RoomDomain = Remesh.domain({ const onMessage$ = callbackToObservable(peerRoom.onMessage.bind(peerRoom)) return onMessage$.pipe( map((message) => { - console.log(message) switch (message.type) { case 'text': return messageListDomain.command.CreateItemCommand({ @@ -165,6 +164,9 @@ const RoomDomain = Remesh.domain({ hateUsers: [] }) case 'like': { + if (!messageListDomain.query.HasItemQuery(message.id)) { + return null + } const _message = get(messageListDomain.query.ItemQuery(message.id)) return messageListDomain.command.UpdateItemCommand({ ..._message, @@ -176,6 +178,9 @@ const RoomDomain = Remesh.domain({ }) } case 'hate': { + if (!messageListDomain.query.HasItemQuery(message.id)) { + return null + } const _message = get(messageListDomain.query.ItemQuery(message.id)) return messageListDomain.command.UpdateItemCommand({ ..._message, diff --git a/src/domain/impls/PeerRoom.ts b/src/domain/impls/PeerRoom.ts index 9806a79..8dc6f81 100644 --- a/src/domain/impls/PeerRoom.ts +++ b/src/domain/impls/PeerRoom.ts @@ -20,7 +20,7 @@ class PeerRoom { this.room = joinRoom({ appId: this.appId }, roomId) this.room?.onPeerJoin((peerId) => console.log(`${peerId} joined`)) - this.room?.onPeerLeave((peerId) => console.log(`${peerId} left`)) + this.room?.onPeerLeave((peerId) => console.log(`${peerId} leaved`)) console.log(this.room.getPeers()) return this.room