From 7fa997d443e963f36f45d6e83b1064facdbca8d2 Mon Sep 17 00:00:00 2001 From: ycc Date: Sat, 6 Apr 2024 12:55:27 +0200 Subject: [PATCH] message preview in progress --- client/helpers/storageHelper.go | 15 +++++++++++++++ client/messagestorage.go | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 client/helpers/storageHelper.go diff --git a/client/helpers/storageHelper.go b/client/helpers/storageHelper.go new file mode 100644 index 0000000..ebadade --- /dev/null +++ b/client/helpers/storageHelper.go @@ -0,0 +1,15 @@ +package helpers + +import ( + "forge.redroom.link/yves/meowlib/client" +) + +func LoadMessagesHistory(peer_id int) ([]client.InternalUserMessage, string, error) { + id := client.GetConfig().GetIdentity() + peer := id.Peers[peer_id] + msgs, err := peer.LoadMessagesHistory(0, 0, 50) + if err != nil { + return nil, "LoadLastMessages: LoadMessagesHistory", err + } + return msgs, "", nil +} diff --git a/client/messagestorage.go b/client/messagestorage.go index 640f426..b62ce20 100644 --- a/client/messagestorage.go +++ b/client/messagestorage.go @@ -224,6 +224,25 @@ func GetMessagesHistory(peer *Peer, inAppMsgCount int, lastDbId int, wantMore in return messages, nil } +// make an image from the files content (loads the first image, or build a more complex view) +func MessagePreview(msg *InternalUserMessage, password string) ([]byte, error) { + // get the hidden file name + if len(msg.FilePaths) == 0 { + return nil, nil + } + // get the hidden file + encData, err := os.ReadFile(msg.FilePaths[0]) + if err != nil { + return nil, err + } + // decrypt the file + data, err := meowlib.SymDecrypt(password, encData) + if err != nil { + return nil, err + } + return data, nil +} + func getMessageCount(dbid string) (int, error) { db, _ := sql.Open("sqlite3", filepath.Join(GetConfig().StoragePath, GetConfig().GetIdentity().Uuid, dbid+GetConfig().DbSuffix)) // Open the created SQLite File defer db.Close()