add preview
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc 2024-04-06 15:44:30 +02:00
parent 7fa997d443
commit 813611bde7

View File

@ -218,20 +218,55 @@ func GetMessagesHistory(peer *Peer, inAppMsgCount int, lastDbId int, wantMore in
ium = DbMessageToInternalUserMessage(id, peer.DbIds[fileidx], &dbm) ium = DbMessageToInternalUserMessage(id, peer.DbIds[fileidx], &dbm)
ium.Dbid = id ium.Dbid = id
ium.Dbfile = peer.DbIds[fileidx] ium.Dbfile = peer.DbIds[fileidx]
messages = append(messages, *ium) messages = append(messages, *ium)
} }
// TODO DB overlap // TODO DB overlap
return messages, nil return messages, nil
} }
// make an image from the files content (loads the first image, or build a more complex view) // Get old messages from a peer
func MessagePreview(msg *InternalUserMessage, password string) ([]byte, error) { func GetMessagePreview(peer *Peer, dbFile string, dbId int64, password string) ([]byte, error) {
// get the hidden file name
if len(msg.FilePaths) == 0 { // There fileidx should provide the db that we need (unless wantMore overlaps the next DB)
return nil, nil db, _ := sql.Open("sqlite3", filepath.Join(GetConfig().StoragePath, GetConfig().GetIdentity().Uuid, dbFile+GetConfig().DbSuffix)) // Open the created SQLite File
defer db.Close()
stm, err := db.Prepare("SELECT id, m FROM message WHERE id=?")
if err != nil {
return nil, err
} }
defer stm.Close()
rows, err := stm.Query(dbId)
if err != nil {
return nil, err
}
defer rows.Close()
var dbm meowlib.DbMessage
for rows.Next() {
var id int64
var m []byte
err = rows.Scan(&id, &m)
if err != nil {
return nil, err
}
decdata, err := meowlib.SymDecrypt(password, m)
if err != nil {
return nil, err
}
err = proto.Unmarshal(decdata, &dbm)
if err != nil {
return nil, err
}
}
return FilePreview(dbm.FilePaths[0], password)
}
func FilePreview(filename string, password string) ([]byte, error) {
// get the hidden file // get the hidden file
encData, err := os.ReadFile(msg.FilePaths[0]) encData, err := os.ReadFile(filename)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -243,6 +278,15 @@ func MessagePreview(msg *InternalUserMessage, password string) ([]byte, error) {
return data, nil return data, nil
} }
// make an image from the files content (loads the first image, or build a more complex view)
func InternalUserMessagePreview(msg *InternalUserMessage, password string) ([]byte, error) {
// get the hidden file name
if len(msg.FilePaths) == 0 {
return nil, nil
}
return FilePreview(msg.FilePaths[0], password)
}
func getMessageCount(dbid string) (int, error) { 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 db, _ := sql.Open("sqlite3", filepath.Join(GetConfig().StoragePath, GetConfig().GetIdentity().Uuid, dbid+GetConfig().DbSuffix)) // Open the created SQLite File
defer db.Close() defer db.Close()