fix: message may not exist
This commit is contained in:
parent
bb9eccd31c
commit
59af3db87e
3 changed files with 10 additions and 2 deletions
|
@ -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
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue