From 01b6988260a676fdb492e427c8d336a0df229a07 Mon Sep 17 00:00:00 2001 From: andrey Date: Wed, 16 Mar 2022 17:28:14 +0100 Subject: [PATCH] QuotedMessage image from http server --- VERSION | 2 +- protocol/common/message.go | 26 ++++++++++++++++++-------- protocol/message_persistence.go | 17 ++++++++++++----- protocol/persistence_test.go | 2 +- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/VERSION b/VERSION index 13bb62857..6512d4b8a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.96.0 +0.96.1 \ No newline at end of file diff --git a/protocol/common/message.go b/protocol/common/message.go index 1bb25a3b6..773e0aca3 100644 --- a/protocol/common/message.go +++ b/protocol/common/message.go @@ -23,20 +23,22 @@ import ( // QuotedMessage contains the original text of the message replied to type QuotedMessage struct { + ID string `json:"id"` + ContentType int64 `json:"contentType"` // From is a public key of the author of the message. From string `json:"from"` Text string `json:"text"` ParsedText json.RawMessage `json:"parsedText,omitempty"` - // Base64Image is the converted base64 image - Base64Image string `json:"image,omitempty"` - // Base64Audio is the converted base64 audio - Base64Audio string `json:"audio,omitempty"` - // AudioDurationMs is the audio duration in milliseconds - AudioDurationMs uint64 `json:"audioDurationMs,omitempty"` + // ImageLocalURL is the local url of the image + ImageLocalURL string `json:"image,omitempty"` // CommunityID is the id of the community advertised CommunityID string `json:"communityId,omitempty"` } +func (m *QuotedMessage) PrepareImageURL(port int) { + m.ImageLocalURL = fmt.Sprintf("https://localhost:%d/messages/images?messageId=%s", port, m.ID) +} + type CommandState int const ( @@ -163,9 +165,17 @@ type Message struct { } func (m *Message) PrepareServerURLs(port int) { - m.ImageLocalURL = fmt.Sprintf("https://localhost:%d/messages/images?messageId=%s", port, m.ID) m.Identicon = fmt.Sprintf("https://localhost:%d/messages/identicons?publicKey=%s", port, m.From) - m.AudioLocalURL = fmt.Sprintf("https://localhost:%d/messages/audio?messageId=%s", port, m.ID) + + if m.QuotedMessage != nil && m.QuotedMessage.ContentType == int64(protobuf.ChatMessage_IMAGE) { + m.QuotedMessage.PrepareImageURL(port) + } + if m.ContentType == protobuf.ChatMessage_IMAGE { + m.ImageLocalURL = fmt.Sprintf("https://localhost:%d/messages/images?messageId=%s", port, m.ID) + } + if m.ContentType == protobuf.ChatMessage_AUDIO { + m.AudioLocalURL = fmt.Sprintf("https://localhost:%d/messages/audio?messageId=%s", port, m.ID) + } } func (m *Message) MarshalJSON() ([]byte, error) { diff --git a/protocol/message_persistence.go b/protocol/message_persistence.go index ea02fea9e..e1d72ee29 100644 --- a/protocol/message_persistence.go +++ b/protocol/message_persistence.go @@ -102,6 +102,8 @@ func (db sqlitePersistence) tableUserMessagesAllFieldsJoin() string { m2.parsed_text, m2.audio_duration_ms, m2.community_id, + m2.id, + m2.content_type, c.alias, c.identicon` } @@ -115,6 +117,8 @@ type scanner interface { } func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message *common.Message, others ...interface{}) error { + var quotedID sql.NullString + var ContentType sql.NullInt64 var quotedText sql.NullString var quotedParsedText []byte var quotedFrom sql.NullString @@ -180,6 +184,8 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message "edParsedText, "edAudioDuration, "edCommunityID, + "edID, + &ContentType, &alias, &identicon, } @@ -198,11 +204,12 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message if quotedText.Valid { message.QuotedMessage = &common.QuotedMessage{ - From: quotedFrom.String, - Text: quotedText.String, - ParsedText: quotedParsedText, - AudioDurationMs: uint64(quotedAudioDuration.Int64), - CommunityID: quotedCommunityID.String, + ID: quotedID.String, + ContentType: ContentType.Int64, + From: quotedFrom.String, + Text: quotedText.String, + ParsedText: quotedParsedText, + CommunityID: quotedCommunityID.String, } } message.Alias = alias.String diff --git a/protocol/persistence_test.go b/protocol/persistence_test.go index 69830d092..0fba13678 100644 --- a/protocol/persistence_test.go +++ b/protocol/persistence_test.go @@ -354,7 +354,7 @@ func TestMessageReplies(t *testing.T) { require.Nil(t, retrievedMessages[0].QuotedMessage) require.Equal(t, "id-1", retrievedMessages[1].ResponseTo) - require.Equal(t, &common.QuotedMessage{From: "1", Text: "content-1"}, retrievedMessages[1].QuotedMessage) + require.Equal(t, &common.QuotedMessage{ID: "id-1", From: "1", Text: "content-1"}, retrievedMessages[1].QuotedMessage) require.Equal(t, "", retrievedMessages[2].ResponseTo) require.Nil(t, retrievedMessages[2].QuotedMessage)