Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Commit

Permalink
fix(adapter): replace single quote with double quote in @mention, bet…
Browse files Browse the repository at this point in the history
…ter handle datafeed errors

<mention email='[email protected]'/> generates a http 500 error while <mention email="[email protected]"/> does not
datafeed/x/read alternately returns http 400 after 204 (raised with Symphony)
  • Loading branch information
jonfreedman committed Aug 2, 2016
1 parent 82c6045 commit 7c2b358
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 17 additions & 9 deletions src/adapter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SymphonyAdapter extends Adapter
reply: (envelope, strings...) ->
@robot.logger.debug "Reply"
for string in strings
@symphony.sendMessage(envelope.room, "<messageML><mention email='#{envelope.user.emailAddress}'/> #{string}</messageML>", 'MESSAGEML')
@symphony.sendMessage(envelope.room, "<messageML><mention email=\"#{envelope.user.emailAddress}\"/> #{string}</messageML>", 'MESSAGEML')

run: =>
@robot.logger.info "Initialising..."
Expand All @@ -53,30 +53,38 @@ class SymphonyAdapter extends Adapter
@robot.emit 'error', new Error("Unable to resolve identity: #{err}")
hourlyRefresh = memoize @symphony.getUser, {maxAge: 3600000, length: 1}
@userLookup = (userId) => hourlyRefresh userId
@symphony.createDatafeed()
@_createDatafeed()
.then (response) =>
@robot.logger.info "Created datafeed: #{response.id}"
this.on 'poll', @_pollDatafeed
@emit 'connected'
@robot.logger.debug "'connected' event emitted"
@emit 'poll', response.id
@robot.logger.debug "First 'poll' event emitted"
.fail (err) =>
@robot.emit 'error', new Error("Unable to create datafeed: #{err}")
return

close: =>
@robot.logger.debug 'Removing datafeed poller'
this.removeListener 'poll', @_pollDatafeed

_createDatafeed: =>
@symphony.createDatafeed()
.then (response) =>
if response.id?
@robot.logger.info "Created datafeed: #{response.id}"
this.removeAllListeners 'poll'
this.on 'poll', @_pollDatafeed
@emit 'poll', response.id
@robot.logger.debug "First 'poll' event emitted"
else
@robot.emit 'error', new Error("Unable to create datafeed: #{response}")
.fail (err) =>
@robot.emit 'error', new Error("Unable to create datafeed: #{err}")

_pollDatafeed: (id) =>
# defer execution to ensure we don't go into an infinite polling loop
process.nextTick =>
@robot.logger.debug "Polling datafeed #{id}"
@symphony.readDatafeed(id)
.then (response) =>
if response?
@robot.logger.debug "Received #{response.length} datafeed messages"
@robot.logger.debug "Received #{response.length ? 0} datafeed messages"
@_receiveMessage msg for msg in response when msg.v2messageType = 'V2Message'
@emit 'poll', id
.fail (err) =>
Expand Down
2 changes: 1 addition & 1 deletion test/adapter-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ describe 'Adapter test suite', () ->
adapter.reply(envelope, 'foo bar baz')
adapter.close()
nock.on 'received', () ->
assert.isAtLeast((m for m in nock.messages when m.message is "<messageML><mention email='[email protected]'/> foo bar baz</messageML>").length, 1)
assert.isAtLeast((m for m in nock.messages when m.message is "<messageML><mention email=\"[email protected]\"/> foo bar baz</messageML>").length, 1)
done()
adapter.run()

0 comments on commit 7c2b358

Please sign in to comment.