Permalink
Browse files

Show twitter avatars in message log.

  • Loading branch information...
1 parent 12e55ce commit b117ba48c7a6c827b931013c881ff44a4ee5e7c7 @toolness committed Jul 4, 2012
Showing with 47 additions and 22 deletions.
  1. +10 −0 static/index.html
  2. +9 −2 static/log-area.js
  3. +5 −2 static/main.js
  4. +23 −18 static/twitter.js
View
@@ -93,6 +93,16 @@
width: 85%;
}
+#messages .log.message .content .twitter-user {
+ float: left;
+ padding-right: 4px;
+}
+
+#messages .log.message .content .twitter-user img {
+ width: 32px;
+ height: 32px;
+}
+
#messages .log.message time {
text-align: right;
display: inline-block;
View
@@ -17,6 +17,7 @@ define([
return function LogArea(options) {
var messages = $(options.element);
+ var twitterUsers = options.twitterUsers;
var scrollToTimeout;
function addToLog(element, forceScroll) {
@@ -86,10 +87,16 @@ define([
timestamp: timestamp.toString(),
prettyTime: prettyDate(timestamp)
}).trim();
+ html = $(html);
+
+ var avatar = twitterUsers.getAvatarElement(options.nick);
+ if (avatar)
+ $(".content", html).prepend(avatar);
+
if (options.where)
- $(html).appendTo(options.where)
+ html.appendTo(options.where)
else
- addToLog($(html), options.forceScroll);
+ addToLog(html, options.forceScroll);
},
log: function log(type, msg) {
if (msg === undefined) {
View
@@ -59,11 +59,14 @@ define([
function start() {
var login = new Login();
var loginInfo = login.get();
- var logArea = new LogArea({element: $("#messages")});
- var log = logArea.log;
var irc = new IRC();
var userListView = new UserListView(irc.users, $("#users"));
var twitterUsers = new twitter.TwitterUsers(irc);
+ var logArea = new LogArea({
+ element: $("#messages"),
+ twitterUsers: twitterUsers
+ });
+ var log = logArea.log;
var twitterViewMixIn = new twitter.TwitterViewMixIn(userListView,
twitterUsers);
var cmdLine = new CommandLine($("#cmd"), irc, logArea, login,
View
@@ -35,6 +35,26 @@ define([
delete this.users[nick];
this.irc.setCustomGlobalMetadata(this.PREFIX + nick, twitterUser);
this.emit('change');
+ },
+ getAvatarElement: function(nick) {
+ for (var baseNick in this.users) {
+ if (misc.doesNickMatch(baseNick, nick)) {
+ var twitterName = this.users[baseNick];
+
+ if (!twitterName)
+ return null;
+
+ var a = $('<a class="twitter-user" target="_blank"></a>')
+ .attr('href', PROFILE_URL + twitterName)
+ .attr('title', nick + ' is @' + twitterName + ' on Twitter.');
+ var img = $('<img>')
+ .attr('alt', 'Twitter avatar for ' + twitterName)
+ .attr('src', AVATAR_IMG + twitterName)
+ .appendTo(a);
+ return a;
+ }
+ }
+ return null;
}
};
@@ -44,24 +64,9 @@ define([
TwitterUsers: TwitterUsers,
TwitterViewMixIn: function(userListView, twitterUsers) {
function insertTwitterInfo(nick) {
- for (var baseNick in twitterUsers.users) {
- if (misc.doesNickMatch(baseNick, nick)) {
- var twitterName = twitterUsers.users[baseNick];
-
- if (!twitterName)
- return;
-
- var a = $('<a class="twitter-user" target="_blank"></a>')
- .attr('href', PROFILE_URL + twitterName)
- .attr('title', nick + ' is @' + twitterName + ' on Twitter.');
- var img = $('<img>')
- .attr('alt', 'Twitter avator for ' + twitterName)
- .attr('src', AVATAR_IMG + twitterName)
- .appendTo(a);
- userListView.getElementForNick(nick).prepend(a);
- return;
- }
- }
+ var a = twitterUsers.getAvatarElement(nick);
+ if (a)
+ userListView.getElementForNick(nick).prepend(a);
}
userListView.users.on('add', insertTwitterInfo);

0 comments on commit b117ba4

Please sign in to comment.