fix: message may not exist

This commit is contained in:
molvqingtai 2024-09-17 02:48:03 +08:00
parent bb9eccd31c
commit 59af3db87e
3 changed files with 10 additions and 2 deletions

View file

@ -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
},

View file

@ -155,7 +155,6 @@ const RoomDomain = Remesh.domain({
const onMessage$ = callbackToObservable<RoomMessage>(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,

View file

@ -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