mirror of
https://github.com/status-im/wakuconnect-chat-sdk.git
synced 2025-01-11 20:54:37 +00:00
add basic validateMessage function
This commit is contained in:
parent
24614aaca0
commit
e976c5bc1f
29
packages/status-js/src/utils/validate-message.ts
Normal file
29
packages/status-js/src/utils/validate-message.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import type { ChatMessage } from '~/protos/chat-message'
|
||||
|
||||
// TODO?: maybe this should normalize the message?
|
||||
export function validateMessage(message: ChatMessage): boolean {
|
||||
if (message.messageType !== 'COMMUNITY_CHAT') {
|
||||
return false
|
||||
}
|
||||
|
||||
switch (message.contentType) {
|
||||
case 'TEXT_PLAIN': {
|
||||
return message.text !== ''
|
||||
}
|
||||
case 'IMAGE': {
|
||||
if (message.image.type === 'UNKNOWN_IMAGE_TYPE') {
|
||||
return false
|
||||
}
|
||||
|
||||
return message.image.payload.length !== 0
|
||||
}
|
||||
case 'AUDIO': {
|
||||
if (message.audio.type === 'UNKNOWN_AUDIO_TYPE') {
|
||||
return false
|
||||
}
|
||||
return message.audio.payload.length !== 0
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user