From d90fe86a61e98c06b9f289f5bb7adc30c979a90f Mon Sep 17 00:00:00 2001 From: andrey Date: Fri, 1 Oct 2021 11:59:42 +0200 Subject: [PATCH] revert mentions for chat preview --- VERSION | 2 +- protocol/chat.go | 4 ++++ protocol/messenger_chats.go | 19 +++++++++++++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index 99ce4001a..0ebc30b27 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.89.5 +0.89.6 diff --git a/protocol/chat.go b/protocol/chat.go index 576630691..feb57fb97 100644 --- a/protocol/chat.go +++ b/protocol/chat.go @@ -2,6 +2,7 @@ package protocol import ( "crypto/ecdsa" + "encoding/json" "errors" "math/rand" @@ -155,6 +156,9 @@ type ChatPreview struct { // SyncedFrom is the time from when it was synced with a mailserver SyncedFrom uint32 `json:"syncedFrom,omitempty"` + // ParsedText is the parsed markdown for displaying + ParsedText json.RawMessage `json:"parsedText,omitempty"` + Text string `json:"text,omitempty"` ContentType protobuf.ChatMessage_ContentType `json:"contentType,omitempty"` diff --git a/protocol/messenger_chats.go b/protocol/messenger_chats.go index fb37fc7f9..6fda9783b 100644 --- a/protocol/messenger_chats.go +++ b/protocol/messenger_chats.go @@ -8,6 +8,8 @@ import ( "github.com/status-im/status-go/protocol/protobuf" "github.com/status-im/status-go/protocol/requests" "github.com/status-im/status-go/protocol/transport" + + "strings" ) func (m *Messenger) Chats() []*Chat { @@ -52,10 +54,19 @@ func (m *Messenger) ChatsPreview() []*ChatPreview { if chat.LastMessage != nil { chatPreview.ContentType = chat.LastMessage.ContentType if chat.LastMessage.ContentType == protobuf.ChatMessage_TEXT_PLAIN { - if len(chat.LastMessage.Text) > 200 { - chatPreview.Text = chat.LastMessage.Text[:200] - } else { - chatPreview.Text = chat.LastMessage.Text + + simplifiedText, err := chat.LastMessage.GetSimplifiedText("", nil) + + if err == nil { + if len(simplifiedText) > 100 { + chatPreview.Text = simplifiedText[:100] + } else { + chatPreview.Text = simplifiedText + } + if strings.Contains(chatPreview.Text, "0x") { + //if there is a mention, we would like to send parsed text as well + chatPreview.ParsedText = chat.LastMessage.ParsedText + } } } }