Skip to content

Commit

Permalink
Refactor getRoomInfoFromIdOrName
Browse files Browse the repository at this point in the history
Return nothing if not using flowdock adapter
Use find instead of filter
Rename param for consistency with other methods
Add docstring
  • Loading branch information
kb0rg committed Jul 4, 2019
1 parent 43c281b commit 3ef9ad1
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions lib/flowdock-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,30 @@ function getRoomNameFromId(robot, roomId) {
}
}

function getRoomInfoFromIdOrName(robot, flowIdOrName) {
function getRoomInfoFromIdOrName(robot, roomIdOrName) {
// Returns a flow object with all available information about a given flow
// or null
// The response object is equivalent to a successful response from a GET call
// to either of the following endpoints in the flowdock api:
// `/flows/:organization/:flow` (get flow by name)
// `/flows/find?id=:id` (get flow by ID)
// This allows us to bypass the API, and offers more detailed information
// than the adapter provides with its `findFlow` (which only returns id)
// or its `flowFromParams` (which only looks up by id)
// This also allows us to return a reasonable default if not using flowdock
// For full reponse object details see:
// https://www.flowdock.com/api/flows

if (!robot.adapter.flows) {
return []
return
}
let joinedFlowObjects = robot.adapter.joinedFlows()
let flowData = joinedFlowObjects.filter(flow => {
if (flow.id === flowIdOrName || flow.name === flowIdOrName.toLowerCase()) {
return true
} else {
return false
}
return joinedFlowObjects.find(flow => {
return (
flow.id === roomIdOrName ||
flow.name.toLowerCase() === roomIdOrName.toLowerCase()
)
})
// there should only be one...
return flowData[0]
}

function getJoinedFlowIds(robot) {
Expand Down

0 comments on commit 3ef9ad1

Please sign in to comment.