This commit is contained in:
@ -225,9 +225,7 @@ func GetMessagesHistory(peer *Peer, inAppMsgCount int, lastDbId int, wantMore in
|
||||
return messages, nil
|
||||
}
|
||||
|
||||
// Get old messages from a peer
|
||||
func GetMessagePreview(peer *Peer, dbFile string, dbId int64, password string) ([]byte, error) {
|
||||
|
||||
func GetDbMessage(dbFile string, dbId int64, password string) (*meowlib.DbMessage, error) {
|
||||
// There fileidx should provide the db that we need (unless wantMore overlaps the next DB)
|
||||
db, _ := sql.Open("sqlite3", filepath.Join(GetConfig().StoragePath, GetConfig().GetIdentity().Uuid, dbFile+GetConfig().DbSuffix)) // Open the created SQLite File
|
||||
defer db.Close()
|
||||
@ -261,9 +259,44 @@ func GetMessagePreview(peer *Peer, dbFile string, dbId int64, password string) (
|
||||
}
|
||||
|
||||
}
|
||||
return &dbm, nil
|
||||
}
|
||||
|
||||
func UpdateDbMessage(dbm *meowlib.DbMessage, dbFile string, dbId int64, password string) error {
|
||||
db, _ := sql.Open("sqlite3", filepath.Join(GetConfig().StoragePath, GetConfig().GetIdentity().Uuid, dbFile+GetConfig().DbSuffix)) // Open the created SQLite File
|
||||
defer db.Close()
|
||||
// Encrypt message
|
||||
out, err := proto.Marshal(dbm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
encData, err := meowlib.SymEncrypt(password, out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Insert message
|
||||
updateMessageSQL := `UPDATE message SET m=? WHERE id=?`
|
||||
statement, err := db.Prepare(updateMessageSQL) // Prepare statement.
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = statement.Exec(encData, dbId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get old messages from a peer
|
||||
func GetMessagePreview(dbFile string, dbId int64, password string) ([]byte, error) {
|
||||
dbm, err := GetDbMessage(dbFile, dbId, password)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return FilePreview(dbm.FilePaths[0], password)
|
||||
}
|
||||
|
||||
// decrypt the a file and returns the raw content
|
||||
func FilePreview(filename string, password string) ([]byte, error) {
|
||||
// get the hidden file
|
||||
encData, err := os.ReadFile(filename)
|
||||
@ -278,7 +311,7 @@ func FilePreview(filename string, password string) ([]byte, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// make an image from the files content (loads the first image, or build a more complex view)
|
||||
// return the raw content 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 {
|
||||
@ -296,7 +329,6 @@ func getMessageCount(dbid string) (int, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user