Refactor GetMessagesHistory and LoadLastMessages functions to use slice of InternalUserMessage instead of pointer to InternalUserMessage.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc 2024-02-20 20:30:55 +01:00
parent defafcf996
commit 9dcb579d93
2 changed files with 5 additions and 5 deletions

View File

@ -123,8 +123,8 @@ 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
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])
@ -162,7 +162,7 @@ func GetMessagesHistory(peer *Peer, inAppMsgCount int, lastDbId int, wantMore in
defer rows.Close() defer rows.Close()
for rows.Next() { for rows.Next() {
var ium InternalUserMessage var ium *InternalUserMessage
var um meowlib.UserMessage var um meowlib.UserMessage
var id int64 var id int64
var m []byte var m []byte
@ -182,7 +182,7 @@ func GetMessagesHistory(peer *Peer, inAppMsgCount int, lastDbId int, wantMore in
ium = InternalUserMessageFromUserMessage(peer, &um) ium = InternalUserMessageFromUserMessage(peer, &um)
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

View File

@ -288,7 +288,7 @@ func (p *Peer) UpdateMessage(msg InternalUserMessage) error {
return nil return nil
} }
func (p *Peer) LoadLastMessages(alreadyLoadedCount int, oldestMessageId int, qty int) ([]*InternalUserMessage, error) { func (p *Peer) LoadLastMessages(alreadyLoadedCount int, oldestMessageId int, qty int) ([]InternalUserMessage, error) {
return GetMessagesHistory(p, alreadyLoadedCount, oldestMessageId, 1, p.GetDbPassword()) return GetMessagesHistory(p, alreadyLoadedCount, oldestMessageId, 1, p.GetDbPassword())
} }