QuotedMessage image from http server
This commit is contained in:
parent
d60a6713fe
commit
01b6988260
|
@ -23,20 +23,22 @@ import (
|
||||||
|
|
||||||
// QuotedMessage contains the original text of the message replied to
|
// QuotedMessage contains the original text of the message replied to
|
||||||
type QuotedMessage struct {
|
type QuotedMessage struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
ContentType int64 `json:"contentType"`
|
||||||
// From is a public key of the author of the message.
|
// From is a public key of the author of the message.
|
||||||
From string `json:"from"`
|
From string `json:"from"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
ParsedText json.RawMessage `json:"parsedText,omitempty"`
|
ParsedText json.RawMessage `json:"parsedText,omitempty"`
|
||||||
// Base64Image is the converted base64 image
|
// ImageLocalURL is the local url of the image
|
||||||
Base64Image string `json:"image,omitempty"`
|
ImageLocalURL 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"`
|
|
||||||
// CommunityID is the id of the community advertised
|
// CommunityID is the id of the community advertised
|
||||||
CommunityID string `json:"communityId,omitempty"`
|
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
|
type CommandState int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -163,9 +165,17 @@ type Message struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Message) PrepareServerURLs(port int) {
|
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.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) {
|
func (m *Message) MarshalJSON() ([]byte, error) {
|
||||||
|
|
|
@ -102,6 +102,8 @@ func (db sqlitePersistence) tableUserMessagesAllFieldsJoin() string {
|
||||||
m2.parsed_text,
|
m2.parsed_text,
|
||||||
m2.audio_duration_ms,
|
m2.audio_duration_ms,
|
||||||
m2.community_id,
|
m2.community_id,
|
||||||
|
m2.id,
|
||||||
|
m2.content_type,
|
||||||
c.alias,
|
c.alias,
|
||||||
c.identicon`
|
c.identicon`
|
||||||
}
|
}
|
||||||
|
@ -115,6 +117,8 @@ type scanner interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message *common.Message, others ...interface{}) error {
|
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 quotedText sql.NullString
|
||||||
var quotedParsedText []byte
|
var quotedParsedText []byte
|
||||||
var quotedFrom sql.NullString
|
var quotedFrom sql.NullString
|
||||||
|
@ -180,6 +184,8 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message
|
||||||
"edParsedText,
|
"edParsedText,
|
||||||
"edAudioDuration,
|
"edAudioDuration,
|
||||||
"edCommunityID,
|
"edCommunityID,
|
||||||
|
"edID,
|
||||||
|
&ContentType,
|
||||||
&alias,
|
&alias,
|
||||||
&identicon,
|
&identicon,
|
||||||
}
|
}
|
||||||
|
@ -198,11 +204,12 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message
|
||||||
|
|
||||||
if quotedText.Valid {
|
if quotedText.Valid {
|
||||||
message.QuotedMessage = &common.QuotedMessage{
|
message.QuotedMessage = &common.QuotedMessage{
|
||||||
From: quotedFrom.String,
|
ID: quotedID.String,
|
||||||
Text: quotedText.String,
|
ContentType: ContentType.Int64,
|
||||||
ParsedText: quotedParsedText,
|
From: quotedFrom.String,
|
||||||
AudioDurationMs: uint64(quotedAudioDuration.Int64),
|
Text: quotedText.String,
|
||||||
CommunityID: quotedCommunityID.String,
|
ParsedText: quotedParsedText,
|
||||||
|
CommunityID: quotedCommunityID.String,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
message.Alias = alias.String
|
message.Alias = alias.String
|
||||||
|
|
|
@ -354,7 +354,7 @@ func TestMessageReplies(t *testing.T) {
|
||||||
require.Nil(t, retrievedMessages[0].QuotedMessage)
|
require.Nil(t, retrievedMessages[0].QuotedMessage)
|
||||||
|
|
||||||
require.Equal(t, "id-1", retrievedMessages[1].ResponseTo)
|
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.Equal(t, "", retrievedMessages[2].ResponseTo)
|
||||||
require.Nil(t, retrievedMessages[2].QuotedMessage)
|
require.Nil(t, retrievedMessages[2].QuotedMessage)
|
||||||
|
|
Loading…
Reference in New Issue