Skip to content

Commit

Permalink
QuotedMessage image from http server
Browse files Browse the repository at this point in the history
  • Loading branch information
flexsurfer committed Mar 21, 2022
1 parent d60a671 commit 01b6988
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.96.0
0.96.1
26 changes: 18 additions & 8 deletions protocol/common/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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) {
Expand Down
17 changes: 12 additions & 5 deletions protocol/message_persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`
}
Expand All @@ -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
Expand Down Expand Up @@ -180,6 +184,8 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message
&quotedParsedText,
&quotedAudioDuration,
&quotedCommunityID,
&quotedID,
&ContentType,
&alias,
&identicon,
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion protocol/persistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 01b6988

Please sign in to comment.