From 6867086c4fa77281755f2a3a508eb706efba0222 Mon Sep 17 00:00:00 2001 From: ycc Date: Mon, 25 Mar 2024 13:24:43 +0100 Subject: [PATCH] Http helper function added --- client/helpers/networkHelper.go | 30 ++++++++++++++++++++++++++++++ doc/sq_srvinv03.puml | 2 +- doc/sq_srvinv04.puml | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 client/helpers/networkHelper.go diff --git a/client/helpers/networkHelper.go b/client/helpers/networkHelper.go new file mode 100644 index 0000000..ab28b87 --- /dev/null +++ b/client/helpers/networkHelper.go @@ -0,0 +1,30 @@ +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 +} diff --git a/doc/sq_srvinv03.puml b/doc/sq_srvinv03.puml index 90b0594..fd49b46 100644 --- a/doc/sq_srvinv03.puml +++ b/doc/sq_srvinv03.puml @@ -8,5 +8,5 @@ NativeLib -> Bastet : invitationGetMessage Bastet -> Server : send accept message Server -> Redis : store accept message Server -> Bastet : accept message ok -Bastet -> User : msg sent +Bastet -> User : accept msg sent @enduml \ No newline at end of file diff --git a/doc/sq_srvinv04.puml b/doc/sq_srvinv04.puml index 460cbed..c84ea0a 100644 --- a/doc/sq_srvinv04.puml +++ b/doc/sq_srvinv04.puml @@ -5,5 +5,5 @@ NativeLib -> Server : get new messages Server -> NativeLib : send invitation message Server -> Redis : store accept message Server -> Bastet : accept message ok -Bastet -> User : msg sent +Bastet -> User : invitation sent is accepted @enduml \ No newline at end of file