Skip to content

Instantly share code, notes, and snippets.

@akahn
Forked from tmm1/README.md
Created February 10, 2011 17:25
Show Gist options
  • Save akahn/820926 to your computer and use it in GitHub Desktop.
Save akahn/820926 to your computer and use it in GitHub Desktop.
Embed gravatars in Propane chat
#!/bin/bash
cd /Applications/Propane.app/Contents/Resources
cp enhancer.js enhancer.original.js
curl -O https://gist.github.com/raw/820926/3716e769dfbbce1073f4fd1a18cefadf6e7d3f75/propane-gravatars.diff
patch < propane-gravatars.diff
say 'All done. Please restart Propane.'
--- /Applications/Propane.app/Contents/Resources/enhancer.js
+++ /Applications/Propane.app/Contents/Resources/enhancer.js
@@ -58,9 +58,29 @@ if (window.propane) {
Campfire.PropaneResponder = Class.create({
initialize: function(chat) {
+ var self = this
this.chat = chat;
+
+ chat.transcript.element.childElements().each(function(elem){
+ var msg = new Campfire.Message(chat, elem)
+ self.addGravatar(msg)
+ })
+
+ this.chat.layoutmanager.layout();
+ this.chat.windowmanager.scrollToBottom();
},
-
+ addGravatar: function(message) {
+ if (message.actsLikeTextMessage()) {
+ var author = message.authorElement();
+
+ if (author.visible()) {
+ author.insert({after: '<img alt="'+message.author()+'" width="24" height="24" align="top" style="margin-left: 5px; border-radius:3px" src="http://paperless-campfire-gravatar.heroku.com/?user_id='+this.authorID(message)+'">'});
+ author.hide()
+ message.bodyCell.insert({top: '<strong>' + message.author() + '</strong>'})
+ }
+ }
+ },
+
authorID: function(message) {
if (Element.hasClassName(message.element, 'you'))
return this.chat.userID;
@@ -116,6 +136,11 @@ if (window.propane) {
}
window.propane.messageInserted(message.id(), this.authorID(message), authorText, message.kind, body);
+
+ this.addGravatar(message);
+
+ if (this.chat.scrollToBottom)
+ this.chat.windowmanager.scrollToBottom();
}
},
hideEnterLeave: function() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment