31 lines
696 B
Go
31 lines
696 B
Go
package helpers
|
|
|
|
import (
|
|
"forge.redroom.link/yves/meowlib"
|
|
"forge.redroom.link/yves/meowlib/client"
|
|
)
|
|
|
|
func HttpSendMessage(serverUid string, message []byte) ([]byte, error) {
|
|
id := client.GetConfig().GetIdentity()
|
|
srv, err := id.MessageServers.LoadServer(serverUid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
// gettig server Public key if missing
|
|
if srv.PublicKey == "" {
|
|
srvdata, err := meowlib.HttpGetId(srv.Url)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
//print(srvdata["publicKey"])
|
|
srv.PublicKey = srvdata["publicKey"]
|
|
id.MessageServers.StoreServer(srv)
|
|
}
|
|
|
|
response, err := meowlib.HttpPostMessage(srv.Url, message)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return response, nil
|
|
}
|