diff --git a/VERSION b/VERSION index bca061d98..731d500dc 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.56.7 +0.56.8 diff --git a/protocol/persistence.go b/protocol/persistence.go index 664db9242..35e87a63e 100644 --- a/protocol/persistence.go +++ b/protocol/persistence.go @@ -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 } diff --git a/protocol/persistence_test.go b/protocol/persistence_test.go index 1f7e8b588..7d4daacf7 100644 --- a/protocol/persistence_test.go +++ b/protocol/persistence_test.go @@ -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) +}