This commit is contained in:
parent
1b6cebac22
commit
34127cd14f
|
@ -334,11 +334,12 @@ func (s *MessengerDeleteMessageSuite) TestDeleteImageMessageFirstThenMessage() {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
messageID1 := "message-id1"
|
messageID1 := "message-id1"
|
||||||
messageID2 := "message-id2"
|
messageID2 := "message-id2"
|
||||||
|
albumID := "album-id1"
|
||||||
|
|
||||||
messageCount := 2
|
messageCount := 2
|
||||||
var album []*common.Message
|
var album []*common.Message
|
||||||
for i := 0; i < messageCount; i++ {
|
for i := 0; i < messageCount; i++ {
|
||||||
image, err := buildImageWithoutAlbumIDMessage(*ourChat)
|
image, err := buildImageWithAlbumIDMessage(*ourChat, albumID)
|
||||||
image.Clock = 1
|
image.Clock = 1
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
album = append(album, image)
|
album = append(album, image)
|
||||||
|
|
|
@ -2685,17 +2685,20 @@ func (m *Messenger) getMessagesToCheckForDelete(message *common.Message) ([]*com
|
||||||
var messagesToCheck []*common.Message
|
var messagesToCheck []*common.Message
|
||||||
if message.ContentType == protobuf.ChatMessage_IMAGE {
|
if message.ContentType == protobuf.ChatMessage_IMAGE {
|
||||||
image := message.GetImage()
|
image := message.GetImage()
|
||||||
messagesInTheAlbum, err := m.persistence.albumMessages(message.ChatId, image.GetAlbumId())
|
if image != nil && image.AlbumId != "" {
|
||||||
if err != nil {
|
messagesInTheAlbum, err := m.persistence.albumMessages(message.ChatId, image.GetAlbumId())
|
||||||
return nil, err
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
messagesToCheck = append(messagesToCheck, messagesInTheAlbum...)
|
||||||
}
|
}
|
||||||
messagesToCheck = append(messagesToCheck, messagesInTheAlbum...)
|
|
||||||
}
|
}
|
||||||
messagesToCheck = append(messagesToCheck, message)
|
messagesToCheck = append(messagesToCheck, message)
|
||||||
return messagesToCheck, nil
|
return messagesToCheck, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) checkForDeletes(message *common.Message) error {
|
func (m *Messenger) checkForDeletes(message *common.Message) error {
|
||||||
|
// Get all messages part of the album
|
||||||
messagesToCheck, err := m.getMessagesToCheckForDelete(message)
|
messagesToCheck, err := m.getMessagesToCheckForDelete(message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -2703,25 +2706,28 @@ func (m *Messenger) checkForDeletes(message *common.Message) error {
|
||||||
|
|
||||||
var messageDeletes []*DeleteMessage
|
var messageDeletes []*DeleteMessage
|
||||||
applyDelete := false
|
applyDelete := false
|
||||||
|
// Loop all messages part of the album, if one of them is marked as deleted, we delete them all
|
||||||
for _, messageToCheck := range messagesToCheck {
|
for _, messageToCheck := range messagesToCheck {
|
||||||
if !applyDelete {
|
// Check for any pending deletes
|
||||||
// Check for any pending deletes
|
// If any pending deletes are available and valid, apply them
|
||||||
// If any pending deletes are available and valid, apply them
|
messageDeletes, err = m.persistence.GetDeletes(messageToCheck.ID, messageToCheck.From)
|
||||||
messageDeletes, err = m.persistence.GetDeletes(messageToCheck.ID, messageToCheck.From)
|
if err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if len(messageDeletes) == 0 {
|
if len(messageDeletes) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Once one messageDelete has been found, we apply it to all the images in the album
|
// Once one messageDelete has been found, we apply it to all the images in the album
|
||||||
applyDelete = true
|
applyDelete = true
|
||||||
|
break
|
||||||
err := m.applyDeleteMessage(messageDeletes, messageToCheck)
|
}
|
||||||
if err != nil {
|
if applyDelete {
|
||||||
return err
|
for _, messageToCheck := range messagesToCheck {
|
||||||
|
err := m.applyDeleteMessage(messageDeletes, messageToCheck)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -2324,7 +2324,7 @@ func (s *MessengerSuite) TestResendExpiredEmojis() {
|
||||||
s.True(rawMessage.SendCount >= 2)
|
s.True(rawMessage.SendCount >= 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildImageWithoutAlbumIDMessage(chat Chat) (*common.Message, error) {
|
func buildImageWithAlbumIDMessage(chat Chat, albumID string) (*common.Message, error) {
|
||||||
file, err := os.Open("../_assets/tests/test.jpg")
|
file, err := os.Open("../_assets/tests/test.jpg")
|
||||||
if err != err {
|
if err != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -2351,12 +2351,17 @@ func buildImageWithoutAlbumIDMessage(chat Chat) (*common.Message, error) {
|
||||||
Type: protobuf.ImageType_JPEG,
|
Type: protobuf.ImageType_JPEG,
|
||||||
Width: 1200,
|
Width: 1200,
|
||||||
Height: 1000,
|
Height: 1000,
|
||||||
|
AlbumId: albumID,
|
||||||
}
|
}
|
||||||
message.Payload = &protobuf.ChatMessage_Image{Image: &image}
|
message.Payload = &protobuf.ChatMessage_Image{Image: &image}
|
||||||
|
|
||||||
return message, nil
|
return message, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildImageWithoutAlbumIDMessage(chat Chat) (*common.Message, error) {
|
||||||
|
return buildImageWithAlbumIDMessage(chat, "")
|
||||||
|
}
|
||||||
|
|
||||||
type testTimeSource struct{}
|
type testTimeSource struct{}
|
||||||
|
|
||||||
func (t *testTimeSource) GetCurrentTime() uint64 {
|
func (t *testTimeSource) GetCurrentTime() uint64 {
|
||||||
|
|
Loading…
Reference in New Issue