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 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
|
||||||
},
|
},
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue