liftopia/jarvis — pull request #29 by amdtech (2014-04-18 17:33:00+00:00)
Title: Switch to alternative adapter to fix mentions

The current hipchat adapter appears to have trouble picking up the mentions and saving new users correctly. Someone already did the work, so here it is :smile:

Here's the differences (https://github.com/negativetwelve/hubot-hipchat/compare/hipchat:master...master):
```diff
diff --git a/src/connector.coffee b/src/connector.coffee
index d8c51c5..6fb5254 100644
--- a/src/connector.coffee
+++ b/src/connector.coffee
@@ -476,6 +476,7 @@ onStanza = (stanza) ->
return if not from
if type is "unavailable"
@emit "leave", from, room, name
+ # @emit "leave", from, name, room
else if type is "available" and entity.attrs.role is "participant"
@emit "enter", from, room, name

diff --git a/src/hipchat.coffee b/src/hipchat.coffee
index e4b1890..18b8c4b 100644
--- a/src/hipchat.coffee
+++ b/src/hipchat.coffee
@@ -88,12 +88,19 @@ class HipChat extends Adapter

saveUsers = (users) =>
# Save users to brain
+ console.log("save users")
+ @logger.info users
for user in users
user.id = @userIdFromJid user.jid
# userForId will not overwrite an existing user
- if user.id of @robot.brain.data.users
+ if user.id in @robot.brain.data.users
delete @robot.brain.data.users[user.id]
@robot.brain.userForId user.id, user
+ @robot.brain.data.users[user.id]['mention_name'] = user.mention_name
+ @robot.brain.emit('save', @robot.brain.data)
+ @logger.info "After setting the users..."
+ @logger.info @robot.brain.data.users
+

# Fetch user info
connector.getRoster (err, users, stanza) =>
@@ -121,6 +128,7 @@ class HipChat extends Adapter
@logger.error "Can't list users: #{errmsg err}" if err

connector.onRosterChange (users) =>
+ console.log("Roster has changed")
saveUsers(users)

handleMessage = (opts) =>
@@ -156,19 +164,18 @@ class HipChat extends Adapter
message: message
reply_to: from

- changePresence = (PresenceMessage, user_jid, room_jid, currentName) =>
+ changePresence = (PresenceMessage, user_jid, room_jid, current_name) =>
# buffer presence events until the roster fetch completes
# to ensure user data is properly loaded
init.done =>
user = @robot.brain.userForId(@userIdFromJid(user_jid)) or {}
if user
user.room = room_jid
- # If an updated name was sent as part of a presence, update it now
- user.name = currentName if currentName.length
+ user.name = current_name if current_name.length
@receive new PresenceMessage(user)

- connector.onEnter (user_jid, room_jid, currentName) =>
- changePresence EnterMessage, user_jid, room_jid, currentName
+ connector.onEnter (user_jid, room_jid, current_name) =>
+ changePresence EnterMessage, user_jid, room_jid, current_name

connector.onLeave (user_jid, room_jid) ->
changePresence LeaveMessage, user_jid, room_jid```