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 ItemQuery = MessageListModule.query.ItemQuery
const HasItemQuery = MessageListModule.query.HasItemByKeyQuery
const ChangeListEvent = domain.event({ const ChangeListEvent = domain.event({
name: 'MessageList.ChangeListEvent', name: 'MessageList.ChangeListEvent',
impl: ({ get }) => { impl: ({ get }) => {
@ -128,6 +130,7 @@ const MessageListDomain = Remesh.domain({
return { return {
query: { query: {
HasItemQuery,
ItemQuery, ItemQuery,
ListQuery ListQuery
}, },

View file

@ -155,7 +155,6 @@ const RoomDomain = Remesh.domain({
const onMessage$ = callbackToObservable<RoomMessage>(peerRoom.onMessage.bind(peerRoom)) const onMessage$ = callbackToObservable<RoomMessage>(peerRoom.onMessage.bind(peerRoom))
return onMessage$.pipe( return onMessage$.pipe(
map((message) => { map((message) => {
console.log(message)
switch (message.type) { switch (message.type) {
case 'text': case 'text':
return messageListDomain.command.CreateItemCommand({ return messageListDomain.command.CreateItemCommand({
@ -165,6 +164,9 @@ const RoomDomain = Remesh.domain({
hateUsers: [] hateUsers: []
}) })
case 'like': { case 'like': {
if (!messageListDomain.query.HasItemQuery(message.id)) {
return null
}
const _message = get(messageListDomain.query.ItemQuery(message.id)) const _message = get(messageListDomain.query.ItemQuery(message.id))
return messageListDomain.command.UpdateItemCommand({ return messageListDomain.command.UpdateItemCommand({
..._message, ..._message,
@ -176,6 +178,9 @@ const RoomDomain = Remesh.domain({
}) })
} }
case 'hate': { case 'hate': {
if (!messageListDomain.query.HasItemQuery(message.id)) {
return null
}
const _message = get(messageListDomain.query.ItemQuery(message.id)) const _message = get(messageListDomain.query.ItemQuery(message.id))
return messageListDomain.command.UpdateItemCommand({ return messageListDomain.command.UpdateItemCommand({
..._message, ..._message,

View file

@ -20,7 +20,7 @@ class PeerRoom {
this.room = joinRoom({ appId: this.appId }, roomId) this.room = joinRoom({ appId: this.appId }, roomId)
this.room?.onPeerJoin((peerId) => console.log(`${peerId} joined`)) 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()) console.log(this.room.getPeers())
return this.room return this.room