diff --git a/Emulsion.Tests/Xmpp/EmulsionXmppTests.fs b/Emulsion.Tests/Xmpp/EmulsionXmppTests.fs index ac263001..ae798154 100644 --- a/Emulsion.Tests/Xmpp/EmulsionXmppTests.fs +++ b/Emulsion.Tests/Xmpp/EmulsionXmppTests.fs @@ -153,7 +153,7 @@ type SendTests(outputHelper: ITestOutputHelper) = let client = XmppClientFactory.create( addMessageHandler = (fun _ h -> messageHandlers.Add h), - send = fun m -> messageId.SetResult(SharpXmppHelper.getMessageId m) + send = fun m -> messageId.SetResult(Option.get <| SharpXmppHelper.getMessageId m) ) let outgoingMessage = { author = "author"; text = "text" } diff --git a/Emulsion.Tests/Xmpp/SharpXmppHelperTests.fs b/Emulsion.Tests/Xmpp/SharpXmppHelperTests.fs index 68e6189e..75fcf1ef 100644 --- a/Emulsion.Tests/Xmpp/SharpXmppHelperTests.fs +++ b/Emulsion.Tests/Xmpp/SharpXmppHelperTests.fs @@ -10,7 +10,7 @@ open Emulsion.Xmpp [] let ``Message body has a proper namespace``() = - let message = SharpXmppHelper.message None "cthulhu@test" "text" + let message = SharpXmppHelper.message "" "cthulhu@test" "text" let body = Seq.exactlyOne(message.Descendants()) Assert.Equal(XNamespace.Get "jabber:client", body.Name.Namespace) diff --git a/Emulsion.Tests/Xmpp/XmppClientTests.fs b/Emulsion.Tests/Xmpp/XmppClientTests.fs index d9147160..87d89632 100644 --- a/Emulsion.Tests/Xmpp/XmppClientTests.fs +++ b/Emulsion.Tests/Xmpp/XmppClientTests.fs @@ -184,7 +184,7 @@ let ``sendRoomMessage's result doesn't get resolved after receiving other messag let deliveryTask = Async.StartAsTask deliveryInfo.Delivery Assert.False deliveryTask.IsCompleted - let otherMessage = SharpXmppHelper.message (Some "xxx") "nickname@example.org" "foo bar" + let otherMessage = SharpXmppHelper.message "xxx" "nickname@example.org" "foo bar" messageHandler otherMessage Assert.False deliveryTask.IsCompleted ) diff --git a/Emulsion/Xmpp/SharpXmppHelper.fs b/Emulsion/Xmpp/SharpXmppHelper.fs index 450fe82c..bcd3e7ea 100644 --- a/Emulsion/Xmpp/SharpXmppHelper.fs +++ b/Emulsion/Xmpp/SharpXmppHelper.fs @@ -47,10 +47,9 @@ let joinRoom (client: XmppClient) (roomJid: string) (nickname: string): unit = let room = bookmark roomJid nickname client.BookmarkManager.Join(room) -let message (id: string option) (toAddr: string) (text: string): XMPPMessage = - // TODO[F]: Make id a mandatory parameter? +let message (id: string) (toAddr: string) (text: string): XMPPMessage = let m = XMPPMessage() - id |> Option.iter (fun id -> m.SetAttributeValue(Id, id)) + m.SetAttributeValue(Id, id) m.SetAttributeValue(Type, "groupchat") m.SetAttributeValue(To, toAddr) let body = XElement(Body) diff --git a/Emulsion/Xmpp/XmppClient.fs b/Emulsion/Xmpp/XmppClient.fs index eedb3a80..baacffbb 100644 --- a/Emulsion/Xmpp/XmppClient.fs +++ b/Emulsion/Xmpp/XmppClient.fs @@ -116,11 +116,14 @@ let private awaitMessageReceival (client: IXmppClient) (lifetime: Lifetime) mess messageLifetimeDefinition.Dispose() } +let private newMessageId(): string = + Guid.NewGuid().ToString() + /// Sends the message to the room. Returns an object that allows to track the message receival. let sendRoomMessage (client: IXmppClient) (lifetime: Lifetime) (messageInfo: MessageInfo): Async = async { - let messageId = Guid.NewGuid().ToString() // TODO[F]: Move to a new function - let message = SharpXmppHelper.message (Some messageId) messageInfo.RecipientJid.FullJid messageInfo.Text + let messageId = newMessageId() + let message = SharpXmppHelper.message messageId messageInfo.RecipientJid.FullJid messageInfo.Text let! delivery = Async.StartChild <| awaitMessageReceival client lifetime messageId client.Send message return {