Moved message.ContentType base checks to a switch
This commit is contained in:
parent
8089468e83
commit
154a169ffb
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue