From ea3e59ffeefa623373b4a39ecf7fa5558e384ad0 Mon Sep 17 00:00:00 2001 From: frank Date: Thu, 18 Jan 2024 21:18:01 +0800 Subject: [PATCH] replace mention name with public key (#4579) * replace mention with public key * bump version --- VERSION | 2 +- protocol/messenger.go | 8 ++++++++ protocol/messenger_messages.go | 8 +++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 032763fe1..da34a74e3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.172.4 +0.172.5 diff --git a/protocol/messenger.go b/protocol/messenger.go index 19fc500ba..9cc53e94c 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -2297,6 +2297,14 @@ func (m *Messenger) sendChatMessage(ctx context.Context, message *common.Message } message.DisplayName = displayName + + replacedText, err := m.mentionsManager.ReplaceWithPublicKey(message.ChatId, message.Text) + if err == nil { + message.Text = replacedText + } else { + m.logger.Error("failed to replace text with public key", zap.String("chatID", message.ChatId), zap.String("text", message.Text)) + } + if len(message.ImagePath) != 0 { err := message.LoadImage() diff --git a/protocol/messenger_messages.go b/protocol/messenger_messages.go index 2cef2bc60..7d3b44f5a 100644 --- a/protocol/messenger_messages.go +++ b/protocol/messenger_messages.go @@ -63,7 +63,13 @@ func (m *Messenger) EditMessage(ctx context.Context, request *requests.EditMessa editMessage := NewEditMessage() - editMessage.Text = request.Text + replacedText, err := m.mentionsManager.ReplaceWithPublicKey(message.ChatId, request.Text) + if err != nil { + m.logger.Error("failed to replace text with public key", zap.String("chatID", message.ChatId), zap.String("text", request.Text)) + // use original text as fallback + replacedText = request.Text + } + editMessage.Text = replacedText editMessage.ContentType = request.ContentType editMessage.ChatId = message.ChatId editMessage.MessageId = message.ID