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:
parent
80fe18bef9
commit
798877788c
|
@ -259,18 +259,26 @@ func (m *Messenger) ResolvePrimaryName(mentionID string) (string, error) {
|
||||||
// EnvelopeSent triggered when envelope delivered at least to 1 peer.
|
// EnvelopeSent triggered when envelope delivered at least to 1 peer.
|
||||||
func (interceptor EnvelopeEventsInterceptor) EnvelopeSent(identifiers [][]byte) {
|
func (interceptor EnvelopeEventsInterceptor) EnvelopeSent(identifiers [][]byte) {
|
||||||
if interceptor.Messenger != nil {
|
if interceptor.Messenger != nil {
|
||||||
var ids []string
|
signalIDs := make([][]byte, 0, len(identifiers))
|
||||||
for _, identifierBytes := range identifiers {
|
for _, identifierBytes := range identifiers {
|
||||||
ids = append(ids, types.EncodeHex(identifierBytes))
|
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))
|
||||||
|
}
|
||||||
|
|
||||||
err := interceptor.Messenger.processSentMessages(ids)
|
message, err := interceptor.Messenger.MessageByID(messageID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
interceptor.Messenger.logger.Info("messenger failed to process sent messages", zap.Error(err))
|
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)
|
||||||
// We notify the client, regardless whether we were able to mark them as sent
|
|
||||||
interceptor.EnvelopeEventsHandler.EnvelopeSent(identifiers)
|
|
||||||
} else {
|
} else {
|
||||||
// NOTE(rasom): In case if interceptor.Messenger is not nil and
|
// NOTE(rasom): In case if interceptor.Messenger is not nil and
|
||||||
// some error occurred on processing sent message we don't want
|
// some error occurred on processing sent message we don't want
|
||||||
|
@ -682,35 +690,33 @@ func (m *Messenger) EnableBackedupMessagesProcessing() {
|
||||||
m.processBackedupMessages = true
|
m.processBackedupMessages = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) processSentMessages(ids []string) error {
|
func (m *Messenger) processSentMessage(id string) error {
|
||||||
if m.connectionState.Offline {
|
if m.connectionState.Offline {
|
||||||
return errors.New("Can't mark message as sent while offline")
|
return errors.New("Can't mark message as sent while offline")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, id := range ids {
|
rawMessage, err := m.persistence.RawMessageByID(id)
|
||||||
rawMessage, err := m.persistence.RawMessageByID(id)
|
// If we have no raw message, we create a temporary one, so that
|
||||||
// If we have no raw message, we create a temporary one, so that
|
// the sent status is preserved
|
||||||
// the sent status is preserved
|
if err == sql.ErrNoRows || rawMessage == nil {
|
||||||
if err == sql.ErrNoRows || rawMessage == nil {
|
rawMessage = &common.RawMessage{
|
||||||
rawMessage = &common.RawMessage{
|
ID: id,
|
||||||
ID: id,
|
MessageType: protobuf.ApplicationMetadataMessage_CHAT_MESSAGE,
|
||||||
MessageType: protobuf.ApplicationMetadataMessage_CHAT_MESSAGE,
|
|
||||||
}
|
|
||||||
} else if err != nil {
|
|
||||||
return errors.Wrapf(err, "Can't get raw message with id %v", id)
|
|
||||||
}
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
return errors.Wrapf(err, "Can't get raw message with id %v", id)
|
||||||
|
}
|
||||||
|
|
||||||
rawMessage.Sent = true
|
rawMessage.Sent = true
|
||||||
|
|
||||||
err = m.persistence.SaveRawMessage(rawMessage)
|
err = m.persistence.SaveRawMessage(rawMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Can't save raw message marked as sent")
|
return errors.Wrapf(err, "Can't save raw message marked as sent")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = m.UpdateMessageOutgoingStatus(id, common.OutgoingStatusSent)
|
err = m.UpdateMessageOutgoingStatus(id, common.OutgoingStatusSent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -2167,7 +2167,7 @@ func (s *MessengerSuite) TestSentEventTracking() {
|
||||||
s.False(rawMessage.Sent)
|
s.False(rawMessage.Sent)
|
||||||
|
|
||||||
//when message sent, its sent field should be true after we got confirmation
|
//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)
|
s.NoError(err)
|
||||||
|
|
||||||
rawMessage, err = s.m.persistence.RawMessageByID(inputMessage.ID)
|
rawMessage, err = s.m.persistence.RawMessageByID(inputMessage.ID)
|
||||||
|
@ -2392,7 +2392,7 @@ func (s *MessengerSuite) TestMessageSent() {
|
||||||
s.False(rawMessage.Sent)
|
s.False(rawMessage.Sent)
|
||||||
|
|
||||||
//imitate chat message sent
|
//imitate chat message sent
|
||||||
err = s.m.processSentMessages([]string{inputMessage.ID})
|
err = s.m.processSentMessage(inputMessage.ID)
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
|
|
||||||
rawMessage, err = s.m.persistence.RawMessageByID(inputMessage.ID)
|
rawMessage, err = s.m.persistence.RawMessageByID(inputMessage.ID)
|
||||||
|
@ -2402,8 +2402,7 @@ func (s *MessengerSuite) TestMessageSent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerSuite) TestProcessSentMessages() {
|
func (s *MessengerSuite) TestProcessSentMessages() {
|
||||||
ids := []string{"a"}
|
err := s.m.processSentMessage("a")
|
||||||
err := s.m.processSentMessages(ids)
|
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue