Validate edit

This commit is contained in:
Andrea Maria Piana 2021-06-25 12:20:40 +02:00
parent e68fad2788
commit c18d827d54
2 changed files with 21 additions and 0 deletions

View File

@ -39,6 +39,24 @@ func ValidateMembershipUpdateMessage(message *protocol.MembershipUpdateMessage,
return nil
}
func ValidateEditMessage(message protobuf.EditMessage) error {
if message.Clock == 0 {
return errors.New("clock can't be 0")
}
if len(message.ChatId) == 0 {
return errors.New("chat-id can't be empty")
}
if len(message.MessageId) == 0 {
return errors.New("message-id can't be empty")
}
if message.MessageType == protobuf.MessageType_UNKNOWN_MESSAGE_TYPE || message.MessageType == protobuf.MessageType_SYSTEM_MESSAGE_PRIVATE_GROUP {
return errors.New("unknown message type")
}
return ValidateText(message.Text)
}
func ValidateReceivedPairInstallation(message *protobuf.PairInstallation, whisperTimestamp uint64) error {
if err := validateClockValue(message.Clock, whisperTimestamp); err != nil {
return err

View File

@ -490,6 +490,9 @@ func (m *Messenger) handleWrappedCommunityDescriptionMessage(payload []byte) (*c
}
func (m *Messenger) HandleEditMessage(response *MessengerResponse, editMessage EditMessage) error {
if err := ValidateEditMessage(editMessage.EditMessage); err != nil {
return err
}
messageID := editMessage.MessageId
// Check if it's already in the response
originalMessage := response.GetMessage(messageID)