QuotedMessage image from http server

This commit is contained in:
andrey 2022-03-16 17:28:14 +01:00 committed by flexsurfer
parent d60a6713fe
commit 01b6988260
4 changed files with 32 additions and 15 deletions

View File

@ -1 +1 @@
0.96.0
0.96.1

View File

@ -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) {

View File

@ -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
&quotedParsedText,
&quotedAudioDuration,
&quotedCommunityID,
&quotedID,
&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

View File

@ -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)