handle no db yet in message retrieve
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
f40f6520d2
commit
0a70206b11
@ -90,6 +90,10 @@ func StoreMessage(peer *Peer, usermessage *meowlib.UserMessage, filenames []stri
|
|||||||
// Get new messages from a peer
|
// Get new messages from a peer
|
||||||
func GetNewMessages(peer *Peer, lastDbId int, password string) ([]*InternalUserMessage, error) {
|
func GetNewMessages(peer *Peer, lastDbId int, password string) ([]*InternalUserMessage, error) {
|
||||||
var messages []*InternalUserMessage
|
var messages []*InternalUserMessage
|
||||||
|
// handle no db yet
|
||||||
|
if len(peer.DbIds) == 0 {
|
||||||
|
return messages, nil
|
||||||
|
}
|
||||||
fileidx := len(peer.DbIds) - 1
|
fileidx := len(peer.DbIds) - 1
|
||||||
// There fileidx should provide the db that we need (unless wantMore overlaps the next DB)
|
// 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
|
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
|
// Get old messages from a peer
|
||||||
func GetMessagesHistory(peer *Peer, inAppMsgCount int, lastDbId int, wantMore int, password string) ([]InternalUserMessage, error) {
|
func GetMessagesHistory(peer *Peer, inAppMsgCount int, lastDbId int, wantMore int, password string) ([]InternalUserMessage, error) {
|
||||||
var messages []InternalUserMessage
|
var messages []InternalUserMessage
|
||||||
|
// handle no db yet
|
||||||
|
if len(peer.DbIds) == 0 {
|
||||||
|
return messages, nil
|
||||||
|
}
|
||||||
fileidx := len(peer.DbIds) - 1
|
fileidx := len(peer.DbIds) - 1
|
||||||
// initialize count with last db message count
|
// initialize count with last db message count
|
||||||
countStack, err := getMessageCount(peer.DbIds[fileidx])
|
countStack, err := getMessageCount(peer.DbIds[fileidx])
|
||||||
|
@ -42,6 +42,12 @@ func TestStoreMessage(t *testing.T) {
|
|||||||
|
|
||||||
func TestManyStoreMessage(t *testing.T) {
|
func TestManyStoreMessage(t *testing.T) {
|
||||||
id := createId()
|
id := createId()
|
||||||
|
// test with zero messages
|
||||||
|
messages, err := GetMessagesHistory(id.Peers[0], 0, 0, 10, GetConfig().memoryPassword)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, len(messages), 0, "not 0 message")
|
||||||
for i := 1; i < 100; i++ {
|
for i := 1; i < 100; i++ {
|
||||||
var um meowlib.UserMessage
|
var um meowlib.UserMessage
|
||||||
um.Data = []byte(randomLenString(20, 200))
|
um.Data = []byte(randomLenString(20, 200))
|
||||||
@ -50,7 +56,7 @@ func TestManyStoreMessage(t *testing.T) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
messages, err := GetMessagesHistory(id.Peers[0], 0, 0, 10, GetConfig().memoryPassword)
|
messages, err = GetMessagesHistory(id.Peers[0], 0, 0, 10, GetConfig().memoryPassword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user