Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore empty XMPP messages #69

Merged
merged 1 commit into from
Aug 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Emulsion.Tests/Xmpp/SharpXmppHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,18 @@ let ``isHistoricalMessage returns false for an ordinary message``() =
let ``isHistoricalMessage returns true for a message with delay``() =
let message = XmppMessageFactory.create(delayDate = "2010-01-01")
Assert.True(SharpXmppHelper.isHistoricalMessage message)

[<Fact>]
let ``Message without body is considered as empty``(): unit =
let message = XmppMessageFactory.create()
Assert.True(SharpXmppHelper.isEmptyMessage message)

[<Fact>]
let ``Message consisting of whitespace is considered as empty``(): unit =
let message = XmppMessageFactory.create(text = " \t ")
Assert.True(SharpXmppHelper.isEmptyMessage message)

[<Fact>]
let ``Message with text is not considered as empty``(): unit =
let message = XmppMessageFactory.create(text = " t ")
Assert.False(SharpXmppHelper.isEmptyMessage message)
4 changes: 4 additions & 0 deletions Emulsion/Xmpp/SharpXmppHelper.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Emulsion.Xmpp.SharpXmppHelper

open System
open System.Xml.Linq

open SharpXMPP
Expand Down Expand Up @@ -61,6 +62,9 @@ let isHistoricalMessage (message : XMPPMessage) : bool =
|> Seq.isEmpty
)

let isEmptyMessage(message: XMPPMessage): bool =
String.IsNullOrWhiteSpace message.Text

let parseMessage (message: XMPPMessage): Message =
let nickname =
getAttributeValue message From
Expand Down
1 change: 1 addition & 0 deletions Emulsion/Xmpp/XmppClient.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let private signedInHandler (logger: ILogger) (settings: XmppSettings) (client:
let private shouldSkipMessage settings message =
SharpXmppHelper.isOwnMessage (settings.Nickname) message
|| SharpXmppHelper.isHistoricalMessage message
|| SharpXmppHelper.isEmptyMessage message

let private messageHandler (logger: ILogger) settings onMessage = XmppConnection.MessageHandler(fun _ element ->
logger.Verbose("Incoming XMPP message: {Message}", element)
Expand Down