This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@@ -26,29 +27,25 @@ func PackMessageForServer(packedMsg *meowlib.PackedUserMessage, srvuid string) (
|
||||
}
|
||||
|
||||
func CreateStorePackUserMessageForServer(message string, srvuid string, peer_uid string, replyToUid string, filelist []string) ([]byte, string, error) {
|
||||
usermessage, _, _, errtxt, err := CreateAndStoreUserMessage(message, peer_uid, replyToUid, filelist)
|
||||
usermessage, errtxt, err := CreateAndStoreUserMessage(message, peer_uid, replyToUid, filelist)
|
||||
if err != nil {
|
||||
return nil, errtxt, err
|
||||
}
|
||||
return PackMessageForServer(usermessage, srvuid)
|
||||
}
|
||||
|
||||
// CreateAndStoreUserMessage creates, stores and packs a user message.
|
||||
// It returns the packed message, the message DB file UUID, the SQLite row ID,
|
||||
// an error location string, and the error. The caller should set MessageDbFile
|
||||
// and MessageDbId on the SendJob from the returned dbFile and dbId values.
|
||||
func CreateAndStoreUserMessage(message string, peer_uid string, replyToUid string, filelist []string) (packedMsg *meowlib.PackedUserMessage, dbFile string, dbId int64, errTxt string, err error) {
|
||||
func CreateAndStoreUserMessage(message string, peer_uid string, replyToUid string, filelist []string) (*meowlib.PackedUserMessage, string, error) {
|
||||
peer := client.GetConfig().GetIdentity().Peers.GetFromUid(peer_uid)
|
||||
|
||||
// Creating User message
|
||||
usermessage, err := peer.BuildSimpleUserMessage([]byte(message))
|
||||
if err != nil {
|
||||
return nil, "", 0, "PrepareServerMessage : BuildSimpleUserMessage", err
|
||||
return nil, "PrepareServerMessage : BuildSimpleUserMessage", err
|
||||
}
|
||||
for _, file := range filelist {
|
||||
err = usermessage.AddFile(file, client.GetConfig().Chunksize)
|
||||
if err != nil {
|
||||
return nil, "", 0, "PrepareServerMessage : AddFile", err
|
||||
return nil, "PrepareServerMessage : AddFile", err
|
||||
}
|
||||
}
|
||||
usermessage.Status.Sent = uint64(time.Now().UTC().Unix())
|
||||
@@ -57,20 +54,16 @@ func CreateAndStoreUserMessage(message string, peer_uid string, replyToUid strin
|
||||
// Store message
|
||||
err = peer.StoreMessage(usermessage, nil)
|
||||
if err != nil {
|
||||
return nil, "", 0, "messageBuildPostprocess : StoreMessage", err
|
||||
return nil, "messageBuildPostprocess : StoreMessage", err
|
||||
}
|
||||
|
||||
// Prepare cyphered + packed user message
|
||||
packedMsg, err = peer.ProcessOutboundUserMessage(usermessage)
|
||||
packedMsg, err := peer.ProcessOutboundUserMessage(usermessage)
|
||||
if err != nil {
|
||||
return nil, "", 0, "messageBuildPostprocess : ProcessOutboundUserMessage", err
|
||||
return nil, "messageBuildPostprocess : ProcessOutboundUserMessage", err
|
||||
}
|
||||
|
||||
if peer.LastMessage != nil {
|
||||
dbFile = peer.LastMessage.Dbfile
|
||||
dbId = peer.LastMessage.Dbid
|
||||
}
|
||||
return packedMsg, dbFile, dbId, "", nil
|
||||
return packedMsg, "", nil
|
||||
}
|
||||
|
||||
func BuildAckMessage(messageUid string, srvuid string, peer_uid string, received int64, processed int64) ([]byte, string, error) {
|
||||
@@ -107,6 +100,20 @@ func ReadAckMessageResponse() {
|
||||
//! update the status in message store
|
||||
}
|
||||
|
||||
// GetPeerLastMessageDbInfo returns the DB location of the most recently stored
|
||||
// message for the given peer. Call this immediately after CreateAndStoreUserMessage
|
||||
// to get the values needed for SendJob.MessageDbFile and SendJob.MessageDbId.
|
||||
func GetPeerLastMessageDbInfo(peer_uid string) (dbFile string, dbId int64, errTxt string, err error) {
|
||||
peer := client.GetConfig().GetIdentity().Peers.GetFromUid(peer_uid)
|
||||
if peer == nil {
|
||||
return "", 0, "GetPeerLastMessageDbInfo: peer not found", errors.New("peer not found")
|
||||
}
|
||||
if peer.LastMessage == nil {
|
||||
return "", 0, "GetPeerLastMessageDbInfo: no message stored yet", errors.New("no message stored yet for this peer")
|
||||
}
|
||||
return peer.LastMessage.Dbfile, peer.LastMessage.Dbid, "", nil
|
||||
}
|
||||
|
||||
// ProcessSentMessages scans every send queue under storagePath/queues/, updates
|
||||
// the message storage entry with server delivery info for each sent job, then
|
||||
// removes the job from the queue. Returns the number of messages updated.
|
||||
|
||||
Reference in New Issue
Block a user