Skip to content

Commit

Permalink
Merge pull request #231 from Crim/master
Browse files Browse the repository at this point in the history
Adds support in the adapter for topic change events.
  • Loading branch information
rbergman committed Apr 20, 2015
2 parents 44f8f71 + c581faf commit 219cdc0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/connector.coffee
Expand Up @@ -336,6 +336,11 @@ module.exports = class Connector extends EventEmitter
# - `callback`: Function to be triggered: `function (fromJid, message)`
onPrivateMessage: onMessageFor "privateMessage"

# Emitted whenever the connector receives a topic change in a room
#
# - `callback`: Function to be triggered: `function ()`
onTopic: (callback) -> @on "topic", callback

onEnter: (callback) -> @on "enter", callback

onLeave: (callback) -> @on "leave", callback
Expand Down Expand Up @@ -419,16 +424,26 @@ onStanza = (stanza) ->

if stanza.is "message"
if stanza.attrs.type is "groupchat"
body = stanza.getChildText "body"
return if not body
# Ignore chat history

return if stanza.getChild "delay"
fromJid = new xmpp.JID stanza.attrs.from
fromChannel = fromJid.bare().toString()
fromNick = fromJid.resource
# Ignore our own messages
return if fromNick is @name
@emit "message", fromChannel, fromNick, body
# Look for body msg
body = stanza.getChildText "body"
# look for Subject: http://xmpp.org/extensions/xep-0045.html#subject-mod
subject = stanza.getChildText "subject"
if body
# message stanza
@emit "message", fromChannel, fromNick, body
else if subject
# subject stanza
@emit "topic", fromChannel, fromNick, subject
else
# Skip parsing other types and return
return

else if stanza.attrs.type is "chat"
# Message without body is probably a typing notification
Expand Down
9 changes: 8 additions & 1 deletion src/hipchat.coffee
@@ -1,4 +1,4 @@
{Adapter, TextMessage, EnterMessage, LeaveMessage, User} = require "../../hubot"
{Adapter, TextMessage, EnterMessage, LeaveMessage, TopicMessage, User} = require "../../hubot"
HTTPS = require "https"
{inspect} = require "util"
Connector = require "./connector"
Expand Down Expand Up @@ -93,6 +93,13 @@ class HipChat extends Adapter

init = promise()

connector.onTopic (channel, from, message) =>
@logger.info "Topic change: " + message
author = getAuthor: => @robot.brain.userForName(from) or new User(from)
author.room = @roomNameFromJid(channel)
@receive new TopicMessage(author, message, 'id')


connector.onDisconnect =>
@logger.info "Disconnected from #{host}"

Expand Down

0 comments on commit 219cdc0

Please sign in to comment.