2024-03-23 20:09:14 +01:00
|
|
|
package helpers
|
|
|
|
|
|
|
|
import "forge.redroom.link/yves/meowlib/client"
|
|
|
|
|
|
|
|
func PrepareUserMessage(message string, srvuid string, peer_idx int, filelist []string) ([]byte, string, error) {
|
|
|
|
|
|
|
|
peer := client.GetConfig().GetIdentity().Peers[peer_idx]
|
|
|
|
srv, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(srvuid)
|
|
|
|
if err != nil {
|
|
|
|
return nil, "PrepareServerMessage : LoadServer", err
|
|
|
|
}
|
|
|
|
// Creating User message
|
|
|
|
usermessage, err := peer.BuildSimpleUserMessage([]byte(message))
|
|
|
|
if err != nil {
|
|
|
|
return nil, "PrepareServerMessage : BuildSimpleUserMessage", err
|
|
|
|
}
|
|
|
|
for _, file := range filelist {
|
|
|
|
err = usermessage.AddFile(file, client.GetConfig().Chunksize)
|
|
|
|
if err != nil {
|
|
|
|
return nil, "PrepareServerMessage : AddFile", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Prepare cyphered + packed user message
|
|
|
|
packedMsg, err := peer.ProcessOutboundUserMessage(usermessage)
|
|
|
|
if err != nil {
|
|
|
|
return nil, "PrepareServerMessage : ProcessOutboundUserMessage", err
|
|
|
|
}
|
|
|
|
// Creating Server message for transporting the user message
|
|
|
|
toServerMessage := srv.BuildToServerMessageFromUserMessage(packedMsg)
|
|
|
|
data, err := srv.ProcessOutboundMessage(toServerMessage)
|
|
|
|
if err != nil {
|
|
|
|
return nil, "PrepareServerMessage : ProcessOutboundMessage", err
|
|
|
|
}
|
2024-04-06 10:13:25 +02:00
|
|
|
// Store message
|
|
|
|
err = peer.StoreMessage(usermessage, filelist)
|
|
|
|
if err != nil {
|
|
|
|
return nil, "PrepareServerMessage : StoreMessage", err
|
|
|
|
}
|
2024-03-23 20:09:14 +01:00
|
|
|
return data, "", nil
|
|
|
|
}
|