handle no db yet in message retrieve
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc
2024-03-05 23:15:19 +01:00
parent f40f6520d2
commit 0a70206b11
2 changed files with 15 additions and 1 deletions

View File

@ -90,6 +90,10 @@ func StoreMessage(peer *Peer, usermessage *meowlib.UserMessage, filenames []stri
// Get new messages from a peer
func GetNewMessages(peer *Peer, lastDbId int, password string) ([]*InternalUserMessage, error) {
var messages []*InternalUserMessage
// handle no db yet
if len(peer.DbIds) == 0 {
return messages, nil
}
fileidx := len(peer.DbIds) - 1
// There fileidx should provide the db that we need (unless wantMore overlaps the next DB)
db, _ := sql.Open("sqlite3", filepath.Join(GetConfig().StoragePath, peer.DbIds[fileidx]+GetConfig().DbSuffix)) // Open the created SQLite File
@ -139,6 +143,10 @@ func GetNewMessages(peer *Peer, lastDbId int, password string) ([]*InternalUserM
// Get old messages from a peer
func GetMessagesHistory(peer *Peer, inAppMsgCount int, lastDbId int, wantMore int, password string) ([]InternalUserMessage, error) {
var messages []InternalUserMessage
// handle no db yet
if len(peer.DbIds) == 0 {
return messages, nil
}
fileidx := len(peer.DbIds) - 1
// initialize count with last db message count
countStack, err := getMessageCount(peer.DbIds[fileidx])