Skip to content
Snippets Groups Projects
Commit b9013bef authored by Bernardo Cardoso's avatar Bernardo Cardoso
Browse files

Add some missing useful functions in API and bindings

parent 589f1b88
No related branches found
No related tags found
No related merge requests found
...@@ -222,6 +222,10 @@ func (cl *Client) GetSwitchboard() *switchboard.Switchboard { ...@@ -222,6 +222,10 @@ func (cl *Client) GetSwitchboard() *switchboard.Switchboard {
return cl.sess.GetSwitchboard() return cl.sess.GetSwitchboard()
} }
func (cl *Client) GetCurrentUser() *id.User {
return cl.sess.GetCurrentUser().User
}
// Logout closes the connection to the server at this time and does // Logout closes the connection to the server at this time and does
// nothing with the user id. In the future this will release resources // nothing with the user id. In the future this will release resources
// and safely release any sensitive memory. // and safely release any sensitive memory.
......
...@@ -181,7 +181,7 @@ func TestSend(t *testing.T) { ...@@ -181,7 +181,7 @@ func TestSend(t *testing.T) {
// Test send with valid inputs // Test send with valid inputs
err = client.Send(APIMessage{SenderID: userID, Payload: []byte("test"), err = client.Send(APIMessage{SenderID: userID, Payload: []byte("test"),
RecipientID: userID}) RecipientID: client.GetCurrentUser()})
if err != nil { if err != nil {
t.Errorf("Error sending message: %v", err) t.Errorf("Error sending message: %v", err)
} }
......
...@@ -83,6 +83,14 @@ func (cl *Client) StopListening(listenerHandle string) { ...@@ -83,6 +83,14 @@ func (cl *Client) StopListening(listenerHandle string) {
cl.client.StopListening(listenerHandle) cl.client.StopListening(listenerHandle)
} }
func (cl *Client) GetSwitchboard() *switchboard.Switchboard {
return cl.client.GetSwitchboard()
}
func (cl *Client) GetCurrentUser() *id.User {
return cl.client.GetCurrentUser()
}
func FormatTextMessage(message string) []byte { func FormatTextMessage(message string) []byte {
return api.FormatTextMessage(message) return api.FormatTextMessage(message)
} }
......
...@@ -212,13 +212,13 @@ func TestListen(t *testing.T) { ...@@ -212,13 +212,13 @@ func TestListen(t *testing.T) {
client.Login(regRes, gwAddress, "") client.Login(regRes, gwAddress, "")
listener := MockListener(false) listener := MockListener(false)
client.Listen(id.ZeroID[:], int32(cmixproto.Type_NO_TYPE), &listener) client.Listen(id.ZeroID[:], int32(cmixproto.Type_NO_TYPE), &listener)
client.client.GetSwitchboard().Speak(&parse.Message{ client.GetSwitchboard().Speak(&parse.Message{
TypedBody: parse.TypedBody{ TypedBody: parse.TypedBody{
MessageType: 0, MessageType: 0,
Body: []byte("stuff"), Body: []byte("stuff"),
}, },
Sender: id.ZeroID, Sender: id.ZeroID,
Receiver: id.ZeroID, Receiver: client.GetCurrentUser(),
}) })
if !listener { if !listener {
t.Error("Message not received") t.Error("Message not received")
...@@ -259,7 +259,7 @@ func TestStopListening(t *testing.T) { ...@@ -259,7 +259,7 @@ func TestStopListening(t *testing.T) {
listener := MockListener(false) listener := MockListener(false)
handle := client.Listen(id.ZeroID[:], int32(cmixproto.Type_NO_TYPE), &listener) handle := client.Listen(id.ZeroID[:], int32(cmixproto.Type_NO_TYPE), &listener)
client.StopListening(handle) client.StopListening(handle)
client.client.GetSwitchboard().Speak(&parse.Message{ client.GetSwitchboard().Speak(&parse.Message{
TypedBody: parse.TypedBody{ TypedBody: parse.TypedBody{
MessageType: 0, MessageType: 0,
Body: []byte("stuff"), Body: []byte("stuff"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment