fix(edit)_: make sure the contentType stays the same after an edit (#6133)
Fixes https://github.com/status-im/status-desktop/issues/16741 The issue was that in image messages, you can update the text, but then the ContentType would become Text and lose the image. The solution is to ignore ContentType changes, since there is no way to change the type of message.
This commit is contained in:
parent
78da423569
commit
92ba63b282
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue