revert mentions for chat preview

This commit is contained in:
andrey 2021-10-01 11:59:42 +02:00 committed by flexsurfer
parent c3ced09839
commit d90fe86a61
3 changed files with 20 additions and 5 deletions

View File

@ -1 +1 @@
0.89.5
0.89.6

View File

@ -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"`

View File

@ -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]
simplifiedText, err := chat.LastMessage.GetSimplifiedText("", nil)
if err == nil {
if len(simplifiedText) > 100 {
chatPreview.Text = simplifiedText[:100]
} else {
chatPreview.Text = chat.LastMessage.Text
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
}
}
}
}