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