fix_: add method to retrieve prepared message (#5102)
* Add Test_WHEN_MessageContainsImage_THEN_PreparedMessageByIDContainsLink * Add Messenger.PreparedMessageByID call fixes #13684
This commit is contained in:
parent
b5f8f792d5
commit
2fb6d615fd
|
@ -4197,7 +4197,17 @@ func (m *Messenger) storeSyncBookmarks(bookmarkMap map[string]*browsers.Bookmark
|
|||
}
|
||||
|
||||
func (m *Messenger) MessageByID(id string) (*common.Message, error) {
|
||||
return m.persistence.MessageByID(id)
|
||||
msg, err := m.persistence.MessageByID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if m.httpServer != nil {
|
||||
err = m.prepareMessage(msg, m.httpServer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
func (m *Messenger) MessagesExist(ids []string) (map[string]bool, error) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package protocol
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
@ -198,3 +199,30 @@ func (s *TestMessengerPrepareMessageSuite) Test_WHEN_QuotedMessageDoesNotContain
|
|||
|
||||
s.Require().Equal(json.RawMessage(nil), retrievedMessages[0].QuotedMessage.AlbumImages)
|
||||
}
|
||||
|
||||
func (s *TestMessengerPrepareMessageSuite) Test_WHEN_MessageContainsImage_THEN_PreparedMessageByIDContainsLink() {
|
||||
// GIVEN: message with image saved to DB
|
||||
message := s.generateTextMessage("id-1", "1", 1, "")
|
||||
message.ContentType = protobuf.ChatMessage_IMAGE
|
||||
message.Payload = &protobuf.ChatMessage_Image{
|
||||
Image: &protobuf.ImageMessage{
|
||||
Format: 1,
|
||||
Payload: RandomBytes(100),
|
||||
},
|
||||
}
|
||||
|
||||
err := s.m.SaveMessages([]*common.Message{message})
|
||||
s.Require().NoError(err)
|
||||
|
||||
mediaServer, err := server.NewMediaServer(s.m.database, nil, nil, nil)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(mediaServer.Start())
|
||||
s.m.httpServer = mediaServer
|
||||
|
||||
// WHEN: message is prepared
|
||||
loadedMessage, err := s.m.MessageByID(message.ID)
|
||||
s.Require().NoError(err)
|
||||
|
||||
// THEN: message contains image link
|
||||
s.Require().True(strings.HasPrefix(loadedMessage.ImageLocalURL, "https://Localhost"))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue