Moved message.ContentType base checks to a switch

This commit is contained in:
Samuel Hawksby-Robinson 2020-07-10 14:00:58 +01:00 committed by Andrea Maria Piana
parent 8089468e83
commit 154a169ffb
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
1 changed files with 9 additions and 12 deletions

View File

@ -167,19 +167,18 @@ func ValidateReceivedChatMessage(message *protobuf.ChatMessage, whisperTimestamp
return errors.New("chatId can't be empty")
}
if message.ContentType == protobuf.ChatMessage_UNKNOWN_CONTENT_TYPE {
return errors.New("unknown content type")
}
if message.ContentType == protobuf.ChatMessage_TRANSACTION_COMMAND {
return errors.New("can't receive request address for transaction from others")
}
if message.MessageType == protobuf.ChatMessage_UNKNOWN_MESSAGE_TYPE || message.MessageType == protobuf.ChatMessage_SYSTEM_MESSAGE_PRIVATE_GROUP {
return errors.New("unknown message type")
}
if message.ContentType == protobuf.ChatMessage_STICKER {
switch message.ContentType {
case protobuf.ChatMessage_UNKNOWN_CONTENT_TYPE:
return errors.New("unknown content type")
case protobuf.ChatMessage_TRANSACTION_COMMAND:
return errors.New("can't receive request address for transaction from others")
case protobuf.ChatMessage_STICKER:
if message.Payload == nil {
return errors.New("no sticker content")
}
@ -190,9 +189,8 @@ func ValidateReceivedChatMessage(message *protobuf.ChatMessage, whisperTimestamp
if len(sticker.Hash) == 0 {
return errors.New("sticker hash not set")
}
}
if message.ContentType == protobuf.ChatMessage_IMAGE {
case protobuf.ChatMessage_IMAGE:
if message.Payload == nil {
return errors.New("no image content")
}
@ -203,7 +201,6 @@ func ValidateReceivedChatMessage(message *protobuf.ChatMessage, whisperTimestamp
if len(image.Payload) == 0 {
return errors.New("image payload empty")
}
if image.Type == protobuf.ImageMessage_UNKNOWN_IMAGE_TYPE {
return errors.New("image type unknown")
}