morpheus

A Matrix client written in Go-QT
git clone git://archive.git.mtrnord.blog/Nordgedanken/morpheus.git
Log | Files | Refs | README | LICENSE

commit 89ccc954f2974b76db9e90b05765ff5bcaccf005
parent 05b216a798a0c81d6a8f1840cb7983750aca1b56
Author: MTRNord <mtrnord1@gmail.com>
Date:   Wed, 22 Nov 2017 19:25:23 +0100

Fix message CacheLoading fails and fix RoomAvatar Caching

Signed-off-by: MTRNord <mtrnord1@gmail.com>

Diffstat:
Mmatrix/rooms.go | 7+++++--
Mui/MainUI.go | 67+++++++++++++++++++++++++++++++++++--------------------------------
2 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/matrix/rooms.go b/matrix/rooms.go @@ -124,12 +124,15 @@ func (r *Room) GetRoomAvatar() (avatarResp *gui.QPixmap, err error) { } // Update cache - txn := db.NewTransaction(true) // Read-write txn - DBSetErr := txn.Set([]byte("room|"+r.RoomID+"|84x84"), []byte(IMGdata)) + DBSetErr := db.Update(func(txn *badger.Txn) error { + DBSetErr := txn.Set([]byte("room|"+r.RoomID+"|84x84"), []byte(IMGdata)) + return DBSetErr + }) if DBSetErr != nil { err = DBSetErr return } + } else { IMGdata = roomAvatarData } diff --git a/ui/MainUI.go b/ui/MainUI.go @@ -396,7 +396,7 @@ func (m *MainUI) loadCache() (err error) { if strings.HasSuffix(stringKey, "|id") { if !contains(doneMsg, stringValue) { // Remember we already added this message to the view - doneMsg = append(doneMsg, stringKey) + doneMsg = append(doneMsg, stringValue) // Get all Data senderItem, senderErr := txn.Get([]byte(strings.Replace(stringKey, "|id", "|sender", -1))) @@ -441,17 +441,18 @@ func (m *MainUI) loadCache() (err error) { } if strings.HasSuffix(stringKey, "|sender") { - if !contains(doneMsg, stringValue) { + idItem, idErr := txn.Get([]byte(strings.Replace(stringKey, "|sender", "|id", -1))) + if idErr != nil { + return errors.WithMessage(idErr, "Key: "+strings.Replace(stringKey, "|sender", "|id", -1)) + } + idValue, idValueErr := idItem.Value() + if idValueErr != nil { + return idValueErr + } + id := fmt.Sprintf("%s", idValue) + + if !contains(doneMsg, id) { // Remember we already added this message to the view - idItem, idErr := txn.Get([]byte(strings.Replace(stringKey, "|sender", "|id", -1))) - if idErr != nil { - return errors.WithMessage(idErr, "Key: "+strings.Replace(stringKey, "|sender", "|id", -1)) - } - idValue, idValueErr := idItem.Value() - if idValueErr != nil { - return idValueErr - } - id := fmt.Sprintf("%s", idValue) doneMsg = append(doneMsg, id) // Get all Data @@ -489,18 +490,19 @@ func (m *MainUI) loadCache() (err error) { } if strings.HasSuffix(stringKey, "|messageString") { - if !contains(doneMsg, stringValue) { - // Remember we already added this message to the view - idItem, idErr := txn.Get([]byte(strings.Replace(stringKey, "|messageString", "|id", -1))) - if idErr != nil { - return errors.WithMessage(idErr, "Key: "+strings.Replace(stringKey, "|messageString", "|id", -1)) - } + idItem, idErr := txn.Get([]byte(strings.Replace(stringKey, "|messageString", "|id", -1))) + if idErr != nil { + return errors.WithMessage(idErr, "Key: "+strings.Replace(stringKey, "|messageString", "|id", -1)) + } - idValue, idValueErr := idItem.Value() - if idValueErr != nil { - return idValueErr - } - id := fmt.Sprintf("%s", idValue) + idValue, idValueErr := idItem.Value() + if idValueErr != nil { + return idValueErr + } + id := fmt.Sprintf("%s", idValue) + + if !contains(doneMsg, id) { + // Remember we already added this message to the view doneMsg = append(doneMsg, id) // Get all Data @@ -538,17 +540,18 @@ func (m *MainUI) loadCache() (err error) { } if strings.HasSuffix(stringKey, "|timestamp") { - if !contains(doneMsg, stringValue) { + idItem, idErr := txn.Get([]byte(strings.Replace(stringKey, "|timestamp", "|id", -1))) + if idErr != nil { + return errors.WithMessage(idErr, "Key: "+strings.Replace(stringKey, "|timestamp", "|id", -1)) + } + idValue, idValueErr := idItem.Value() + if idValueErr != nil { + return idValueErr + } + id := fmt.Sprintf("%s", idValue) + + if !contains(doneMsg, id) { // Remember we already added this message to the view - idItem, idErr := txn.Get([]byte(strings.Replace(stringKey, "|timestamp", "|id", -1))) - if idErr != nil { - return errors.WithMessage(idErr, "Key: "+strings.Replace(stringKey, "|timestamp", "|id", -1)) - } - idValue, idValueErr := idItem.Value() - if idValueErr != nil { - return idValueErr - } - id := fmt.Sprintf("%s", idValue) doneMsg = append(doneMsg, id) // Get all Data