add basic validateMessage function

This commit is contained in:
Pavel Prichodko 2022-06-10 13:43:48 +02:00 committed by Felicio Mununga
parent 24614aaca0
commit e976c5bc1f
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
1 changed files with 29 additions and 0 deletions

View 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
}