fix_: delivered message should not send envelope sent signal (#5502)

* fix_: delivered message should not send envelope sent signal

* chore_: refactor
This commit is contained in:
kaichao 2024-07-11 19:41:49 +08:00 committed by GitHub
parent 80fe18bef9
commit 798877788c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 34 deletions

View File

@ -259,18 +259,26 @@ func (m *Messenger) ResolvePrimaryName(mentionID string) (string, error) {
// EnvelopeSent triggered when envelope delivered at least to 1 peer.
func (interceptor EnvelopeEventsInterceptor) EnvelopeSent(identifiers [][]byte) {
if interceptor.Messenger != nil {
var ids []string
signalIDs := make([][]byte, 0, len(identifiers))
for _, identifierBytes := range identifiers {
ids = append(ids, types.EncodeHex(identifierBytes))
}
err := interceptor.Messenger.processSentMessages(ids)
messageID := types.EncodeHex(identifierBytes)
err := interceptor.Messenger.processSentMessage(messageID)
if err != nil {
interceptor.Messenger.logger.Info("messenger failed to process sent messages", zap.Error(err))
}
// We notify the client, regardless whether we were able to mark them as sent
interceptor.EnvelopeEventsHandler.EnvelopeSent(identifiers)
message, err := interceptor.Messenger.MessageByID(messageID)
if err != nil {
interceptor.Messenger.logger.Error("failed to query message outgoing status", zap.Error(err))
continue
}
if message.OutgoingStatus == common.OutgoingStatusDelivered {
// We don't want to send the signal if the message was already marked as delivered
continue
}
signalIDs = append(signalIDs, identifierBytes)
}
interceptor.EnvelopeEventsHandler.EnvelopeSent(signalIDs)
} else {
// NOTE(rasom): In case if interceptor.Messenger is not nil and
// some error occurred on processing sent message we don't want
@ -682,12 +690,11 @@ func (m *Messenger) EnableBackedupMessagesProcessing() {
m.processBackedupMessages = true
}
func (m *Messenger) processSentMessages(ids []string) error {
func (m *Messenger) processSentMessage(id string) error {
if m.connectionState.Offline {
return errors.New("Can't mark message as sent while offline")
}
for _, id := range ids {
rawMessage, err := m.persistence.RawMessageByID(id)
// If we have no raw message, we create a temporary one, so that
// the sent status is preserved
@ -711,7 +718,6 @@ func (m *Messenger) processSentMessages(ids []string) error {
if err != nil {
return err
}
}
return nil
}

View File

@ -2167,7 +2167,7 @@ func (s *MessengerSuite) TestSentEventTracking() {
s.False(rawMessage.Sent)
//when message sent, its sent field should be true after we got confirmation
err = s.m.processSentMessages([]string{inputMessage.ID})
err = s.m.processSentMessage(inputMessage.ID)
s.NoError(err)
rawMessage, err = s.m.persistence.RawMessageByID(inputMessage.ID)
@ -2392,7 +2392,7 @@ func (s *MessengerSuite) TestMessageSent() {
s.False(rawMessage.Sent)
//imitate chat message sent
err = s.m.processSentMessages([]string{inputMessage.ID})
err = s.m.processSentMessage(inputMessage.ID)
s.NoError(err)
rawMessage, err = s.m.persistence.RawMessageByID(inputMessage.ID)
@ -2402,8 +2402,7 @@ func (s *MessengerSuite) TestMessageSent() {
}
func (s *MessengerSuite) TestProcessSentMessages() {
ids := []string{"a"}
err := s.m.processSentMessages(ids)
err := s.m.processSentMessage("a")
s.Require().NoError(err)
}