mirror of
https://github.com/status-im/status-go.git
synced 2025-02-21 19:28:29 +00:00
Fix mark messages seen
If a chat had a last message the persistence call `Chat()` would not decode `LastMessage` correctly. This commit fixes the issue.
This commit is contained in:
parent
ba126e9fe0
commit
2e231e690e
@ -277,6 +277,7 @@ func (db sqlitePersistence) Chat(chatID string) (*Chat, error) {
|
||||
chat Chat
|
||||
encodedMembers []byte
|
||||
encodedMembershipUpdates []byte
|
||||
lastMessageBytes []byte
|
||||
)
|
||||
|
||||
err := db.db.QueryRow(`
|
||||
@ -305,7 +306,7 @@ func (db sqlitePersistence) Chat(chatID string) (*Chat, error) {
|
||||
&chat.DeletedAtClockValue,
|
||||
&chat.UnviewedMessagesCount,
|
||||
&chat.LastClockValue,
|
||||
&chat.LastMessage,
|
||||
&lastMessageBytes,
|
||||
&encodedMembers,
|
||||
&encodedMembershipUpdates,
|
||||
&chat.Muted,
|
||||
@ -328,6 +329,15 @@ func (db sqlitePersistence) Chat(chatID string) (*Chat, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Restore last message
|
||||
if lastMessageBytes != nil {
|
||||
message := &Message{}
|
||||
if err = json.Unmarshal(lastMessageBytes, message); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.LastMessage = message
|
||||
}
|
||||
|
||||
return &chat, nil
|
||||
}
|
||||
|
||||
|
@ -514,3 +514,18 @@ func TestMessagesAudioDurationMsNull(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, m, 1)
|
||||
}
|
||||
|
||||
func TestSaveChat(t *testing.T) {
|
||||
db, err := openTestDB()
|
||||
require.NoError(t, err)
|
||||
p := sqlitePersistence{db: db}
|
||||
|
||||
chat := CreatePublicChat("test-chat", &testTimeSource{})
|
||||
chat.LastMessage = &Message{}
|
||||
err = p.SaveChat(chat)
|
||||
require.NoError(t, err)
|
||||
|
||||
retrievedChat, err := p.Chat(chat.ID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, &chat, retrievedChat)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user