Fix bug with tracking & merge community changes
This commit is contained in:
parent
824bb17ba9
commit
a182f3e699
|
@ -275,53 +275,54 @@ func (s *MessageSender) sendCommunity(
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
return nil, nil
|
||||||
wrappedMessage, err := s.wrapMessageV1(rawMessage)
|
}
|
||||||
|
|
||||||
|
wrappedMessage, err := s.wrapMessageV1(rawMessage)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it's a chat message, we send it on the community chat topic
|
||||||
|
if rawMessage.MessageType == protobuf.ApplicationMetadataMessage_CHAT_MESSAGE {
|
||||||
|
messageSpec, err := s.protocol.BuildHashRatchetMessage(rawMessage.CommunityID, wrappedMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's a chat message, we send it on the community chat topic
|
payload, err := proto.Marshal(messageSpec.Message)
|
||||||
if rawMessage.MessageType == protobuf.ApplicationMetadataMessage_CHAT_MESSAGE {
|
if err != nil {
|
||||||
messageSpec, err := s.protocol.BuildHashRatchetMessage(rawMessage.CommunityID, wrappedMessage)
|
return nil, errors.Wrap(err, "failed to marshal")
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
hash, newMessage, err = s.sendCommunityChatMessage(ctx, rawMessage, payload)
|
||||||
}
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
payload, err := proto.Marshal(messageSpec.Message)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "failed to marshal")
|
|
||||||
}
|
|
||||||
hash, newMessage, err = s.sendCommunityChatMessage(ctx, rawMessage, payload)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
sentMessage := &SentMessage{
|
|
||||||
Spec: messageSpec,
|
|
||||||
MessageIDs: messageIDs,
|
|
||||||
}
|
|
||||||
|
|
||||||
s.notifyOnSentMessage(sentMessage)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
payload := wrappedMessage
|
|
||||||
|
|
||||||
pubkey, err := crypto.DecompressPubkey(rawMessage.CommunityID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "failed to decompress pubkey")
|
|
||||||
}
|
|
||||||
hash, newMessage, err = s.sendCommunityMessage(ctx, pubkey, payload, messageIDs)
|
|
||||||
if err != nil {
|
|
||||||
s.logger.Error("failed to send a community message", zap.Error(err))
|
|
||||||
return nil, errors.Wrap(err, "failed to send a message spec")
|
|
||||||
}
|
|
||||||
|
|
||||||
s.logger.Debug("sent community message ", zap.String("messageID", messageID.String()), zap.String("hash", types.EncodeHex(hash)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sentMessage := &SentMessage{
|
||||||
|
Spec: messageSpec,
|
||||||
|
MessageIDs: messageIDs,
|
||||||
|
}
|
||||||
|
|
||||||
|
s.notifyOnSentMessage(sentMessage)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
payload := wrappedMessage
|
||||||
|
|
||||||
|
pubkey, err := crypto.DecompressPubkey(rawMessage.CommunityID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "failed to decompress pubkey")
|
||||||
|
}
|
||||||
|
hash, newMessage, err = s.sendCommunityMessage(ctx, pubkey, payload, messageIDs)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("failed to send a community message", zap.Error(err))
|
||||||
|
return nil, errors.Wrap(err, "failed to send a message spec")
|
||||||
|
}
|
||||||
|
|
||||||
|
s.logger.Debug("sent community message ", zap.String("messageID", messageID.String()), zap.String("hash", types.EncodeHex(hash)))
|
||||||
}
|
}
|
||||||
|
|
||||||
s.transport.Track(messageIDs, hash, newMessage)
|
s.transport.Track(messageIDs, hash, newMessage)
|
||||||
return messageID, nil
|
return messageID, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,10 +255,8 @@ func (r *MessengerResponse) Merge(response *MessengerResponse) error {
|
||||||
len(response.Bookmarks)+
|
len(response.Bookmarks)+
|
||||||
len(response.clearedHistories)+
|
len(response.clearedHistories)+
|
||||||
len(response.VerificationRequests)+
|
len(response.VerificationRequests)+
|
||||||
len(response.trustStatus)+
|
|
||||||
len(response.DiscordChannels)+
|
len(response.DiscordChannels)+
|
||||||
len(response.DiscordCategories)+
|
len(response.DiscordCategories) != 0 {
|
||||||
len(response.CommunityChanges) != 0 {
|
|
||||||
return ErrNotImplemented
|
return ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,6 +270,7 @@ func (r *MessengerResponse) Merge(response *MessengerResponse) error {
|
||||||
r.AddVerificationRequests(response.VerificationRequests)
|
r.AddVerificationRequests(response.VerificationRequests)
|
||||||
r.AddTrustStatuses(response.trustStatus)
|
r.AddTrustStatuses(response.trustStatus)
|
||||||
r.AddActivityCenterNotifications(response.ActivityCenterNotifications())
|
r.AddActivityCenterNotifications(response.ActivityCenterNotifications())
|
||||||
|
r.CommunityChanges = append(r.CommunityChanges, response.CommunityChanges...)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue