feat(QuotedMessage): pass Deleted to QuotedMessage

This is to let the front end determine a new message if the quoted message is deleted instead of just unknown
This commit is contained in:
Jonathan Rainville 2023-01-11 16:09:40 -05:00
parent 7717f9519f
commit cb1d80c082
4 changed files with 24 additions and 11 deletions

View File

@ -1 +1 @@
0.122.2
0.122.3

View File

@ -37,6 +37,8 @@ type QuotedMessage struct {
HasSticker bool `json:"sticker,omitempty"`
// CommunityID is the id of the community advertised
CommunityID string `json:"communityId,omitempty"`
Deleted bool `json:"deleted,omitempty"`
}
type CommandState int

View File

@ -16,7 +16,7 @@ var basicMessagesSelectQuery = `
SELECT %s %s
FROM user_messages m1
LEFT JOIN user_messages m2
ON m1.response_to = m2.id AND m2.deleted = 0
ON m1.response_to = m2.id
LEFT JOIN contacts c
ON m1.source = c.id
LEFT JOIN discord_messages dm
@ -170,6 +170,7 @@ func (db sqlitePersistence) tableUserMessagesAllFieldsJoin() string {
m2.community_id,
m2.id,
m2.content_type,
m2.deleted,
c.alias,
c.identicon`
}
@ -190,6 +191,7 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message
var quotedFrom sql.NullString
var quotedAudioDuration sql.NullInt64
var quotedCommunityID sql.NullString
var quotedDeleted sql.NullBool
var serializedMentions []byte
var serializedLinks []byte
var alias sql.NullString
@ -289,6 +291,7 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message
&quotedCommunityID,
&quotedID,
&ContentType,
&quotedDeleted,
&alias,
&identicon,
}
@ -318,6 +321,12 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message
}
if quotedText.Valid {
if quotedDeleted.Bool == true {
message.QuotedMessage = &common.QuotedMessage{
ID: quotedID.String,
Deleted: quotedDeleted.Bool,
}
} else {
message.QuotedMessage = &common.QuotedMessage{
ID: quotedID.String,
ContentType: ContentType.Int64,
@ -325,6 +334,8 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message
Text: quotedText.String,
ParsedText: quotedParsedText,
CommunityID: quotedCommunityID.String,
Deleted: quotedDeleted.Bool,
}
}
}
message.Alias = alias.String

View File

@ -555,9 +555,9 @@ func TestMessageReplies(t *testing.T) {
require.Equal(t, "", retrievedMessages[4].ResponseTo)
require.Nil(t, retrievedMessages[4].QuotedMessage)
// We have a ResponseTo, but no QuotedMessage, since the message was deleted
// We have a ResponseTo, but no QuotedMessage only gives the ID and Deleted
require.Equal(t, "id-4", retrievedMessages[0].ResponseTo)
require.Nil(t, retrievedMessages[0].QuotedMessage)
require.Equal(t, &common.QuotedMessage{ID: "id-4", Deleted: true}, retrievedMessages[0].QuotedMessage)
}
func TestMessageByChatIDWithTheSameClocks(t *testing.T) {