mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-04-06 01:25:38 +00:00
fix(webapp): fix error in chat when message is undefined or null (#9438)
This commit is contained in:
parent
b629307f4e
commit
779841a711
@ -365,6 +365,7 @@ export default {
|
|||||||
const msgs = []
|
const msgs = []
|
||||||
;[...this.messages, ...Message].forEach((m) => {
|
;[...this.messages, ...Message].forEach((m) => {
|
||||||
if (m.senderId !== this.currentUser.id) m.seen = true
|
if (m.senderId !== this.currentUser.id) m.seen = true
|
||||||
|
m.content = m.content || ''
|
||||||
m.date = new Date(m.date).toDateString()
|
m.date = new Date(m.date).toDateString()
|
||||||
m.avatar = m.avatar?.w320
|
m.avatar = m.avatar?.w320
|
||||||
msgs[m.indexId] = m
|
msgs[m.indexId] = m
|
||||||
@ -385,7 +386,9 @@ export default {
|
|||||||
const roomIndex = this.rooms.findIndex((r) => r.id === data.chatMessageAdded.room.id)
|
const roomIndex = this.rooms.findIndex((r) => r.id === data.chatMessageAdded.room.id)
|
||||||
const changedRoom = { ...this.rooms[roomIndex] }
|
const changedRoom = { ...this.rooms[roomIndex] }
|
||||||
changedRoom.lastMessage = data.chatMessageAdded
|
changedRoom.lastMessage = data.chatMessageAdded
|
||||||
changedRoom.lastMessage.content = changedRoom.lastMessage.content.trim().substring(0, 30)
|
changedRoom.lastMessage.content = (changedRoom.lastMessage.content || '')
|
||||||
|
.trim()
|
||||||
|
.substring(0, 30)
|
||||||
changedRoom.lastMessageAt = data.chatMessageAdded.date
|
changedRoom.lastMessageAt = data.chatMessageAdded.date
|
||||||
// Move changed room to the top of the list
|
// Move changed room to the top of the list
|
||||||
changedRoom.index = data.chatMessageAdded.date
|
changedRoom.index = data.chatMessageAdded.date
|
||||||
@ -445,7 +448,7 @@ export default {
|
|||||||
const roomIndex = this.rooms.findIndex((r) => r.id === roomId)
|
const roomIndex = this.rooms.findIndex((r) => r.id === roomId)
|
||||||
if (roomIndex !== -1) {
|
if (roomIndex !== -1) {
|
||||||
const changedRoom = { ...this.rooms[roomIndex] }
|
const changedRoom = { ...this.rooms[roomIndex] }
|
||||||
changedRoom.lastMessage.content = content
|
changedRoom.lastMessage.content = (content || '').trim().substring(0, 30)
|
||||||
|
|
||||||
// Move changed room to the top of the list
|
// Move changed room to the top of the list
|
||||||
changedRoom.index = changedRoom.lastMessage.date
|
changedRoom.index = changedRoom.lastMessage.date
|
||||||
@ -461,7 +464,9 @@ export default {
|
|||||||
|
|
||||||
if (createdMessagePayload && roomIndex !== -1) {
|
if (createdMessagePayload && roomIndex !== -1) {
|
||||||
const changedRoom = { ...this.rooms[roomIndex] }
|
const changedRoom = { ...this.rooms[roomIndex] }
|
||||||
changedRoom.lastMessage.content = createdMessagePayload.content.trim().substring(0, 30)
|
changedRoom.lastMessage.content = (createdMessagePayload.content || '')
|
||||||
|
.trim()
|
||||||
|
.substring(0, 30)
|
||||||
changedRoom.lastMessage.date = createdMessagePayload.date
|
changedRoom.lastMessage.date = createdMessagePayload.date
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -492,9 +497,9 @@ export default {
|
|||||||
lastMessage: room.lastMessage
|
lastMessage: room.lastMessage
|
||||||
? {
|
? {
|
||||||
...room.lastMessage,
|
...room.lastMessage,
|
||||||
content: room.lastMessage?.content?.trim().substring(0, 30),
|
content: (room.lastMessage?.content || '').trim().substring(0, 30),
|
||||||
}
|
}
|
||||||
: {},
|
: { content: '' },
|
||||||
users: room.users.map((u) => {
|
users: room.users.map((u) => {
|
||||||
return { ...u, username: u.name, avatar: u.avatar?.w320 }
|
return { ...u, username: u.name, avatar: u.avatar?.w320 }
|
||||||
}),
|
}),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user