diff --git a/protocol/messenger_edit_message_test.go b/protocol/messenger_edit_message_test.go index e670329a7..40778482b 100644 --- a/protocol/messenger_edit_message_test.go +++ b/protocol/messenger_edit_message_test.go @@ -90,6 +90,88 @@ func (s *MessengerEditMessageSuite) TestEditMessage() { s.Require().Equal(ErrInvalidEditOrDeleteAuthor, err) } +func (s *MessengerEditMessageSuite) TestEditImageMessage() { + theirMessenger := s.newMessenger() + defer TearDownMessenger(&s.Suite, theirMessenger) + + theirChat := CreateOneToOneChat("Their 1TO1", &s.privateKey.PublicKey, s.m.transport) + err := theirMessenger.SaveChat(theirChat) + s.Require().NoError(err) + + ourChat := CreateOneToOneChat("Our 1TO1", &theirMessenger.identity.PublicKey, s.m.transport) + err = s.m.SaveChat(ourChat) + s.Require().NoError(err) + + const messageCount = 1 + var album []*common.Message + + for i := 0; i < messageCount; i++ { + image, err := buildImageWithoutAlbumIDMessage(*ourChat) + s.NoError(err) + image.Text = "my message" + album = append(album, image) + } + + sendResponse, err := s.m.SendChatMessages(context.Background(), album) + s.NoError(err) + s.Require().Len(sendResponse.Messages(), messageCount) + + ogMessage := sendResponse.Messages()[0] + + response, err := WaitOnMessengerResponse( + theirMessenger, + func(r *MessengerResponse) bool { + if len(r.messages) == 0 { + return false + } + _, ok := r.messages[ogMessage.ID] + return ok + }, + "no messages", + ) + s.Require().NoError(err) + s.Require().Len(response.Chats(), 1) + s.Require().Len(response.Messages(), 1) + + messageID, err := types.DecodeHex(ogMessage.ID) + s.Require().NoError(err) + + editedText := "edited text" + editedMessage := &requests.EditMessage{ + ID: messageID, + Text: editedText, + } + + sendResponse, err = s.m.EditMessage(context.Background(), editedMessage) + + s.Require().NoError(err) + s.Require().Len(sendResponse.Messages(), 1) + s.Require().Equal(editedText, sendResponse.Messages()[0].Text) + s.Require().Equal(protobuf.ChatMessage_IMAGE, sendResponse.Messages()[0].ContentType) + + response, err = WaitOnMessengerResponse( + theirMessenger, + func(r *MessengerResponse) bool { + if len(r.messages) == 0 { + return false + } + _, ok := r.messages[sendResponse.Messages()[0].ID] + return ok + }, + "no messages", + ) + s.Require().NoError(err) + s.Require().Len(response.Messages(), 1) + s.Require().NotEmpty(response.Messages()[0].EditedAt) + s.Require().False(response.Messages()[0].New) + s.Require().Equal(protobuf.ChatMessage_IMAGE, response.Messages()[0].ContentType) + + // Check DB to make sure the message is still an image + dbMessage, err := s.m.persistence.MessageByID(ogMessage.ID) + s.Require().NoError(err) + s.Require().Equal(protobuf.ChatMessage_IMAGE, dbMessage.ContentType) +} + func (s *MessengerEditMessageSuite) TestEditBridgeMessage() { theirMessenger := s.newMessenger() defer TearDownMessenger(&s.Suite, theirMessenger) @@ -136,9 +218,8 @@ func (s *MessengerEditMessageSuite) TestEditBridgeMessage() { editedText := "edited text" editedMessage := &requests.EditMessage{ - ID: messageID, - Text: editedText, - ContentType: protobuf.ChatMessage_BRIDGE_MESSAGE, + ID: messageID, + Text: editedText, } sendResponse, err = theirMessenger.EditMessage(context.Background(), editedMessage) diff --git a/protocol/messenger_messages.go b/protocol/messenger_messages.go index e9ff7590a..b723218a7 100644 --- a/protocol/messenger_messages.go +++ b/protocol/messenger_messages.go @@ -70,7 +70,7 @@ func (m *Messenger) EditMessage(ctx context.Context, request *requests.EditMessa replacedText = request.Text } editMessage.Text = replacedText - editMessage.ContentType = request.ContentType + editMessage.ContentType = message.ContentType // The contentType cannot change editMessage.ChatId = message.ChatId editMessage.MessageId = message.ID editMessage.Clock = clock diff --git a/protocol/requests/edit_message.go b/protocol/requests/edit_message.go index 60c88f21a..76ac140b3 100644 --- a/protocol/requests/edit_message.go +++ b/protocol/requests/edit_message.go @@ -5,18 +5,16 @@ import ( "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/protocol/common" - "github.com/status-im/status-go/protocol/protobuf" ) var ErrEditMessageInvalidID = errors.New("edit-message: invalid id") var ErrEditMessageInvalidText = errors.New("edit-message: invalid text") type EditMessage struct { - ID types.HexBytes `json:"id"` - Text string `json:"text"` - ContentType protobuf.ChatMessage_ContentType `json:"content-type"` - LinkPreviews []common.LinkPreview `json:"linkPreviews"` - StatusLinkPreviews []common.StatusLinkPreview `json:"statusLinkPreviews"` + ID types.HexBytes `json:"id"` + Text string `json:"text"` + LinkPreviews []common.LinkPreview `json:"linkPreviews"` + StatusLinkPreviews []common.StatusLinkPreview `json:"statusLinkPreviews"` } func (e *EditMessage) Validate() error {